cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components CocoonComponentManager.java
Date Fri, 15 Nov 2002 15:12:35 GMT
cziegeler    2002/11/15 07:12:35

  Modified:    src/java/org/apache/cocoon/components
                        CocoonComponentManager.java
  Log:
  New Object to support RequestLifecycleComponents
  
  Revision  Changes    Path
  1.31      +136 -13   xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java
  
  Index: CocoonComponentManager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- CocoonComponentManager.java	15 Nov 2002 13:31:36 -0000	1.30
  +++ CocoonComponentManager.java	15 Nov 2002 15:12:35 -0000	1.31
  @@ -75,9 +75,9 @@
   
   /**
    * Cocoon Component Manager.
  - * This manager extends the <code>ExcaliburComponentManager</code>
  - * by a special lifecycle handling for a RequestLifecycleComponent
  - * and by handling the lookup of the <code>SourceResolver</code> (in development)
  + * This manager extends the {@link ExcaliburComponentManager}
  + * by a special lifecycle handling for a {@link RequestLifecycleComponent}
  + * and by handling the lookup of the <code>SourceResolver</code>
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
  @@ -86,6 +86,10 @@
   extends ExcaliburComponentManager
   implements SourceResolver
   {
  +    /** The key used to store the current process environment */
  +    private static final String PROCESS_KEY =
  +               "org.apache.cocoon.components.CocoonComponentManager";
  +         
       /** The environment information */
       private static InheritableThreadLocal environmentStack = new InheritableThreadLocal();
   
  @@ -158,7 +162,7 @@
                   while (iter.hasNext()) {
                       final Object[] o = (Object[])iter.next();
                       final Component component = (Component)o[0];
  -                    ((CocoonComponentManager)o[1]).releaseRLComponent( component );
  +                    ((ComponentManager)o[1]).release( component );
                   }
                   if (objects.length > 6) {
                       final List automaticReleasedComponents = (List)objects[6];
  @@ -195,7 +199,7 @@
           Map values = new HashMap(5);
           Long key = new Long(System.currentTimeMillis());
           processes.put(key, values);
  -        env.getObjectModel().put("org.apache.cocoon.components.CocoonComponentManager",
key);
  +        env.getObjectModel().put(PROCESS_KEY, key);
           return key;
       }
       
  @@ -261,6 +265,22 @@
           final Stack stack = (Stack)environmentStack.get();
           if ( null != stack && !stack.empty()) {
               final Object[] objects = (Object[])stack.peek();
  +            /* new version that will fix the RequestLifecycleComponent bug
  +            Map objectModel = (Map)objects[1];
  +            Object processKey = objectModel.get(PROCESS_KEY);
  +            if ( null != processKey) {
  +                Map processes = (Map)processList.get();
  +                if ( null != processes) {
  +                    EnvironmentDescription envDesc = (EnvironmentDescription)processes.get(processKey);
  +                    if (envDesc != null) {
  +                        final Component component = envDesc.getRequestLifecycleComponent(role);
  +                        if (null != component) {
  +                            return component;
  +                        }
  +                    }
  +                }
  +            }
  +            */
               final Map components = (Map)objects[2];
               final Object[] o = (Object[])components.get(role);
               if ( null != o  ) {
  @@ -419,13 +439,6 @@
       }
   
       /**
  -     * Release a RequestLifecycleComponent
  -     */
  -    protected void releaseRLComponent( final Component component ) {
  -        super.release( component );
  -    }
  -
  -    /**
        * Get a <code>Source</code> object.
        */
       public Source resolveURI(final String location)
  @@ -456,4 +469,114 @@
       public void release( final Source source ) {
           this.sourceResolver.release( source );
       }
  +}
  +
  +final class EnvironmentDescription {
  +    
  +    Environment environment;
  +    Map         objectModel;
  +    Map         requestLifecycleComponents = new HashMap(5);
  +    List        autoreleaseComponents      = new ArrayList(2);
  +    
  +    /**
  +     * Constructor
  +     */
  +    EnvironmentDescription(Environment env, Map objectModel) {
  +        this.environment = env;
  +        this.objectModel = objectModel;
  +    }
  +    
  +    /**
  +     * Release all components of this environment
  +     * All RequestLifecycleComponents and autoreleaseComponents are
  +     * released.
  +     */
  +    void release() {
  +        final Iterator iter = this.requestLifecycleComponents.values().iterator();
  +        while (iter.hasNext()) {
  +            final Object[] o = (Object[])iter.next();
  +            final Component component = (Component)o[0];
  +            ((ComponentManager)o[1]).release( component );
  +        }
  +        
  +        for(int i = 0; i < autoreleaseComponents.size(); i++) {
  +            final Object[] o = (Object[])autoreleaseComponents.get(i);
  +            final Component component = (Component)o[0];
  +            if (o[1] instanceof ComponentManager) {
  +                ((ComponentManager)o[1]).release( component );
  +            } else {
  +                ((ComponentSelector)o[1]).release( component );
  +                if (o[2] != null) {
  +                    ((ComponentManager)o[2]).release( (Component)o[1] );
  +                }
  +            }
  +        }
  +    }
  +    
  +    /**
  +     * Add a RequestLifecycleComponent to the environment
  +     */
  +    void addRequestLifecycleComponent(final String role, 
  +                                      final Component co, 
  +                                      final ComponentManager manager) {
  +        this.requestLifecycleComponents.put(role, new Object[] {co, manager});
  +    }
  +    
  +    /**
  +     * Search a RequestLifecycleComponent
  +     */
  +    Component getRequestLifecycleComponent(final String role) {
  +        final Object[] o = (Object[])this.requestLifecycleComponents.get(role);
  +        if ( null != o ) {
  +            return (Component)o[0];
  +        }
  +        return null;
  +    }
  +
  +    /**
  +     * Add an automatically released component
  +     */
  +    public void addToAutoRelease(final ComponentSelector selector,
  +                                  final Component         component,
  +                                  final ComponentManager  manager) {
  +        this.autoreleaseComponents.add(new Object[] {component, selector, manager});
  +    }
  +
  +    /**
  +     * Add an automatically released component
  +     */
  +    public void addToAutoRelease(final ComponentManager manager,
  +                                  final Component        component) {
  +        this.autoreleaseComponents.add(new Object[] {component, manager});
  +    }
  +
  +    /**
  +     * Remove from automatically released components
  +     */
  +    public void removeFromAutoRelease(final Component component)
  +    throws ProcessingException {
  +        int i = 0;
  +        boolean found = false;
  +        while (i < this.autoreleaseComponents.size() && !found) {
  +            final Object[] o = (Object[])this.autoreleaseComponents.get(i);
  +            if (o[0] == component) {
  +                found = true;
  +                if (o[1] instanceof ComponentManager) {
  +                    ((ComponentManager)o[1]).release( component );
  +                } else {
  +                    ((ComponentSelector)o[1]).release( component );
  +                    if (o[2] != null) {
  +                        ((ComponentManager)o[2]).release( (Component)o[1] );
  +                    }
  +                }
  +                this.autoreleaseComponents.remove(i);
  +            } else {
  +                i++;
  +            }
  +        }
  +        if (!found) {
  +            throw new ProcessingException("Unable to remove component from automatic release:
component not found.");
  +        }
  +    }
  +        
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message