org.w3c.jigsaw.servlet
Class ServletWrapper

java.lang.Object
  |
  +--org.w3c.tools.resources.AttributeHolder
        |
        +--org.w3c.tools.resources.Resource
              |
              +--org.w3c.tools.resources.FramedResource
                    |
                    +--org.w3c.jigsaw.servlet.ServletWrapper
Direct Known Subclasses:
RemoteServletWrapper

public class ServletWrapper
extends org.w3c.tools.resources.FramedResource
implements javax.servlet.ServletConfig


Inner Class Summary
protected  class ServletWrapper.TimeoutManager
           
 
Field Summary
protected static int ATTR_PARAMETERS
          Attribute index - The init parameters for that servlet.
protected static int ATTR_SERVLET_CLASS
          Attributes index - The servlet class name.
protected static int ATTR_SERVLET_CONTEXT
          Attribute index - Our parent-inherited servlet context.
protected static int ATTR_SERVLET_TIMEOUT
          Attributes index - The servlet timeout
protected static int ATTR_SESSION_CONTEXT
          Attribute index - Our parent-inherited session context.
protected static boolean debug
           
protected  boolean inited
          Is out servler initialized ?
protected  javax.servlet.Servlet servlet
          The servlet wrapped within that Jigsaw resource.
protected  ServletWrapper.TimeoutManager timeoutManager
           
 
Fields inherited from class org.w3c.tools.resources.FramedResource
ATTR_OID, attrListener, debugEvent, event_disabled, framesRef, structListener
 
Fields inherited from class org.w3c.tools.resources.Resource
ATTR_CONTEXT, ATTR_HELP_URL, ATTR_IDENTIFIER, ATTR_LAST_MODIFIED, ATTR_PARENT, ATTR_RESOURCE_FRAMES, ATTR_STORE_ENTRY, ATTR_URL
 
Fields inherited from class org.w3c.tools.resources.AttributeHolder
attributes, slowpickle, values
 
Constructor Summary
ServletWrapper()
           
 
Method Summary
 boolean acceptUnload()
           
protected  void checkServlet()
          Check the servlet class, ans try to initialize it.
protected  AutoReloadServletLoader createNewLocalServletLoader(boolean keepold)
           
protected  void destroyServlet()
          Destroy the servlet we are wrapping.
 java.lang.String getInitParameter(java.lang.String string)
          Servlet stub implementation - Get an init parameter value.
 java.util.Enumeration getInitParameterNames()
          Servlet stub implementation - Get all init parameters.
protected  AutoReloadServletLoader getLocalServletLoader()
          Get or create a suitable LocalServletLoader instance to load that servlet.
 javax.servlet.Servlet getServlet()
          Get the servlet we are wrapping.
 java.lang.String getServletClass()
          Get the class name of the wrapped servlet.
 javax.servlet.ServletContext getServletContext()
          Servlet stub implementation - Get that servlet context.
 java.io.File getServletDirectory()
          The Path where we can find the servlet class file.
 ArrayDictionary getServletParameters()
          Get the init parameters for our wrapped servlet.
protected  long getServletTimeout()
           
 JigsawHttpSessionContext getSessionContext()
           
 void initialize(java.lang.Object[] values)
          Initialize this servlet wrapper resource.
protected  void invalidateAllSession()
           
protected  boolean isInited()
           
protected  boolean isWrappingAServlet()
          Check if the Servletclass wrapped is a Servlet class without initializing it.
protected  boolean launchServlet()
          Launch the servlet we are wrapping.
protected  boolean launchServlet(java.lang.Class cls)
          Initialize our servlet from the given (loaded) class.
 void notifyUnload()
           
protected  void service(org.w3c.jigsaw.http.Request request, org.w3c.jigsaw.http.Reply reply)
           
 void setValue(int idx, java.lang.Object value)
          Catch assignements to the servlet class name attribute.
protected  void setValueOfSuperClass(int idx, java.lang.Object value)
           
 
Methods inherited from class org.w3c.tools.resources.FramedResource
addAttributeChangedListener, addStructureChangedListener, collectFramesReference, delete, disableEvent, displayEvent, enableEvent, eventDisabled, fireAttributeChangeEvent, fireStructureChangedEvent, fireStructureChangedEvent, frameAdded, frameModified, frameRemoved, getClone, getFrame, getFrame, getFrameReference, getFrameReference, getFramesReference, getOid, lookup, markModified, perform, performFrames, postAttributeChangeEvent, postEvent, postStructureChangedEvent, postStructureChangedEvent, processEvent, registerFrame, registerFrameIfNone, removeAttributeChangedListener, removeStructureChangedListener, unregisterFrame
 
Methods inherited from class org.w3c.tools.resources.Resource
checkMultipleLock, collectFrames, getContext, getFrame, getFrames, getHelpURL, getHelpURL, getIdentifier, getLastModified, getParent, getResourceReference, getServer, getSpace, getSpaceEntry, getStoreEntry, getURLPath, getValue, getValue, isInitialized, setContext, setContext, setValue, updateAttributes
 
Methods inherited from class org.w3c.tools.resources.AttributeHolder
definesAttribute, definesAttribute, getAttributes, getBoolean, getChar, getClone, getClone, getDouble, getFloat, getInt, getLong, getString, getValue, initialize, lookupAttribute, pickle, print, setBoolean, setChar, setDouble, setFloat, setInt, setLong, setString, setValue, unpickle, unpickle, unpickle, unpickleInstance, unpickleInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeoutManager

