You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2004/02/05 14:59:08 UTC

cvs commit: cocoon-2.2/src/java/org/apache/cocoon/components/pipeline ProcessingPipeline.java AbstractProcessingPipeline.java

cziegeler    2004/02/05 05:59:07

  Modified:    src/java/org/apache/cocoon/environment Environment.java
                        AbstractEnvironment.java
               src/java/org/apache/cocoon/components/cprocessor
                        InvokeContext.java TreeProcessor.java
               src/java/org/apache/cocoon/components/pipeline
                        ProcessingPipeline.java
                        AbstractProcessingPipeline.java
  Log:
  Code cleanup
  
  Revision  Changes    Path
  1.12      +1 -2      cocoon-2.2/src/java/org/apache/cocoon/environment/Environment.java
  
  Index: Environment.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/Environment.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Environment.java	30 Oct 2003 12:31:05 -0000	1.11
  +++ Environment.java	5 Feb 2004 13:58:51 -0000	1.12
  @@ -121,7 +121,6 @@
        * The returned stream is buffered by the environment. If the
        * buffer size is -1 then the complete output is buffered.
        * If the buffer size is 0, no buffering takes place.
  -     * This method replaces {@link #getOutputStream()}.
        */
       OutputStream getOutputStream(int bufferSize) throws IOException;
   
  
  
  
  1.24      +62 -65    cocoon-2.2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
  
  Index: AbstractEnvironment.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- AbstractEnvironment.java	30 Oct 2003 16:50:46 -0000	1.23
  +++ AbstractEnvironment.java	5 Feb 2004 13:58:52 -0000	1.24
  @@ -74,7 +74,7 @@
       implements Environment {
   
       /** The current uri in progress */
  -    protected String uris;
  +    protected String uri;
   
       /** The prefix */
       protected String prefix;
  @@ -108,7 +108,7 @@
        * Constructs the abstract environment
        */
       public AbstractEnvironment(String uri, String view, String action) {
  -        this.uris = uri;
  +        this.uri = uri;
           this.view = view;
           this.action = action;
           this.objectModel = new HashMap();
  @@ -146,33 +146,31 @@
       /**
        * Helper method to extract the action name from the request.
        */
  -     protected static String extractAction(Request req) {
  -         String action = req.getParameter(Constants.ACTION_PARAM);
  -         if (action != null) {
  -             /* TC: still support the deprecated syntax */
  -             return action;
  -         } else {
  -             for(Enumeration e = req.getParameterNames(); e.hasMoreElements(); ) {
  -                 String name = (String)e.nextElement();
  -                 if (name.startsWith(Constants.ACTION_PARAM_PREFIX)) {
  -                     if (name.endsWith(".x") || name.endsWith(".y")) {
  -                         return name.substring(Constants.ACTION_PARAM_PREFIX.length(),name.length()-2);
  -                     } else {
  -                         return name.substring(Constants.ACTION_PARAM_PREFIX.length());
  -                     }
  -                 }
  -             }
  -             return null;
  -         }
  -     }
  -
  -    // Sitemap methods
  +    protected static String extractAction(Request req) {
  +        String action = req.getParameter(Constants.ACTION_PARAM);
  +        if (action != null) {
  +            /* TC: still support the deprecated syntax */
  +            return action;
  +        } else {
  +            for(Enumeration e = req.getParameterNames(); e.hasMoreElements(); ) {
  +                String name = (String)e.nextElement();
  +                if (name.startsWith(Constants.ACTION_PARAM_PREFIX)) {
  +                    if (name.endsWith(".x") || name.endsWith(".y")) {
  +                        return name.substring(Constants.ACTION_PARAM_PREFIX.length(),name.length()-2);
  +                    } else {
  +                        return name.substring(Constants.ACTION_PARAM_PREFIX.length());
  +                    }
  +                }
  +            }
  +            return null;
  +        }
  +    }
   
  -    /**
  -     * Returns the uri in progress. The prefix is stripped off
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#getURI()
        */
       public String getURI() {
  -        return this.uris;
  +        return this.uri;
       }
   
       /* (non-Javadoc)
  @@ -187,77 +185,80 @@
        */
       public void setURI(String prefix, String value) {
           this.prefix = prefix;
  -        this.uris = value;
  +        this.uri = value;
       }
   
  -    /**
  -     * Returns the request view
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#getView()
        */
       public String getView() {
           return this.view;
       }
   
  -    /**
  -     * Returns the request action
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#getAction()
        */
       public String getAction() {
           return this.action;
       }
   
  -    /**
  -     * Set a status code
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#setStatus(int)
        */
       public void setStatus(int statusCode) {
       }
   
  -    /**
  -     * Returns a Map containing environment specific objects
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#getObjectModel()
        */
       public Map getObjectModel() {
           return this.objectModel;
       }
   
  -    /**
  -     * Check if the response has been modified since the same
  -     * "resource" was requested.
  -     * The caller has to test if it is really the same "resource"
  -     * which is requested.
  -     * @return true if the response is modified or if the
  -     *         environment is not able to test it
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#isResponseModified(long)
        */
       public boolean isResponseModified(long lastModified) {
           return true; // always modified
       }
   
  -    /**
  -     * Mark the response as not modified.
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#setResponseIsNotModified()
        */
       public void setResponseIsNotModified() {
           // does nothing
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#getAttribute(java.lang.String)
  +     */
       public Object getAttribute(String name) {
           return this.attributes.get(name);
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#setAttribute(java.lang.String, java.lang.Object)
  +     */
       public void setAttribute(String name, Object value) {
           this.attributes.put(name, value);
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#removeAttribute(java.lang.String)
  +     */
       public void removeAttribute(String name) {
           this.attributes.remove(name);
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#getAttributeNames()
  +     */
       public Enumeration getAttributeNames() {
           return new IteratorEnumeration(this.attributes.keySet().iterator());
       }
   
  -    /**
  -     * Get the output stream where to write the generated resource.
  -     * The returned stream is buffered by the environment. If the
  -     * buffer size is -1 then the complete output is buffered.
  -     * If the buffer size is 0, no buffering takes place.
  -     * This method replaces {@link #getOutputStream()}.
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#getOutputStream(int)
        */
       public OutputStream getOutputStream(int bufferSize)
       throws IOException {
  @@ -274,13 +275,9 @@
           }
       }
   
  -    /**
  -     * Reset the response if possible. This allows error handlers to have
  -     * a higher chance to produce clean output if the pipeline that raised
  -     * the error has already output some data.
  -     *
  -     * @return true if the response was successfully reset
  -    */
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#tryResetResponse()
  +     */
       public boolean tryResetResponse()
       throws IOException {
           if (this.secureOutputStream != null) {
  @@ -290,8 +287,8 @@
           return false;
       }
   
  -    /**
  -     * Commit the response
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#commitResponse()
        */
       public void commitResponse()
       throws IOException {
  @@ -302,17 +299,17 @@
           }
       }
   
  -    /**
  -     * Notify that the processing starts.
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#startingProcessing()
        */
       public void startingProcessing() {
           // do nothing here
       }
   
  -    /**
  -     * Notify that the processing is finished
  -     * This can be used to cleanup the environment object
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.environment.Environment#finishingProcessing()
        */
       public void finishingProcessing() {
  +        // do nothing here
       }
   }
  
  
  
  1.6       +4 -7      cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/InvokeContext.java
  
  Index: InvokeContext.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/InvokeContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InvokeContext.java	10 Jan 2004 14:38:19 -0000	1.5
  +++ InvokeContext.java	5 Feb 2004 13:58:55 -0000	1.6
  @@ -63,8 +63,6 @@
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.cocoon.components.pipeline.ProcessingPipeline;
   import org.apache.cocoon.components.cprocessor.variables.VariableResolver;
  -import org.apache.cocoon.environment.internal.EnvironmentContext;
  -import org.apache.cocoon.environment.internal.EnvironmentHelper;
   
   /**
    * The invocation context of <code>ProcessingNode</code>s.
  @@ -168,15 +166,14 @@
               this.pipelinesManager = this.currentManager;
   
               this.processingPipeline = (ProcessingPipeline)this.pipelinesManager.lookup(ProcessingPipeline.ROLE);
  +            if (this.isBuildingPipelineOnly) {
  +                this.processingPipeline.setInternalServiceManager(this.pipelinesManager);
  +            }
               this.processingPipeline.reservice( this.pipelinesManager );
               this.processingPipeline.setup(
                     VariableResolver.buildParameters(this.processingPipelineParameters,
                                                      this, this.processingPipelineObjectModel)
               );
  -            if (this.isBuildingPipelineOnly) {
  -                EnvironmentContext context = EnvironmentHelper.getCurrentEnvironmentContext();
  -                context.addAttribute(TreeProcessor.PIPELINE_KEY, this.pipelinesManager);
  -            }
           }
           return this.processingPipeline;
       }
  
  
  
  1.17      +1 -10     cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/TreeProcessor.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TreeProcessor.java	28 Jan 2004 10:17:16 -0000	1.16
  +++ TreeProcessor.java	5 Feb 2004 13:58:55 -0000	1.17
  @@ -84,7 +84,6 @@
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
   import org.apache.cocoon.environment.Environment;
  -import org.apache.cocoon.environment.internal.EnvironmentContext;
   import org.apache.cocoon.environment.internal.EnvironmentHelper;
   import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
   import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
  @@ -118,9 +117,6 @@
       /** The sitemap namespace */
       public static final String SITEMAP_NS = "http://apache.org/cocoon/sitemap/1.0";
       
  -    /** The key for the pipeline component */
  -    public static final String PIPELINE_KEY = ProcessingPipeline.class.getName();
  -    
       /** The key for the processor inside the component context */
       public static final String CONTEXT_TREE_PROCESSOR = TreeProcessor.class.getName();
       
  @@ -550,12 +546,7 @@
        * @see org.apache.cocoon.Processor#releasePipeline(org.apache.cocoon.components.pipeline.ProcessingPipeline)
        */
       public void releasePipeline(Environment environment, ProcessingPipeline pipeline) {
  -        EnvironmentContext context = EnvironmentHelper.getEnvironmentContext(environment);
  -        ServiceManager manager = (ServiceManager)context.getAttribute(PIPELINE_KEY);
  -        if ( manager != null ) {
  -            manager.release(pipeline);
  -            context.removeAttribute(PIPELINE_KEY);
  -        }
  +        pipeline.releaseInternalPipeline();
       }
   
       /**
  
  
  
  1.8       +18 -2     cocoon-2.2/src/java/org/apache/cocoon/components/pipeline/ProcessingPipeline.java
  
  Index: ProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/pipeline/ProcessingPipeline.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ProcessingPipeline.java	27 Jan 2004 13:27:47 -0000	1.7
  +++ ProcessingPipeline.java	5 Feb 2004 13:59:01 -0000	1.8
  @@ -73,7 +73,7 @@
    *
    * <p>
    * A <code>ProcessingPipeline</code> is <code>Recomposable</code> since the
  - * <code>ComponentManager</code> used to get the generators, transformers etc.
  + * <code>ServiceManager</code> used to get the generators, transformers etc.
    * depends on the pipeline assembly engine where they are defined (i.e. a given
    * sitemap file).
    *
  @@ -157,6 +157,22 @@
       boolean process(Environment environment)
       throws ProcessingException;
   
  +    /**
  +     * Release this component if it is used as an internal pipeline
  +     * When the pipeline is used during an internal processing, the part looking
  +     * up the pipeline object is not able to release it anymore.
  +     * So, in this case the pipeline itself remembers the service manager
  +     * and can release itself using this method.
  +     */
  +    void releaseInternalPipeline();
  +
  +    /**
  +     * Set the manager that looked up this pipeline for internal
  +     * pipeline processing. This allows the {@link #releaseInternalPipeline}
  +     * method to release itself
  +     */
  +    void setInternalServiceManager(ServiceManager manager);
  +    
       /**
        * Prepare an internal processing
        * @param environment          The current environment.
  
  
  
  1.28      +24 -4     cocoon-2.2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
  
  Index: AbstractProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- AbstractProcessingPipeline.java	31 Jan 2004 13:08:49 -0000	1.27
  +++ AbstractProcessingPipeline.java	5 Feb 2004 13:59:01 -0000	1.28
  @@ -124,7 +124,7 @@
       /** the service manager set with service() */
       protected ServiceManager manager;
   
  -    /** the service manager set with service() and recompose() */
  +    /** the service manager set with service() and reservice() */
       protected ServiceManager newManager;
   
       /** The configuration */
  @@ -148,13 +148,33 @@
       /** The current Processor */
       protected Processor processor;
       
  -    /**
  -     * Serviceable Interface
  +    /** The internal manager for releasing */
  +    private ServiceManager internalManager;
  +    
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
        */
       public void service(ServiceManager manager)
       throws ServiceException {
           this.manager = manager;
           this.newManager = manager;
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.components.pipeline.ProcessingPipeline#release()
  +     */
  +    public final void releaseInternalPipeline() {
  +        if ( this.internalManager != null ) {
  +            this.internalManager.release(this);
  +            this.internalManager = null;
  +        }
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.components.pipeline.ProcessingPipeline#setInternalServiceManager(org.apache.avalon.framework.service.ServiceManager)
  +     */
  +    public final void setInternalServiceManager(ServiceManager manager) {
  +        this.internalManager = manager;
       }
   
       /**