You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/09/21 05:01:13 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/sitemap AbstractSitemap.java Handler.java Manager.java SitemapManager.java

vgritsenko    2002/09/20 20:01:13

  Modified:    src/java/org/apache/cocoon/components/language/markup/sitemap/java
                        Tag: cocoon_2_0_3_branch sitemap.xsl
               src/java/org/apache/cocoon/sitemap Tag: cocoon_2_0_3_branch
                        AbstractSitemap.java Handler.java Manager.java
                        SitemapManager.java
  Log:
  Fix sneaky sitemap reloading bug:
  When parent sitemap is modified, it is recompiled and reloaded.
  All sub-sitemaps of this sitemap also has to be reloaded because
  they have references to the parent sitemap's ComponentSelectors.
  This bug is the cause of some NPEs in the XSLT processor.
  TreeProcessor already had this fix (it disposes all mounted TreeProcessors
  when reloading).
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.11.2.7  +22 -7     xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl
  
  Index: sitemap.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl,v
  retrieving revision 1.11.2.6
  retrieving revision 1.11.2.7
  diff -u -r1.11.2.6 -r1.11.2.7
  --- sitemap.xsl	11 Aug 2002 20:10:38 -0000	1.11.2.6
  +++ sitemap.xsl	21 Sep 2002 03:01:13 -0000	1.11.2.7
  @@ -1,4 +1,5 @@
   <?xml version="1.0"?>
  +
   <!--
    *****************************************************************************
    * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  @@ -1264,6 +1265,7 @@
   
     <!-- generate the code to invoke a sub sitemap  -->
     <xsl:template match="map:mount">
  +    <xsl:call-template name="line-number"/>
       <xsl:if test="@src=''">
         <xsl:call-template name="error">
           <xsl:with-param name="message">
  @@ -1289,6 +1291,13 @@
         </xsl:choose>
       </xsl:variable>
   
  +    <xsl:variable name="check-delay">
  +      <xsl:choose>
  +        <xsl:when test="@check-delay"><xsl:value-of select="@check-delay"/></xsl:when>
  +        <xsl:otherwise>10000L</xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
       <xsl:variable name="reload-method">
         <xsl:choose>
           <xsl:when test="@reload-method='asynchron'">true</xsl:when>
  @@ -1306,9 +1315,17 @@
   
       <!-- generate the code to invoke the sitemapManager which handles delegation of control to sub sitemaps -->
       if (internalRequest)
  -      return sitemapManager.invoke (this.manager, environment, <xsl:apply-templates select="@uri-prefix"/>, <xsl:apply-templates select="@src"/>, <xsl:value-of select="$check-reload"/>, <xsl:value-of select="$reload-method"/>, pipeline, eventPipeline);
  -    else
  -      if (true) return sitemapManager.invoke (this.manager, environment, <xsl:apply-templates select="@uri-prefix"/>, <xsl:apply-templates select="@src"/>, <xsl:value-of select="$check-reload"/>, <xsl:value-of select="$reload-method"/>);
  +      return invoke(environment, <xsl:apply-templates select="@uri-prefix"/>
  +        <xsl:text>, </xsl:text><xsl:apply-templates select="@src"/>
  +        <xsl:text>, </xsl:text><xsl:value-of select="$check-reload"/>
  +        <xsl:text>, </xsl:text><xsl:value-of select="$reload-method"/>
  +        <xsl:text>, </xsl:text><xsl:value-of select="$check-delay"/>, pipeline, eventPipeline);
  +    else if (true)
  +      return invoke(environment, <xsl:apply-templates select="@uri-prefix"/>
  +        <xsl:text>, </xsl:text><xsl:apply-templates select="@src"/>
  +        <xsl:text>, </xsl:text><xsl:value-of select="$check-reload"/>
  +        <xsl:text>, </xsl:text><xsl:value-of select="$reload-method"/>
  +        <xsl:text>, </xsl:text><xsl:value-of select="$check-delay"/>);
     </xsl:template> <!-- match="map:mount" -->
   
   
  @@ -1571,8 +1588,6 @@
         }
       </xsl:for-each>
     </xsl:template>
  -
  -
   
     <!-- this template generates the code to collect configurations for a specific sitemap component -->
     <xsl:template name="nested-config-components">
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.4  +109 -72   xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java
  
  Index: AbstractSitemap.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java,v
  retrieving revision 1.10.2.3
  retrieving revision 1.10.2.4
  diff -u -r1.10.2.3 -r1.10.2.4
  --- AbstractSitemap.java	11 Aug 2002 20:12:00 -0000	1.10.2.3
  +++ AbstractSitemap.java	21 Sep 2002 03:01:13 -0000	1.10.2.4
  @@ -62,6 +62,7 @@
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.Processor;
   import org.apache.cocoon.acting.Action;
   import org.apache.cocoon.components.CocoonComponentManager;
   import org.apache.cocoon.components.classloader.RepositoryClassLoader;
  @@ -93,6 +94,7 @@
    * Base class for generated <code>Sitemap</code> classes
    *
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  + * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
    * @version CVS $Id$
    */
   public abstract class AbstractSitemap extends AbstractLoggable implements Sitemap, Disposable, ThreadSafe {
  @@ -123,6 +125,7 @@
       protected DefaultSitemapComponentSelector actions;
       protected DefaultSitemapComponentSelector matchers;
       protected DefaultSitemapComponentSelector selectors;
  +    protected DefaultSitemapComponentSelector sitemaps;
   
       /**
        * Set the role manager
  @@ -165,6 +168,7 @@
               this.actions = new DefaultSitemapComponentSelector();
               this.matchers = new DefaultSitemapComponentSelector();
               this.selectors = new DefaultSitemapComponentSelector();
  +            this.sitemaps = new DefaultSitemapComponentSelector();
   
               // Set Parent Sitemap Selectors
               try {
  @@ -190,6 +194,7 @@
               this.setupSelector(this.actions);
               this.setupSelector(this.matchers);
               this.setupSelector(this.selectors);
  +            this.setupSelector(this.sitemaps);
   
               // Add the Selectors
               this.manager.addComponentInstance(Generator.ROLE + "Selector", this.generators);
  @@ -199,13 +204,15 @@
               this.manager.addComponentInstance(Action.ROLE + "Selector", this.actions);
               this.manager.addComponentInstance(Matcher.ROLE + "Selector", this.matchers);
               this.manager.addComponentInstance(Selector.ROLE + "Selector", this.selectors);
  +            this.manager.addComponentInstance(Processor.ROLE + "Selector", this.sitemaps);
   
               // obtain selector for InputModules
               this.inputModuleSelector = (ComponentSelector) this.manager.lookup(InputModule.ROLE +"Selector");
  -
           } catch (Exception e) {
  -            getLogger().error("cannot obtain the Component", e);
  -            throw new ComponentException("cannot obtain the URLFactory", e);
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug("Cannot obtain the URLFactory (" + e + ")");
  +            }
  +            throw new ComponentException("Cannot obtain the URLFactory", e);
           }
       }
   
  @@ -239,63 +246,86 @@
       }
   
       /**
  -     * Determines whether generated content has changed since
  -     * last invocation. Users may override this method to take
  -     * advantage of SAX event cacheing
  -     *
  -     * @param request The request whose data must be inspected to assert whether
  -     * dynamically generated content has changed
  -     * @return Whether content has changes for this request's data
  -     */
  -
  -    /*
  -    public boolean hasContentChanged(Request request) {
  -    return true;
  -    }
  -    */
  -
  -    /**
  -    * Loads a class specified in a sitemap component definition and
  -    * initialize it
  -    */
  -
  -    public void load_component(int type, Object hint, String classURL, Configuration configuration,
  -        String mime_type) throws Exception {
  -            Class clazz = null;
  -            //FIXME(GP): Is it true that a class name containing a colon should be an URL?
  -            if (classURL.indexOf(':') > 1) {
  -                URL url = urlFactory.getURL(classURL);
  -                byte[] b = getByteArrayFromStream(url.openStream());
  -                clazz = ((RepositoryClassLoader)ClassUtils.getClassLoader()).defineClass(b);
  -            } else {
  -                clazz = ClassUtils.loadClass(classURL);
  -            }
  -            if (!Component.class.isAssignableFrom(clazz)) {
  -                throw new IllegalAccessException("Object " + classURL + " is not a Component");
  -            }
  -            switch (type) {
  -                case Sitemap.GENERATOR:
  -                    this.generators.addComponent(hint, clazz, configuration);
  -                    break;
  -                case Sitemap.TRANSFORMER:
  -                    this.transformers.addComponent(hint, clazz, configuration);
  -                    break;
  -                case Sitemap.SERIALIZER:
  -                    this.serializers.addSitemapComponent(hint, clazz, configuration, mime_type);
  -                    break;
  -                case Sitemap.READER:
  -                    this.readers.addSitemapComponent(hint, clazz, configuration, mime_type);
  -                    break;
  -                case Sitemap.ACTION:
  -                    this.actions.addComponent(hint, clazz, configuration);
  -                    break;
  -                case Sitemap.MATCHER:
  -                    this.matchers.addComponent(hint, clazz, configuration);
  -                    break;
  -                case Sitemap.SELECTOR:
  -                    this.selectors.addComponent(hint, clazz, configuration);
  -                    break;
  -            }
  +     * Loads a class specified in a sitemap component definition and
  +     * initialize it
  +     */
  +    public void load_component(int type, Object hint, String classURL,
  +                               Configuration configuration,
  +                               String mime_type) throws Exception
  +    {
  +        Class clazz = null;
  +        //FIXME(GP): Is it true that a class name containing a colon should be an URL?
  +        if (classURL.indexOf(':') > 1) {
  +            URL url = urlFactory.getURL(classURL);
  +            byte[] b = getByteArrayFromStream(url.openStream());
  +            clazz = ((RepositoryClassLoader)ClassUtils.getClassLoader()).defineClass(b);
  +        } else {
  +            clazz = ClassUtils.loadClass(classURL);
  +        }
  +        if (!Component.class.isAssignableFrom(clazz)) {
  +            throw new IllegalAccessException("Object " + classURL + " is not a Component");
  +        }
  +        switch (type) {
  +            case Sitemap.GENERATOR:
  +                this.generators.addComponent(hint, clazz, configuration);
  +                break;
  +            case Sitemap.TRANSFORMER:
  +                this.transformers.addComponent(hint, clazz, configuration);
  +                break;
  +            case Sitemap.SERIALIZER:
  +                this.serializers.addSitemapComponent(hint, clazz, configuration, mime_type);
  +                break;
  +            case Sitemap.READER:
  +                this.readers.addSitemapComponent(hint, clazz, configuration, mime_type);
  +                break;
  +            case Sitemap.ACTION:
  +                this.actions.addComponent(hint, clazz, configuration);
  +                break;
  +            case Sitemap.MATCHER:
  +                this.matchers.addComponent(hint, clazz, configuration);
  +                break;
  +            case Sitemap.SELECTOR:
  +                this.selectors.addComponent(hint, clazz, configuration);
  +                break;
  +        }
  +    }
  +
  +    protected boolean invoke(Environment environment,
  +                             String prefix,
  +                             String source,
  +                             boolean checkReload,
  +                             boolean reloadAsync,
  +                             long checkDelay) throws Exception
  +    {
  +        Handler handler = null;
  +        try {
  +            handler = (Handler)this.sitemaps.select(source);
  +        } catch (ComponentException e) {
  +            handler = sitemapManager.createHandler(this.manager, source, checkReload, reloadAsync, checkDelay);
  +            this.sitemaps.addComponentInstance(source, handler);
  +        }
  +
  +        return sitemapManager.invoke(handler, environment, prefix, source);
  +    }
  +
  +    protected boolean invoke(Environment environment,
  +                             String prefix,
  +                             String source,
  +                             boolean checkReload,
  +                             boolean reloadAsync,
  +                             long checkDelay,
  +                             StreamPipeline pipeline,
  +                             EventPipeline eventPipeline) throws Exception
  +    {
  +        Handler handler = null;
  +        try {
  +            handler = (Handler)this.sitemaps.select(source);
  +        } catch (ComponentException e) {
  +            handler = sitemapManager.createHandler(this.manager, source, checkReload, reloadAsync, checkDelay);
  +            this.sitemaps.addComponentInstance(source, handler);
  +        }
  +
  +        return sitemapManager.invoke(handler, environment, prefix, source, pipeline, eventPipeline);
       }
   
       private byte[] getByteArrayFromStream(InputStream stream) {
  @@ -325,7 +355,7 @@
         * Replaces occurences of xpath like expressions in an argument String
         * with content from a List of Maps
         */
  -    protected String substitute(List list, String expr, Environment environment) 
  +    protected String substitute(List list, String expr, Environment environment)
           throws PatternException, NumberFormatException {
   
           if (expr == null) {
  @@ -363,24 +393,23 @@
                           s = s.substring(m + 3);
                       }
                       value = ((Map)list.get(k)).get(s);
  -                } else { // InputModule expression
  +                } else {
  +                    // InputModule expression
                       String inputName = s.substring(0,n);
                       String inputAttribute = s.substring(n + 1);
                       InputModule input = null;
  -                    if (getLogger().isDebugEnabled())
  -                        getLogger().debug("Using "+inputName+" to obtain "+inputAttribute);
                       try {
                           input = (InputModule) this.inputModuleSelector.select(inputName);
  -                        if (getLogger().isDebugEnabled())
  -                            getLogger().debug((input!=null?"Got ":"No ")+inputName);
                           value = input.getAttribute(inputAttribute, null, environment.getObjectModel());
                       } catch (Exception e) {
  -                        if (getLogger().isWarnEnabled())
  -                            getLogger().warn("Problem obtaining attribute " + inputAttribute 
  +                        if (getLogger().isWarnEnabled()) {
  +                            getLogger().warn("Problem obtaining attribute " + inputAttribute
                                                + " from " + inputName + " : " + e.getMessage());
  +                        }
                       } finally {
  -                        if (input != null) 
  +                        if (input != null) {
                               this.inputModuleSelector.release(input);
  +                        }
                       }
                   }
                   if (value != null){
  @@ -388,7 +417,7 @@
                       if (getLogger().isDebugEnabled()) {
                           getLogger().debug("Substitute evaluated value for " + s + " as " + value);
                       }
  -                }else{
  +                } else {
                       getLogger().warn("Substitute: value not found for " + s + " while evaluating " + expr);
                   }
               }
  @@ -485,6 +514,10 @@
        * dispose
        */
       public void dispose() {
  +        if (this.getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("Disposing");
  +        }
  +
           if (this.inputModuleSelector != null) {
               this.manager.release(inputModuleSelector);
           }
  @@ -514,7 +547,11 @@
           manager.release(this.selectors);
           this.selectors = null;
   
  -        manager = null;
  +        manager.release(this.sitemaps);
  +        this.sitemaps = null;
  +
  +        this.manager.dispose();
  +        this.manager = null;
       }
   
       /**
  
  
  
  1.14.2.3  +56 -64    xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/Handler.java
  
  Index: Handler.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/Handler.java,v
  retrieving revision 1.14.2.2
  retrieving revision 1.14.2.3
  diff -u -r1.14.2.2 -r1.14.2.3
  --- Handler.java	4 Aug 2002 04:11:53 -0000	1.14.2.2
  +++ Handler.java	21 Sep 2002 03:01:13 -0000	1.14.2.3
  @@ -51,7 +51,6 @@
   package org.apache.cocoon.sitemap;
   
   import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  @@ -62,7 +61,6 @@
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.Processor;
   import org.apache.cocoon.components.CocoonComponentManager;
  -import org.apache.cocoon.components.language.generator.CompiledComponent;
   import org.apache.cocoon.components.language.generator.ProgramGenerator;
   import org.apache.cocoon.components.pipeline.EventPipeline;
   import org.apache.cocoon.components.pipeline.StreamPipeline;
  @@ -74,7 +72,6 @@
   import org.apache.cocoon.environment.SourceResolver;
   import org.xml.sax.SAXException;
   
  -import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.net.MalformedURLException;
   import java.net.URL;
  @@ -93,13 +90,15 @@
   
       /** the component manager */
       protected ComponentManager manager;
  +    protected ProgramGenerator programGenerator;
  +
  +    /** The source handler for the sitemap components */
  +    protected SourceHandler sourceHandler;
   
       /** the source of this sitemap */
       protected String sourceFileName;
       protected Source source;
  -
  -    /** the last error */
  -    protected Exception exception;
  +    protected String contextFileName;
   
       /** the managed sitemap */
       protected Sitemap sitemap = null;
  @@ -108,50 +107,41 @@
       /** the regenerating thread */
       protected Thread regeneration;
       protected volatile boolean isRegenerationRunning = false;
  -    protected Source contextSource;
  -
  -    /** the sitemaps base path */
  -    protected String basePath;
  -
  -    /** The source handler for the sitemap components */
  -    protected SourceHandler sourceHandler;
   
  -    // FIXME : ugly hack to pass delay information from the main sitemap configuration
  -    // (the way to pass it cleanly from SitemapManager isn't obvious).
  -    protected static long sitemapCheckDelay = 10000L; // default is 10 secs.
  +    /** the last error */
  +    protected Exception exception;
   
  -    static void setSitemapCheckDelay(long delay) {
  -        sitemapCheckDelay = delay;
  -    }
  +    protected long checkDelay = 10000L; // default is 10 secs.
   
       public Handler() {}
   
       /**
        * Contextualizable
        */
  -    public void contextualize(Context context)
  -    throws ContextException {
  +    public void contextualize(Context context) throws ContextException {
       }
   
       /**
        * Composable
        */
  -    public void compose(ComponentManager manager)
  -    throws ComponentException {
  +    public void compose(ComponentManager manager) throws ComponentException {
           this.manager = manager;
           this.sourceHandler = (SourceHandler)manager.lookup(SourceHandler.ROLE);
  +        this.programGenerator = (ProgramGenerator)this.manager.lookup(ProgramGenerator.ROLE);
       }
   
  -    public void setSourceFileName(String sourceFileName)
  -    {
  +    public void setSourceFileName(String sourceFileName) {
           this.sourceFileName = sourceFileName;
       }
   
  -    public void setCheckReload(boolean check_reload)
  -    {
  +    public void setCheckReload(boolean check_reload) {
           this.check_reload = check_reload;
       }
   
  +    public void setCheckDelay(long delay) {
  +        this.checkDelay = delay;
  +    }
  +
       protected boolean available() {
           return (sitemap != null);
       }
  @@ -170,7 +160,7 @@
           return isRegenerationRunning;
       }
   
  -    protected void regenerateAsynchronously(Environment environment) throws Exception {
  +    private void regenerateAsynchronously(Environment environment) throws Exception {
           if (this.sourceFileName.charAt(this.sourceFileName.length() - 1) == '/') {
               this.sourceFileName = this.sourceFileName + "sitemap.xmap";
           }
  @@ -178,12 +168,19 @@
           try {
               environment.setSourceHandler(this.sourceHandler);
   
  -            if (this.source != null) this.source.recycle();
  +            if (this.source != null) {
  +                this.source.recycle();
  +            }
               this.source = new DelayedRefreshSourceWrapper(
  -                environment.resolve(this.sourceFileName), this.sitemapCheckDelay);
  +                environment.resolve(this.sourceFileName), this.checkDelay);
   
  -            if (this.contextSource != null) this.contextSource.recycle();
  -            this.contextSource = environment.resolve("");
  +            Source contextSource = null;
  +            try {
  +                contextSource = environment.resolve("");
  +                contextFileName = contextSource.getSystemId();
  +            } finally {
  +                if (contextSource != null) contextSource.recycle();
  +            }
           } finally {
               environment.setSourceHandler(oldSourceHandler);
           }
  @@ -195,8 +192,7 @@
               /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */
               try {
                   regeneration.setContextClassLoader(Thread.currentThread().getContextClassLoader());
  -            } catch (Exception e) {
  -            }
  +            } catch (Exception e) { }
   
               /* clear old exception if any */
               this.exception = null;
  @@ -208,9 +204,13 @@
   
       protected void regenerate(Environment environment) throws Exception {
           getLogger().debug("Beginning sitemap regeneration");
  -        this.regenerateAsynchronously(environment);
  -        if (regeneration != null) {
  -            this.regeneration.join();
  +        synchronized(this) {
  +            if (!available() || hasChanged()) {
  +                if (regeneration == null)
  +                    this.regenerateAsynchronously(environment);
  +                if (regeneration != null)
  +                    this.regeneration.join();
  +            }
           }
           throwEventualException();
       }
  @@ -258,19 +258,13 @@
           }
       }
   
  -    public void setBasePath(String basePath) {
  -        this.basePath = basePath;
  -    }
  -
       /** Generate the Sitemap class */
       public void run() {
           Sitemap smap = null;
           String markupLanguage = "sitemap";
           String programmingLanguage = "java";
  -        ProgramGenerator programGenerator = null;
           try {
  -            programGenerator = (ProgramGenerator)this.manager.lookup(ProgramGenerator.ROLE);
  -            smap = (Sitemap)programGenerator.load(this.manager, this.sourceFileName, markupLanguage,
  +            smap = (Sitemap)programGenerator.load(this.manager, this.source, markupLanguage,
                       programmingLanguage, this);
               if (smap instanceof AbstractLoggable) {
                   ((AbstractLoggable)smap).setLogger(getLogger());
  @@ -279,7 +273,7 @@
               // Swap old and new sitemaps
               Sitemap oldSitemap = this.sitemap;
               this.sitemap = smap;
  -            programGenerator.release((CompiledComponent)oldSitemap);
  +            programGenerator.release(oldSitemap);
   
               // add the source factory for the cocoon protocol
               this.sourceHandler.addFactory("cocoon",
  @@ -298,12 +292,8 @@
                   this.exception = new ProcessingException("Error compiling sitemap",t);
               }
           } finally {
  -            this.manager.release(programGenerator);
  -
               this.regeneration = null;
               this.isRegenerationRunning = false;
  -            this.contextSource.recycle();
  -            this.contextSource = null;
           }
       }
   
  @@ -321,26 +311,30 @@
        * dispose
        */
       public void dispose() {
  +        if (this.sitemap != null) {
  +            programGenerator.release(this.sitemap);
  +            this.sitemap = null;
  +        }
  +
           if (this.source != null) {
  +            this.programGenerator.remove(this.source);
               this.source.recycle();
               this.source = null;
           }
  -        if (this.contextSource != null) {
  -            this.contextSource.recycle();
  -            this.contextSource = null;
  -        }
   
  -        manager.release(this.sourceHandler);
  +        this.manager.release(this.programGenerator);
  +        this.programGenerator = null;
  +
  +        this.manager.release(this.sourceHandler);
           this.sourceHandler = null;
   
  -        this.basePath = null;
           this.sourceFileName = null;
           this.exception = null;
  -        this.sitemap = null;
           this.check_reload = true;
           this.regeneration = null;
           this.isRegenerationRunning = false;
  -        manager = null;
  +
  +        this.manager = null;
       }
   
       /**
  @@ -350,15 +344,14 @@
       throws ProcessingException, SAXException, IOException {
           if (systemId == null) throw new SAXException("Invalid System ID");
   
  -        URL context = new URL(this.contextSource.getSystemId());
  +        URL context = new URL(this.contextFileName);
   
           if (systemId.length() == 0)
               return this.sourceHandler.getSource(null, context, systemId);
           if (systemId.indexOf(":") > 1)
               return this.sourceHandler.getSource(null, systemId);
           if (systemId.charAt(0) == '/')
  -            return this.sourceHandler.getSource(null, new StringBuffer(context.getProtocol())
  -                                                .append(":").append(systemId).toString());
  +            return this.sourceHandler.getSource(null, context.getProtocol() + ":" + systemId);
           return this.sourceHandler.getSource(null, context, systemId);
       }
   
  @@ -375,8 +368,8 @@
        * Get a <code>Source</code> object.
        */
       public org.apache.excalibur.source.Source resolveURI(final String location,
  -                                                                String baseURI,
  -                                                                final Map    parameters)
  +                                                         String baseURI,
  +                                                         final Map parameters)
       throws MalformedURLException, IOException, ComponentException {
           throw new RuntimeException("Handler.resolveURI() is not implemented yet.");
       }
  @@ -387,5 +380,4 @@
       public void release( final org.apache.excalibur.source.Source source ) {
           throw new RuntimeException("Handler.release() is not implemented yet.");
       }
  -
   }
  
  
  
  1.9.2.1   +43 -129   xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/Manager.java
  
  Index: Manager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/Manager.java,v
  retrieving revision 1.9
  retrieving revision 1.9.2.1
  diff -u -r1.9 -r1.9.2.1
  --- Manager.java	22 Feb 2002 07:03:55 -0000	1.9
  +++ Manager.java	21 Sep 2002 03:01:13 -0000	1.9.2.1
  @@ -89,9 +89,6 @@
   {
       protected Context context;
   
  -    /** The vectors of sub sitemaps */
  -    protected HashMap sitemaps = new HashMap();
  -
       /** The configuration */
       protected Configuration conf;
   
  @@ -120,7 +117,8 @@
           this.sitemapLogKitManager = logkit;
       }
   
  -    /** get a configuration
  +    /**
  +     * Get a configuration
        * @param conf the configuration
        */
       public void configure(Configuration conf)
  @@ -133,7 +131,7 @@
                   handlerClass = Class.forName(value);
               } catch (ClassNotFoundException ex) {
                   throw new ConfigurationException("Cannot find Handler class "
  -                                             + value);
  +                        + value);
               }
           }
       }
  @@ -145,33 +143,29 @@
           this.context = context;
       }
   
  -    /** get a component manager
  +    /**
  +     * Get a component manager
        * @param manager the component manager
        */
       public void compose(ComponentManager manager) {
           this.manager = manager;
       }
   
  -    /** invokes the sitemap handler to process a request
  +    /**
  +     * Invokes the sitemap handler to process a request
        * @param environment the environment
        * @param uri_prefix the prefix to the URI
        * @param source the source of the sitemap
  -     * @param check_reload should the sitemap be automagically reloaded
  -     * @param reload_asynchron should the sitemap be reloaded asynchron
        * @throws Exception there may be several excpetions thrown
        * @return states if the requested resource was produced
        */
  -    public boolean invoke(ComponentManager newManager,
  +    public boolean invoke(Handler sitemapHandler,
                             Environment environment,
                             String uri_prefix,
  -                          String source,
  -                          boolean check_reload,
  -                          boolean reload_asynchron)
  +                          String source)
       throws Exception {
  -        // get a sitemap handler
  -        Handler sitemapHandler = getHandler(newManager, environment, source, check_reload, reload_asynchron);
  -        // setup to invoke the processing
  -        setupProcessing(environment, sitemapHandler, uri_prefix, source);
  +        // Setup to invoke the processing
  +        setupProcessing(sitemapHandler, environment);
           String prefix = environment.getURIPrefix();
           String uri    = environment.getURI();
           try {
  @@ -182,28 +176,23 @@
           }
       }
   
  -    /** invokes the sitemap handler to process a request
  +    /**
  +     * Invokes the sitemap handler to process a request
        * @param environment the environment
        * @param uri_prefix the prefix to the URI
        * @param source the source of the sitemap
  -     * @param check_reload should the sitemap be automagically reloaded
  -     * @param reload_asynchron should the sitemap be reloaded asynchron
        * @throws Exception there may be several excpetions thrown
        * @return states if the requested resource was produced
        */
  -    public boolean invoke(ComponentManager newManager,
  +    public boolean invoke(Handler sitemapHandler,
                             Environment environment,
                             String uri_prefix,
                             String source,
  -                          boolean check_reload,
  -                          boolean reload_asynchron,
                             StreamPipeline pipeline,
                             EventPipeline eventPipeline)
       throws Exception {
  -        // get a sitemap handler
  -        Handler sitemapHandler = getHandler(newManager, environment, source, check_reload, reload_asynchron);
  -        // setup to invoke the processing
  -        setupProcessing(environment, sitemapHandler, uri_prefix, source);
  +        // Setup to invoke the processing
  +        setupProcessing(sitemapHandler, environment);
           String prefix = environment.getURIPrefix();
           String uri    = environment.getURI();
           try {
  @@ -214,102 +203,13 @@
           }
       }
   
  -    /** has the sitemap changed
  -     * @return whether the sitemap file has changed
  -     */
  -    public boolean hasChanged() {
  -        Handler sitemapHandler = null;
  -        Iterator iter = sitemaps.values().iterator();
  -        while (iter.hasNext()) {
  -            sitemapHandler = (Handler)iter.next();
  -            if ((sitemapHandler != null) && (sitemapHandler.hasChanged())) {
  -                return true;
  -            }
  -        }
  -        return false;
  -    }
  -
  -    protected void generateSitemap(String sitemapFileName, Environment environment)
  -    throws Exception {
  -        getHandler(this.manager, environment, sitemapFileName, true, false);
  -    }
  -
  -    private Handler getHandler(final ComponentManager newManager,
  -                               final Environment environment,
  -                               final String source,
  -                               final boolean check_reload,
  -                               final boolean reload_asynchron)
  -    throws Exception {
  -        Handler sitemapHandler = (Handler)sitemaps.get(source);
  -        if (sitemapHandler != null) {
  -            // The following is a little bit complicated:
  -            // If the sitemap handler is not available, it is regenerated
  -            // If it is available:
  -            //    The handler is only queried if it has changed if
  -            //    the check_reload flag is true
  -            if (sitemapHandler.available()) {
  -                if (check_reload && sitemapHandler.hasChanged()) {
  -                    // The sitemap has been changed.
  -                    if (reload_asynchron) {
  -                        // In asynchron mode the first request entering this
  -                        // starts the regeneration. All other request comming
  -                        // in, use the old sitemap until the new is generated.
  -                        if (!sitemapHandler.isRegenerating()) {
  -                            sitemapHandler.regenerateAsynchronously(environment);
  -                        }
  -                    } else {
  -                        // In synchron mode the first request starts the
  -                        // regeneration, all other requests are blocked
  -                        // until the regeneration is finished. This is done
  -                        // by the synchronized statement
  -                        if (!sitemapHandler.isRegenerating()) {
  -                            synchronized (this) {
  -                                sitemapHandler.regenerate(environment);
  -                            }
  -                        } else {
  -                            synchronized (this) {
  -                                // Dummy statement
  -                                this.hashCode();
  -                            }
  -                        }
  -                    }
  -                }
  -            } else {
  -                sitemapHandler.regenerate(environment);
  -            }
  -        } else {
  -            // Also this looks a little bit strange, it should work
  -            // if no handler is available, the generation of the new
  -            // handler is synchronized.
  -            // The first incoming request creates the handler and blocks
  -            // all incoming requests. When the generation is finished
  -            // all other requests enter (one after the other) this method
  -            // and get the new created handler with the first get
  -            // statement
  -            synchronized (this) {
  -                sitemapHandler = (Handler)sitemaps.get(source);
  -                if (sitemapHandler == null) {
  -                    sitemapHandler = (Handler)handlerClass.newInstance();
  -                    sitemapHandler.setSourceFileName(source);
  -                    sitemapHandler.setCheckReload(check_reload);
  -                    sitemapHandler.setLogger(getLogger());
  -                    sitemapHandler.compose(newManager);
  -                    sitemapHandler.contextualize(this.context);
  -                    if (sitemapHandler instanceof Configurable)
  -                        ((Configurable)sitemapHandler).configure(conf);
  -                    sitemapHandler.regenerate(environment);
  -                    sitemaps.put(source, sitemapHandler);
  -                }
  -            }
  +    private void setupProcessing(Handler sitemapHandler, Environment environment)
  +            throws Exception
  +    {
  +        if (!sitemapHandler.available() || sitemapHandler.hasChanged()) {
  +            sitemapHandler.regenerate(environment);
           }
  -        return sitemapHandler;
  -    }
   
  -    private void setupProcessing(Environment environment,
  -                                 Handler sitemapHandler,
  -                                 String uri_prefix,
  -                                 String source)
  -    throws Exception {
           if (!sitemapHandler.available()) {
               if (sitemapHandler.getException() != null) {
                   throw sitemapHandler.getException();
  @@ -320,18 +220,32 @@
           }
       }
   
  +    protected Handler createHandler(final ComponentManager newManager,
  +                                 final String source,
  +                                 final boolean check_reload,
  +                                 final boolean reload_async,
  +                                 final long check_delay)
  +    throws Exception {
  +        Handler sitemapHandler = null;
  +        synchronized (this) {
  +            sitemapHandler = (Handler)handlerClass.newInstance();
  +            sitemapHandler.setSourceFileName(source);
  +            sitemapHandler.setCheckReload(check_reload);
  +            sitemapHandler.setCheckDelay(check_delay);
  +            sitemapHandler.setLogger(getLogger());
  +            sitemapHandler.compose(newManager);
  +            sitemapHandler.contextualize(this.context);
  +            if (sitemapHandler instanceof Configurable)
  +                ((Configurable)sitemapHandler).configure(conf);
  +        }
  +        return sitemapHandler;
  +    }
  +
       /**
        * Disposable
        */
       public void dispose() {
           context = null;
  -        for (Iterator i = sitemaps.values().iterator(); i.hasNext();) {
  -            Handler sitemapHandler = (Handler)i.next();
  -            if (sitemapHandler != null) {
  -                sitemapHandler.dispose();
  -            }
  -        }
  -        sitemaps.clear();
           conf = null;
           manager = null;
       }
  
  
  
  1.10.2.1  +24 -22    xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/SitemapManager.java
  
  Index: SitemapManager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/SitemapManager.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- SitemapManager.java	22 Feb 2002 07:03:55 -0000	1.10
  +++ SitemapManager.java	21 Sep 2002 03:01:13 -0000	1.10.2.1
  @@ -73,6 +73,7 @@
   import org.xml.sax.InputSource;
   
   import java.io.InputStream;
  +import java.util.HashMap;
   
   /**
    * A <code>Processor</code> based on the sitemap language files.
  @@ -86,31 +87,22 @@
       /** The sitemap file */
       protected String sitemapFileName;
   
  -    /** Check reloading of sitemap */
  -    private boolean checkSitemapReload = true;
  -
  -    /** reload sitemap asynchron */
  -    private boolean reloadSitemapAsynchron = true;
  +    /** The root sitemap's handler */
  +    protected Handler sitemapHandler;
   
       public void configure(Configuration sconf) throws ConfigurationException {
   
           super.configure(sconf);
   
           this.sitemapFileName = sconf.getAttribute("file");
  -
  -        String value = sconf.getAttribute("check-reload", "yes");
  -        this.checkSitemapReload = !(value != null && value.equalsIgnoreCase("no"));
  -
  -        value = sconf.getAttribute("reload-method", "asynchron");
  -        this.reloadSitemapAsynchron = !(value != null && value.equalsIgnoreCase("synchron"));
  -
  -        long checkDelay = sconf.getAttributeAsLong("check-delay", 1L);
  -        Handler.setSitemapCheckDelay(checkDelay * 1000L);
  +        boolean checkReload = sconf.getAttributeAsBoolean("check-reload", true);
  +        boolean reloadAsynchron = sconf.getAttributeAsBoolean("reload-method", false);
  +        long checkDelay = sconf.getAttributeAsLong("check-delay", 1L) * 1000;
   
           if (this.getLogger().isDebugEnabled()) {
               getLogger().debug("Sitemap location = " + this.sitemapFileName);
  -            getLogger().debug("Checking sitemap reload = " + this.checkSitemapReload);
  -            getLogger().debug("Reloading sitemap asynchron = " + this.reloadSitemapAsynchron);
  +            getLogger().debug("Checking sitemap reload = " + checkReload);
  +            getLogger().debug("Reloading sitemap asynchron = " + reloadAsynchron);
               getLogger().debug("Sitemap check delay = " + checkDelay + " sec");
           }
   
  @@ -138,21 +130,26 @@
   
           AbstractSitemap.setRoleManager(sitemapRoleManager, sconf);
           AbstractSitemap.setLogKitManager(this.sitemapLogKitManager);
  +
  +        try {
  +            sitemapHandler = createHandler(this.manager, this.sitemapFileName, checkReload, reloadAsynchron, checkDelay);
  +        } catch (Exception e) {
  +            throw new ConfigurationException("Failed to create sitemap handler", e);
  +        }
       }
   
       /**
        * Process the given <code>Environment</code> to generate the sitemap.
        */
       public void generateSitemap(Environment environment) throws Exception {
  -        super.generateSitemap(this.sitemapFileName, environment);
  +        this.sitemapHandler.regenerate(environment);
       }
   
       /**
        * Process the given <code>Environment</code> producing the output.
        */
       public boolean process(Environment environment) throws Exception {
  -        return this.invoke(this.manager, environment, "", this.sitemapFileName,
  -                           this.checkSitemapReload, this.reloadSitemapAsynchron);
  +        return invoke(sitemapHandler, environment, "", sitemapFileName);
       }
   
       /**
  @@ -163,7 +160,12 @@
                              StreamPipeline pipeline,
                              EventPipeline eventPipeline)
       throws Exception {
  -        return this.invoke(this.manager, environment, "", this.sitemapFileName,
  -                           this.checkSitemapReload, this.reloadSitemapAsynchron, pipeline, eventPipeline);
  +        return invoke(sitemapHandler, environment, "", sitemapFileName, pipeline, eventPipeline);
  +    }
  +
  +    public void dispose() {
  +        this.sitemapHandler.dispose();
  +        this.sitemapHandler = null;
  +        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