You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@locus.apache.org on 2000/09/10 21:57:46 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon/sitemap AbstractSitemap.java ResourcePipeline.java

giacomo     00/09/10 12:57:46

  Modified:    src/org/apache/cocoon/sitemap Tag: xml-cocoon2
                        AbstractSitemap.java ResourcePipeline.java
  Log:
  Class loading and configuration fixed
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.7   +36 -32    xml-cocoon/src/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java
  
  Index: AbstractSitemap.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- AbstractSitemap.java	2000/09/06 23:22:25	1.1.2.6
  +++ AbstractSitemap.java	2000/09/10 19:57:45	1.1.2.7
  @@ -17,37 +17,37 @@
   import org.apache.avalon.Composer;
   import org.apache.avalon.Configurable;
   import org.apache.avalon.Configuration;
  -import org.apache.cocoon.ProcessingException; 
  -import org.apache.cocoon.Processor; 
  -import org.apache.cocoon.environment.Environment; 
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.Processor;
  +import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.util.ClassUtils;
   
  -import org.xml.sax.SAXException; 
  +import org.xml.sax.SAXException;
   
   /**
    * Base class for generated <code>Sitemap</code> classes
    *
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/09/06 23:22:25 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/09/10 19:57:45 $
    */
   public abstract class AbstractSitemap
  -         implements Sitemap {      
  -    /** The component manager instance */  
  -    protected ComponentManager manager=null;  
  - 
  -    /** The sitemap manager instance */  
  -    protected SitemapManager sitemapManager=null;  
  +         implements Sitemap {
  +    /** The component manager instance */
  +    protected ComponentManager manager=null;
   
  +    /** The sitemap manager instance */
  +    protected SitemapManager sitemapManager=null;
  +
       /** The creation date */
       protected static long dateCreated = -1L;
  -  
  -    /**  
  -     * Set the current <code>ComponentManager</code> instance used by this  
  -     * <code>Composer</code>.  
  -     */  
  -    public void setComponentManager(ComponentManager manager) {  
  -        this.manager=manager;  
  -    }  
  +
  +    /**
  +     * Set the current <code>ComponentManager</code> instance used by this
  +     * <code>Composer</code>.
  +     */
  +    public void setComponentManager(ComponentManager manager) {
  +        this.manager=manager;
  +    }
   
       /**
        * Determines whether this generator's source files have changed
  @@ -75,29 +75,33 @@
           return true;
       }
   
  -     /** 
  +     /**
         * Loads a class specified in a sitemap component definition and
         * initialize it
  -      */ 
  +      */
       protected Component load_component(String classURL, Configuration conf) throws Exception {
           Object comp = ClassUtils.newInstance(classURL);
           if (!(comp instanceof Component)) {
               throw new IllegalAccessException ("Object " + classURL + " is not a Component");
           }
  +        /* (GP)FIXME: The new AvalonAware release should contain Interfaces to mark classes
  +           an ThreadSafe, Recyclable or Poolable and depending on that should instanciate
  +           and configurate these objects accordingly
           if (comp instanceof Composer) {
               ((Composer) comp).setComponentManager(this.manager);
           }
           if (comp instanceof Configurable) {
               ((Configurable) comp).setConfiguration(conf);
           }
  -        return ((Component) comp); 
  -    } 
  +        */
  +        return ((Component) comp);
  +    }
   
  -     /** 
  +     /**
         * Replaces occurences of xpath like expressions in an argument String
         * with content from a List of Lists
  -      */ 
  -    protected String substitute (List list, String expr) 
  +      */
  +    protected String substitute (List list, String expr)
       throws PatternException, NumberFormatException {
           StringBuffer result = new StringBuffer();
           String s = null;
  @@ -112,10 +116,10 @@
               while (ii <= expr.length() && (i = expr.indexOf('{', ii)) != -1) {
                   result.append(expr.substring(ii, i));
                   j = expr.indexOf('}', i);
  -                if (j < i) 
  +                if (j < i)
                       throw new PatternException ("invalid expression in \""+expr+"\"");
                   ii = j+1;
  -                if (j == -1) 
  +                if (j == -1)
                       throw new PatternException ("invalid expression in URL "+expr);
                   k = list.size() - 1;
                   s = expr.substring (i+1,j);
  @@ -131,12 +135,12 @@
               if (ii < expr.length()) {
                   result.append(expr.substring(ii));
               }
  -            return (result.toString()); 
  +            return (result.toString());
           } catch (Exception e) {
  -            throw new PatternException 
  +            throw new PatternException
                       ("error occurred during evaluation of expression \""
                        +expr+"\" at position "+(i+1)+"\n"
  -                     + e.getMessage());        
  +                     + e.getMessage());
           }
       }
   
  @@ -146,4 +150,4 @@
        */
       public abstract boolean process (Environment environment)
       throws Exception;
  -} 
  +}
  
  
  
  1.1.2.14  +31 -28    xml-cocoon/src/org/apache/cocoon/sitemap/Attic/ResourcePipeline.java
  
  Index: ResourcePipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/ResourcePipeline.java,v
  retrieving revision 1.1.2.13
  retrieving revision 1.1.2.14
  diff -u -r1.1.2.13 -r1.1.2.14
  --- ResourcePipeline.java	2000/08/16 05:08:19	1.1.2.13
  +++ ResourcePipeline.java	2000/09/10 19:57:45	1.1.2.14
  @@ -24,6 +24,7 @@
   import org.apache.cocoon.reading.Reader;
   import org.apache.cocoon.transformation.Transformer;
   import org.apache.cocoon.serialization.Serializer;
  +import org.apache.cocoon.util.ClassUtils;
   import org.apache.cocoon.xml.XMLProducer;
   
   import org.xml.sax.SAXException;
  @@ -31,7 +32,7 @@
   
   /**
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.13 $ $Date: 2000/08/16 05:08:19 $
  + * @version CVS $Revision: 1.1.2.14 $ $Date: 2000/09/10 19:57:45 $
    */
   public class ResourcePipeline implements Composer {
       private Generator generator = null;
  @@ -59,10 +60,10 @@
           this.manager = manager;
       }
   
  -    public void setGenerator (Generator generator, String source, 
  -                              Configuration conf, Parameters param) 
  -    throws InstantiationException, IllegalAccessException {
  -        this.generator = (Generator)generator.getClass().newInstance();
  +    public void setGenerator (Generator generator, String source,
  +                              Configuration conf, Parameters param)
  +    throws Exception {
  +        this.generator = (Generator)ClassUtils.newInstance(generator.getClass().getName());
           this.initComponent (this.generator, conf);
           this.generatorSource = source;
           this.generatorParam = param;
  @@ -72,42 +73,42 @@
           return this.generator;
       }
   
  -    public void setReader (Reader reader, String source, 
  -                           Configuration conf, Parameters param) 
  -    throws InstantiationException, IllegalAccessException {
  +    public void setReader (Reader reader, String source,
  +                           Configuration conf, Parameters param)
  +    throws Exception {
           this.setReader (reader, source, conf, param, null);
       }
   
  -    public void setReader (Reader reader, String source, 
  -                           Configuration conf, Parameters param, String mimeType) 
  -    throws InstantiationException, IllegalAccessException {
  -        this.reader = (Reader)reader.getClass().newInstance();
  +    public void setReader (Reader reader, String source,
  +                           Configuration conf, Parameters param, String mimeType)
  +    throws Exception {
  +        this.reader = (Reader)ClassUtils.newInstance(reader.getClass().getName());
           this.initComponent (this.reader, conf);
           this.readerSource = source;
           this.readerParam = param;
           this.readerMimeType = mimeType;
       }
   
  -    public void setSerializer (Serializer serializer, String source, 
  -                               Configuration conf, Parameters param) 
  -    throws InstantiationException, IllegalAccessException {
  +    public void setSerializer (Serializer serializer, String source,
  +                               Configuration conf, Parameters param)
  +    throws Exception {
           this.setSerializer (serializer, source, conf, param, null);
       }
   
  -    public void setSerializer (Serializer serializer, String source, 
  -                               Configuration conf, Parameters param, String mimeType) 
  -    throws InstantiationException, IllegalAccessException {
  -        this.serializer = (Serializer)serializer.getClass().newInstance();
  +    public void setSerializer (Serializer serializer, String source,
  +                               Configuration conf, Parameters param, String mimeType)
  +    throws Exception {
  +        this.serializer = (Serializer)ClassUtils.newInstance(serializer.getClass().getName());
           this.initComponent (this.serializer, conf);
           this.serializerSource = source;
           this.serializerParam = param;
           this.serializerMimeType = mimeType;
       }
   
  -    public void addTransformer (Transformer transformer, String source, 
  -                               Configuration conf, Parameters param) 
  -    throws InstantiationException, IllegalAccessException {
  -        Transformer transfmr = (Transformer)transformer.getClass().newInstance();
  +    public void addTransformer (Transformer transformer, String source,
  +                               Configuration conf, Parameters param)
  +    throws Exception {
  +        Transformer transfmr = (Transformer)ClassUtils.newInstance(transformer.getClass().getName());
           this.initComponent (transfmr, conf);
           this.transformers.add (transfmr);
           this.transformerSources.add (source);
  @@ -126,6 +127,8 @@
                   } else if (readerMimeType != null) {
                       environment.setContentType (readerMimeType);
                   } else {
  +                    /* (GP)FIXME: Reaching here we havn't set a mime-type. This
  +                     * case should be prevented by the sitemap generating stylesheet */
                   }
                   reader.setOutputStream (environment.getOutputStream());
                   reader.generate();
  @@ -143,7 +146,7 @@
               int i = transformers.size();
               for (int j=0; j < i; j++) {
                   transformer = (Transformer) transformers.elementAt (j);
  -                transformer.setup ((EntityResolver)environment, environment.getObjectModel(), 
  +                transformer.setup ((EntityResolver)environment, environment.getObjectModel(),
                                  (String)transformerSources.elementAt (j),
                                  (Parameters)transformerParams.elementAt (j));
                   producer.setConsumer (transformer);
  @@ -154,7 +157,7 @@
               if (mime_type != null)
                       environment.setContentType (mime_type);
               else if (serializerMimeType != null)
  -                    environment.setContentType (serializerMimeType); 
  +                    environment.setContentType (serializerMimeType);
               serializer.setOutputStream (environment.getOutputStream());
               producer.setConsumer (serializer);
               generator.generate();
  @@ -169,9 +172,9 @@
        * @param conf <code>Configuration</code> of the <code>Component</code>
        */
       private void initComponent (Component comp, Configuration conf) {
  -        if (comp instanceof Composer) 
  +        if (comp instanceof Composer)
               ((Composer)comp).setComponentManager (manager);
  -        if (comp instanceof Configurable) 
  +        if (comp instanceof Configurable)
               ((Configurable)comp).setConfiguration (conf);
       }
  -} 
  +}