org.apache.cocoon.spring
Class SpringComponentLocator

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.spring.SpringComponentLocator
All Implemented Interfaces:
ComponentLocator, Configurable, Contextualizable, Disposable, EnterSitemapEventListener, EventListener, Initializable, LeaveSitemapEventListener, LogEnabled, Serviceable, SitemapListener

public class SpringComponentLocator
extends AbstractLogEnabled
implements ComponentLocator, Contextualizable, Serviceable, Configurable, Initializable, Disposable, EnterSitemapEventListener, LeaveSitemapEventListener

This is the connection between Cocoon and Spring. We create an own web application context.

Version:
$Id: SpringComponentLocator.java 227218 2005-08-03 13:21:41Z cziegeler $

Field Summary
static String APPLICATION_CONTEXT_REQUEST_ATTRIBUTE
           
protected  Core cocoon
           
protected  String configLocation
           
protected  Context context
           
protected  String contextClassName
           
protected  EnvironmentHelper environmentHelper
           
protected  String locatorFactorySelector
           
protected  ServiceManager manager
           
protected  String parentContextKey
           
protected  SourceResolver resolver
           
protected  ServletContext servletContext
           
protected  CocoonApplicationContext wac
           
 
Constructor Summary
SpringComponentLocator()
           
 
Method Summary
 void configure(Configuration config)
           
 void contextualize(Context context)
           
protected  org.springframework.context.ApplicationContext createCocoonAppContext(org.springframework.context.ApplicationContext parent)
          Create an application context that contains Cocoon specific beans.
protected  CocoonApplicationContext createWebApplicationContext(org.springframework.context.ApplicationContext parent)
          Instantiate the web application context for this loader, either a default CocoonApplicationContext or a custom context class if specified.
 void dispose()
          Close Spring's web application context.
 void enteredSitemap(EnterSitemapEvent event)
           
 Object getComponent(String key)
           
protected  org.springframework.context.ApplicationContext getParentContext()
          Get the parent application context: this is either the context of a parent sitemap or an optional web application context set by the spring servlet (filter).
 boolean hasComponent(String key)
           
 void initialize()
          Initialize Spring's web application context.
 void leftSitemap(LeaveSitemapEvent event)
           
protected  void registerDefaults(org.springframework.beans.factory.config.ConfigurableListableBeanFactory factory)
          Register cocoon components that will be available for spring components.
 void release(Object component)
           
 void service(ServiceManager aManager)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPLICATION_CONTEXT_REQUEST_ATTRIBUTE

public static final String APPLICATION_CONTEXT_REQUEST_ATTRIBUTE
See Also:
Constant Field Values

servletContext

protected ServletContext servletContext

environmentHelper

protected EnvironmentHelper environmentHelper

manager

protected ServiceManager manager

resolver

protected SourceResolver resolver

cocoon

protected Core cocoon

context

protected Context context

wac

protected CocoonApplicationContext wac

contextClassName

protected String contextClassName

configLocation

protected String configLocation

locatorFactorySelector

protected String locatorFactorySelector

parentContextKey

protected String parentContextKey
Constructor Detail

SpringComponentLocator

public SpringComponentLocator()
Method Detail

contextualize

public void contextualize(Context context)
                   throws ContextException
Specified by:
contextualize in interface Contextualizable
Throws:
ContextException
See Also:
Contextualizable.contextualize(org.apache.avalon.framework.context.Context)

service

public void service(ServiceManager aManager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException
See Also:
Serviceable.service(org.apache.avalon.framework.service.ServiceManager)

configure

public void configure(Configuration config)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException
See Also:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)

initialize

public void initialize()
                throws Exception
Initialize Spring's web application context.

Specified by:
initialize in interface Initializable
Throws:
org.springframework.beans.BeansException - if the context couldn't be initialized
Exception
See Also:
Initializable.initialize()

dispose

public void dispose()
Close Spring's web application context.

Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()

hasComponent

public boolean hasComponent(String key)
Specified by:
hasComponent in interface ComponentLocator
See Also:
ComponentLocator.hasComponent(java.lang.String)

getComponent

public Object getComponent(String key)
                    throws ProcessingException
Specified by:
getComponent in interface ComponentLocator
Throws:
ProcessingException
See Also:
ComponentLocator.getComponent(java.lang.String)

release

public void release(Object component)
Specified by:
release in interface ComponentLocator
See Also:
ComponentLocator.release(java.lang.Object)

createWebApplicationContext

protected CocoonApplicationContext createWebApplicationContext(org.springframework.context.ApplicationContext parent)
                                                        throws org.springframework.beans.BeansException
Instantiate the web application context for this loader, either a default CocoonApplicationContext or a custom context class if specified.

This implementation expects custom contexts to be a subclass of CocoonApplicationContext.

Parameters:
parent - the parent ApplicationContext to use, or null if none
Throws:
org.springframework.beans.BeansException - if the context couldn't be initialized

createCocoonAppContext

protected org.springframework.context.ApplicationContext createCocoonAppContext(org.springframework.context.ApplicationContext parent)
Create an application context that contains Cocoon specific beans.

Returns:
A new application context

registerDefaults

protected void registerDefaults(org.springframework.beans.factory.config.ConfigurableListableBeanFactory factory)
Register cocoon components that will be available for spring components.

Parameters:
factory - The factory to register with.

getParentContext

protected org.springframework.context.ApplicationContext getParentContext()
Get the parent application context: this is either the context of a parent sitemap or an optional web application context set by the spring servlet (filter).

Returns:
A parent application context or null

enteredSitemap

public void enteredSitemap(EnterSitemapEvent event)
Specified by:
enteredSitemap in interface EnterSitemapEventListener
See Also:
EnterSitemapEventListener.enteredSitemap(org.apache.cocoon.sitemap.EnterSitemapEvent)

leftSitemap

public void leftSitemap(LeaveSitemapEvent event)
Specified by:
leftSitemap in interface LeaveSitemapEventListener
See Also:
LeaveSitemapEventListener.leftSitemap(org.apache.cocoon.sitemap.LeaveSitemapEvent)


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.