Annotation of java/classes/org/w3c/jigsaw/servlet/RemoteServletWrapper.java, revision 1.9
1.5 ylafon 1: // RemoteServletWrapper.java
1.9 ! bmahe 2: // $Id: RemoteServletWrapper.java,v 1.8 1998/07/23 16:38:48 bmahe Exp $
1.5 ylafon 3: // (c) COPYRIGHT MIT and INRIA, 1997.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
1.6 bmahe 6: package org.w3c.jigsaw.servlet;
1.1 abaird 7:
1.4 bmahe 8: import javax.servlet.*;
1.1 abaird 9:
1.6 bmahe 10: import org.w3c.tools.resources.store.*;
11: import org.w3c.tools.resources.*;
1.1 abaird 12:
1.2 abaird 13: /**
14: * @author Alexandre Rafalovitch <alex@access.com.au>
15: * @author Anselm Baird-Smith <abaird@w3.org>
16: */
17:
1.1 abaird 18: public class RemoteServletWrapper extends ServletWrapper {
1.8 bmahe 19: private static final boolean debug = false;
1.1 abaird 20:
21: /**
22: * Attribute index - The servlet content base.
23: */
24: protected static int ATTR_SERVLET_BASE = -1;
25:
26: static {
27: Class c = null;
28: Attribute a = null;
29: try {
1.6 bmahe 30: c = Class.forName("org.w3c.jigsaw.servlet.RemoteServletWrapper");
1.1 abaird 31: } catch (Exception ex) {
32: ex.printStackTrace();
33: System.exit(1);
34: }
35: // Register the servlet base URL:
36: a = new StringAttribute("servlet-base"
37: , null
38: , Attribute.EDITABLE|Attribute.MANDATORY);
39: ATTR_SERVLET_BASE = AttributeRegistry.registerAttribute(c, a);
40: }
41: /**
42: * The ServletLoader instance for loading that servlet.
43: */
44: protected ServletLoader loader = null;
45:
1.9 ! bmahe 46: protected void checkServlet()
! 47: throws ClassNotFoundException, ServletException
! 48: {
1.7 bmahe 49: if (! inited)
50: inited = launchServlet();
51: }
52:
1.1 abaird 53: /**
54: * Get or create a suitable ServletLoader instance to load that servlet.
55: * @return A ServletLoader instance.
56: */
57:
58: protected synchronized ServletLoader getServletLoader() {
59: if ( loader == null ) {
60: loader = new ServletLoader(this);
61: }
62: return loader;
63: }
64:
65: /**
66: * Get the remote servlet URL base.
67: * @return The String encoded base URL for that servlet, or <strong>null
68: * </strong> if undefined.
69: */
70:
71: public String getServletBase() {
72: return getString(ATTR_SERVLET_BASE, null);
73: }
74:
75: public void setValue(int idx, Object value) {
1.7 bmahe 76: super.setValueOfSuperClass(idx, value);
1.9 ! bmahe 77: try {
! 78: if ((idx == ATTR_SERVLET_CLASS) && (value != null))
! 79: inited = launchServlet();
! 80: if ((idx == ATTR_SERVLET_BASE) && (value != null))
! 81: inited = launchServlet();
! 82: } catch (Exception ex) {
! 83: String msg = ("unable to set servlet class \""+
! 84: getServletClass()+
! 85: "\" : "+
! 86: ex.getMessage());
! 87: getServer().errlog(msg);
! 88: }
1.1 abaird 89: }
90:
1.9 ! bmahe 91: protected boolean launchServlet()
! 92: throws ClassNotFoundException, ServletException
! 93: {
1.1 abaird 94: if ( debug )
95: System.out.println("Launching servlet: "+getServletClass());
96: // Get and check the servlet class:
97: if ( servlet != null )
98: destroyServlet();
99: // Load appropriate servlet class:
100: Class c = null;
101: try {
102: // Load the servlet class through the loader:
103: c = getServletLoader().loadClass(getServletClass(), true);
104: } catch (ClassFormatError er) {
105: String msg = ("class \""+getServletClass()+"\" loaded from "
106: + getServletBase() + ", invalid format.");
107: if ( debug )
108: er.printStackTrace();
109: getServer().errlog(this, msg);
110: } catch (ClassNotFoundException ex) {
111: String msg = ("class \""+getServletClass()+"\" loaded from "
112: + getServletBase() + ", not found.");
113: if ( debug )
114: ex.printStackTrace();
115: getServer().errlog(this, msg);
116: }
117: return (c != null) ? launchServlet(c) : false;
118: }
119:
120:
121: }
Webmaster