org.apache.cocoon.components.treeprocessor
Class DefaultTreeBuilder

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.components.treeprocessor.DefaultTreeBuilder
All Implemented Interfaces:
Contextualizable, Disposable, LogEnabled, Poolable, Recyclable, Serviceable, TreeBuilder
Direct Known Subclasses:
SitemapLanguage

public class DefaultTreeBuilder
extends AbstractLogEnabled
implements TreeBuilder, Contextualizable, Serviceable, Recyclable, Disposable

Version:
CVS $Id: DefaultTreeBuilder.java 312592 2005-10-10 09:46:36Z cziegeler $
Author:
Sylvain Wallez

Nested Class Summary
 
Nested classes inherited from class org.apache.cocoon.components.treeprocessor.TreeBuilder
TreeBuilder.EventComponent
 
Field Summary
protected  ComponentLocator applicationContainer
          Optional application container
protected  Map attributes
           
protected  List enterSitemapEventListeners
          Optional event listeners for the enter sitemap event
protected  ClassLoader itsClassLoader
          The classloader for the processor that we are building.
protected  ProcessorComponentInfo itsComponentInfo
          The sitemap component information grabbed while building itsMaanger
protected  String itsNamespace
          The namespace of configuration for the processor that we are building.
protected  List leaveSitemapEventListeners
          Optional event listeners for the leave sitemap event
protected  ServiceManager parentProcessorManager
          Component processor of the parent manager (can be null for the root sitemap)
protected  ConcreteTreeProcessor processor
          The tree processor that we are building.
 
Fields inherited from interface org.apache.cocoon.components.treeprocessor.TreeBuilder
ROLE
 
Constructor Summary
DefaultTreeBuilder()
           
 
Method Summary
 ProcessingNode build(Configuration tree)
          Build a processing tree from a Configuration.
 void contextualize(Context context)
           
protected  ClassLoader createClassLoader(Configuration tree)
           
protected  Context createContext(Configuration tree)
          Create a context that will be used for all Contextualizable ProcessingNodeBuilders and ProcessingNodes.
 ProcessingNodeBuilder createNodeBuilder(Configuration config)
           
protected  ServiceManager createServiceManager(ClassLoader classloader, Context context, Configuration tree)
          Create a service manager that will be used for all Serviceable ProcessingNodeBuilders and ProcessingNodes.
protected  ProcessingNode createTree(Configuration tree)
          Create the tree once component manager and node builders have been set up.
 void dispose()
           
 Object getAttribute(String name)
          Get the value of an attribute.
protected  String getBuilderConfigURL()
          Get the location of the treebuilder config file.
 ClassLoader getBuiltProcessorClassLoader()
           
 ServiceManager getBuiltProcessorManager()
           
 ComponentLocator getComponentLocator()
          Return the sitemap component locator - if available.
 List getDisposableNodes()
          Return the list of ProcessingNodes part of this tree that are Disposable.
 List getEnterSitemapEventListeners()
          Return all event listers that are registered for the EnterSitemapEvent.
 List getLeaveSitemapEventListeners()
          Return all event listers that are registered for the LeaveSitemapEvent.
protected  LocationImpl getLocation(Configuration config)
           
 String getNamespace()
          Get the namespace URI that builders should use to find their nodes.
protected  Map getParameters(Configuration config, Location location)
          Get <xxx:parameter> elements as a Map of ListOfMapResolvers, that can be turned into parameters using ListOfMapResolver.buildParameters().
 ConcreteTreeProcessor getProcessor()
           
 ProcessingNode getRegisteredNode(String name)
           
 String getTypeForStatement(Configuration statement, String role)
          Get the type for a statement : it returns the 'type' attribute if present, and otherwhise the default type defined for this role in the components declarations.
protected  void linkNodes()
          Resolve links : call linkNode() on all LinkedProcessingNodeBuilders.
 void recycle()
           
 boolean registerNode(String name, ProcessingNode node)
          Register a ProcessingNode under a given name.
