org.apache.cocoon.components.treeprocessor
Class DefaultTreeBuilder

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.treeprocessor.DefaultTreeBuilder
All Implemented Interfaces:
RoleManageable, Poolable, Recyclable, Disposable, Component, Composable, Recomposable, Configurable, Contextualizable, LogEnabled, TreeBuilder
Direct Known Subclasses:
SitemapLanguage

public class DefaultTreeBuilder
extends AbstractLogEnabled
implements TreeBuilder, Recomposable, Configurable, Contextualizable, RoleManageable, Recyclable, Disposable

Version:
CVS $Id: DefaultTreeBuilder.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Sylvain Wallez

Field Summary
protected  Map attributes
           
protected  ComponentSelector builderSelector
          Selector for ProcessingNodeBuilders
protected  Configuration configuration
           
protected  Context context
           
protected  String fileName
           
protected  String languageName
           
protected  LifecycleHelper lifecycle
           
protected  ComponentManager manager
          Component manager created by createComponentManager(Configuration).
protected  String namespace
           
protected  String parameterElement
           
protected  ComponentManager parentManager
          The parent component manager, set using compose() and recompose() (implementation of Recomposable).
protected  RoleManager parentRoleManager
          The parent role manager, set using setRoleManager (implementation of RoleManageable).
protected  ConcreteTreeProcessor processor
          The tree processor that we're building.
protected  RoleManager roleManager
          Role manager result created by createRoleManager().
 
Constructor Summary
DefaultTreeBuilder()
           
 
Method Summary
 ProcessingNode build(Configuration tree)
          Build a processing tree from a Configuration.
 ProcessingNode build(Source source)
           
 void compose(ComponentManager manager)
           
 void configure(Configuration config)
          Configurable
 void contextualize(Context context)
           
protected  ComponentSelector createBuilderSelector()
          Create a ComponentSelector for ProcessingNodeBuilders.
protected  ComponentManager createComponentManager(Configuration tree)
          Create a component manager that will be used for all Composable ProcessingNodeBuilders and ProcessingNodes.
 ProcessingNodeBuilder createNodeBuilder(Configuration config)
           
protected  RoleManager createRoleManager()
          Create a role manager that will be used by all RoleManageable components.
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.
 List getDisposableNodes()
          Return the list of ProcessingNodes part of this tree that are Disposable.
 String getFileName()
           
 String getLanguage()
          Returns the language that is being built (e.g.
protected  LocationImpl getLocation(Configuration config)
           
 String getNamespace()
          Get the namespace URI that builders should use to find their nodes.
 String getParameterName()
          Returns the name of the parameter element.
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)
           
 ComponentManager getSitemapComponentManager()
          Return the sitemap component manager
 String getTypeForStatement(Configuration statement, String role)
          Get the type for a statement : it returns the 'type' attribute if present, and otherwhise the default hint of the ExtendedSelector designated by role role.
protected  void linkNodes()
          Resolve links : call linkNode() on all LinkedProcessingNodeBuilders.
 void recompose(ComponentManager manager)
           
 void recycle()
           
 boolean registerNode(String name, ProcessingNode node)
          Register a ProcessingNode under a given name.
 void setAttribute(String name, Object value)
          Add an attribute.
 void setProcessor(ConcreteTreeProcessor processor)
           
 void setRoleManager(RoleManager rm)
           
 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're building.


context

protected Context context

parentManager

protected ComponentManager parentManager
The parent component manager, set using compose() and recompose() (implementation of Recomposable).


parentRoleManager

protected RoleManager parentRoleManager
The parent role manager, set using setRoleManager (implementation of RoleManageable).


configuration

protected Configuration configuration

manager

protected ComponentManager manager
Component manager created by createComponentManager(Configuration).


roleManager

protected RoleManager roleManager
Role manager result created by createRoleManager().


builderSelector

protected ComponentSelector builderSelector
Selector for ProcessingNodeBuilders


lifecycle

protected LifecycleHelper lifecycle

namespace

protected String namespace

parameterElement

protected String parameterElement

languageName

protected String languageName

fileName

protected String fileName
Constructor Detail

DefaultTreeBuilder

public DefaultTreeBuilder()
Method Detail

contextualize

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

compose

public void compose(ComponentManager manager)
             throws ComponentException
Specified by:
compose in interface Composable
Throws:
ComponentException

recompose

public void recompose(ComponentManager manager)
               throws ComponentException
Specified by:
recompose in interface Recomposable
Throws:
ComponentException

setRoleManager

public void setRoleManager(RoleManager rm)
Specified by:
setRoleManager in interface RoleManageable

configure

public void configure(Configuration config)
               throws ConfigurationException
Configurable

Specified by:
configure in interface Configurable
Throws:
ConfigurationException

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

createRoleManager

protected RoleManager createRoleManager()
                                 throws Exception
Create a role manager that will be used by all RoleManageable components. The default here is to create a role manager with the contents of the <roles> element of the configuration.

Subclasses can redefine this method to create roles from other sources than the one used here.

Returns:
the role manager
Throws:
Exception

createComponentManager

protected ComponentManager createComponentManager(Configuration tree)
                                           throws Exception
Create a component manager that will be used for all Composable ProcessingNodeBuilders and ProcessingNodes.

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

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

Returns:
a component manager
Throws:
Exception

createBuilderSelector

protected ComponentSelector createBuilderSelector()
                                           throws Exception
Create a ComponentSelector for ProcessingNodeBuilders. It creates a selector with the contents of the "node" element of the configuration.

Returns:
a selector for node builders
Throws:
Exception

setProcessor

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

getProcessor

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

getLanguage

public String getLanguage()
Returns the language that is being built (e.g. "sitemap").

Specified by:
getLanguage in interface TreeBuilder

getParameterName

public String getParameterName()
Returns the name of the parameter element.

Specified by:
getParameterName in interface TreeBuilder

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(Source source)
                     throws Exception
Specified by:
build in interface TreeBuilder
Throws:
Exception

getFileName

public String getFileName()
Specified by:
getFileName 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

getSitemapComponentManager

public ComponentManager getSitemapComponentManager()
Return the sitemap component manager

Specified by:
getSitemapComponentManager 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 hint of the ExtendedSelector designated by role role.

Specified by:
getTypeForStatement in interface TreeBuilder
Throws:
ConfigurationException - if the default type could not be found.

recycle

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

dispose

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


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.