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 17:07:56 GMT
cziegeler    2002/11/15 09:07:56

  Modified:    src/java/org/apache/cocoon/components
                        CocoonComponentManager.java
  Log:
  Hopefully fixing bug 12293
  
  Revision  Changes    Path
  1.32      +84 -112   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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- CocoonComponentManager.java	15 Nov 2002 15:12:35 -0000	1.31
  +++ CocoonComponentManager.java	15 Nov 2002 17:07:56 -0000	1.32
  @@ -72,6 +72,7 @@
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceResolver;
  +import sun.tools.tree.ThisExpression;
   
   /**
    * Cocoon Component Manager.
  @@ -126,27 +127,22 @@
           super(manager);
       }
   
  -    private static final Integer ONE = new Integer(1);
  -    private static final Integer TWO = new Integer(2);
  -
       /**
        * This hook must be called by the sitemap each time a sitemap is entered
        */
       public static void enterEnvironment(Environment env,
  -                                        Map         objectModel,
  -                                        Processor   processor) {
  +                                          Map         objectModel,
  +                                          Processor   processor) {
           if (environmentStack.get() == null) {
               environmentStack.set(new Stack());
           }
           final Stack stack = (Stack)environmentStack.get();
  -        if (!stack.empty()) {
  -            final Object[] objects = (Object[])stack.peek();
  -            if ( objects[1] == objectModel ) {
  -                stack.push(new Object[] {env, objectModel, objects[2], TWO, processor,
processor.getComponentConfigurations()});
  -                return;
  -            }
  +        stack.push(new Object[] {env, processor});
  +        
  +        EnvironmentDescription desc = getDescription(objectModel);
  +        if ( null != desc ) {
  +            desc.addSitemapConfiguration(processor.getComponentConfigurations());
           }
  -        stack.push(new Object[] {env, objectModel, new HashMap(5), ONE, processor, processor.getComponentConfigurations(),
new ArrayList(2)});
       }
   
       /**
  @@ -156,30 +152,6 @@
           final Stack stack = (Stack)environmentStack.get();
           if (null != stack && !stack.empty()) {
               final Object[] objects = (Object[])stack.pop();
  -            if (objects[3] == ONE) {
  -                final Map components = (Map)objects[2];
  -                final Iterator iter = components.values().iterator();
  -                while (iter.hasNext()) {
  -                    final Object[] o = (Object[])iter.next();
  -                    final Component component = (Component)o[0];
  -                    ((ComponentManager)o[1]).release( component );
  -                }
  -                if (objects.length > 6) {
  -                    final List automaticReleasedComponents = (List)objects[6];
  -                    for(int i = 0; i < automaticReleasedComponents.size(); i++) {
  -                        final Object[] o = (Object[])automaticReleasedComponents.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] );
  -                            }
  -                        }
  -                    }
  -                }
  -            }
           }
       }
   
  @@ -196,9 +168,9 @@
               processes = new HashMap(4);
               processList.set(processes);
           }
  -        Map values = new HashMap(5);
  +        EnvironmentDescription desc = new EnvironmentDescription(env);
           Long key = new Long(System.currentTimeMillis());
  -        processes.put(key, values);
  +        processes.put(key, desc);
           env.getObjectModel().put(PROCESS_KEY, key);
           return key;
       }
  @@ -213,7 +185,6 @@
       public static void endProcessing(Object key) {
           Map processes = (Map)processList.get();
           if ( null != processes ) {
  -
               processes.remove(key);            
           }
       }
  @@ -235,7 +206,7 @@
       public static Processor getCurrentProcessor() {
           final Stack stack = (Stack)environmentStack.get();
           if (null != stack && !stack.empty()) {
  -            return (Processor) ((Object[])stack.peek())[4];
  +            return (Processor) ((Object[])stack.peek())[1];
           }
           return null;
       }
  @@ -265,26 +236,10 @@
           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  ) {
  -                final Component component = (Component) o[0];
  +            final Map objectModel = ((Environment)objects[0]).getObjectModel();
  +            EnvironmentDescription desc = getDescription(objectModel);
  +            if ( null != desc ) {
  +                final Component component = desc.getRequestLifecycleComponent(role);
                   if (null != component) {
                       return component;
                   }
  @@ -297,20 +252,22 @@
                   throw new ComponentException("ComponentManager has no Environment Stack.");
               }
               final Object[] objects = (Object[]) stack.peek();
  -            final Map components = (Map)objects[2];
  -            // first test if the parent CM has already initialized this component
  -            if (components.containsKey( role ) == false) {
  -                try {
  -                    if (component instanceof Recomposable) {
  -                        ((Recomposable) component).recompose(this);
  -                    }
  -                    ((RequestLifecycleComponent) component).setup((org.apache.cocoon.environment.SourceResolver)objects[0],
  -                                                                  (Map)objects[1]);
  -                    if (component instanceof SitemapConfigurable) {
  -                        for(int i=0; i < stack.size(); i++) {
  -                            Object[] o = (Object[])stack.get(i);
  -                            Configuration parent = (Configuration)o[5];
  -                            if ( null != parent ) {
  +            final Map objectModel = ((Environment)objects[0]).getObjectModel();
  +            EnvironmentDescription desc = getDescription(objectModel);
  +            if ( null != desc ) {
  +
  +                // first test if the parent CM has already initialized this component
  +                if ( !desc.containsRequestLifecycleComponent( role ) ) {
  +                    try {
  +                        if (component instanceof Recomposable) {
  +                            ((Recomposable) component).recompose(this);
  +                        }
  +                        ((RequestLifecycleComponent) component).setup((org.apache.cocoon.environment.SourceResolver)objects[0],
  +                                                                      (Map)objects[1]);
  +                        if (component instanceof SitemapConfigurable) {
  +                            List configs = desc.getSitemapConfigurations();
  +                            for(int i=0; i < configs.size(); i++) {
  +                                Configuration parent = (Configuration)configs.get(i);
                                   Configuration cc = parent.getChild( role, false );
                                   if ( null != cc ) {
                                       ((SitemapConfigurable) component).setSitemapConfiguration(cc);
  @@ -330,11 +287,11 @@
                                   }
                               }
                           }
  +                    } catch (Exception local) {
  +                        throw new ComponentException("Exception during setup of RequestLifecycleComponent
with role '"+role+"'", local);
                       }
  -                } catch (Exception local) {
  -                    throw new ComponentException("Exception during setup of RequestLifecycleComponent
with role '"+role+"'", local);
  +                    desc.addRequestLifecycleComponent(role, component, this);
                   }
  -                components.put(role, new Object[] {component, this});
               }
           }
           return component;
  @@ -368,8 +325,11 @@
           final Stack stack = (Stack)environmentStack.get();
           if ( null != stack && !stack.empty()) {
               final Object[] objects = (Object[])stack.firstElement();
  -            final List automaticReleasedComponents = (List)objects[6];
  -            automaticReleasedComponents.add(new Object[] {component, selector, manager});
  +            final Map objectModel = ((Environment)objects[0]).getObjectModel();
  +            EnvironmentDescription desc = getDescription(objectModel);
  +            if ( null != desc ) {
  +                desc.addToAutoRelease(selector, component, manager);
  +            }
           } else {
               throw new ProcessingException("Unable to add component for automatic release:
no environment available.");
           }
  @@ -384,8 +344,11 @@
           final Stack stack = (Stack)environmentStack.get();
           if ( null != stack && !stack.empty()) {
               final Object[] objects = (Object[])stack.firstElement();
  -            final List automaticReleasedComponents = (List)objects[6];
  -            automaticReleasedComponents.add(new Object[] {component, manager});
  +            final Map objectModel = ((Environment)objects[0]).getObjectModel();
  +            EnvironmentDescription desc = getDescription(objectModel);
  +            if ( null != desc ) {
  +                desc.addToAutoRelease(manager, component);
  +            }
           } else {
               throw new ProcessingException("Unable to add component for automatic release:
no environment available.");
           }
  @@ -399,28 +362,10 @@
           final Stack stack = (Stack)environmentStack.get();
           if ( null != stack && !stack.empty()) {
               final Object[] objects = (Object[])stack.firstElement();
  -            final List automaticReleasedComponents = (List)objects[6];
  -            int i = 0;
  -            boolean found = false;
  -            while (i < automaticReleasedComponents.size() && !found) {
  -                final Object[] o = (Object[])automaticReleasedComponents.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] );
  -                        }
  -                    }
  -                    automaticReleasedComponents.remove(i);
  -                } else {
  -                    i++;
  -                }
  -            }
  -            if (!found) {
  -                throw new ProcessingException("Unable to remove component from automatic
release: component not found.");
  +            final Map objectModel = ((Environment)objects[0]).getObjectModel();
  +            EnvironmentDescription desc = getDescription(objectModel);
  +            if ( null != desc ) {
  +                desc.removeFromAutoRelease(component);
               }
           } else {
               throw new ProcessingException("Unable to remove component from automatic release:
no environment available.");
  @@ -469,6 +414,18 @@
       public void release( final Source source ) {
           this.sourceResolver.release( source );
       }
  +
  +    private static EnvironmentDescription getDescription(Map objectModel) {
  +        Object processKey = objectModel.get(PROCESS_KEY);
  +        if ( null != processKey) {
  +            Map processes = (Map)CocoonComponentManager.processList.get();
  +            if ( null != processes) {
  +                return (EnvironmentDescription)processes.get(processKey);
  +            }
  +        }
  +        return null;
  +    }
  +    
   }
   
   final class EnvironmentDescription {
  @@ -477,13 +434,14 @@
       Map         objectModel;
       Map         requestLifecycleComponents = new HashMap(5);
       List        autoreleaseComponents      = new ArrayList(2);
  +    List        sitemapConfigurations      = new ArrayList(4);
       
       /**
        * Constructor
        */
  -    EnvironmentDescription(Environment env, Map objectModel) {
  +    EnvironmentDescription(Environment env) {
           this.environment = env;
  -        this.objectModel = objectModel;
  +        this.objectModel = env.getObjectModel();
       }
       
       /**
  @@ -522,6 +480,10 @@
           this.requestLifecycleComponents.put(role, new Object[] {co, manager});
       }
       
  +    boolean containsRequestLifecycleComponent(final String role) {
  +        return this.requestLifecycleComponents.containsKey( role );
  +    }
  +    
       /**
        * Search a RequestLifecycleComponent
        */
  @@ -536,24 +498,24 @@
       /**
        * Add an automatically released component
        */
  -    public void addToAutoRelease(final ComponentSelector selector,
  -                                  final Component         component,
  -                                  final ComponentManager  manager) {
  +    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) {
  +    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)
  +    void removeFromAutoRelease(final Component component)
       throws ProcessingException {
           int i = 0;
           boolean found = false;
  @@ -579,4 +541,14 @@
           }
       }
           
  +    void addSitemapConfiguration(Configuration conf) {
  +        if (conf != null) {
  +            this.sitemapConfigurations.add(conf);
  +        }
  +    }
  +    
  +    List getSitemapConfigurations() {
  +        return this.sitemapConfigurations;
  +    }
  +    
   }
  
  
  

----------------------------------------------------------------------
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