jfun.yan.web
Class YanLoader

java.lang.Object
  extended by jfun.yan.web.YanLoader
Direct Known Subclasses:
XFireLoader

public class YanLoader
extends java.lang.Object

This class is responsible for setting up web integration for Yan.

Author:
Ben Yu Jan 17, 2006 1:27:59 PM

Field Summary
static java.lang.String CONFIG_FILE_PARAM
          Name of servlet context parameter that can specify the configuration file for the root container, falling back to DEFAULT_CONFIG_FILE otherwise.
static java.lang.String CONTAINER_ROOT
          The name of the servlet context attribut that holds the Container instance.
static java.lang.String DEFAULT_CONFIG_FILE
          The default location of the yan configuration file.
static java.lang.String DEFAULT_NUTS_FILE
          The default xml file that configures the non-spring nut classes.
static java.lang.String DEFAULT_SPRING_NUTS_FILE
          The default xml file that configures spring aware nut classes.
static java.lang.String LIFECYCLE_MANAGER_ROOT
          The name of the servlet context attribute that holds the life cycle manager instance.
static java.lang.String SERVLET_CONTEXT_KEY
          The service key for the ServletContext object.
static java.lang.String TRUE
          The value "true" that should be specified for USE_SPRING if Spring framework integration is desired.
static java.lang.String USE_SPRING
          Name of the servlet context parameter that specifies whether Spring framework integration is required.
 
Constructor Summary
YanLoader()
           
 
Method Summary
protected  void decorateProcessor(NutsProcessor processor, javax.servlet.ServletContext ctxt)
          Decorate a NutsProcessor object by adding or removing features.
 void destroy(javax.servlet.ServletContext servletContext)
          Destroy the container.
protected  NutsProcessor getNutsProcessor(java.lang.ClassLoader cloader, ResourceLoader rloader, javax.servlet.ServletContext ctxt)
          Construct a NutsProcessor object based on the configuration information stored in ServletContext.
 Container initContainer(java.lang.ClassLoader cloader, javax.servlet.ServletContext servletContext)
          Initialize this object by instantiating container and life cycle manager.
 Container initContainer(javax.servlet.ServletContext ctxt)
          Initialize this object by instantiating container and life cycle manager.
protected  Container loadParentContainer(javax.servlet.ServletContext servletContext)
          Load the parent Container object that's shared among web applications.
protected  NutsProcessor process(java.lang.ClassLoader cloader, javax.servlet.ServletContext ctxt)
          Create a NutsProcessor object based on the configuration in ServletContext.
protected static void registerServletContext(Container container, javax.servlet.ServletContext ctxt)
          Register the ServletContext into the container using either WebUtils.DEFAULT_SERVLET_CONTEXT_PROPERTY or else ServletContext.class as long as there's no ServletContext component already registered.
protected  void setSpringAware(NutsProcessor processor, javax.servlet.ServletContext ctxt)
          Decorate NutsProcessor object with nut classes that integrates Spring framework and also aware of the web infrastructure, i.e.
protected  void setWebAware(NutsProcessor processor, javax.servlet.ServletContext ctxt)
          Decorate NutsProcessor object with nut classes that are aware of the web infrastructure, i.e.
 void start()
          Call start on the life cycle manager.
 void stop()
          Call stop on the life cycle manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_FILE_PARAM

public static final java.lang.String CONFIG_FILE_PARAM
Name of servlet context parameter that can specify the configuration file for the root container, falling back to DEFAULT_CONFIG_FILE otherwise.

See Also:
Constant Field Values

USE_SPRING

public static final java.lang.String USE_SPRING
Name of the servlet context parameter that specifies whether Spring framework integration is required. The default is "false".

See Also:
Constant Field Values

TRUE

public static final java.lang.String TRUE
The value "true" that should be specified for USE_SPRING if Spring framework integration is desired.


DEFAULT_CONFIG_FILE

public static final java.lang.String DEFAULT_CONFIG_FILE
The default location of the yan configuration file.

See Also:
Constant Field Values

SERVLET_CONTEXT_KEY

public static final java.lang.String SERVLET_CONTEXT_KEY
The service key for the ServletContext object.

See Also:
Constant Field Values

CONTAINER_ROOT

public static final java.lang.String CONTAINER_ROOT
The name of the servlet context attribut that holds the Container instance. Equal to the fully qualified class name of Container.


LIFECYCLE_MANAGER_ROOT

public static final java.lang.String LIFECYCLE_MANAGER_ROOT
The name of the servlet context attribute that holds the life cycle manager instance. Equal to the fully qualified name of LifecycleManager.


DEFAULT_NUTS_FILE

public static final java.lang.String DEFAULT_NUTS_FILE
The default xml file that configures the non-spring nut classes.

See Also:
Constant Field Values

DEFAULT_SPRING_NUTS_FILE

public static final java.lang.String DEFAULT_SPRING_NUTS_FILE
The default xml file that configures spring aware nut classes.