protected  VariableResolver resolve(String expression)
          Resolve expression using its manager
 void service(ServiceManager manager)
           
 void setAttribute(String name, Object value)
          Add an attribute.
 void setParentProcessorManager(ServiceManager manager)
           
 void setProcessor(ConcreteTreeProcessor processor)
           
 ProcessingNode setupNode(ProcessingNode node, Configuration config)
          Setup a ProcessingNode by setting its location, calling all the lifecycle interfaces it implements and giving it the parameter map if it's a ParameterizableNode.
 
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

attributes

protected Map attributes

processor

protected ConcreteTreeProcessor processor
The tree processor that we are building.


itsNamespace

protected String itsNamespace
The namespace of configuration for the processor that we are building.


itsClassLoader

protected ClassLoader itsClassLoader
The classloader for the processor that we are building. It is created by createServiceManager(ClassLoader, Context, Configuration).


itsComponentInfo

protected ProcessorComponentInfo itsComponentInfo
The sitemap component information grabbed while building itsMaanger


applicationContainer

protected ComponentLocator applicationContainer
Optional application container


enterSitemapEventListeners

protected List enterSitemapEventListeners
Optional event listeners for the enter sitemap event


leaveSitemapEventListeners

protected List leaveSitemapEventListeners
Optional event listeners for the leave sitemap event


parentProcessorManager

protected ServiceManager parentProcessorManager
Component processor of the parent manager (can be null for the root sitemap)

Constructor Detail

DefaultTreeBuilder

public DefaultTreeBuilder()
Method Detail

contextualize

public void contextualize(Context context)
                   throws ContextException
Specified by:
contextualize in interface Contextualizable
Throws:
ContextException

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException

getBuilderConfigURL

protected String getBuilderConfigURL()
Get the location of the treebuilder config file. Can be overridden for other versions.

Returns:
The location of the treebuilder config file

setParentProcessorManager

public void setParentProcessorManager(ServiceManager manager)
Specified by:
setParentProcessorManager in interface TreeBuilder

setAttribute

public void setAttribute(String name,
                         Object value)
Description copied from interface: TreeBuilder
Add an attribute. Useful to transmit information between distant (in the tree) node builders

Specified by:
setAttribute in interface TreeBuilder

getAttribute

public Object getAttribute(String name)
Description copied from interface: TreeBuilder
Get the value of an attribute.

Specified by:
getAttribute in interface TreeBuilder

createContext

protected Context createContext(Configuration tree)
                         throws Exception
Create a context that will be used for all Contextualizable ProcessingNodeBuilders and ProcessingNodes.

The default here is to simply return the context set in contextualize(), i.e. the context set by the calling TreeProcessor.

Subclasses can redefine this method to create a context local to a tree, such as for sitemap's <map:components>.

Returns:
a context
Throws:
Exception

createClassLoader

protected ClassLoader createClassLoader(Configuration tree)
                                 throws Exception
Throws:
Exception

createServiceManager

protected ServiceManager createServiceManager(ClassLoader classloader,
                                              Context context,
                                              Configuration tree)
                                       throws Exception
Create a service manager that will be used for all Serviceable ProcessingNodeBuilders and ProcessingNodes.

The default here is to simply return the manager set in compose(), i.e. the component manager set by the calling TreeProcessor.

Subclasses can redefine this method to create a service manager local to a tree, such as for sitemap's <map:components>.

Returns:
a component manager
Throws:
Exception

setProcessor

public void setProcessor(ConcreteTreeProcessor processor)
Specified by:
setProcessor in interface TreeBuilder

getProcessor

public ConcreteTreeProcessor getProcessor()
Specified by:
getProcessor in interface TreeBuilder

getBuiltProcessorManager

public ServiceManager getBuiltProcessorManager()
Specified by:
getBuiltProcessorManager in interface TreeBuilder

getBuiltProcessorClassLoader

public ClassLoader getBuiltProcessorClassLoader()
Specified by:
getBuiltProcessorClassLoader in interface TreeBuilder

getComponentLocator

public ComponentLocator getComponentLocator()
Description copied from interface: TreeBuilder
Return the sitemap component locator - if available.

Specified by:
getComponentLocator in interface TreeBuilder
See Also:
TreeBuilder.getComponentLocator()

getEnterSitemapEventListeners

