ovidiu      02/01/08 15:21:00

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap
                        SitemapComponents.java
  Log:
  Moved the old contents of this file to SchemeSitemap.java. This file now implements 
the code to read the components.xconf file, which contains information on the 
components that can be used by the sitemap.
  
  Revision  Changes    Path
  1.2       +114 -229  
xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SitemapComponents.java
  
  Index: SitemapComponents.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SitemapComponents.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SitemapComponents.java    3 Jan 2002 12:31:35 -0000       1.1
  +++ SitemapComponents.java    8 Jan 2002 23:21:00 -0000       1.2
  @@ -1,271 +1,156 @@
   package org.apache.cocoon.scheme.sitemap;
   
  +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.parameters.Parameters;
  +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;
   import org.apache.cocoon.components.pipeline.EventPipeline;
  +import org.apache.cocoon.components.pipeline.StreamPipeline;
   import org.apache.cocoon.environment.Environment;
  -import sisc.ContinuationException;
  -import sisc.Interpreter;
  -import sisc.ModuleAdapter;
  -import sisc.data.Pair;
  -import sisc.data.Symbol;
  -import sisc.data.Value;
  -import sisc.modules.J2S;
  +import org.apache.cocoon.sitemap.AbstractSitemap;
  +import org.apache.cocoon.sitemap.Sitemap;
   
   /**
  - * This class contains the definition of the Scheme functions:
  - *
  - * <ul>
  - *
  - *  <li><b>sitemap:generate</b> - create a new {@link
  - *  org.apache.cocoon.components.pipeline.EventPipeline}, and adds the
  - *  generator specified by the function arguments to it.</it>
  - *
  - *  <li><b>sitemap:transform</b> - creates a transformer object of the type
  - *  specified by the arguments, adds it to the pipeline passed as
  - *  argument, and returns the pipeline.</li>
  - *
  - *  <li><b>sitemap:read</b> - creates a new {@link
  - *  org.apache.cocoon.components.pipeline.StreamPipeline} and a new
  - *  {@link org.apache.cocoon.reading.Reader}, adds the reader to the
  - *  pipeline, and returns the pipeline.
  - *
  - * </ul>
  + * This class is responsible with configuring the ComponentManager
  + * appropriately with the sitemap components to be used in
  + * sitemaps. These components are read from the components.xconf file
  + * at configuration time by this class.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ovidiu Predescu</a>
  - * @since December 20, 2001
  - *
  - * @see org.apache.cocoon.components.pipeline.EventPipeline
  - * @see org.apache.cocoon.components.pipeline.StreamPipeline
  - * @see org.apache.cocoon.reading.Reader
  + * @since January 4, 2002
    */
  -public class SitemapComponents extends ModuleAdapter
  +public class SitemapComponents extends AbstractSitemap implements Configurable
   {
  -  public String getModuleName()
  -  {
  -    return "Apache Cocoon Sitemap Components";
  -  }
  -
  -  public float getModuleVersion()
  +  protected String defaultGenerator;
  +  protected String defaultTransformer;
  +  protected String defaultReader;
  +  protected String defaultSerializer;
  +  protected String defaultSelector;
  +  
  +  public void configure(Configuration confs)
  +    throws ConfigurationException
     {
  -    return 1.0f;
  -  }
  -
  -  public static final int GENERATE = 1, TRANSFORM = 2, READER = 3;
  -
  -  protected Parameters emptyParam = new Parameters();
  -
  -  /**
  -   * Creates a new <code>SitemapComponents</code> instance. Defines
  -   * the Scheme functions implemented by this module.
  -   */
  -  public SitemapComponents()
  -  {
  -    define("sitemap:generate", GENERATE);
  -    define("sitemap:transform", TRANSFORM);
  -    define("sitemap:read", READER);
  -  }
  +    System.out.print("Loading the sitemap components... ");
  +    System.out.flush();
   
  -  /**
  -   * The SISC evaluator function for this module. Executes the actual
  -   * Java code corresponding to the Scheme functions defined by the
  -   * module.
  -   *
  -   * @param primid an <code>int</code> value
  -   * @param r an <code>Interpreter</code> value
  -   * @return a <code>Value</code> value
  -   */
  -  public Value eval(int primid, Interpreter r)
  -    throws ContinuationException
  -  {
       try {
  -      switch (r.vlr.length) {
  -
  -        // Three argument functions
  -      case 3:
  -        switch (primid) {
  -        case GENERATE:
  -          return generate(r.vlr[0], r.vlr[1], r.vlr[2]);
  -        case READER:
  -          return read(r.vlr[0], r.vlr[1], r.vlr[2]);
  -        default:
  -          break;
  -        }
  -
  -        // Four argument functions
  -      case 4:
  -        switch (primid) {
  -        case TRANSFORM:
  -          return transform (r.vlr[0], r.vlr[1], r.vlr[2], r.vlr[3]);
  -        }
  -      }
  +      Configuration generatorsConf = confs.getChild("generators");
  +      defaultGenerator = generatorsConf.getAttribute("default");
  +      Configuration[] gConf = generatorsConf.getChildren("generator");
  +      for (int i = 0; i < gConf.length; i++)        
  +        load_component(Sitemap.GENERATOR,
  +                       gConf[i].getAttribute("name", ""),
  +                       gConf[i].getAttribute("src"),
  +                       gConf[i],
  +                       gConf[i].getAttribute("mime-type", null));
  +
  +      Configuration readersConf = confs.getChild("readers");
  +      defaultReader = readersConf.getAttribute("default");
  +      Configuration[] rConf = readersConf.getChildren("reader");
  +      for (int i = 0; i < rConf.length; i++)
  +        load_component(Sitemap.READER,
  +                       rConf[i].getAttribute("name", ""),
  +                       rConf[i].getAttribute("src"),
  +                       rConf[i],
  +                       rConf[i].getAttribute("mime-type", null));
  +
  +      Configuration transformersConf = confs.getChild("transformers");
  +      defaultTransformer = transformersConf.getAttribute("default");
  +      Configuration[] tConf = transformersConf.getChildren("transformer");
  +      for (int i = 0; i < tConf.length; i++)
  +        load_component(Sitemap.TRANSFORMER,
  +                       tConf[i].getAttribute("name", ""),
  +                       tConf[i].getAttribute("src"),
  +                       tConf[i],
  +                       tConf[i].getAttribute("mime-type", null));
  +
  +      Configuration serializersConf = confs.getChild("serializers");
  +      defaultSerializer = serializersConf.getAttribute("default");
  +      Configuration[] sConf = serializersConf.getChildren("serializer");
  +      for (int i = 0; i < sConf.length; i++)
  +        load_component(Sitemap.SERIALIZER,
  +                       sConf[i].getAttribute("name", ""),
  +                       sConf[i].getAttribute("src"),
  +                       sConf[i],
  +                       sConf[i].getAttribute("mime-type", null));
  +
  +      Configuration selectorsConf = confs.getChild("selectors");
  +      defaultSelector = selectorsConf.getAttribute("default");
  +      Configuration[] slConf = selectorsConf.getChildren("selector");
  +      for (int i = 0; i < slConf.length; i++)
  +        load_component(Sitemap.SELECTOR,
  +                       slConf[i].getAttribute("name", ""),
  +                       slConf[i].getAttribute("src"),
  +                       slConf[i],
  +                       slConf[i].getAttribute("mime-type", null));
       }
       catch (Exception ex) {
  -      ex.printStackTrace();
  -      throw new RuntimeException(ex.toString());
  +      throw new ConfigurationException(ex.toString());
       }
   
  -    throw new RuntimeException("Invalid number of arguments to function "
  -                               + r.acc);
  +    System.out.println("done");
     }
   
  -  /**
  -   * Type cast function from a Scheme wrapper of a ComponentManager.
  -   *
  -   * @param scm a Scheme wrapper instance of a ComponentManager.
  -   * @return a <code>ComponentManager</code> value
  -   */
  -  static public ComponentManager componentManager(Value scm)
  +  public EventPipeline getEventPipeline()
  +    throws ComponentException
     {
  -    try {
  -      return (ComponentManager)(((J2S.JavaObject)scm).o);
  -    }
  -    catch (ClassCastException ex) {
  -      typeError("ComponentManager", scm);
  -    }
  -    return null;
  +    EventPipeline pipeline = (EventPipeline)manager.lookup(EventPipeline.ROLE);
  +    pipeline.recompose(manager);
  +    return pipeline;
     }
   
  -  /**
  -   * Type cast function from a Scheme wrapper of an Environment
  -   * instance.
  -   *
  -   * @param senv a Scheme wrapper of an Environment instance.
  -   * @return an <code>Environment</code> value
  -   */
  -  static public Environment environment(Value senv)
  +  public StreamPipeline getStreamPipeline()
  +    throws ComponentException
     {
  -    try {
  -      return (Environment)(((J2S.JavaObject)senv).o);
  -    }
  -    catch (ClassCastException ex) {
  -      typeError("Environment", senv);
  -    }
  -    return null;
  +    StreamPipeline pipeline
  +      = (StreamPipeline)manager.lookup(StreamPipeline.ROLE);
  +    pipeline.recompose(manager);
  +    return pipeline;
     }
   
  -  /**
  -   * Retrieve an entry from an association list. Uses eq? to compare
  -   * the CAR of each entry.
  -   *
  -   * @param l the association list
  -   * @param v the value to be searched for
  -   * @return a <code>Pair</code> value representing the entry, or
  -   * <tt>FALSE</tt> if no such entry is present.
  -   */
  -  static public Value assq (Value l, Value v)
  -  {
  -    Pair list = pair(l);
  -    while (list != EMPTYLIST) {
  -      Pair entry = pair(list.car);
  -      if (entry.car.eq(v))
  -        return entry;
  -      list = pair(list.cdr);
  -    }
  -    return FALSE;
  +  public void releasePipeline(Component pipeline)
  +  {
  +    manager.release(pipeline);
     }
   
  -  /**
  -   * Assumes the <tt>sparams</tt> is either an association list or the
  -   * FALSE value. It returns either an empty Avalon
  -   * <tt>Parameters</tt> instance, or a <tt>Parameters</tt> instance
  -   * that contains the values extracted from the association list.
  -   *
  -   * @param sparams a <code>Value</code> value, either <tt>FALSE</tt>
  -   * or an association list
  -   * @return an Avalon <code>Parameters</code> instance
  -   */
  -  public Parameters getParameters(Value sparams)
  -  {
  -    Parameters params = emptyParam;
  -
  -    if (!sparams.eq(FALSE)) {
  -      params = new Parameters();
  -      Pair sparamValues = pair(pair(sparams).cdr);
  -      while (sparamValues != EMPTYLIST) {
  -        Pair entry = pair(sparamValues.car);
  -        String name = string(entry.car);
  -        String value = string(entry.cdr);
  -        params.setParameter(name, value);
  -        sparamValues = pair(sparamValues.cdr);
  -      }
  -    }
  +  public String getDefaultGeneratorType()
  +  {
  +    return defaultGenerator;
  +  }
   
  -    return params;
  +  public String getDefaultTransformerType()
  +  {
  +    return defaultTransformer;
     }
   
  -  /**
  -   * <p>Creates a new <tt>EventPipeline</tt> instance, and a new
  -   * Generator instance. Adds the Generator to the pipeline.
  -   *
  -   * <p>The type of the generator is specified in the <tt>sargs</tt>
  -   * list, which is a Scheme association list. The parameters to be
  -   * passed to the generators, if any, should be present in this
  -   * association list as the value of the <it>params</it> entry. This
  -   * value should be another association list, where the CAR of each
  -   * entry is the name of the parameter, and the CDR of the entry is
  -   * the actual value.
  -   *
  -   * <p>The recognized parameters are:
  -   *
  -   * <ul>
  -   *
  -   *  <li><b>src</b> - (required) the source of the generator
  -   *
  -   *  <li><b>type</b> - (optional) the type of generator. If not
  -   *  specified, <it>file</it> is assumed.
  -   *
  -   *  <li><b>params</b> - (optional) the parameters to be passed to
  -   *  the generator. The CDR of this association entry should be
  -   *  another association entry, that contains the names and values of
  -   *  the parameters.
  -   *
  -   * </ul>
  -   *
  -   * @param scm the Scheme wrapper for the ComponentManager instance
  -   * @param senv the Scheme wrapper for the Environment instance
  -   * @param sargs the Scheme arguments, as list
  -   * @return a Scheme wrapper for the <tt>EventPipeline</tt> instance
  -   */
  -  public Value generate(Value scm, Value senv, Value sargs)
  -    throws Exception
  +  public String getDefaultReaderType()
     {
  -    ComponentManager manager = componentManager(scm);
  -    Environment env = environment(senv);
  -    EventPipeline eventPipeline;
  -
  -    eventPipeline = (EventPipeline)manager.lookup(EventPipeline.ROLE);
  -    eventPipeline.recompose(manager);
  -
  -    // Obtain the 'src' attribute
  -    Value ssrc = assq(sargs, Symbol.get("src"));
  -    System.out.println("sargs = " + sargs + ", ssrc = " + ssrc);
  -    if (ssrc.eq(FALSE))
  -      throw new RuntimeException("No 'src' attribute specified for 'generate'!");
  -    String src = string(pair(ssrc).cdr);
  -
  -    // Obtain the 'type' attribute
  -    Value stype = assq(sargs, Symbol.get("type"));
  -    String type = "file";
  -    if (!stype.eq(FALSE))
  -      type = string(pair(ssrc).cdr);
  -
  -    // Obtain the parameters
  -    Value sparams = assq(sargs, Symbol.get("params"));
  -    Parameters params = getParameters(sparams);
  +    return defaultReader;
  +  }
   
  -    eventPipeline.setGenerator(type, src, params);
  +  public String getDefaultSerializerType()
  +  {
  +    return defaultSerializer;
  +  }
   
  -    return new J2S.JavaObject(eventPipeline);
  +  public String getDefaultSelectorType()
  +  {
  +    return defaultSelector;
     }
   
  -  public Value read(Value scm, Value senv, Value sargs)
  +  public boolean process(Environment environment)
  +    throws Exception
     {
  -    return null;
  +    throw new Exception("Should not be invoked");
     }
   
  -  public Value transform(Value scm, Value senv, Value sargs, Value spipeline)
  +  public boolean process(Environment environment, StreamPipeline pipeline,
  +                         EventPipeline eventPipeline)
  +    throws Exception
     {
  -    return null;
  +    throw new Exception("Should not be invoked");
     }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to