cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From step...@apache.org
Subject cvs commit: xml-cocoon2/src/scratchpad/src/org/apache/cocoon/generation SourceDescriptionGenerator.java
Date Wed, 21 Aug 2002 15:35:47 GMT
stephan     2002/08/21 08:35:47

  Modified:    src/scratchpad/src/org/apache/cocoon/generation
                        SourceDescriptionGenerator.java
  Log:
  Reduce Source lookup's.
  
  Revision  Changes    Path
  1.13      +46 -25    xml-cocoon2/src/scratchpad/src/org/apache/cocoon/generation/SourceDescriptionGenerator.java
  
  Index: SourceDescriptionGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/generation/SourceDescriptionGenerator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SourceDescriptionGenerator.java	20 Aug 2002 16:25:34 -0000	1.12
  +++ SourceDescriptionGenerator.java	21 Aug 2002 15:35:47 -0000	1.13
  @@ -89,8 +89,8 @@
   import java.net.MalformedURLException;
   import java.util.Enumeration;
   import java.util.Date;
  +import java.util.Hashtable;
   import java.util.Map;
  -import java.util.Stack;
   
   /**
    * Generates a description from a source of a repository.
  @@ -101,7 +101,7 @@
    * @version CVS $Id$
    */
   public class SourceDescriptionGenerator extends ComposerGenerator 
  -        implements CacheableProcessingComponent{
  +        implements CacheableProcessingComponent, Recyclable {
   
       /** Namespace of the source description. */
       private static final String SOURCE_NS = "http://xml.apache.org/cocoon/source/2.0";
  @@ -164,6 +164,9 @@
       /** How deep the generator traverse the source */ 
       private int deep = 1;
   
  +    /** Traversed source for the keys and validities */
  +    private Hashtable cachedsources = null;
  +
       /**
        * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
        * the source and sitemap <code>Parameters</code> used to process the request.
  @@ -176,6 +179,9 @@
           this.permissions = parameters.getParameterAsBoolean("permissions", true);
           this.locks = parameters.getParameterAsBoolean("locks", true);
           this.version = parameters.getParameterAsBoolean("version", true);
  +
  +        this.cachedsources = new Hashtable();
  +        collectSources(this.cachedsources, this.source, this.deep);
       }
   
       /**
  @@ -187,16 +193,16 @@
       public Serializable generateKey() {
           StringBuffer key = new StringBuffer();
           key.append("SDG(");
  -        Stack sources = new Stack();
  -        collectSources(sources, this.source, this.deep);
  +
           Source source;
  -        while (!sources.empty()) {
  -            source = (Source)sources.pop();
  +        for (Enumeration e = cachedsources.elements(); e.hasMoreElements();) {
  +            source = (Source)e.nextElement();
  +
               key.append(source.getSystemId());
  -            if (!sources.empty())
  +            if (e.hasMoreElements())
                   key.append(";");
  -            this.resolver.release(source);
           }
  +
           key.append(")");
           return key.toString();
       }
  @@ -209,21 +215,21 @@
        */
       public SourceValidity generateValidity() {
           AggregatedValidity validity = new AggregatedValidity();
  -        Stack sources = new Stack();
  -        collectSources(sources, this.source, this.deep);
  +
           Source source;
  -        while (!sources.empty()) {
  -            source = (Source)sources.pop();
  +        for (Enumeration e = cachedsources.elements(); e.hasMoreElements();) {
  +            source = (Source)e.nextElement();
  +
               validity.add(source.getValidity());
  -            this.resolver.release(source);
           }
  +
           return validity;
       }
   
       /**
        * Traverse the source tree and retrieve all sources.
        */
  -    private void collectSources(Stack sources, String uri, int deep) {
  +    private void collectSources(Hashtable sources, String uri, int deep) {
           Source source = null;
           try {
               source = this.resolver.resolveURI(uri);
  @@ -232,7 +238,7 @@
               return;
           }
   
  -        sources.push(source);
  +        sources.put(uri, source);
   
           if (source instanceof TraversableSource) {
               TraversableSource traversablesource = (TraversableSource)source;
  @@ -270,12 +276,7 @@
       private void pushSourceDescription(String systemid, int deep) 
           throws SAXException, SourceException, ProcessingException, IOException {
   
  -        Source source = null;
  -        try { 
  -            source = this.resolver.resolveURI(systemid);
  -        } catch (MalformedURLException urle) {
  -            throw new ProcessingException("Could not retrieve a source", urle);
  -        }
  +        Source source = (Source)this.cachedsources.get(systemid);
   
           try {
               AttributesImpl attributes = new AttributesImpl();
  @@ -374,9 +375,7 @@
   
           } catch (SAXException saxe) {
               throw saxe;
  -        } finally {
  -            this.resolver.release(source);
  -        }
  +        } 
       }
   
       private void pushLiveSourceProperties(InspectableSource source) throws SAXException,
SourceException {
  @@ -489,6 +488,28 @@
   
               this.contentHandler.endElement(SOURCE_NS, LOCKS_NODE_NAME, LOCKS_NODE_QNAME);
           }
  +    }
  +
  +    /**
  +     * Recycle this component.
  +     * All instance variables are set to <code>null</code>.
  +     */
  +    public void recycle() {
  +        if (cachedsources!=null) {
  +            for (Enumeration e = cachedsources.elements(); e.hasMoreElements();) {
  +                this.resolver.release((Source)e.nextElement());
  +            }
  +            cachedsources = null;
  +        }
  +    }
  +
  +    /**
  +     * Release all resources.
  +     */
  +    public void dispose() {
  +        recycle();
  +
  +        super.dispose();
       }
   }
   
  
  
  

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