bloritsch    01/06/08 10:53:38

  Modified:    src/org/apache/cocoon/sitemap Tag: cocoon_20_branch
                        AbstractSitemap.java SitemapComponentSelector.java
                        sitemap.roles
  Log:
  Make Sitemap Component inheritance work properly.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.5   +50 -22    xml-cocoon2/src/org/apache/cocoon/sitemap/AbstractSitemap.java
  
  Index: AbstractSitemap.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/AbstractSitemap.java,v
  retrieving revision 1.4.2.4
  retrieving revision 1.4.2.5
  diff -u -r1.4.2.4 -r1.4.2.5
  --- AbstractSitemap.java      2001/06/08 14:41:59     1.4.2.4
  +++ AbstractSitemap.java      2001/06/08 17:53:31     1.4.2.5
  @@ -36,7 +36,6 @@
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.util.ClassUtils;
   import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
  -import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
   import org.apache.avalon.excalibur.component.RoleManager;
   import org.apache.avalon.excalibur.component.DefaultRoleManager;
   
  @@ -44,7 +43,7 @@
    * Base class for generated <code>Sitemap</code> classes
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.4.2.4 $ $Date: 2001/06/08 14:41:59 $
  + * @version CVS $Revision: 1.4.2.5 $ $Date: 2001/06/08 17:53:31 $
    */
   public abstract class AbstractSitemap extends AbstractLoggable implements Sitemap, 
Disposable, ThreadSafe {
       private Context context;
  @@ -63,13 +62,13 @@
   
       /** The creation date */
       protected static long dateCreated = -1L;
  -    protected ExcaliburComponentSelector generators;
  -    protected ExcaliburComponentSelector transformers;
  +    protected SitemapComponentSelector generators;
  +    protected SitemapComponentSelector transformers;
       protected SitemapComponentSelector serializers;
       protected SitemapComponentSelector readers;
  -    protected ExcaliburComponentSelector actions;
  -    protected ExcaliburComponentSelector matchers;
  -    protected ExcaliburComponentSelector selectors;
  +    protected SitemapComponentSelector actions;
  +    protected SitemapComponentSelector matchers;
  +    protected SitemapComponentSelector selectors;
   
       /**
        * Set the role manager
  @@ -90,37 +89,66 @@
           this.manager.setLogger(getLogger());
           this.manager.contextualize(this.context);
           this.manager.setRoleManager(AbstractSitemap.roleManager);
  +
           try {
  -            this.manager.configure(AbstractSitemap.defaultConfig);
               this.urlFactory = (URLFactory)manager.lookup(Roles.URL_FACTORY);
  -            this.generators = new ExcaliburComponentSelector();
  +
  +            // Create Sitemap Selectors
  +            this.generators = new SitemapComponentSelector();
  +            this.transformers = new SitemapComponentSelector();
  +            this.serializers = new SitemapComponentSelector();
  +            this.readers = new SitemapComponentSelector();
  +            this.actions = new SitemapComponentSelector();
  +            this.matchers = new SitemapComponentSelector();
  +            this.selectors = new SitemapComponentSelector();
  +
  +            // Set Parent Sitemap Selectors
  +            if (AbstractSitemap.defaultConfig == null) {
  +                try {
  +                    this.generators.setParentSelector((SitemapComponentSelector) 
this.manager.lookup(Roles.GENERATORS));
  +                    this.transformers.setParentSelector((SitemapComponentSelector) 
this.manager.lookup(Roles.TRANSFORMERS));
  +                    this.serializers.setParentSelector((SitemapComponentSelector) 
this.manager.lookup(Roles.SERIALIZERS));
  +                    this.readers.setParentSelector((SitemapComponentSelector) 
this.manager.lookup(Roles.READERS));
  +                    this.actions.setParentSelector((SitemapComponentSelector) 
this.manager.lookup(Roles.ACTIONS));
  +                    this.matchers.setParentSelector((SitemapComponentSelector) 
this.manager.lookup(Roles.MATCHERS));
  +                    this.selectors.setParentSelector((SitemapComponentSelector) 
this.manager.lookup(Roles.SELECTORS));
  +                } catch (ComponentException ce) {
  +                    /* we are ignoring those exceptions.  We just want
  +                     * to ensure that the selectors get initialized
  +                     * properly
  +                     */
  +                }
  +            }
  +
  +            // Setup the Selectors
               this.setupSelector(this.generators);
  -            this.manager.addComponentInstance(Roles.GENERATORS, this.generators);
  -            this.transformers = new ExcaliburComponentSelector();
               this.setupSelector(this.transformers);
  -            this.manager.addComponentInstance(Roles.TRANSFORMERS, 
this.transformers);
  -            this.serializers = new SitemapComponentSelector();
               this.setupSelector(this.serializers);
  -            this.manager.addComponentInstance(Roles.SERIALIZERS, this.serializers);
  -            this.readers = new SitemapComponentSelector();
               this.setupSelector(this.readers);
  -            this.manager.addComponentInstance(Roles.READERS, this.readers);
  -            this.actions = new ExcaliburComponentSelector();
               this.setupSelector(this.actions);
  -            this.manager.addComponentInstance(Roles.ACTIONS, this.actions);
  -            this.matchers = new ExcaliburComponentSelector();
               this.setupSelector(this.matchers);
  -            this.manager.addComponentInstance(Roles.MATCHERS, this.matchers);
  -            this.selectors = new ExcaliburComponentSelector();
               this.setupSelector(this.selectors);
  +
  +            // Add the Selectors
  +            this.manager.addComponentInstance(Roles.GENERATORS, this.generators);
  +            this.manager.addComponentInstance(Roles.TRANSFORMERS, 
this.transformers);
  +            this.manager.addComponentInstance(Roles.SERIALIZERS, this.serializers);
  +            this.manager.addComponentInstance(Roles.READERS, this.readers);
  +            this.manager.addComponentInstance(Roles.ACTIONS, this.actions);
  +            this.manager.addComponentInstance(Roles.MATCHERS, this.matchers);
               this.manager.addComponentInstance(Roles.SELECTORS, this.selectors);
  +
  +            if (AbstractSitemap.defaultConfig != null) {
  +                this.manager.configure(AbstractSitemap.defaultConfig);
  +                AbstractSitemap.defaultConfig = null;
  +            }
           } catch (Exception e) {
               getLogger().error("cannot obtain the Component", e);
               throw new ComponentException("cannot obtain the URLFactory", e);
           }
       }
   
  -    private void setupSelector(ExcaliburComponentSelector selector) throws 
