cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: cocoon-2.1/src/test/org/apache/cocoon/components/treeprocessor/variables PreparedVariableResolverTestCase.java
Date Fri, 16 Jul 2004 12:36:46 GMT
sylvain     2004/07/16 05:36:46

  Modified:    src/java/org/apache/cocoon cocoon.roles
               src/java/org/apache/cocoon/components/treeprocessor
                        AbstractProcessingNodeBuilder.java
                        DefaultTreeBuilder.java ProcessorComponentInfo.java
                        SimpleSelectorProcessingNode.java TreeBuilder.java
                        TreeProcessor.java sitemap-language.xml
               src/java/org/apache/cocoon/components/treeprocessor/sitemap
                        ActTypeNode.java ComponentsSelector.java
                        MatchNode.java PreparableMatchNode.java
                        SelectNode.java SelectNodeBuilder.java
                        SerializeNodeBuilder.java SitemapLanguage.java
                        SwitchSelectNode.java
               src/blocks/profiler/java/org/apache/cocoon/components/profiler
                        ProfilingCachingProcessingPipeline.java
                        ProfilingNonCachingProcessingPipeline.java
               src/blocks/scratchpad/java/org/apache/cocoon/components/pipeline/impl
                        ExpiresCachingProcessingPipeline.java
               src/test/org/apache/cocoon/components/treeprocessor/variables
                        PreparedVariableResolverTestCase.java
  Log:
  Refactoring of the sitemap engine to decouple it as much as possible of the container implementation. TreeBuilder is now a regular component declared in cocoon.roles, and several implementations can exist for different versions of the sitemap language.
  
  Revision  Changes    Path
  1.17      +52 -0     cocoon-2.1/src/java/org/apache/cocoon/cocoon.roles
  
  Index: cocoon.roles
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/cocoon.roles,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- cocoon.roles	25 May 2004 07:28:24 -0000	1.16
  +++ cocoon.roles	16 Jul 2004 12:36:44 -0000	1.17
  @@ -95,10 +95,62 @@
          shorthand="store-janitor"
          default-class="org.apache.excalibur.store.impl.StoreJanitorImpl"/>
   
  +  <!--=========================================================================
  +       Sitemap engine
  +      =========================================================================-->
  +
  +  <!-- the sitemap engine -->
     <role name="org.apache.cocoon.Processor"
           shorthand="sitemap"
           default-class="org.apache.cocoon.components.treeprocessor.TreeProcessor"/>
  +  
  +  <!-- the tree builder for the sitemap language (additional implementations can be added here
  +       or in cocoon.xconf for other implementations)
  +       
  +       The shorthand attribute is actually of no use, but the rolemanager requires it -->
  +  <role name="org.apache.cocoon.components.treeprocessor.TreeBuilder/sitemap-1.0"
  +        shorthand="treebuilder-1.0-should-actually-never-be-used"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage"/>
  +
  +  <!-- the various elements of map:components -->
  +  <role name="org.apache.cocoon.components.pipeline.ProcessingPipelineSelector"
  +        shorthand="pipes"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +
  +  <role name="org.apache.cocoon.acting.ActionSelector"
  +        shorthand="actions"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +      
  +  <role name="org.apache.cocoon.selection.SelectorSelector"
  +        shorthand="selectors"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +      
  +  <role name="org.apache.cocoon.matching.MatcherSelector"
  +        shorthand="matchers"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +      
  +  <role name="org.apache.cocoon.generation.GeneratorSelector"
  +        shorthand="generators"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +      
  +  <role name="org.apache.cocoon.transformation.TransformerSelector"
  +        shorthand="transformers"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +      
  +  <role name="org.apache.cocoon.serialization.SerializerSelector"
  +        shorthand="serializers"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +      
  +  <role name="org.apache.cocoon.reading.ReaderSelector"
  +        shorthand="readers"
  +        default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  +          
  +  <role name="org.apache.cocoon.components.notification.NotifyingBuilder"
  +        shorthand="notifying-builder"
  +        default-class="org.apache.cocoon.components.notification.DefaultNotifyingBuilder"/>  
   
  +  <!--=========================================================================-->
  +  
     <role name="org.apache.cocoon.components.classloader.ClassLoaderManager"
           shorthand="classloader"
           default-class="org.apache.cocoon.components.classloader.ClassLoaderManagerImpl"/>
  
  
  
  1.7       +2 -6      cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
  
  Index: AbstractProcessingNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractProcessingNodeBuilder.java	15 Jul 2004 12:49:50 -0000	1.6
  +++ AbstractProcessingNodeBuilder.java	16 Jul 2004 12:36:45 -0000	1.7
  @@ -35,15 +35,11 @@
   
   
   public abstract class AbstractProcessingNodeBuilder extends AbstractLogEnabled
  -  implements ProcessingNodeBuilder /*, Serviceable*/ {
  +  implements ProcessingNodeBuilder {
   
       protected TreeBuilder treeBuilder;
       
       protected ServiceManager manager;
  -
  -//    public void service(ServiceManager manager) throws ServiceException {
  -//        this.manager = manager;
  -//    }
   
       /* (non-Javadoc)
        * @see org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder#setBuilder(org.apache.cocoon.components.treeprocessor.TreeBuilder)
  
  
  
  1.14      +78 -149   cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
  
  Index: DefaultTreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultTreeBuilder.java	15 Jul 2004 12:49:50 -0000	1.13
  +++ DefaultTreeBuilder.java	16 Jul 2004 12:36:45 -0000	1.14
  @@ -21,7 +21,6 @@
   import java.util.List;
   import java.util.Map;
   
  -import org.apache.avalon.excalibur.component.DefaultRoleManager;
   import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
   import org.apache.avalon.excalibur.component.RoleManageable;
   import org.apache.avalon.excalibur.component.RoleManager;
  @@ -29,11 +28,9 @@
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.component.WrapperComponentManager;
  -import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.configuration.DefaultConfiguration;
  -import org.apache.avalon.framework.configuration.NamespacedSAXConfigurationHandler;
  +import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
  @@ -43,7 +40,6 @@
   import org.apache.avalon.framework.service.ServiceSelector;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.service.WrapperServiceSelector;
  -import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.ExtendedComponentSelector;
   import org.apache.cocoon.components.LifecycleHelper;
   import org.apache.cocoon.components.source.SourceUtil;
  @@ -51,6 +47,7 @@
   import org.apache.cocoon.sitemap.PatternException;
   import org.apache.cocoon.sitemap.SitemapParameters;
   import org.apache.excalibur.source.Source;
  +import org.apache.excalibur.source.SourceResolver;
   
   /**
    *
  @@ -59,8 +56,8 @@
    */
   public class DefaultTreeBuilder
           extends AbstractLogEnabled
  -        implements TreeBuilder, Configurable, Contextualizable, Serviceable,
  -                   RoleManageable, Recyclable, Disposable {
  +        implements TreeBuilder, Contextualizable, Serviceable,
  +                   RoleManageable, Initializable, Recyclable, Disposable {
   
       protected Map attributes = new HashMap();
   
  @@ -84,7 +81,6 @@
        */
       protected RoleManager ownRoleManager;
   
  -    protected Configuration configuration;
       // -------------------------------------
       
       /**
  @@ -97,11 +93,6 @@
        */
       protected ServiceManager processorManager;
   
  -    /**
  -     * Role manager result created by {@link #createRoleManager()}.
  -     */
  -    protected RoleManager processorRoleManager;
  -
       /** Selector for ProcessingNodeBuilders */
       protected ServiceSelector builderSelector;
   
  @@ -138,6 +129,60 @@
       public void service(ServiceManager manager) throws ServiceException {
           this.ownManager = manager;
       }
  +    
  +    /**
  +     * Get the location of the treebuilder config file. Can be overridden for other versions.
  +     * @return
  +     */
  +    protected String getBuilderConfigURL() {
  +        return "resource://org/apache/cocoon/components/treeprocessor/sitemap-language.xml";
  +    }
  +    
  +    public void initialize() throws Exception {
  +        // Load the builder config file
  +        SourceResolver resolver = (SourceResolver)this.ownManager.lookup(SourceResolver.ROLE);
  +        String url = getBuilderConfigURL();
  +        Configuration config;
  +        try {
  +            Source src = resolver.resolveURI(url);
  +            try {
  +                SAXConfigurationHandler handler = new SAXConfigurationHandler();
  +                SourceUtil.toSAX(this.ownManager, src, null, handler);
  +                config = handler.getConfiguration();
  +            } finally {
  +                resolver.release(src);
  +            }
  +        } catch(Exception e) {
  +            throw new ConfigurationException("Could not load TreeBuilder configuration from " + url, e);
  +        } finally {
  +            this.ownManager.release(resolver);
  +        }
  +        
  +        // Create the NodeBuilder selector.
  +        ExcaliburComponentSelector selector = new ExtendedComponentSelector() {
  +            protected String getComponentInstanceName() {
  +                return "node";
  +            }
  +
  +            protected String getClassAttributeName() {
  +                return "builder";
  +            }
  +        };
  +
  +        // Automagically initialize the selector
  +        LifecycleHelper.setupComponent(selector,
  +            getLogger(),
  +            this.context,
  +            this.ownManager,
  +            new WrapperComponentManager(this.ownManager),
  +            this.ownRoleManager,
  +            config.getChild("nodes", false),
  +            true
  +        );
  +
  +        this.builderSelector = new WrapperServiceSelector("BuilderSelector", selector);
  +        
  +    }
   
       public void setParentProcessorManager(ServiceManager manager) {
           this.parentProcessorManager = manager;
  @@ -151,13 +196,6 @@
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
  -     */
  -    public void configure(Configuration config) throws ConfigurationException {
  -        this.configuration = config;
  -    }
  -
  -    /* (non-Javadoc)
        * @see org.apache.cocoon.components.treeprocessor.TreeBuilder#setAttribute(java.lang.String, java.lang.Object)
        */
       public void setAttribute(String name, Object value) {
  @@ -172,31 +210,6 @@
       }
   
       /**
  -     * Create a role manager that will be used by all <code>RoleManageable</code>
  -     * components. The default here is to create a role manager with the contents of
  -     * the &lt;roles&gt; element of the configuration.
  -     * <p>
  -     * Subclasses can redefine this method to create roles from other sources than
  -     * the one used here.
  -     *
  -     * @return the role manager
  -     */
  -    protected RoleManager createRoleManager() throws Exception
  -    {
  -        RoleManager roles = new DefaultRoleManager(this.ownRoleManager);
  -
  -        LifecycleHelper.setupComponent(roles,
  -            getLogger(),
  -            this.context,
  -            this.ownManager,
  -            this.ownRoleManager,
  -            this.configuration.getChild("roles")
  -        );
  -
  -        return roles;
  -    }
  -
  -    /**
        * Create a component manager that will be used for all <code>Composable</code>
        * <code>ProcessingNodeBuilder</code>s and <code>ProcessingNode</code>s.
        * <p>
  @@ -213,69 +226,6 @@
           return this.ownManager;
       }
   
  -    /**
  -     * Create a <code>ComponentSelector</code> for <code>ProcessingNodeBuilder</code>s.
  -     * It creates a selector with the contents of the "node" element of the configuration.
  -     *
  -     * @return a selector for node builders
  -     */
  -    protected ServiceSelector createBuilderSelector(String sitemapVersion)
  -    throws Exception {
  -
  -        // Create the NodeBuilder selector.
  -        ExcaliburComponentSelector selector = new ExtendedComponentSelector() {
  -            protected String getComponentInstanceName() {
  -                return "node";
  -            }
  -
  -            protected String getClassAttributeName() {
  -                return "builder";
  -            }
  -        };
  -
  -        // Merge configuration for tree builder from
  -        // <nodes> and <nodes-{sitemapVersion}>
  -        final Configuration base = this.configuration.getChild("nodes");
  -        final Configuration layer = this.configuration.getChild("nodes-" + sitemapVersion);
  -        if ( layer != null ) {
  -            final DefaultConfiguration merged =
  -                  new DefaultConfiguration( base.getName(),
  -                                      "Merged [layer: " + layer.getLocation()
  -                                      + ", base: " + base.getLocation() + "]" );
  -            merged.addAllChildren(base);
  -            final Configuration[] lc = layer.getChildren();
  -            for( int i = 0; i < lc.length; i++ ) {
  -                final String nodeName = lc[i].getAttribute("name");
  -                final Configuration[] bc = base.getChildren();
  -                boolean found = false;
  -                int m = 0;
  -                while ( m < bc.length && ! found ) {
  -                    if ( nodeName.equals(bc[m].getAttribute("name")) ) {
  -                        found = true;
  -                    } else {
  -                        m++;
  -                    }
  -                }
  -                if ( found ) {
  -                    merged.removeChild( bc[m] );
  -                }
  -                merged.addChild( lc[i] );
  -            }
  -        }
  -        // Automagically initialize the selector
  -        LifecycleHelper.setupComponent(selector,
  -            getLogger(),
  -            this.context,
  -            this.ownManager,
  -            new WrapperComponentManager(this.ownManager),
  -            this.ownRoleManager,
  -            base,
  -            true
  -        );
  -
  -        return new WrapperServiceSelector("BuilderSelector", selector);
  -    }
  -
       /* (non-Javadoc)
        * @see org.apache.cocoon.components.treeprocessor.TreeBuilder#setProcessor(org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor)
        */
  @@ -372,40 +322,13 @@
           return this.namespace;
       }
   
  -    public ProcessingNode build(Source source)
  -    throws Exception {
  -
  -        try {
  -            // Build a namespace-aware configuration object
  -            NamespacedSAXConfigurationHandler handler = new NamespacedSAXConfigurationHandler();
  -            SourceUtil.toSAX( source, handler );
  -            Configuration treeConfig = handler.getConfiguration();
  -
  -            this.namespace = treeConfig.getNamespace();
  -
  -            // get the namespace version
  -            final int pos = this.namespace.lastIndexOf('/');
  -            if ( pos == -1 ) {
  -                throw new ProcessingException("Namespace " + this.namespace + " does not have a version number.");
  -            }
  -            if ( !this.namespace.substring(0, pos).equals("http://apache.org/cocoon/sitemap") ) {
  -                throw new ProcessingException("Namespace " + this.namespace + " is not a valid sitemap namespace.");
  -            }
  -            return build(treeConfig, this.namespace.substring(pos+1));
  -        } catch (ProcessingException e) {
  -            throw e;
  -        } catch(Exception e) {
  -            throw new ProcessingException("Failed to load sitemap from " +
  -                source.getURI(), e);
  -        }
  -    }
  -
       /**
        * Build a processing tree from a <code>Configuration</code>.
        */
  -    protected ProcessingNode build(Configuration tree, String sitemapVersion) throws Exception {
  -
  -        this.processorRoleManager = createRoleManager();
  +    public ProcessingNode build(Configuration tree) throws Exception {
  +        
  +        // The namespace use in the whole sitemap is the one of the root element
  +        this.namespace = tree.getNamespace();
   
           this.processorManager = createServiceManager(tree);
   
  @@ -413,12 +336,10 @@
           this.lifecycle = new LifecycleHelper(getLogger(),
               this.context,
               this.processorManager,
  -            this.processorRoleManager,
  +            this.ownRoleManager,
               null // configuration
           );
   
  -        this.builderSelector = createBuilderSelector(sitemapVersion);
  -
           // Calls to getRegisteredNode() are forbidden
           this.canGetNode = false;
   
  @@ -565,19 +486,27 @@
       }
       
       public void recycle() {
  +        
  +        // Reset all data created during the build
  +        this.attributes.clear();
  +        this.canGetNode = false;
  +        this.disposableNodes = new ArrayList(); // Must not be cleared as it's used for processor disposal
  +        this.initializableNodes.clear();
  +        this.lifecycle = null; // Created in build()
  +        this.linkedBuilders.clear();
  +        this.namespace = null; // Set in build()
  +        this.parentProcessorManager = null; // Set in setParentProcessorManager()
  +        this.processor = null; // Set in setProcessor()
  +        this.processorManager = null; // Set in build()
  +        this.registeredNodes.clear();
  +
           this.lifecycle = null; // Created in build()
           this.initializableNodes.clear();
           this.linkedBuilders.clear();
           this.canGetNode = false;
           this.registeredNodes.clear();
   
  -        // Don't clear disposableNodes as they're used by the Processor
  -        this.disposableNodes = new ArrayList();
           VariableResolverFactory.setDisposableCollector(null);
  -
  -        this.processor = null;
  -        this.processorManager = null;
  -        this.processorRoleManager = null;
       }
   
       public void dispose() {
  
  
  
  1.2       +1 -15     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
  
  Index: ProcessorComponentInfo.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProcessorComponentInfo.java	15 Jul 2004 12:49:50 -0000	1.1
  +++ ProcessorComponentInfo.java	16 Jul 2004 12:36:45 -0000	1.2
  @@ -42,12 +42,6 @@
       /** Lock that prevents further modification */
       private boolean locked = false;
       
  -//    /**
  -//     * Does this processor have mount instructions? If yes, we must keep this data to
  -//     * build child processors, else we can discard it.
  -//     */
  -//    private boolean hasMount;
  -    
       /**
        * Component-related data (see methods below for key names). We use a single Map
        * to reduce memory usage, as each kind of data has a limited number of entries.
  @@ -66,14 +60,6 @@
       public ServiceManager getServiceManager() {
           return this.manager;
       }
  -    
  -//    public void foundMountInstruction() {
  -//        this.hasMount = true;
  -//    }
  -//    
  -//    public boolean hasMountInstruction() {
  -//        return this.hasMount;
  -//    }
       
       /** Store some data, creating the storage map if needed */
       private void setData(String key, Object value) {
  
  
  
  1.6       +27 -37    cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/SimpleSelectorProcessingNode.java
  
  Index: SimpleSelectorProcessingNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/SimpleSelectorProcessingNode.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleSelectorProcessingNode.java	15 Jul 2004 12:49:50 -0000	1.5
  +++ SimpleSelectorProcessingNode.java	16 Jul 2004 12:36:45 -0000	1.6
  @@ -23,6 +23,7 @@
   import org.apache.avalon.framework.thread.ThreadSafe;
   
   /**
  + * Base class for processing nodes that are based on a component in a Selector (act, match, select, etc).
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
    * @version CVS $Id$
  @@ -37,7 +38,7 @@
       private ServiceManager manager;
       
       /** Selector where to get components from */
  -    protected ServiceSelector selector;
  +    private ServiceSelector selector;
       
       /** The underlying component, if it's threadsafe. Null otherwise */
       private Object threadSafeComponent;
  @@ -60,44 +61,33 @@
           }
       }
       
  -    protected boolean hasThreadSafeComponent() {
  -        return this.threadSafeComponent != null;
  +    /**
  +     * Get the component to be used by this node. That component may be cached for faster
  +     * execution if it's ThreadSafe. In any case, a call to {@link #releaseComponent(Object)} must
  +     * be done to release the component if needed.
  +     * 
  +     * @return the component to use
  +     * @throws ServiceException if component lookup fails
  +     */
  +    protected Object getComponent() throws ServiceException {
  +        if (this.threadSafeComponent != null) {
  +            return this.threadSafeComponent;
  +        } else {
  +            return this.selector.select(this.componentName);
  +        }
       }
       
  -    protected Object getThreadSafeComponent() {
  -        return this.threadSafeComponent;
  +    /**
  +     * Release the component used by this node (does nothing if it's the cached
  +     * ThreadSafe component)
  +     * 
  +     * @param obj the component
  +     */
  +    protected void releaseComponent(Object obj) {
  +        if (obj != this.threadSafeComponent) {
  +            this.selector.release(obj);
  +        }
       }
  -
  -//    public void setSelector(ServiceSelector selector) {
  -//        this.selector = selector;
  -//    }
  -
  -//    /**
  -//     * Tests if the component designated by this node using the selector and component name
  -//     * is <code>ThreadSafe</code>, and return it if true.
  -//     * <p>
  -//     * Note : this method must be called <i>after</i> <code>setSelector()</code>.
  -//     */
  -//    protected Object getThreadSafeComponent() throws ServiceException {
  -//        return getThreadSafeComponent(this.componentName);
  -//    }
  -//
  -//    /**
  -//     * Tests if the component designated by this node using the selector and component name
  -//     * is <code>ThreadSafe</code>, and return it if true.
  -//     * <p>
  -//     * Note : this method must be called <i>after</i> <code>setSelector()</code>.
  -//     * @throws ServiceException
  -//     */
  -//    protected Object getThreadSafeComponent(String name) throws ServiceException {
  -//        Object component = this.selector.select(name);
  -//        if (component instanceof ThreadSafe) {
  -//            return component;
  -//        } else {
  -//            this.selector.release(component);
  -//            return null;
  -//        }
  -//    }
       
       public void dispose() {
           this.selector.release(this.threadSafeComponent);
  
  
  
  1.8       +5 -4      cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java
  
  Index: TreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TreeBuilder.java	15 Jul 2004 12:49:50 -0000	1.7
  +++ TreeBuilder.java	16 Jul 2004 12:36:45 -0000	1.8
  @@ -21,7 +21,6 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.excalibur.source.Source;
   
   /**
    *
  @@ -30,6 +29,8 @@
    */
   
   public interface TreeBuilder extends Component {
  +    
  +    final static String ROLE = TreeBuilder.class.getName();
   
       void setProcessor(ConcreteTreeProcessor processor);
       
  @@ -57,9 +58,9 @@
       String getNamespace();
   
       /**
  -     * Build a processing tree from a <code>Source</code>.
  +     * Build a processing tree from a <code>Configuration</code> object holding the sitemap program.
        */
  -    ProcessingNode build(Source source) throws Exception;
  +    ProcessingNode build(Configuration config) throws Exception;
   
       /**
        * Return the list of <code>ProcessingNodes</code> part of this tree that are
  
  
  
  1.40      +68 -56    cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- TreeProcessor.java	15 Jul 2004 12:49:50 -0000	1.39
  +++ TreeProcessor.java	16 Jul 2004 12:36:45 -0000	1.40
  @@ -19,12 +19,12 @@
   
   import org.apache.avalon.excalibur.component.RoleManageable;
   import org.apache.avalon.excalibur.component.RoleManager;
  -import org.apache.avalon.excalibur.pool.Recyclable;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.configuration.NamespacedSAXConfigurationHandler;
   import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
  @@ -37,13 +37,13 @@
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.Processor;
   import org.apache.cocoon.components.ContextHelper;
  -import org.apache.cocoon.components.LifecycleHelper;
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.internal.EnvironmentHelper;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceResolver;
  +import org.apache.regexp.RE;
   
   /**
    * Interpreted tree-traversal implementation of a pipeline assembly language.
  @@ -78,9 +78,6 @@
       /** The root role manager */
       protected RoleManager rootRoleManager;
   
  -    /** Sitemap TreeBuilder */
  -    protected TreeBuilder treeBuilder;
  -
       /** Last modification time */
       protected long lastModified = 0;
   
  @@ -90,12 +87,9 @@
       /** Delay for <code>sourceLastModified</code>. */
       protected long lastModifiedDelay;
   
  -    /** The current language configuration */
  -    protected Configuration currentLanguage;
  -
       /** The file to process */
       protected String fileName;
  -
  +    
       /** Check for reload? */
       protected boolean checkReload;
   
  @@ -146,7 +140,6 @@
           ContainerUtil.enableLogging(this.environmentHelper, this.getLogger());
           ContainerUtil.service(this.environmentHelper, this.parentServiceManager);
           this.environmentHelper.changeContext(sitemapSource, prefix);
  -        this.createTreeBuilder();
       }
   
       /**
  @@ -225,31 +218,6 @@
               throw new ConfigurationException(msg, e);
           }
   
  -        this.createTreeBuilder();
  -    }
  -
  -    /**
  -     * Create a new tree builder for this sitemap
  -     */
  -    protected void createTreeBuilder()
  -    throws ConfigurationException {
  -        // Create a builder for the sitemap language
  -        try {
  -            this.treeBuilder = (TreeBuilder)Thread.currentThread()
  -                    .getContextClassLoader()
  -                    .loadClass("org.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage").newInstance();
  -
  -            LifecycleHelper.setupComponent(this.treeBuilder,
  -                                           getLogger(),
  -                                           this.context,
  -                                           this.parentServiceManager,
  -                                           this.rootRoleManager,
  -                                           this.treeBuilderConfiguration);
  -        } catch(ConfigurationException ce) {
  -            throw ce;
  -        } catch(Exception e) {
  -            throw new ConfigurationException("Could not setup sitemap builder.", e);
  -        }
       }
   
       /**
  @@ -331,7 +299,41 @@
       public EnvironmentHelper getEnvironmentHelper() {
           return this.environmentHelper;
       }
  +    
  +    /**
  +     * Get the tree builder role from the sitemap program (as a configuration object).
  +     * This method should report very any problem very clearly, as it is the entry point of any
  +     * Cocoon application.
  +     * 
  +     * @param sitemapProgram the sitemap
  +     * @return the treebuilder role
  +     * @throws ConfigurationException if a suitable role could not be found
  +     */
  +    private TreeBuilder getTreeBuilder(Configuration sitemapProgram) throws ConfigurationException {
  +        
  +        String ns = sitemapProgram.getNamespace();
  +        
  +        RE re = new RE("http://apache.org/cocoon/sitemap/(\\d\\.\\d)");
  +        
  +        if (!re.match(ns)) {
  +            throw new ConfigurationException("Unknown sitemap namespace (" + ns + ") at " +
  +                    this.source.getURI());
  +        }
  +        
  +        String version = re.getParen(1);
  +        String result = TreeBuilder.ROLE + "/sitemap-" + version;
  +        
  +        try {
  +            return (TreeBuilder)this.parentServiceManager.lookup(result);
  +        } catch(Exception ex) {
  +            throw new ConfigurationException("This version of Cocoon does not handle sitemap version " +
  +                    version + " at " + this.source.getURI(), ex);
  +        }
  +    }
   
  +    /**
  +     * Sets up the concrete processor, building or rebuilding it if necessary.
  +     */
       private void setupConcreteProcessor(Environment env) throws Exception {
           // first, check for sitemap changes
           if (this.concreteProcessor == null ||
  @@ -340,6 +342,10 @@
           }
       }
   
  +    /**
  +     * Build the concrete processor (i.e. loads the sitemap). Should be called
  +     * only by setupProcessor();
  +     */
       private synchronized void buildConcreteProcessor(Environment env) throws Exception {
   
           // Now that we entered the synchronized area, recheck what's already
  @@ -350,12 +356,9 @@
           }
   
           long startTime = System.currentTimeMillis();
  -
  -        // Get a builder
  -        ConcreteTreeProcessor newProcessor = new ConcreteTreeProcessor(this);
           long newLastModified;
  -        this.setupLogger(newProcessor);
  -
  +        ConcreteTreeProcessor newProcessor;
  +        
           // We have to do a call to enterProcessor() here as during building
           // of the tree, components (e.g. actions) are already instantiated
           // (ThreadSafe ones mostly).
  @@ -363,34 +366,46 @@
           // current service manager they must get this one - which is currently
           // in the process of initialization.
           EnvironmentHelper.enterProcessor(this, this.parentServiceManager, env);
  +        
           try {
  -            if (this.treeBuilder instanceof Recyclable) {
  -                ((Recyclable)this.treeBuilder).recycle();
  -            }
               
  -            this.treeBuilder.setProcessor(newProcessor);
  -            this.treeBuilder.setParentProcessorManager(this.parentServiceManager);
  +            // Load the sitemap file
               if (this.fileName == null) {
                   this.fileName = "sitemap.xmap";
               }
  -
               if (this.source == null) {
                   this.source = new DelayedRefreshSourceWrapper(this.resolver.resolveURI(this.fileName),
                                                                 lastModifiedDelay);
               }
  -
  +            
  +            // Build a namespace-aware configuration object
  +            NamespacedSAXConfigurationHandler handler = new NamespacedSAXConfigurationHandler();
  +            SourceUtil.toSAX(this.source, handler );
  +            Configuration sitemapProgram = handler.getConfiguration();
               newLastModified = this.source.getLastModified();
  -
  -            ProcessingNode root = this.treeBuilder.build(this.source);
  -
  -            newProcessor.setProcessorData(root, this.treeBuilder.getDisposableNodes());
               
  +            newProcessor = new ConcreteTreeProcessor(this);
  +            this.setupLogger(newProcessor);
  +    
  +            // Get the treebuilder that can handle this version of the sitemap.
  +            TreeBuilder treeBuilder = getTreeBuilder(sitemapProgram);
  +    
  +            try {
  +                treeBuilder.setProcessor(newProcessor);
  +                treeBuilder.setParentProcessorManager(this.parentServiceManager);
  +    
  +                ProcessingNode root = treeBuilder.build(sitemapProgram);
  +                newProcessor.setProcessorData(root, treeBuilder.getDisposableNodes());
  +
  +            } finally {
  +                this.parentServiceManager.release(treeBuilder);                
  +            }                
           } finally {
               EnvironmentHelper.leaveProcessor();
           }
   
           if (getLogger().isDebugEnabled()) {
  -            double time = (this.lastModified - startTime) / 1000.0;
  +            double time = (System.currentTimeMillis() - startTime) / 1000.0;
               getLogger().debug("TreeProcessor built in " + time + " secs from " + source.getURI());
           }
   
  @@ -414,9 +429,6 @@
           // are none when a TreeProcessor is disposed.
           ContainerUtil.dispose(this.concreteProcessor);
           this.concreteProcessor = null;
  -
  -        ContainerUtil.dispose(this.treeBuilder);
  -        this.treeBuilder = null;
   
           if (this.parentServiceManager != null) {
               if (this.source != null) {
  
  
  
  1.2       +2 -84     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap-language.xml
  
  Index: sitemap-language.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap-language.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sitemap-language.xml	9 Jun 2004 09:41:15 -0000	1.1
  +++ sitemap-language.xml	16 Jul 2004 12:36:45 -0000	1.2
  @@ -16,19 +16,7 @@
   -->
   
   <!DOCTYPE sitemap-language [
  -  <!ELEMENT sitemap-language (parameter, roles, nodes)>
  -  <!ELEMENT roles (role+)>
  -  <!ELEMENT role (hint*)>
  -  <!ATTLIST role
  -    name CDATA #REQUIRED
  -    shorthand CDATA #REQUIRED
  -    default-class CDATA #REQUIRED
  -  >
  -  <!ELEMENT hint EMPTY>
  -  <!ATTLIST hint
  -    shorthand CDATA #REQUIRED
  -    class CDATA #REQUIRED
  -  >
  +  <!ELEMENT sitemap-language (nodes)>
     <!ELEMENT nodes (node+)>
     <!ELEMENT node (allowed-children*, ignored-children*, forbidden-children*)>
     <!ATTLIST node
  @@ -42,77 +30,7 @@
   
   <sitemap-language>
   
  -    <!-- New roles available to components created within a sitemap (i.e. in <map:components>) -->
  -    <roles>
  -      <role name="org.apache.cocoon.acting.ActionSelector"
  -            shorthand="actions"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  -      
  -      <role name="org.apache.cocoon.selection.SelectorSelector"
  -            shorthand="selectors"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  -      
  -      <role name="org.apache.cocoon.components.pipeline.ProcessingPipelineSelector"
  -            shorthand="pipes"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  -
  -      <role name="org.apache.cocoon.matching.MatcherSelector"
  -            shorthand="matchers"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector">
  -
  -        <!-- since <map:components> is a regular xconf, we can define shorthand for
  -             well-known implementations.
  -             
  -             The hint below allows the following to be written in <map:matchers> :
  -               <regexp-uri-matcher name="regexp"/>
  -             in place of :
  -               <map:matcher name="regexp" src="org.apache.cocoon.matching.RegexpURIMatcher"/>
  -          -->
  -        <hint shorthand="regexp-uri-matcher"
  -              class="org.apache.cocoon.matching.RegexpURIMatcher"/>
  -
  -        <hint shorthand="wildcard-uri-matcher"
  -              class="org.apache.cocoon.matching.WildcardURIMatcher"/>
  -
  -      </role>
  -      
  -      <role name="org.apache.cocoon.generation.GeneratorSelector"
  -            shorthand="generators"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector">
  -
  -        <hint shorthand="file-generator"
  -              class="org.apache.cocoon.generation.FileGenerator"/>
  -
  -      </role>
  -      
  -      <role name="org.apache.cocoon.transformation.TransformerSelector"
  -            shorthand="transformers"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector">
  -
  -        <hint shorthand="XSLT-transformer"
  -              class="org.apache.cocoon.transformation.TraxTransformer"/>
  -
  -        <hint shorthand="cinclude-transformer"
  -              class="org.apache.cocoon.transformation.CIncludeTransformer"/>
  -
  -      </role>
  -      
  -      <role name="org.apache.cocoon.serialization.SerializerSelector"
  -            shorthand="serializers"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  -      
  -      <role name="org.apache.cocoon.reading.ReaderSelector"
  -            shorthand="readers"
  -            default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/>
  -          
  -      <role name="org.apache.cocoon.components.notification.NotifyingBuilder"
  -            shorthand="notifying-builder"
  -            default-class="org.apache.cocoon.components.notification.DefaultNotifyingBuilder"/>  
  -
  -    </roles>
  -    
  -    <!-- node definitions for the sitemap language 
  -         that apply to all version -->
  +    <!-- node definitions for the sitemap language -->
       <nodes>
         <!-- A node has the following attributes :
              - name : the node name, given as a local name in the language namespace (no prefix)
  
  
  
  1.11      +7 -18     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActTypeNode.java
  
  Index: ActTypeNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActTypeNode.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ActTypeNode.java	15 Jul 2004 12:49:50 -0000	1.10
  +++ ActTypeNode.java	16 Jul 2004 12:36:45 -0000	1.11
  @@ -98,28 +98,17 @@
               }
           }
   
  -        // If action is ThreadSafe, avoid select() and try/catch block (faster !)
  -        if (this.hasThreadSafeComponent()) {
  -            actionResult = this.executor.invokeAction(this, 
  +        Action action = (Action)getComponent();
  +        try {
  +            actionResult = this.executor.invokeAction(this,
                                                objectModel, 
  -                                             (Action)this.getThreadSafeComponent(), 
  +                                             action, 
                                                redirector, 
                                                resolver, 
                                                resolvedSource, 
                                                resolvedParams);
  -        } else {
  -            Action action = (Action)this.selector.select(this.componentName);
  -            try {
  -                actionResult = this.executor.invokeAction(this,
  -                                                 objectModel, 
  -                                                 action, 
  -                                                 redirector, 
  -                                                 resolver, 
  -                                                 resolvedSource, 
  -                                                 resolvedParams);
  -            } finally {
  -                this.selector.release(action);
  -            }
  +        } finally {
  +            releaseComponent(action);
           }
   
           if (redirector.hasRedirected()) {
  
  
  
  1.13      +1 -5      cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
  
  Index: ComponentsSelector.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ComponentsSelector.java	15 Jul 2004 12:49:50 -0000	1.12
  +++ ComponentsSelector.java	16 Jul 2004 12:36:45 -0000	1.13
  @@ -15,11 +15,8 @@
    */
   package org.apache.cocoon.components.treeprocessor.sitemap;
   
  -import java.util.HashMap;
   import java.util.HashSet;
  -import java.util.Map;
   import java.util.Set;
  -import java.util.StringTokenizer;
   
   import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.avalon.framework.component.ComponentException;
  @@ -28,7 +25,6 @@
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.cocoon.acting.Action;
   import org.apache.cocoon.components.ExtendedComponentSelector;
  -import org.apache.cocoon.components.container.ComponentLocatorImpl;
   import org.apache.cocoon.components.pipeline.ProcessingPipeline;
   import org.apache.cocoon.generation.Generator;
   import org.apache.cocoon.matching.Matcher;
  
  
  
  1.6       +9 -19     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MatchNode.java
  
  Index: MatchNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MatchNode.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MatchNode.java	15 Jul 2004 12:49:50 -0000	1.5
  +++ MatchNode.java	16 Jul 2004 12:36:45 -0000	1.6
  @@ -66,25 +66,15 @@
   
           Map result = null;
   
  -        if (this.hasThreadSafeComponent()) {
  -            // Avoid select() and try/catch block (faster !)
  +        Matcher matcher = (Matcher)getComponent();
  +        try {
               result = this.executor.invokeMatcher(this, 
  -                                                 objectModel, 
  -                                                 (Matcher)this.getThreadSafeComponent(), 
  -                                                 resolvedPattern, 
  -                                                 resolvedParams);
  -        } else {
  -            // Get matcher from selector
  -            Matcher matcher = (Matcher)this.selector.select(this.componentName);
  -            try {
  -                result = this.executor.invokeMatcher(this, 
  -                        objectModel, 
  -                        matcher, 
  -                        resolvedPattern, 
  -                        resolvedParams);
  -            } finally {
  -                this.selector.release(matcher);
  -            }
  +                    objectModel, 
  +                    matcher, 
  +                    resolvedPattern, 
  +                    resolvedParams);
  +        } finally {
  +            releaseComponent(matcher);
           }
   
           if (result != null) {
  
  
  
  1.9       +9 -16     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java
  
  Index: PreparableMatchNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PreparableMatchNode.java	15 Jul 2004 12:49:50 -0000	1.8
  +++ PreparableMatchNode.java	16 Jul 2004 12:36:45 -0000	1.9
  @@ -66,7 +66,7 @@
       public void initialize() throws Exception {
   
           // Prepare the pattern
  -        PreparableMatcher matcher = (PreparableMatcher)selector.select(componentName);
  +        PreparableMatcher matcher = (PreparableMatcher)getComponent();
   
           try {
               this.preparedPattern = matcher.preparePattern(this.pattern);
  @@ -74,7 +74,7 @@
               String msg = "Invalid pattern '" + this.pattern + "' for matcher at " + this.getLocation();
               throw new ConfigurationException(msg, pe);
           } finally {
  -            selector.release(matcher);
  +            releaseComponent(matcher);
           }
       }
   
  @@ -94,19 +94,12 @@
   
           Map result = null;
   
  -        if (this.getThreadSafeComponent() != null) {
  -            // Avoid select() and try/catch block (faster !)
  -            result = ((PreparableMatcher)this.getThreadSafeComponent()).preparedMatch(preparedPattern, objectModel, resolvedParams);
  -
  -        } else {
  -            // Get matcher from selector
  -            PreparableMatcher matcher = (PreparableMatcher)this.selector.select(this.componentName);
  -            try {
  -                result = matcher.preparedMatch(preparedPattern, objectModel, resolvedParams);
  -
  -            } finally {
  -                this.selector.release(matcher);
  -            }
  +        PreparableMatcher matcher = (PreparableMatcher)getComponent();
  +        try {
  +            result = matcher.preparedMatch(preparedPattern, objectModel, resolvedParams);
  +
  +        } finally {
  +            releaseComponent(matcher);
           }
   
           if (result != null) {
  
  
  
  1.6       +6 -26     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java
  
  Index: SelectNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SelectNode.java	15 Jul 2004 12:49:50 -0000	1.5
  +++ SelectNode.java	16 Jul 2004 12:36:45 -0000	1.6
  @@ -74,12 +74,12 @@
           final Map objectModel = env.getObjectModel();
           final Parameters resolvedParams = VariableResolver.buildParameters(this.parameters, context, objectModel);
   
  -        // If selector is ThreadSafe, avoid select() and try/catch block (faster !)
  -        if (this.getThreadSafeComponent() != null) {
  +        final Selector selector = (Selector)getComponent();
  +        try {
   
               for (int i = 0; i < this.whenTests.length; i++) {
                   if ( this.executor.invokeSelector(this, objectModel,
  -                        (Selector)this.getThreadSafeComponent(),
  +                        selector,
                           whenTests[i].resolve(context, objectModel),
                           resolvedParams)) {
                       return invokeNodes(this.whenNodes[i], env, context);
  @@ -91,28 +91,8 @@
               }
   
               return false;
  -
  -        } else {
  -            final Selector selector = (Selector)this.selector.select(this.componentName);
  -            try {
  -
  -                for (int i = 0; i < this.whenTests.length; i++) {
  -                    if ( this.executor.invokeSelector(this, objectModel,
  -                            selector,
  -                            whenTests[i].resolve(context, objectModel),
  -                            resolvedParams)) {
  -                        return invokeNodes(this.whenNodes[i], env, context);
  -                    }
  -                }
  -
  -                if (this.otherwhiseNodes != null) {
  -                    return invokeNodes(this.otherwhiseNodes, env, context);
  -                }
  -
  -                return false;
  -            } finally {
  -                this.selector.release(selector);
  -            }
  +        } finally {
  +            releaseComponent(selector);
           }
       }
   }
  
  
  
  1.4       +4 -5      cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java
  
  Index: SelectNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SelectNodeBuilder.java	15 Jul 2004 12:49:50 -0000	1.3
  +++ SelectNodeBuilder.java	16 Jul 2004 12:36:45 -0000	1.4
  @@ -15,6 +15,9 @@
    */
   package org.apache.cocoon.components.treeprocessor.sitemap;
   
  +import java.util.ArrayList;
  +import java.util.List;
  +
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.service.ServiceSelector;
  @@ -22,12 +25,8 @@
   import org.apache.cocoon.components.treeprocessor.ProcessingNode;
   import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
   import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
  -import org.apache.cocoon.matching.Matcher;
   import org.apache.cocoon.selection.Selector;
   import org.apache.cocoon.selection.SwitchSelector;
  -
  -import java.util.ArrayList;
  -import java.util.List;
   
   /**
    *
  
  
  
  1.5       +4 -6      cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
  
  Index: SerializeNodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SerializeNodeBuilder.java	15 Jul 2004 12:49:50 -0000	1.4
  +++ SerializeNodeBuilder.java	16 Jul 2004 12:36:45 -0000	1.5
  @@ -15,17 +15,15 @@
    */
   package org.apache.cocoon.components.treeprocessor.sitemap;
   
  +import java.util.Collection;
  +import java.util.Map;
  +
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
   import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
   import org.apache.cocoon.components.treeprocessor.ProcessingNode;
   import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
  -
  -import org.apache.cocoon.reading.Reader;
   import org.apache.cocoon.serialization.Serializer;
  -
  -import java.util.Collection;
  -import java.util.Map;
   
   /**
    *
  
  
  
  1.14      +7 -13     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
  
  Index: SitemapLanguage.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SitemapLanguage.java	15 Jul 2004 12:49:50 -0000	1.13
  +++ SitemapLanguage.java	16 Jul 2004 12:36:45 -0000	1.14
  @@ -79,21 +79,15 @@
               config = new DefaultConfiguration("", "");
           }
   
  -        CocoonComponentManager newManager = new CocoonComponentManager(new WrapperComponentManager(this.parentProcessorManager));
  +        final LoggerManager loggerManager = (LoggerManager) this.parentProcessorManager.lookup(LoggerManager.ROLE);
   
  +        CocoonComponentManager newManager = new CocoonComponentManager(new WrapperComponentManager(this.parentProcessorManager));
  +        
  +        // Go through the component lifecycle
           newManager.enableLogging(getLogger());
  -
  -        final LoggerManager loggerManager = (LoggerManager) this.parentProcessorManager.lookup(LoggerManager.ROLE);
           newManager.setLoggerManager(loggerManager);
  -
  -        if (null != this.context ) {
  -            newManager.contextualize(this.context);
  -        }
  -
  -        if (null != this.processorRoleManager) {
  -            newManager.setRoleManager(this.processorRoleManager);
  -        }
  -
  +        newManager.contextualize(this.context);
  +        newManager.setRoleManager(this.ownRoleManager);
           newManager.configure(config);
           newManager.initialize();
   
  
  
  
  1.8       +12 -37    cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SwitchSelectNode.java
  
  Index: SwitchSelectNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SwitchSelectNode.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SwitchSelectNode.java	15 Jul 2004 12:49:50 -0000	1.7
  +++ SwitchSelectNode.java	16 Jul 2004 12:36:45 -0000	1.8
  @@ -72,19 +72,18 @@
           final Map objectModel = env.getObjectModel();
           Parameters resolvedParams = VariableResolver.buildParameters(this.parameters, context, objectModel);
   
  -        // If selector is ThreadSafe, avoid select() and try/catch block (faster !)
  -        if (this.hasThreadSafeComponent()) {
  -
  -            SwitchSelector switchSelector = (SwitchSelector)this.getThreadSafeComponent();
  -            Object ctx = switchSelector.getSelectorContext(objectModel, resolvedParams);
  +        SwitchSelector switchSelector = (SwitchSelector)getComponent();
   
  +        Object ctx = switchSelector.getSelectorContext(objectModel, resolvedParams);
  +       
  +        try {
               for (int i = 0; i < this.whenTests.length; i++) {
                   if (this.executor.invokeSwitchSelector(this, 
  -                                                       objectModel, 
  -                                                       switchSelector, 
  -                                                       whenTests[i].resolve(context, objectModel), 
  -                                                       resolvedParams, 
  -                                                       ctx)) {
  +                        objectModel, 
  +                        switchSelector, 
  +                        whenTests[i].resolve(context, objectModel), 
  +                        resolvedParams, 
  +                        ctx)) {
                       return invokeNodes(this.whenNodes[i], env, context);
                   }
               }
  @@ -94,32 +93,8 @@
               }
   
               return false;
  -
  -        } else {
  -            SwitchSelector switchSelector = (SwitchSelector)this.selector.select(this.componentName);
  -
  -            Object ctx = switchSelector.getSelectorContext(objectModel, resolvedParams);
  -           
  -            try {
  -                for (int i = 0; i < this.whenTests.length; i++) {
  -                    if (this.executor.invokeSwitchSelector(this, 
  -                            objectModel, 
  -                            switchSelector, 
  -                            whenTests[i].resolve(context, objectModel), 
  -                            resolvedParams, 
  -                            ctx)) {
  -                        return invokeNodes(this.whenNodes[i], env, context);
  -                    }
  -                }
  -
  -                if (this.otherwhiseNodes != null) {
  -                    return invokeNodes(this.otherwhiseNodes, env, context);
  -                }
  -
  -                return false;
  -            } finally {
  -                this.selector.release(selector);
  -            }
  +        } finally {
  +            releaseComponent(switchSelector);
           }
       }
   }
  
  
  
  1.9       +19 -21    cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java
  
  Index: ProfilingCachingProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ProfilingCachingProcessingPipeline.java	25 May 2004 07:28:24 -0000	1.8
  +++ ProfilingCachingProcessingPipeline.java	16 Jul 2004 12:36:45 -0000	1.9
  @@ -18,9 +18,9 @@
   import java.io.IOException;
   import java.util.Iterator;
   
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.pipeline.impl.CachingProcessingPipeline;
   import org.apache.cocoon.environment.Environment;
  @@ -50,9 +50,9 @@
        *
        * @param manager    
        */
  -    public void compose(ComponentManager manager) throws ComponentException {
  +    public void service(ServiceManager manager) throws ServiceException {
   
  -        super.compose(manager);
  +        super.service(manager);
           this.profiler = (Profiler) manager.lookup(Profiler.ROLE);
       }
   
  @@ -211,24 +211,22 @@
               }
               this.data.setSetupTime(index++, System.currentTimeMillis()-time);
   
  -            String mimeType = this.serializer.getMimeType();
  -
  -            if (mimeType!=null) {
  -                // we have a mimeType from the component itself
  -                environment.setContentType(mimeType);
  -            } else if (serializerMimeType!=null) {
  -                // there was a mimeType specified in the sitemap pipeline
  +            // Set the mime-type
  +            // the behaviour has changed from 2.1.x to 2.2 according to bug #10277
  +            if (serializerMimeType != null) {
  +                // there was a serializer defined in the sitemap
                   environment.setContentType(serializerMimeType);
  -            } else if (this.sitemapSerializerMimeType!=null) {
  -                // use the mimeType specified in the sitemap component declaration
  -                environment.setContentType(this.sitemapSerializerMimeType);
               } else {
  -                // No mimeType available
  -                String message = "Unable to determine MIME type for "+
  -                                 environment.getURIPrefix()+"/"+
  -                                 environment.getURI();
  -
  -                throw new ProcessingException(message);
  +                // ask to the component itself
  +                String mimeType = this.serializer.getMimeType();
  +                if (mimeType != null) {
  +                    environment.setContentType (mimeType);
  +                } else {
  +                    // No mimeType available
  +                    String message = "Unable to determine MIME type for " +
  +                        environment.getURIPrefix() + "/" + environment.getURI();
  +                    throw new ProcessingException(message);
  +                }
               }
           } catch (SAXException e) {
               throw new ProcessingException("Could not setup pipeline.", e);
  
  
  
  1.9       +19 -21    cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
  
  Index: ProfilingNonCachingProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ProfilingNonCachingProcessingPipeline.java	25 May 2004 07:28:24 -0000	1.8
  +++ ProfilingNonCachingProcessingPipeline.java	16 Jul 2004 12:36:45 -0000	1.9
  @@ -19,9 +19,9 @@
   import java.util.Iterator;
   
   import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline;
   import org.apache.cocoon.environment.Environment;
  @@ -55,9 +55,9 @@
        *
        * @param manager
        */
  -    public void compose(ComponentManager manager) throws ComponentException {
  +    public void service(ServiceManager manager) throws ServiceException {
   
  -        super.compose(manager);
  +        super.service(manager);
           this.profiler = (Profiler) manager.lookup(Profiler.ROLE);
       }
   
  @@ -215,24 +215,22 @@
               }
               this.data.setSetupTime(index++, System.currentTimeMillis()-time);
   
  -            String mimeType = this.serializer.getMimeType();
  -
  -            if (mimeType!=null) {
  -                // we have a mimeType from the component itself
  -                environment.setContentType(mimeType);
  -            } else if (serializerMimeType!=null) {
  -                // there was a mimeType specified in the sitemap pipeline
  +            // Set the mime-type
  +            // the behaviour has changed from 2.1.x to 2.2 according to bug #10277
  +            if (serializerMimeType != null) {
  +                // there was a serializer defined in the sitemap
                   environment.setContentType(serializerMimeType);
  -            } else if (this.sitemapSerializerMimeType!=null) {
  -                // use the mimeType specified in the sitemap component declaration
  -                environment.setContentType(this.sitemapSerializerMimeType);
               } else {
  -                // No mimeType available
  -                String message = "Unable to determine MIME type for "+
  -                                 environment.getURIPrefix()+"/"+
  -                                 environment.getURI();
  -
  -                throw new ProcessingException(message);
  +                // ask to the component itself
  +                String mimeType = this.serializer.getMimeType();
  +                if (mimeType != null) {
  +                    environment.setContentType (mimeType);
  +                } else {
  +                    // No mimeType available
  +                    String message = "Unable to determine MIME type for " +
  +                        environment.getURIPrefix() + "/" + environment.getURI();
  +                    throw new ProcessingException(message);
  +                }
               }
           } catch (SAXException e) {
               throw new ProcessingException("Could not setup pipeline.", e);
  
  
  
  1.6       +4 -4      cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/pipeline/impl/ExpiresCachingProcessingPipeline.java
  
  Index: ExpiresCachingProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/pipeline/impl/ExpiresCachingProcessingPipeline.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ExpiresCachingProcessingPipeline.java	15 Apr 2004 08:05:55 -0000	1.5
  +++ ExpiresCachingProcessingPipeline.java	16 Jul 2004 12:36:45 -0000	1.6
  @@ -20,9 +20,9 @@
   import java.net.SocketException;
   import java.util.Map;
   
  -import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceException;
   import org.apache.cocoon.ConnectionResetException;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CachedResponse;
  @@ -182,7 +182,7 @@
                           super.connectPipeline( environment );
           
                           this.lastConsumer = old;
  -                    } catch ( ComponentException e ) {
  +                    } catch ( ServiceException e ) {
                           throw new ProcessingException("Could not connect pipeline.", e);
                       }
                   } else {
  @@ -192,7 +192,7 @@
                   // we use the cache, so we need an xml deserializer
                   try {
                       this.xmlDeserializer = (XMLDeserializer)this.manager.lookup(XMLDeserializer.ROLE);
  -                } catch ( ComponentException e ) {
  +                } catch ( ServiceException e ) {
                       throw new ProcessingException("Could not connect pipeline.", e);
                   }
               }
  
  
  
  1.6       +14 -14    cocoon-2.1/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java
  
  Index: PreparedVariableResolverTestCase.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PreparedVariableResolverTestCase.java	6 May 2004 19:27:55 -0000	1.5
  +++ PreparedVariableResolverTestCase.java	16 Jul 2004 12:36:46 -0000	1.6
  @@ -50,7 +50,7 @@
           
           Map sitemapElements = new HashMap();
           context.pushMap("sitemap", sitemapElements);
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("123", resolver.resolve(context, getObjectModel()));
       }
   
  @@ -65,7 +65,7 @@
           Map sitemapElements = new HashMap();
           sitemapElements.put("1", "oo");
           context.pushMap("sitemap", sitemapElements);
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("123", resolver.resolve(context, getObjectModel()));
       }
       
  @@ -78,7 +78,7 @@
           Map sitemapElements = new HashMap();
           sitemapElements.put("name", "123");
           context.pushMap("label", sitemapElements);
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("123", resolver.resolve(context, getObjectModel()));        
       }
       
  @@ -91,7 +91,7 @@
           Map sitemapElements = new HashMap();
           sitemapElements.put("1", "abc");
           context.pushMap("label", sitemapElements);
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("123abc", resolver.resolve(context, getObjectModel()));
       }
   
  @@ -104,7 +104,7 @@
           Map sitemapElements = new HashMap();
           sitemapElements.put("1", "abc");
           context.pushMap("label", sitemapElements);
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("123abc/def", resolver.resolve(context, getObjectModel()));
       }
       
  @@ -117,7 +117,7 @@
           Map sitemapElements = new HashMap();
           sitemapElements.put("1", "abc");
           context.pushMap("label", sitemapElements);
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("123abc/def", resolver.resolve(context, getObjectModel()));
       }
   
  @@ -136,7 +136,7 @@
           sitemapElements.put("1", "oscar");
           context.pushMap("label2", sitemapElements);
   
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("from juliet to oscar", resolver.resolve(context, getObjectModel()));
       }
   
  @@ -155,7 +155,7 @@
           sitemapElements.put("1", "oscar");
           context.pushMap("label2", sitemapElements);
   
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("from juliet to oscar", resolver.resolve(context, getObjectModel()));
       }
       
  @@ -169,7 +169,7 @@
           sitemapElements = new HashMap();
           context.pushMap("label", sitemapElements);
           
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("http://cocoon.apache.org", resolver.resolve(context, getObjectModel()));
       }
       
  @@ -183,7 +183,7 @@
           sitemapElements = new HashMap();
           context.pushMap("label", sitemapElements);
           
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals(":colon-starts-this", resolver.resolve(context, getObjectModel()));
       }
       
  @@ -198,7 +198,7 @@
           sitemapElements.put("1", "abc");
           context.pushMap("label", sitemapElements);
           
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("abc:abc", resolver.resolve(context, getObjectModel()));
       }
   
  @@ -212,7 +212,7 @@
           sitemapElements = new HashMap();
           context.pushMap("label", sitemapElements);
   
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("This is a {brace}", resolver.resolve(context, getObjectModel()));
       }
   
  @@ -223,7 +223,7 @@
           
           Map sitemapElements = new HashMap();
           context.pushMap("sitemap", sitemapElements);
  -        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, manager);
  +        VariableResolver resolver = VariableResolverFactory.getResolver(expr, manager);
           assertEquals("", resolver.resolve(context, getObjectModel()));
       }
   }
  
  
  

Mime
View raw message