cziegeler    2003/10/21 06:23:27

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp
                        XSPModuleHelper.java
               src/blocks/linkrewriter/java/org/apache/cocoon/transformation
                        VariableRewriterTransformer.java
                        LinkRewriterTransformer.java
  Log:
  Moving to Serviceable
  
  Revision  Changes    Path
  1.6       +90 -43    
cocoon-2.1/src/java/org/apache/cocoon/components/language/markup/xsp/XSPModuleHelper.java
  
  Index: XSPModuleHelper.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/language/markup/xsp/XSPModuleHelper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XSPModuleHelper.java      24 Sep 2003 21:41:11 -0000      1.5
  +++ XSPModuleHelper.java      21 Oct 2003 13:23:27 -0000      1.6
  @@ -59,7 +59,8 @@
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.ServiceSelector;
   
   import org.apache.cocoon.components.modules.input.InputModule;
   
  @@ -88,12 +89,45 @@
       private final static int OP_VALUES = 1;
       private final static int OP_NAMES = 2;
   
  -    Map inputModules = null;
  -    ComponentManager manager = null;
  -    ComponentSelector inputSelector = null;
  +    private Map inputModules;
  +    private ComponentManager componentManager;
  +    private ComponentSelector componentInputSelector;
  +    private ServiceManager serviceManager;
  +    private ServiceSelector serviceInputSelector;
       
   
       /**
  +     * Get the input module
  +     */
  +    private InputModule getInputModule(String name)
  +    throws CascadingRuntimeException {
  +        if ( this.inputModules == null ) {
  +            throw new RuntimeException("ModuleHelper is not setup 
correctly.");
  +        }
  +        InputModule module = (InputModule) this.inputModules.get(name);
  +        if ( module == null ) {
  +            try {
  +                if ( this.componentManager != null ) {
  +                    if (this.componentInputSelector.hasComponent(name)) {
  +                        module = (InputModule) 
this.componentInputSelector.select(name);
  +                    }                
  +                } else {
  +                    if (this.serviceInputSelector.isSelectable(name)) {
  +                        module = (InputModule) 
this.serviceInputSelector.select(name);
  +                    }                            
  +                }
  +            } catch (Exception e) {
  +                throw new CascadingRuntimeException("Unable to lookup input 
module " + name, e);
  +            }
  +            if ( module == null ) {
  +                throw new RuntimeException("No such InputModule: "+name);
  +            }
  +            this.inputModules.put(name, module);
  +        }
  +        return module;
  +    }
  +    
  +    /**
        * Capsules use of an InputModule. Does all the lookups and so
        * on. Returns either an Object, an Object[], or an Iterator,
        * depending on the method called i.e. the op specified. The
  @@ -115,28 +149,10 @@
       private Object get(int op, String name, String attr, Map objectModel, 
Configuration conf) throws CascadingRuntimeException {
   
           Object value = null;
  -        InputModule input = null;
  -
  -        if (this.inputModules == null) 
  -            this.inputModules = new HashMap();
  -        else
  -            if (this.inputModules.containsKey(name))
  -                input = (InputModule) this.inputModules.get(name);
  +        final InputModule input = this.getInputModule(name);
   
           try {
   
  -            if (this.inputSelector == null)
  -                this.inputSelector = (ComponentSelector) 
this.manager.lookup(INPUT_MODULE_SELECTOR);
  -        
  -            if (input == null) {
  -                if (this.inputSelector.hasComponent(name)) {
  -                    input = (InputModule) this.inputSelector.select(name);
  -                    this.inputModules.put(name, input);
  -                } else {
  -                    throw new RuntimeException("No such InputModule: "+name);
  -                }
  -            }
  -
               switch (op) {
               case OP_GET:    
                   value = input.getAttribute(attr, conf, objectModel);
  @@ -164,27 +180,40 @@
   
       /**
        * Initializes the instance for first use. Stores references to
  -     * component manager and component selector in instance if
  -     * ThreadSafe.
  +     * component manager and component selector in instance 
        *
        * @param manager a <code>ComponentManager</code> value
        * @exception RuntimeException if an error occurs
  +     * @deprecated Use the [EMAIL PROTECTED] #setup(ServiceManager)} method 
instead
        */
       public void setup(ComponentManager manager) throws RuntimeException {
   
           this.inputModules = new HashMap();
  -        this.manager = manager;
  +        this.componentManager = manager;
           try {
  -            this.inputSelector=(ComponentSelector) 
this.manager.lookup(INPUT_MODULE_SELECTOR); 
  -            if (!(this.inputSelector instanceof ThreadSafe)) {
  -                this.manager.release(this.inputSelector);
  -                this.inputSelector = null;
  -            }
  +            this.componentInputSelector = (ComponentSelector) 
this.componentManager.lookup(INPUT_MODULE_SELECTOR); 
           } catch (Exception e) {
               throw new CascadingRuntimeException("Could not obtain selector 
for InputModule.",e);
           }
       }
   
  +    /**
  +     * Initializes the instance for first use. Stores references to
  +     * service manager and service selector in instance 
  +     *
  +     * @param manager a <code>ServiceManager</code> value
  +     * @exception RuntimeException if an error occurs
  +     */
  +    public void setup(ServiceManager manager) throws RuntimeException {
  +
  +        this.inputModules = new HashMap();
  +        this.serviceManager = manager;
  +        try {
  +            this.serviceInputSelector = (ServiceSelector) 
this.serviceManager.lookup(INPUT_MODULE_SELECTOR); 
  +        } catch (Exception e) {
  +            throw new CascadingRuntimeException("Could not obtain selector 
for InputModule.",e);
  +        }
  +    }
   
   
       /**
  @@ -330,19 +359,37 @@
        */
       public void releaseAll() throws RuntimeException {
   
  -        if (this.manager != null && this.inputModules != null) {
  -            try {
  -                if (this.inputSelector == null) {
  -                    this.inputSelector=(ComponentSelector) 
this.manager.lookup(INPUT_MODULE_SELECTOR); 
  +        if ( this.inputModules != null ) {
  +            // test for component manager
  +            if ( this.componentManager != null ) {
  +                try {
  +                    Iterator iter = this.inputModules.keySet().iterator();
  +                    while (iter.hasNext()) {
  +                        this.componentInputSelector.release((InputModule) 
this.inputModules.get(iter.next()));
  +                    }
  +                    this.inputModules = null;
  +                    
this.componentManager.release(this.componentInputSelector);
  +                    this.componentManager = null;
  +                    this.inputModules = null;
  +                } catch (Exception e) {
  +                    throw new CascadingRuntimeException("Could not release 
InputModules.",e);
                   }
  -                Iterator iter = this.inputModules.keySet().iterator();
  -                while (iter.hasNext()) {
  -                    this.inputSelector.release((InputModule) 
this.inputModules.get(iter.next()));
  +                
  +            }
  +            if ( this.serviceManager != null ) {
  +                try {
  +                    Iterator iter = this.inputModules.keySet().iterator();
  +                    while (iter.hasNext()) {
  +                        
this.serviceInputSelector.release(this.inputModules.get(iter.next()));
  +                    }
  +                    this.inputModules = null;
  +                    this.serviceManager.release(this.serviceInputSelector);
  +                    this.serviceManager = null;
  +                    this.inputModules = null;
  +                } catch (Exception e) {
  +                    throw new CascadingRuntimeException("Could not release 
InputModules.",e);
                   }
  -                this.inputModules = null;
  -                this.manager.release(this.inputSelector);
  -            } catch (Exception e) {
  -                throw new CascadingRuntimeException("Could not release 
InputModules.",e);
  +                
               }
           }
       }
  
  
  
  1.6       +12 -14    
cocoon-2.1/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/VariableRewriterTransformer.java
  
  Index: VariableRewriterTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/VariableRewriterTransformer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- VariableRewriterTransformer.java  21 Oct 2003 12:39:16 -0000      1.5
  +++ VariableRewriterTransformer.java  21 Oct 2003 13:23:27 -0000      1.6
  @@ -57,11 +57,8 @@
   import java.util.Set;
   import java.util.StringTokenizer;
   
  +import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
  -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;
   import org.apache.avalon.framework.parameters.Parameters;
  @@ -175,7 +172,7 @@
    * @version CVS $Id$
    */
   public class VariableRewriterTransformer
  -    extends AbstractSAXTransformer implements Composable, Initializable, 
Configurable
  +    extends AbstractSAXTransformer implements Initializable, Disposable
   {
   
       private static String NAMESPACE="";
  @@ -198,14 +195,13 @@
   
       private String badLinkStr;
   
  -    private ComponentManager componentManager;
  -
       /**
        * Configure this component from the map:transformer block.  Called 
before
        * initialization and setup.
        */
       public void configure(Configuration conf)
  -        throws ConfigurationException {
  +    throws ConfigurationException {
  +        super.configure(conf);
           this.origConf = conf;
       }
    
  @@ -215,7 +211,7 @@
       public void initialize() throws Exception {
           this.namespaceURI = NAMESPACE;
           this.modHelper = new XSPModuleHelper();
  -        modHelper.setup(this.componentManager);
  +        modHelper.setup(this.manager);
       }
   
       /**
  @@ -380,10 +376,12 @@
       }
       
       /* (non-Javadoc)
  -     * @see 
org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
  +     * @see org.apache.avalon.framework.activity.Disposable#dispose()
        */
  -    public void compose(ComponentManager manager) throws ComponentException {
  -        this.componentManager = manager;
  +    public void dispose() {
  +        if ( this.modHelper != null ) {
  +            this.modHelper.releaseAll();
  +            this.modHelper = null;
  +        }
       }
  -    
   }
  
  
  
  1.10      +12 -14    
cocoon-2.1/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java
  
  Index: LinkRewriterTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LinkRewriterTransformer.java      21 Oct 2003 12:39:16 -0000      1.9
  +++ LinkRewriterTransformer.java      21 Oct 2003 13:23:27 -0000      1.10
  @@ -57,11 +57,8 @@
   import java.util.Set;
   import java.util.StringTokenizer;
   
  +import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
  -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;
   import org.apache.avalon.framework.parameters.Parameters;
  @@ -185,7 +182,7 @@
    * @version CVS $Id$
    */
   public class LinkRewriterTransformer
  -    extends AbstractSAXTransformer implements Composable, Initializable, 
Configurable
  +    extends AbstractSAXTransformer implements Initializable, Disposable
   {
   
       private static String NAMESPACE="";
  @@ -208,15 +205,13 @@
   
       private String badLinkStr;
   
  -    private ComponentManager componentManager;
  -    
       /**
        * Configure this component from the map:transformer block.  Called 
before
        * initialization and setup.
        */
       public void configure(Configuration conf)
  -        throws ConfigurationException {
  -        if (conf == null) throw new NullPointerException("No static 
configuration passed to LinkRewriter");
  +    throws ConfigurationException {
  +        super.configure(conf);
           this.origConf = conf;
       }
    
  @@ -226,7 +221,7 @@
       public void initialize() throws Exception {
           this.namespaceURI = NAMESPACE;
           this.modHelper = new XSPModuleHelper();
  -        modHelper.setup(this.componentManager);
  +        modHelper.setup(this.manager);
       }
   
       /**
  @@ -400,10 +395,13 @@
       }
   
       /* (non-Javadoc)
  -     * @see 
org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
  +     * @see org.apache.avalon.framework.activity.Disposable#dispose()
        */
  -    public void compose(ComponentManager manager) throws ComponentException {
  -        this.componentManager = manager;
  +    public void dispose() {
  +        if ( this.modHelper != null ) {
  +            this.modHelper.releaseAll();
  +            this.modHelper = null;
  +        }
       }
   
   }
  
  
  

Reply via email to