Exception {
  +    private void setupSelector(SitemapComponentSelector selector) throws Exception {
           selector.setLogger(getLogger());
           selector.contextualize(this.context);
           selector.setRoleManager(AbstractSitemap.roleManager);
  
  
  
  1.2.2.4   +35 -2     
xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapComponentSelector.java
  
  Index: SitemapComponentSelector.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapComponentSelector.java,v
  retrieving revision 1.2.2.3
  retrieving revision 1.2.2.4
  diff -u -r1.2.2.3 -r1.2.2.4
  --- SitemapComponentSelector.java     2001/06/08 14:42:08     1.2.2.3
  +++ SitemapComponentSelector.java     2001/06/08 17:53:33     1.2.2.4
  @@ -8,10 +8,13 @@
   
   package org.apache.cocoon.sitemap;
   
  +import java.util.Collections;
   import java.util.HashMap;
  +import java.util.Map;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -20,16 +23,46 @@
   /** Default component manager for Cocoon's sitemap components.
    * @author <a href="mailto:[EMAIL PROTECTED]";>Berin Loritsch</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Id: SitemapComponentSelector.java,v 1.2.2.3 2001/06/08 14:42:08 
bloritsch Exp $
  + * @version CVS $Id: SitemapComponentSelector.java,v 1.2.2.4 2001/06/08 17:53:33 
bloritsch Exp $
    */
   public class SitemapComponentSelector extends ExcaliburComponentSelector {
  -    private HashMap mime_types;
  +    private Map mime_types;
  +    private ComponentSelector parentSelector;
  +    private boolean initialized = false;
   
       /** The conctructors (same as the Avalon ComponentManager)
        */
       public SitemapComponentSelector() {
           super();
           this.mime_types = new HashMap();
  +    }
  +
  +    public void setParentSelector(ComponentSelector newSelector) {
  +        if ((! this.initialized) && this.parentSelector == null) {
  +            this.parentSelector = newSelector;
  +        }
  +    }
  +
  +    public Component select(Object hint) throws ComponentException {
  +        Component component = null;
  +
  +        try {
  +            component = super.select(hint);
  +        } catch (ComponentException ce) {
  +            if (this.parentSelector != null) {
  +                component = this.parentSelector.select(hint);
  +            } else {
  +                throw ce;
  +            }
  +        }
  +
  +        return component;
  +    }
  +
  +    public void initialize() {
  +        super.initialize();
  +        this.mime_types = Collections.unmodifiableMap(this.mime_types);
  +        this.initialized = true;
       }
   
       public String getMimeTypeForRole(String role) {
  
  
  
  1.1.2.4   +5 -5      xml-cocoon2/src/org/apache/cocoon/sitemap/Attic/sitemap.roles
  
  Index: sitemap.roles
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Attic/sitemap.roles,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- sitemap.roles     2001/06/07 21:13:41     1.1.2.3
  +++ sitemap.roles     2001/06/08 17:53:34     1.1.2.4
  @@ -11,23 +11,23 @@
   
    <role name="org.apache.cocoon.acting.ActionSelector"
          shorthand="action"
  -       
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
  +       default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
   
    <role name="org.apache.cocoon.selection.SelectorSelector"
          shorthand="selector"
  -       
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
  +       default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
   
    <role name="org.apache.cocoon.matching.MatcherSelector"
          shorthand="matcher"
  -       
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
  +       default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
   
    <role name="org.apache.cocoon.generation.GeneratorSelector"
          shorthand="generator"
  -       
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
  +       default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
   
    <role name="org.apache.cocoon.transformation.TransformerSelector"
          shorthand="transformer"
  -       
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
  +       default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
   
    <role name="org.apache.cocoon.serialization.SerializerSelector"
          shorthand="serializer"
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to