cziegeler    2003/03/19 07:21:19

  Modified:    src/java/org/apache/cocoon/components
                        ChainedConfiguration.java
                        CocoonComponentManager.java
  Log:
  Start refactoring SitemapConfigurable
  
  Revision  Changes    Path
  1.2       +220 -4    
cocoon-2.1/src/java/org/apache/cocoon/components/ChainedConfiguration.java
  
  Index: ChainedConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/ChainedConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ChainedConfiguration.java 19 Mar 2003 12:47:34 -0000      1.1
  +++ ChainedConfiguration.java 19 Mar 2003 15:21:19 -0000      1.2
  @@ -51,21 +51,237 @@
   package org.apache.cocoon.components;
   
   import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
   
   /**
    * This configuration object is used for [EMAIL PROTECTED] SitemapConfigurable} 
  - * components. It extends [EMAIL PROTECTED] Configuration} by a parent.
  + * components. It 'extends' [EMAIL PROTECTED] Configuration} by a parent.
    * 
    * @since 2.1
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Id$
    */
  -public interface ChainedConfiguration extends Configuration {
  +public final class ChainedConfiguration implements Configuration {
   
  +    private Configuration wrappedConfiguration;
  +    
  +    private ChainedConfiguration parentConfiguration;
  +    
  +    /**
  +     * Constructor
  +     */
  +    public ChainedConfiguration(Configuration wrapped,
  +                                 ChainedConfiguration parent) {
  +        this.wrappedConfiguration = wrapped;
  +        this.parentConfiguration = parent;
  +    }
  +    
       /** 
        * Get the parent configuration
        * @return the parent configuration or null.
        */
  -    ChainedConfiguration getParent();
  +    public ChainedConfiguration getParent() {
  +        return this.parentConfiguration;
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttribute(java.lang.String, 
java.lang.String)
  +     */
  +    public String getAttribute(String arg0, String arg1) {
  +        return this.wrappedConfiguration.getAttribute(arg0, arg1);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttribute(java.lang.String)
  +     */
  +    public String getAttribute(String arg0) throws ConfigurationException {
  +        return this.wrappedConfiguration.getAttribute(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsBoolean(java.lang.String,
 boolean)
  +     */
  +    public boolean getAttributeAsBoolean(String arg0, boolean arg1) {
  +        return this.wrappedConfiguration.getAttributeAsBoolean(arg0, arg1);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsBoolean(java.lang.String)
  +     */
  +    public boolean getAttributeAsBoolean(String arg0)
  +        throws ConfigurationException {
  +        return this.wrappedConfiguration.getAttributeAsBoolean(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsFloat(java.lang.String,
 float)
  +     */
  +    public float getAttributeAsFloat(String arg0, float arg1) {
  +        return this.wrappedConfiguration.getAttributeAsFloat(arg0, arg1);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsFloat(java.lang.String)
  +     */
  +    public float getAttributeAsFloat(String arg0)
  +        throws ConfigurationException {
  +        return this.wrappedConfiguration.getAttributeAsFloat(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsInteger(java.lang.String,
 int)
  +     */
  +    public int getAttributeAsInteger(String arg0, int arg1) {
  +        return this.wrappedConfiguration.getAttributeAsInteger(arg0, arg1);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsInteger(java.lang.String)
  +     */
  +    public int getAttributeAsInteger(String arg0)
  +        throws ConfigurationException {
  +        return this.wrappedConfiguration.getAttributeAsInteger(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsLong(java.lang.String,
 long)
  +     */
  +    public long getAttributeAsLong(String arg0, long arg1) {
  +        return this.wrappedConfiguration.getAttributeAsLong(arg0, arg1);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeAsLong(java.lang.String)
  +     */
  +    public long getAttributeAsLong(String arg0) throws ConfigurationException {
  +        return this.wrappedConfiguration.getAttributeAsLong(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getAttributeNames()
  +     */
  +    public String[] getAttributeNames() {
  +        return this.wrappedConfiguration.getAttributeNames();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getChild(java.lang.String, 
boolean)
  +     */
  +    public Configuration getChild(String arg0, boolean arg1) {
  +        return this.wrappedConfiguration.getChild(arg0, arg1);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getChild(java.lang.String)
  +     */
  +    public Configuration getChild(String arg0) {
  +        return this.wrappedConfiguration.getChild(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.configuration.Configuration#getChildren()
  +     */
  +    public Configuration[] getChildren() {
  +        return this.wrappedConfiguration.getChildren();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getChildren(java.lang.String)
  +     */
  +    public Configuration[] getChildren(String arg0) {
  +        return this.wrappedConfiguration.getChildren(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.configuration.Configuration#getLocation()
  +     */
  +    public String getLocation() {
  +        return this.wrappedConfiguration.getLocation();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.configuration.Configuration#getName()
  +     */
  +    public String getName() {
  +        return this.wrappedConfiguration.getName();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.configuration.Configuration#getNamespace()
  +     */
  +    public String getNamespace() throws ConfigurationException {
  +        return this.wrappedConfiguration.getNamespace();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.configuration.Configuration#getValue()
  +     */
  +    public String getValue() throws ConfigurationException {
  +        return this.wrappedConfiguration.getValue();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValue(java.lang.String)
  +     */
  +    public String getValue(String arg0) {
  +        return this.wrappedConfiguration.getValue(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValueAsBoolean()
  +     */
  +    public boolean getValueAsBoolean() throws ConfigurationException {
  +        return this.wrappedConfiguration.getValueAsBoolean();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValueAsBoolean(boolean)
  +     */
  +    public boolean getValueAsBoolean(boolean arg0) {
  +        return this.wrappedConfiguration.getValueAsBoolean(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValueAsFloat()
  +     */
  +    public float getValueAsFloat() throws ConfigurationException {
  +        return this.wrappedConfiguration.getValueAsFloat();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValueAsFloat(float)
  +     */
  +    public float getValueAsFloat(float arg0) {
  +        return this.wrappedConfiguration.getValueAsFloat(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValueAsInteger()
  +     */
  +    public int getValueAsInteger() throws ConfigurationException {
  +        return this.wrappedConfiguration.getValueAsInteger();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValueAsInteger(int)
  +     */
  +    public int getValueAsInteger(int arg0) {
  +        return this.wrappedConfiguration.getValueAsInteger(arg0);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.configuration.Configuration#getValueAsLong()
  +     */
  +    public long getValueAsLong() throws ConfigurationException {
  +        return this.wrappedConfiguration.getValueAsLong();
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.avalon.framework.configuration.Configuration#getValueAsLong(long)
  +     */
  +    public long getValueAsLong(long arg0) {
  +        return this.wrappedConfiguration.getValueAsLong(arg0);
  +    }
  +
   }
  
  
  
  1.3       +49 -4     
cocoon-2.1/src/java/org/apache/cocoon/components/CocoonComponentManager.java
  
  Index: CocoonComponentManager.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/CocoonComponentManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CocoonComponentManager.java       12 Mar 2003 12:55:16 -0000      1.2
  +++ CocoonComponentManager.java       19 Mar 2003 15:21:19 -0000      1.3
  @@ -99,7 +99,7 @@
       /** The environment information */
       private static InheritableThreadLocal environmentStack = new 
CloningInheritableThreadLocal();
   
  -    /** The configured <code>SourceResolver</code> */
  +    /** The configured [EMAIL PROTECTED] SourceResolver} */
       private SourceResolver sourceResolver;
   
       /** The [EMAIL PROTECTED] RoleManager} */
  @@ -108,8 +108,11 @@
       /** The root component manager */
       private static ComponentManager rootManager;
       
  +    /** The [EMAIL PROTECTED] SitemapConfigurationHolder}s */
  +    private static Map sitemapConfigurationHolders = new HashMap(5);
  +    
       /** Create the ComponentManager */
  -    public CocoonComponentManager(){
  +    public CocoonComponentManager() {
           super( null, Thread.currentThread().getContextClassLoader() );
           if ( null == rootManager ) rootManager = this;
       }
  @@ -149,6 +152,45 @@
                }
                final EnvironmentStack stack = 
(EnvironmentStack)environmentStack.get();
                stack.push(new Object[] {env, processor, manager});
  +    
  +        /* New:
  +        // do we have the sitemap configurations prepared for this processor?
  +        final Object o = sitemapConfigurationHolders.get(processor);
  +        if ( null == o ) { 
  +            // first we have to lookup the parent processor
  +            final Processor parentProcessor = 
(Processor)env.getAttribute("CocoonComponentManager.processor");
  +
  +            // do we have configurations?
  +            final Configuration currentConf = 
processor.getComponentConfigurations();
  +            final Configuration[] childs = (currentConf == null ? null : 
currentConf.getChildren());
  +            
  +            if ( childs == null ) {
  +                Map configurationMap = null;
  +                if ( null == parentProcessor || parentProcessor.equals(processor)) {
  +                    configurationMap = new HashMap(12);
  +                } else {
  +                    // use configuration from parent
  +                    configurationMap = 
(Map)sitemapConfigurationHolders.get(parentProcessor); 
  +                }
  +                sitemapConfigurationHolders.put(processor, configurationMap);
  +
  +            } else {
  +
  +                Map configurationMap = null;
  +                if ( null == parentProcessor || parentProcessor.equals(processor)) {
  +                    configurationMap = new HashMap(12);
  +                } else {
  +                    // copy all configurations from parent
  +                    configurationMap = new 
HashMap((Map)sitemapConfigurationHolders.get(parentProcessor)); 
  +                }
  +                // and now check for new configurations
  +                for(int m = 0; m < childs.length; m++) {
  +                    
  +                    //final String r = 
this.roleManager.getRoleForName(childs[m].getName());
  +                }
  +            }
  +        }
  +        */
           final EnvironmentDescription desc = 
(EnvironmentDescription)env.getObjectModel().get(PROCESS_KEY);
           desc.addSitemapConfiguration(processor.getComponentConfigurations());
           env.setAttribute("CocoonComponentManager.processor", processor);
  @@ -238,7 +280,6 @@
        * This method return the current sitemap component manager. This
        * is the manager that holds all the components of the currently
        * processed (sub)sitemap.
  -     * FIXME: Do we really want to expose this?
        */
       static public ComponentManager getSitemapComponentManager() {
                final EnvironmentStack stack = 
(EnvironmentStack)environmentStack.get();
  @@ -341,6 +382,10 @@
                   }
               }
           }
  +        /*
  +        if ( null != component && component instanceof SitemapConfigurable) {
  +            // FIXME: how can we prevent that this is called over and over again?
  +        }*/
           return component;
       }
   
  
  
  

Reply via email to