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/org/apache/cocoon/components/url URLFactory.java URLFactoryImpl.java
Date Thu, 13 Dec 2001 11:50:25 GMT
cziegeler    01/12/13 03:50:25

  Modified:    .        Tag: cocoon_20_branch changes.xml
               src/org/apache/cocoon/components/source Tag:
                        cocoon_20_branch SourceHandlerImpl.java
               src/org/apache/cocoon/components/url Tag: cocoon_20_branch
                        URLFactory.java URLFactoryImpl.java
  Log:
  URLFactories can now be Configurable.
  Synced with 2.1: SourceHandlers can be Configurable.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.50  +6 -2      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.2.2.49
  retrieving revision 1.2.2.50
  diff -u -r1.2.2.49 -r1.2.2.50
  --- changes.xml	2001/11/29 12:38:54	1.2.2.49
  +++ changes.xml	2001/12/13 11:50:24	1.2.2.50
  @@ -4,7 +4,7 @@
   
   <!--
     History of Cocoon changes
  -  $Id: changes.xml,v 1.2.2.49 2001/11/29 12:38:54 cziegeler Exp $
  +  $Id: changes.xml,v 1.2.2.50 2001/12/13 11:50:24 cziegeler Exp $
   -->
   
   <changes title="History of Changes">
  @@ -28,7 +28,11 @@
   
    <release version="@version@" date="@date@">
     <action dev="CZ" type="update">
  -     Dummy action
  +    Added support for configurable URLFactories.
  +  </action>
  +  <action dev="CZ" type="update">
  +    Added support for configurable SourceFactories.
  +    Patch submitted by Gianugo Rabellino [gianugo@rabellino.it].
     </action>
    </release>
    <release version="2.0" date="November 29, 2001">
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.10  +11 -5     xml-cocoon2/src/org/apache/cocoon/components/source/SourceHandlerImpl.java
  
  Index: SourceHandlerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/SourceHandlerImpl.java,v
  retrieving revision 1.1.2.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- SourceHandlerImpl.java	2001/11/05 09:59:59	1.1.2.9
  +++ SourceHandlerImpl.java	2001/12/13 11:50:25	1.1.2.10
  @@ -36,7 +36,7 @@
   
   /**
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version $Id: SourceHandlerImpl.java,v 1.1.2.9 2001/11/05 09:59:59 cziegeler Exp $
  + * @version $Id: SourceHandlerImpl.java,v 1.1.2.10 2001/12/13 11:50:25 cziegeler Exp $
    */
   public final class SourceHandlerImpl
   extends AbstractLoggable
  @@ -73,9 +73,10 @@
   
                   getLogger().debug("\tfor protocol: " + protocol + " " + configs[i].getAttribute("class"));
                   sourceFactory = (SourceFactory) ClassUtils.newInstance(configs[i].getAttribute("class"));
  -                this.init(sourceFactory);
  +                this.init(sourceFactory, configs[i]);
                   factories.put(protocol, sourceFactory);
               }
  +
               this.sourceFactories = java.util.Collections.synchronizedMap(factories);
           } catch (ConfigurationException e) {
               throw e;
  @@ -159,20 +160,22 @@
       public void addFactory(String protocol, SourceFactory factory)
       throws ProcessingException {
           try {
  -            this.init(factory);
  +            this.init(factory, null);
               this.sourceFactories.put(protocol, factory);
           } catch (ComponentException e) {
               throw new ProcessingException("cannot initialize factory: " + factory, e);
           } catch (ContextException e) {
               throw new ProcessingException("cannot initialize factory: " + factory, e);
  +        } catch (ConfigurationException e) {
  +            throw new ProcessingException("cannot configure factory: " + factory, e);
           }
       }
   
       /**
        * Init a source factory
        */
  -    private void init(SourceFactory factory)
  -    throws ContextException, ComponentException {
  +    private void init(SourceFactory factory, Configuration config)
  +    throws ContextException, ComponentException, ConfigurationException {
           if (factory instanceof Loggable) {
               ((Loggable) factory).setLogger(getLogger());
           }
  @@ -181,6 +184,9 @@
           }
           if (factory instanceof Composable) {
               ((Composable) factory).compose(this.manager);
  +        }
  +        if (config != null && factory instanceof Configurable) {
  +            ((Configurable) factory).configure(config);
           }
       }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.2.5 +3 -3      xml-cocoon2/src/org/apache/cocoon/components/url/URLFactory.java
  
  Index: URLFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/url/URLFactory.java,v
  retrieving revision 1.1.1.1.2.4
  retrieving revision 1.1.1.1.2.5
  diff -u -r1.1.1.1.2.4 -r1.1.1.1.2.5
  --- URLFactory.java	2001/10/11 08:56:10	1.1.1.1.2.4
  +++ URLFactory.java	2001/12/13 11:50:25	1.1.1.1.2.5
  @@ -7,16 +7,16 @@
    *****************************************************************************/
   package org.apache.cocoon.components.url;
   
  -import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.avalon.framework.component.Component;
   
   import java.net.MalformedURLException;
   import java.net.URL;
   
   /**
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
  - * @version $Id: URLFactory.java,v 1.1.1.1.2.4 2001/10/11 08:56:10 cziegeler Exp $
  + * @version $Id: URLFactory.java,v 1.1.1.1.2.5 2001/12/13 11:50:25 cziegeler Exp $
    */
  -public interface URLFactory extends ThreadSafe {
  +public interface URLFactory extends Component {
   
       String ROLE = "org.apache.cocoon.components.url.URLFactory";
       /**
  
  
  
  1.2.2.10  +69 -9     xml-cocoon2/src/org/apache/cocoon/components/url/URLFactoryImpl.java
  
  Index: URLFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/url/URLFactoryImpl.java,v
  retrieving revision 1.2.2.9
  retrieving revision 1.2.2.10
  diff -u -r1.2.2.9 -r1.2.2.10
  --- URLFactoryImpl.java	2001/10/11 08:56:10	1.2.2.9
  +++ URLFactoryImpl.java	2001/12/13 11:50:25	1.2.2.10
  @@ -7,7 +7,11 @@
    *****************************************************************************/
   package org.apache.cocoon.components.url;
   
  +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;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -16,6 +20,7 @@
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.logger.Loggable;
  +import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.environment.http.HttpContext;
   import org.apache.cocoon.util.ClassUtils;
  @@ -30,9 +35,11 @@
   
   /**
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
  - * @version $Id: URLFactoryImpl.java,v 1.2.2.9 2001/10/11 08:56:10 cziegeler Exp $
  + * @version $Id: URLFactoryImpl.java,v 1.2.2.10 2001/12/13 11:50:25 cziegeler Exp $
    */
  -public class URLFactoryImpl extends AbstractLoggable implements URLFactory, Component,
Configurable, Contextualizable {
  +public class URLFactoryImpl
  +extends AbstractLoggable
  +implements ThreadSafe, Configurable, Disposable, Composable, Contextualizable, URLFactory
{
   
       /**
        * The context
  @@ -44,6 +51,9 @@
        */
       protected Map factories;
   
  +    /** The component manager */
  +    private ComponentManager manager;
  +
       /**
        * Create a URL from a location. This method supports specific
        * pseudo-protocol as defined in its configuration
  @@ -123,7 +133,8 @@
       /**
        * Configure the URLFactories
        */
  -    public void configure(final Configuration conf) throws ConfigurationException {
  +    public void configure(final Configuration conf)
  +    throws ConfigurationException {
           try {
               getLogger().debug("Getting the URLFactories");
               factories = new HashMap();
  @@ -132,14 +143,12 @@
               String protocol = null;
               for (int i = 0; i < configs.length; i++) {
                   protocol = configs[i].getAttribute("name");
  +                if (factories.containsKey(protocol) == true) {
  +                    throw new ConfigurationException("URLFactory defined twice for protocol:
" + protocol);
  +                }
                   getLogger().debug("\tfor protocol: " + protocol + " " + configs[i].getAttribute("class"));
                   urlFactory = (URLFactory) ClassUtils.newInstance(configs[i].getAttribute("class"));
  -                if (urlFactory instanceof Contextualizable) {
  -                    ((Contextualizable) urlFactory).contextualize (this.context);
  -                }
  -                if (urlFactory instanceof Loggable) {
  -                    ((Loggable) urlFactory).setLogger(getLogger());
  -                }
  +                this.init(urlFactory, configs[i]);
                   factories.put(protocol, urlFactory);
               }
           } catch (Exception e) {
  @@ -148,4 +157,55 @@
                                              e.getMessage());
           }
       }
  +
  +    /**
  +     * Set the current <code>ComponentManager</code> instance used by this
  +     * <code>Composable</code>.
  +     */
  +    public void compose(ComponentManager manager)
  +    throws ComponentException {
  +        this.manager = manager;
  +    }
  +
  +    /**
  +     * Dispose
  +     */
  +    public void dispose() {
  +        Iterator iter = this.factories.values().iterator();
  +        URLFactory current;
  +        while (iter.hasNext() == true) {
  +            current = (URLFactory) iter.next();
  +            this.deinit(current);
  +        }
  +        this.factories = null;
  +    }
  +
  +    /**
  +     * Init a url factory
  +     */
  +    private void init(URLFactory factory, Configuration config)
  +    throws ContextException, ComponentException, ConfigurationException {
  +        if (factory instanceof Loggable) {
  +            ((Loggable) factory).setLogger(getLogger());
  +        }
  +        if (factory instanceof Contextualizable) {
  +            ((Contextualizable) factory).contextualize (this.context);
  +        }
  +        if (factory instanceof Composable) {
  +            ((Composable) factory).compose(this.manager);
  +        }
  +        if (config != null && factory instanceof Configurable) {
  +            ((Configurable) factory).configure(config);
  +        }
  +    }
  +
  +    /**
  +     * Deinit a url factory
  +     */
  +    private void deinit(URLFactory factory) {
  +        if (factory instanceof Disposable) {
  +            ((Disposable) factory).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