cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/conf woody-binding.xconf
Date Tue, 12 Aug 2003 16:33:33 GMT
bruno       2003/08/12 09:33:33

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/binding
                        JXPathBindingManager.java
               src/blocks/woody/conf woody-binding.xconf
  Log:
  Make the bindings configurable
  
  Revision  Changes    Path
  1.7       +28 -62    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/JXPathBindingManager.java
  
  Index: JXPathBindingManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/JXPathBindingManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JXPathBindingManager.java	12 Aug 2003 15:38:55 -0000	1.6
  +++ JXPathBindingManager.java	12 Aug 2003 16:33:32 -0000	1.7
  @@ -50,17 +50,18 @@
   */
   package org.apache.cocoon.woody.binding;
   
  -import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.Map;
  -
  -import org.apache.avalon.framework.logger.LogEnabled;
  -import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.woody.util.DomHelper;
  +import org.apache.cocoon.woody.util.SimpleServiceSelector;
   import org.apache.cocoon.woody.datatype.DatatypeManager;
   import org.apache.excalibur.source.Source;
   import org.w3c.dom.Document;
  @@ -72,52 +73,31 @@
    * by usage of the <a href="http://jakarta.apache.org/commons/jxpath/index.html">
    * JXPath package</a>. 
    */
  -public class JXPathBindingManager implements BindingManager, LogEnabled, Serviceable, Disposable
{
  +public class JXPathBindingManager extends AbstractLogEnabled implements BindingManager,
Serviceable, Disposable,
  +        Initializable, Configurable, ThreadSafe {
   
       //TODO caching of the Bindings. 
   
  -    private Logger logger;
  -
       private DatatypeManager datatypeManager;
       private ServiceManager serviceManager;
  -
  -    /**
  -     * Map of specific builders for the different elements in the 
  -     * Binding config.
  -     */
  -    private final Map bindingBuilders = new HashMap();
  -    {
  -        //TODO make this configurable
  -
  -        this.bindingBuilders.put("value", new ValueJXPathBindingBuilder());
  -        this.bindingBuilders.put(
  -            "context",
  -            new ContextJXPathBindingBuilder());
  -        this.bindingBuilders.put(
  -            "repeater",
  -            new RepeaterJXPathBindingBuilder());
  -        this.bindingBuilders.put(
  -            "aggregate",
  -            new AggregateJXPathBindingBuilder());
  -        this.bindingBuilders.put(
  -            "set-attribute",
  -            new SetAttributeJXPathBindingBuilder());
  -        this.bindingBuilders.put(
  -            "insert-node",
  -            new InsertNodeJXPathBindingBuilder());
  -        this.bindingBuilders.put(
  -            "delete-node",
  -            new DeleteNodeJXPathBindingBuilder());
  -        this.bindingBuilders.put(
  -            "insert-bean",
  -            new InsertBeanJXPathBindingBuilder());
  -    }
  +    private Configuration configuration;
  +    private SimpleServiceSelector bindingBuilderSelector;
   
       public void service(ServiceManager serviceManager) throws ServiceException {
           this.serviceManager = serviceManager;
           this.datatypeManager = (DatatypeManager)serviceManager.lookup(DatatypeManager.ROLE);
       }
   
  +    public void configure(Configuration configuration) throws ConfigurationException {
  +        this.configuration = configuration;
  +    }
  +
  +    public void initialize() throws Exception {
  +        bindingBuilderSelector = new SimpleServiceSelector("binding", JXpathBindingBuilderBase.class);
  +        bindingBuilderSelector.enableLogging(getLogger());
  +        bindingBuilderSelector.configure(configuration.getChild("bindings"));
  +    }
  +
       public Binding createBinding(Source bindSrc)
           throws BindingException {
           try {
  @@ -140,27 +120,12 @@
           }
       }
   
  -    public void enableLogging(Logger l) {
  -        this.logger = l;
  -        l.debug("Got logger, passing to the bindingBuilders");
  -        Iterator iter = this.bindingBuilders.values().iterator();
  -        while (iter.hasNext()) {
  -            Object builder = iter.next();
  -            if (builder instanceof LogEnabled) {
  -                ((LogEnabled) builder).enableLogging(l);
  -            }
  -        }
  -    }
  -
  -    protected Logger getLogger() {
  -        return logger;
  -    }
  -
       private Assistant getBuilderAssistant() {
           return new Assistant();
       }
   
       public void dispose() {
  +        bindingBuilderSelector.dispose();
           serviceManager.release(datatypeManager);
       }
   
  @@ -174,11 +139,12 @@
        */
       public class Assistant {
   
  -        private JXpathBindingBuilderBase getBindingBuilder(String bindingType) {
  -            return (JXpathBindingBuilderBase) JXPathBindingManager
  -                .this
  -                .bindingBuilders
  -                .get(bindingType);
  +        private JXpathBindingBuilderBase getBindingBuilder(String bindingType) throws BindingException
{
  +            try {
  +                return (JXpathBindingBuilderBase) bindingBuilderSelector.select(bindingType);
  +            } catch (ServiceException e) {
  +                throw new BindingException("Cannot handle binding element with name \""
+ bindingType + "\".", e);
  +            }
           }
   
           /**
  
  
  
  1.3       +12 -1     cocoon-2.1/src/blocks/woody/conf/woody-binding.xconf
  
  Index: woody-binding.xconf
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/conf/woody-binding.xconf,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- woody-binding.xconf	23 Jul 2003 09:09:18 -0000	1.2
  +++ woody-binding.xconf	12 Aug 2003 16:33:33 -0000	1.3
  @@ -2,6 +2,17 @@
   
   <xconf xpath="/cocoon" unless="woody-binding">
          
  -  <woody-binding logger="woody.binding"/>
  +  <woody-binding logger="woody.binding">
  +    <bindings>
  +      <binding name="value" src="org.apache.cocoon.woody.binding.ValueJXPathBindingBuilder"/>
  +      <binding name="context" src="org.apache.cocoon.woody.binding.ContextJXPathBindingBuilder"/>
  +      <binding name="repeater" src="org.apache.cocoon.woody.binding.RepeaterJXPathBindingBuilder"/>
  +      <binding name="aggregate" src="org.apache.cocoon.woody.binding.AggregateJXPathBindingBuilder"/>
  +      <binding name="set-attribute" src="org.apache.cocoon.woody.binding.SetAttributeJXPathBindingBuilder"/>
  +      <binding name="insert-node" src="org.apache.cocoon.woody.binding.InsertNodeJXPathBindingBuilder"/>
  +      <binding name="delete-node" src="org.apache.cocoon.woody.binding.DeleteNodeJXPathBindingBuilder"/>
  +      <binding name="insert-bean" src="org.apache.cocoon.woody.binding.InsertBeanJXPathBindingBuilder"/>
  +    </bindings>
  +  </woody-binding>
   
   </xconf>
  
  
  

Mime
View raw message