public List getEnterSitemapEventListeners()
Description copied from interface: TreeBuilder
Return all event listers that are registered for the EnterSitemapEvent.

Specified by:
getEnterSitemapEventListeners in interface TreeBuilder
Returns:
A list of TreeBuilder.EventComponents.
See Also:
TreeBuilder.getEnterSitemapEventListeners()

getLeaveSitemapEventListeners

public List getLeaveSitemapEventListeners()
Description copied from interface: TreeBuilder
Return all event listers that are registered for the LeaveSitemapEvent.

Specified by:
getLeaveSitemapEventListeners in interface TreeBuilder
Returns:
A list of TreeBuilder.EventComponents.
See Also:
TreeBuilder.getLeaveSitemapEventListeners()

registerNode

public boolean registerNode(String name,
                            ProcessingNode node)
Description copied from interface: TreeBuilder
Register a ProcessingNode under a given name. For example, ResourceNodeBuilder stores here the ProcessingNodes it produces for use by sitemap pipelines. This allows to turn the tree into a graph. If a node with the name is already registed, the process fails!

Specified by:
registerNode in interface TreeBuilder
Returns:
If the node could be registered, true is returned; otherwise false.
See Also:
TreeBuilder.registerNode(java.lang.String, org.apache.cocoon.components.treeprocessor.ProcessingNode)

getRegisteredNode

public ProcessingNode getRegisteredNode(String name)
Specified by:
getRegisteredNode in interface TreeBuilder

createNodeBuilder

public ProcessingNodeBuilder createNodeBuilder(Configuration config)
                                        throws Exception
Specified by:
createNodeBuilder in interface TreeBuilder
Throws:
Exception

createTree

protected ProcessingNode createTree(Configuration tree)
                             throws Exception
Create the tree once component manager and node builders have been set up. Can be overriden by subclasses to perform pre/post tree creation operations.

Throws:
Exception

linkNodes

protected void linkNodes()
                  throws Exception
Resolve links : call linkNode() on all LinkedProcessingNodeBuilders. Can be overriden by subclasses to perform pre/post resolution operations.

Throws:
Exception

getNamespace

public String getNamespace()
Get the namespace URI that builders should use to find their nodes.

Specified by:
getNamespace in interface TreeBuilder

build

public ProcessingNode build(Configuration tree)
                     throws Exception
Build a processing tree from a Configuration.

Specified by:
build in interface TreeBuilder
Throws:
Exception

getDisposableNodes

public List getDisposableNodes()
Return the list of ProcessingNodes part of this tree that are Disposable. Care should be taken to properly dispose them before trashing the processing tree.

Specified by:
getDisposableNodes in interface TreeBuilder

setupNode

public ProcessingNode setupNode(ProcessingNode node,
                                Configuration config)
                         throws Exception
Setup a ProcessingNode by setting its location, calling all the lifecycle interfaces it implements and giving it the parameter map if it's a ParameterizableNode.

As a convenience, the node is returned by this method to allow constructs like return treeBuilder.setupNode(new MyNode(), config).

Specified by:
setupNode in interface TreeBuilder
Throws:
Exception

getLocation

protected LocationImpl getLocation(Configuration config)

getParameters

protected Map getParameters(Configuration config,
                            Location location)
                     throws ConfigurationException
Get <xxx:parameter> elements as a Map of ListOfMapResolvers, that can be turned into parameters using ListOfMapResolver.buildParameters().

Returns:
the Map of ListOfMapResolver, or null if there are no parameters.
Throws:
ConfigurationException

getTypeForStatement

public String getTypeForStatement(Configuration statement,
                                  String role)
                           throws ConfigurationException
Get the type for a statement : it returns the 'type' attribute if present, and otherwhise the default type defined for this role in the components declarations.

Specified by:
getTypeForStatement in interface TreeBuilder
Parameters:
statement - the statement
role - the component's role (warn: not the selector's role)
Throws:
ConfigurationException - if the type could not be found.

resolve

protected VariableResolver resolve(String expression)
                            throws PatternException
Resolve expression using its manager

Throws:
PatternException

recycle

public void recycle()
Specified by:
recycle in interface Recyclable

dispose

public void dispose()
Specified by:
dispose in interface Disposable


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