protected ServletWrapper.TimeoutManager timeoutManager

debug

protected static final boolean debug

ATTR_SERVLET_CLASS

protected static int ATTR_SERVLET_CLASS
Attributes index - The servlet class name.

ATTR_SERVLET_TIMEOUT

protected static int ATTR_SERVLET_TIMEOUT
Attributes index - The servlet timeout

ATTR_PARAMETERS

protected static int ATTR_PARAMETERS
Attribute index - The init parameters for that servlet.

ATTR_SERVLET_CONTEXT

protected static int ATTR_SERVLET_CONTEXT
Attribute index - Our parent-inherited servlet context.

ATTR_SESSION_CONTEXT

protected static int ATTR_SESSION_CONTEXT
Attribute index - Our parent-inherited session context.

servlet

protected javax.servlet.Servlet servlet
The servlet wrapped within that Jigsaw resource.

inited

protected boolean inited
Is out servler initialized ?
Constructor Detail

ServletWrapper

public ServletWrapper()
Method Detail

getServletDirectory

public java.io.File getServletDirectory()
The Path where we can find the servlet class file.

getInitParameter

public java.lang.String getInitParameter(java.lang.String string)
Servlet stub implementation - Get an init parameter value.
Specified by:
getInitParameter in interface javax.servlet.ServletConfig

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Servlet stub implementation - Get all init parameters.
Specified by:
getInitParameterNames in interface javax.servlet.ServletConfig

getServletContext

public javax.servlet.ServletContext getServletContext()
Servlet stub implementation - Get that servlet context.
Specified by:
getServletContext in interface javax.servlet.ServletConfig

getSessionContext

public JigsawHttpSessionContext getSessionContext()

getServletTimeout

protected long getServletTimeout()

invalidateAllSession

protected void invalidateAllSession()

checkServlet

protected void checkServlet()
                     throws java.lang.ClassNotFoundException,
                            javax.servlet.ServletException
Check the servlet class, ans try to initialize it.
Throws:
java.lang.ClassNotFoundException - if servlet class can't be found.
javax.servlet.ServletException - if servlet can't be initialized.

isInited

protected boolean isInited()

service

protected void service(org.w3c.jigsaw.http.Request request,
                       org.w3c.jigsaw.http.Reply reply)
                throws javax.servlet.ServletException,
                       java.io.IOException

getServletClass

public java.lang.String getServletClass()
Get the class name of the wrapped servlet.
Returns:
The class name for the servlet if attribute is defined. Otherwise the class name is deduced from the resource identifier.

getServletParameters

public ArrayDictionary getServletParameters()
Get the init parameters for our wrapped servlet.
Returns:
An ArrayDictionary instance if the attribute is defined, false otherwise.

setValueOfSuperClass

protected void setValueOfSuperClass(int idx,
                                    java.lang.Object value)

setValue

public void setValue(int idx,
                     java.lang.Object value)
Catch assignements to the servlet class name attribute.

When a change to that attribute is detected, the servlet is automatically reinitialized.

Overrides:
setValue in class org.w3c.tools.resources.FramedResource

destroyServlet

protected void destroyServlet()
Destroy the servlet we are wrapping.

getServlet

public javax.servlet.Servlet getServlet()
Get the servlet we are wrapping.
Returns:
A servlet instance, if the servlet is alredy running, null otherwise.

launchServlet

protected boolean launchServlet(java.lang.Class cls)
                         throws javax.servlet.ServletException
Initialize our servlet from the given (loaded) class.
Parameters:
cls - The servlet loaded main class.
Returns:
A boolean, true if servlet was successfully initialised, false otherwise.
Throws:
javax.servlet.ServletException - if servlet can't be initialized.

isWrappingAServlet

protected boolean isWrappingAServlet()
Check if the Servletclass wrapped is a Servlet class without initializing it. (not the same than checkServlet). used by the ServletIndexer.
Returns:
A boolean.
See Also:
ServletIndexer

launchServlet

protected boolean launchServlet()
                         throws java.lang.ClassNotFoundException,
                                javax.servlet.ServletException
Launch the servlet we are wrapping.

This method either succeed, or the wrapper resource itself will fail to initialize, acting as transparently as possible (in some sense).

Returns:
A boolean, true if servlet launched.
Throws:
java.lang.ClassNotFoundException - if servlet class can't be found.
javax.servlet.ServletException - if servlet can't be initialized.

acceptUnload

public boolean acceptUnload()
Overrides:
acceptUnload in class org.w3c.tools.resources.Resource

notifyUnload

public void notifyUnload()
Overrides:
notifyUnload in class org.w3c.tools.resources.FramedResource

getLocalServletLoader

protected AutoReloadServletLoader getLocalServletLoader()
Get or create a suitable LocalServletLoader instance to load that servlet.
Returns:
A LocalServletLoader instance.

createNewLocalServletLoader

protected AutoReloadServletLoader createNewLocalServletLoader(boolean keepold)

initialize

public void initialize(java.lang.Object[] values)
Initialize this servlet wrapper resource. After the wrapper itself is inited, it performs the servlet initialzation.
Parameters:
values - The default attribute values.
Overrides:
initialize in class org.w3c.tools.resources.FramedResource