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