jefft       2003/06/21 07:08:07

  Modified:    src/java/org/apache/cocoon/components
                        CocoonComponentManager.java
  Log:
  Fix bug 20987
  We shouldn't call the lookup() method in addComponent(), because we're not
  initialize()'ed yet.  Instead, defer the lookup() calls to the initialize()
  method.
  
  Revision  Changes    Path
  1.13      +26 -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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CocoonComponentManager.java       18 Jun 2003 11:06:31 -0000      1.12
  +++ CocoonComponentManager.java       21 Jun 2003 14:08:07 -0000      1.13
  @@ -112,6 +112,10 @@
       /** The parent component manager for implementing parent aware components */
       private ComponentManager parentManager;
       
  +    /** Temporary list of parent-aware components.  Will be null for most of
  +     * our lifecycle. */
  +    private ArrayList parentAwareComponents = new ArrayList();
  +
       /** Create the ComponentManager */
       public CocoonComponentManager() {
           super( null, Thread.currentThread().getContextClassLoader() );
  @@ -463,13 +467,32 @@
           this.sourceResolver.release( source );
       }
   
  +
       /* (non-Javadoc)
        * @see 
org.apache.avalon.excalibur.component.ExcaliburComponentManager#addComponent(java.lang.String,
 java.lang.Class, org.apache.avalon.framework.configuration.Configuration)
        */
       public void addComponent(String role, Class clazz, Configuration conf)
  -    throws ComponentException {
  +        throws ComponentException {
           super.addComponent(role, clazz, conf);
  +        // Note that at this point, we're not initialized and cannot do
  +        // lookups, so defer parental introductions to initialize().
           if ( ParentAware.class.isAssignableFrom( clazz ) ) {
  +            parentAwareComponents.add(role);
  +        }
  +    }
  +
  +    public void initialize()
  +        throws Exception
  +    {
  +        super.initialize();
  +        if (parentAwareComponents == null) {
  +            throw new ComponentException("CocoonComponentManager already 
initialized");
  +        }
  +        // Set parents for parentAware components
  +        Iterator iter = parentAwareComponents.iterator();
  +        while (iter.hasNext()) {
  +            String role = (String)iter.next();
  +            getLogger().debug(".. "+role);
               if ( parentManager != null && parentManager.hasComponent( role ) ) {
                   // lookup new component
                   Component component = null;
  @@ -481,11 +504,10 @@
                   } finally {
                       this.release( component );
                   }
  -                
               }
           }
  +        parentAwareComponents = null;  // null to save memory, and catch logic bugs.
       }
  -
   }
   
   final class EnvironmentDescription {
  
  
  

Reply via email to