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