See Also:
Constant Field Values
Constructor Detail

YanLoader

public YanLoader()
Method Detail

initContainer

public Container initContainer(javax.servlet.ServletContext ctxt)
Initialize this object by instantiating container and life cycle manager. Relevant servlet context parameters are read.

Parameters:
ctxt - the servlet context object.
Returns:
the Container object instantiated.

start

public void start()
           throws java.lang.Throwable
Call start on the life cycle manager.

Throws:
java.lang.Throwable

stop

public void stop()
          throws java.lang.Throwable
Call stop on the life cycle manager.

Throws:
java.lang.Throwable

initContainer

public Container initContainer(java.lang.ClassLoader cloader,
                               javax.servlet.ServletContext servletContext)
Initialize this object by instantiating container and life cycle manager. Relevant servlet context parameters are read.

This implementation calls process(ClassLoader, ServletContext) for interpreting the configuration file and obtaining the Container instance and LifecycleManager instance.

Parameters:
cloader - the ClassLoader used to load component classes.
servletContext - the servlet context object.
Returns:
the Container object instantiated. null is returned if configuration file not found.

loadParentContainer

protected Container loadParentContainer(javax.servlet.ServletContext servletContext)
                                 throws java.lang.Exception
Load the parent Container object that's shared among web applications.

Parameters:
servletContext - the servlet context.
Returns:
the Container object. or null if not found.
Throws:
java.lang.Exception

process

protected NutsProcessor process(java.lang.ClassLoader cloader,
                                javax.servlet.ServletContext ctxt)
                         throws java.lang.Exception
Create a NutsProcessor object based on the configuration in ServletContext. The configuration file is also parsed and interpreted.

This default implementation delegates to getNutsProcessor(ClassLoader, ResourceLoader, ServletContext) for constructing the NutsProcessor object.

If no ServletContext component is registered, the current ServletContext object is registered as a component in the container.

Parameters:
cloader - the ClassLoader object used to load component classes.
ctxt - the ServletContext object.
Returns:
the populated NutsProcessor object.
Throws:
java.lang.Exception - any error.

registerServletContext

protected static void registerServletContext(Container container,
                                             javax.servlet.ServletContext ctxt)
Register the ServletContext into the container using either WebUtils.DEFAULT_SERVLET_CONTEXT_PROPERTY or else ServletContext.class as long as there's no ServletContext component already registered.

Parameters:
container - the Yan container object.
ctxt - the ServletContext object.

getNutsProcessor

protected NutsProcessor getNutsProcessor(java.lang.ClassLoader cloader,
                                         ResourceLoader rloader,
                                         javax.servlet.ServletContext ctxt)
                                  throws java.lang.Exception
Construct a NutsProcessor object based on the configuration information stored in ServletContext. And then call decorateProcessor(NutsProcessor, ServletContext) to decorate it.

Parameters:
cloader - the ClassLoader object used to load component class.
rloader - the ResourceLoader object used to load resource.
ctxt - the ServletContext object.
Returns:
the result NutsProcessor object.
Throws:
java.lang.Exception - any error.

decorateProcessor

protected void decorateProcessor(NutsProcessor processor,
                                 javax.servlet.ServletContext ctxt)
                          throws java.lang.Exception
Decorate a NutsProcessor object by adding or removing features.

This default implementation replaces <bean>, <ctor> and <method> tags with the ones that're aware of the ServletContext.

It does so by registering the ServletContext as a service under SERVLET_CONTEXT_KEY. The customized tags then look up this service and call "setServletContext()" or any other specified receiver method to set this dependency.

Based on whether USE_SPRING parameter is set in ServletContext, this implementation calls either setSpringAware(NutsProcessor, ServletContext) or setWebAware(NutsProcessor, ServletContext) to do the decoration.

Subclasses can override this method to provide customized decoration.

Parameters:
processor - the NutsProcessor object to decorate.
ctxt - the ServletContext object.
Throws:
java.lang.Exception - any error.

setSpringAware

protected void setSpringAware(NutsProcessor processor,
                              javax.servlet.ServletContext ctxt)
                       throws java.lang.Exception
Decorate NutsProcessor object with nut classes that integrates Spring framework and also aware of the web infrastructure, i.e. ServletContext.

Parameters:
processor - the NutsProcessor object to decorate.
ctxt - the ServletContext object.
Throws:
java.lang.Exception - any error.

setWebAware

protected void setWebAware(NutsProcessor processor,
                           javax.servlet.ServletContext ctxt)
                    throws java.lang.Exception
Decorate NutsProcessor object with nut classes that are aware of the web infrastructure, i.e. ServletContext.

Parameters:
processor - the NutsProcessor object to decorate.
ctxt - the ServletContext object.
Throws:
java.lang.Exception - any error.

destroy

public void destroy(javax.servlet.ServletContext servletContext)
Destroy the container.

Parameters:
servletContext - the servlet context.