Author: cziegeler
Date: Mon Nov  1 10:21:13 2004
New Revision: 56265

Added:
   
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentHandler.java
Modified:
   
cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java
   
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java
   
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/generator/GeneratorSelector.java
   
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java
   
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/Program.java
   
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java
   
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java
   
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
   
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
   
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
   
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
Log:
Introduce ComponentHandler interface

Modified: 
cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java
==============================================================================
--- 
cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java
     (original)
+++ 
cocoon/trunk/src/blocks/python/java/org/apache/cocoon/components/language/programming/python/PythonProgram.java
     Mon Nov  1 10:21:13 2004
@@ -24,6 +24,7 @@
 import org.apache.cocoon.components.language.programming.Program;
 import org.apache.cocoon.components.language.generator.CompiledComponent;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
+import org.apache.cocoon.core.container.ComponentHandler;
 
 import java.io.File;
 import java.util.Collection;
@@ -61,9 +62,9 @@
         return file.toString();
     }
 
-    public AbstractComponentHandler getHandler(ServiceManager manager,
+    public ComponentHandler getHandler(ServiceManager manager,
                                        Context context)
-            throws Exception {
+    throws Exception {
 
         return AbstractComponentHandler.getComponentHandler(
                 clazz, config, manager, context, getLogger(), null, null);

Modified: 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java
==============================================================================
--- 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java
    (original)
+++ 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/acting/ServerPagesAction.java
    Mon Nov  1 10:21:13 2004
@@ -28,6 +28,7 @@
 import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
 import org.apache.cocoon.components.sax.XMLByteStreamFragment;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
+import org.apache.cocoon.core.container.ComponentHandler;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Redirector;
 import org.apache.cocoon.environment.Request;
@@ -79,7 +80,7 @@
     public static final String ACTION_RESULT_OBJECT = "xsp-action:result";
     public static final String ACTION_SUCCESS_OBJECT = "xsp-action:success";
 
-    private AbstractComponentHandler generatorHandler;
+    private ComponentHandler generatorHandler;
 
     /* (non-Javadoc)
      * @see 
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)

Modified: 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/generator/GeneratorSelector.java
==============================================================================
--- 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/generator/GeneratorSelector.java
     (original)
+++ 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/generator/GeneratorSelector.java
     Mon Nov  1 10:21:13 2004
@@ -22,6 +22,7 @@
 import org.apache.cocoon.components.language.programming.Program;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
 import org.apache.cocoon.core.container.CocoonServiceSelector;
+import org.apache.cocoon.core.container.ComponentHandler;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -99,7 +100,7 @@
                              Object hint, Program generator)
     throws Exception {
         try {
-            final AbstractComponentHandler handler =
+            final ComponentHandler handler =
                     generator.getHandler(newManager, this.context );
             handler.initialize();
             this.componentHandlers.put(hint, handler);
@@ -116,7 +117,7 @@
     }
 
     public void removeGenerator(Object hint) {
-        AbstractComponentHandler handler = (AbstractComponentHandler) 
this.componentHandlers.remove(hint);
+        ComponentHandler handler = (ComponentHandler) 
this.componentHandlers.remove(hint);
         if (handler != null) {
             handler.dispose();
             this.classManager.reinstantiate();

Modified: 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java
==============================================================================
--- 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java
      (original)
+++ 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java
      Mon Nov  1 10:21:13 2004
@@ -133,12 +133,12 @@
     }
 
     public static String formEncode(String text) throws Exception {
-        return URLEncoder.encode(text);
+        return URLEncoder.encode(text, "utf-8");
     }
 
     // Shameless, ain't it?
     public static String formDecode(String s) throws Exception {
-        return URLDecoder.decode(s);
+        return URLDecoder.decode(s, "utf-8");
     }
 
     /* Logicsheet Utility Methods */

Modified: 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/Program.java
==============================================================================
--- 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/Program.java
     (original)
+++ 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/Program.java
     Mon Nov  1 10:21:13 2004
@@ -19,7 +19,7 @@
 import org.apache.avalon.framework.service.ServiceManager;
 
 import org.apache.cocoon.components.language.generator.CompiledComponent;
-import org.apache.cocoon.core.container.AbstractComponentHandler;
+import org.apache.cocoon.core.container.ComponentHandler;
 
 /**
  * This interface states the functionality of a program.
@@ -38,7 +38,7 @@
     /**
      * Get ComponentHandler which holds instances of this program.
      */
-    AbstractComponentHandler getHandler(ServiceManager manager,
+    ComponentHandler getHandler(ServiceManager manager,
                                 Context context) throws Exception;
 
     /**

Modified: 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java
==============================================================================
--- 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java
    (original)
+++ 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java
    Mon Nov  1 10:21:13 2004
@@ -23,6 +23,7 @@
 import org.apache.cocoon.components.language.generator.CompiledComponent;
 import org.apache.cocoon.components.language.programming.Program;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
+import org.apache.cocoon.core.container.ComponentHandler;
 
 /**
  * This represents program in Java language.
@@ -43,7 +44,7 @@
         return program.getName();
     }
 
-    public AbstractComponentHandler getHandler(ServiceManager manager,
+    public ComponentHandler getHandler(ServiceManager manager,
                                        Context context)
     throws Exception {
 

Modified: 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java
==============================================================================
--- 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java
        (original)
+++ 
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/javascript/JavascriptProgram.java
        Mon Nov  1 10:21:13 2004
@@ -24,6 +24,7 @@
 import org.apache.cocoon.components.language.generator.CompiledComponent;
 import org.apache.cocoon.components.language.programming.Program;
 import org.apache.cocoon.core.container.AbstractComponentHandler;
+import org.apache.cocoon.core.container.ComponentHandler;
 
 import java.io.File;
 import java.util.Collection;
@@ -63,7 +64,7 @@
         return file.toString();
     }
 
-    public AbstractComponentHandler getHandler(ServiceManager manager,
+    public ComponentHandler getHandler(ServiceManager manager,
                                        Context context)
     throws Exception {
 

Modified: 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
==============================================================================
--- 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
   (original)
+++ 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
   Mon Nov  1 10:21:13 2004
@@ -32,7 +32,8 @@
  *
  * @version CVS $Id: AbstractComponentHandler.java 55144 2004-10-20 12:26:09Z 
ugo $
  */
-public abstract class AbstractComponentHandler {
+public abstract class AbstractComponentHandler 
+implements ComponentHandler {
     
     private final Object referenceSemaphore = new Object();
     private int references = 0;
@@ -61,7 +62,7 @@
      *
      * @throws Exception If there were any problems obtaining a 
ComponentHandler
      */
-    public static AbstractComponentHandler getComponentHandler( final Class 
componentClass,
+    public static ComponentHandler getComponentHandler( final Class 
componentClass,
                                                         final Configuration 
configuration,
                                                         final ServiceManager 
serviceManager,
                                                         final Context context,
@@ -217,15 +218,15 @@
         return ( this.references == 0 );
     }
     
-    /**
-     * Dispose of the component handler and any associated Pools and Factories.
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#dispose()
      */
     public void dispose() {
         this.disposed = true;
     }
     
-    /**
-     * Initialize this handler
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.core.container.ComponentHandler#initialize()
      */
     public void initialize() throws Exception {
         if( this.initialized ) {

Modified: 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
==============================================================================
--- 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
     (original)
+++ 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
     Mon Nov  1 10:21:13 2004
@@ -105,7 +105,7 @@
      *
      * @throws Exception If there were any problems obtaining a 
ComponentHandler
      */
-    protected AbstractComponentHandler getComponentHandler( final Class 
componentClass,
+    protected ComponentHandler getComponentHandler( final Class componentClass,
                                                     final Configuration 
configuration,
                                                     final ServiceManager 
serviceManager)
     throws Exception {

Modified: 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
==============================================================================
--- 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
       (original)
+++ 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
       Mon Nov  1 10:21:13 2004
@@ -84,7 +84,7 @@
             throw new ServiceException( role, message );
         }
 
-        AbstractComponentHandler handler = 
(AbstractComponentHandler)this.componentHandlers.get( role );
+        ComponentHandler handler = 
(ComponentHandler)this.componentHandlers.get( role );
 
         // Retrieve the instance of the requested component
         if ( handler == null ) {
@@ -226,8 +226,8 @@
         //  will never be released by more than one thread, this method does 
not need any
         //  synchronization around the access to the map.
 
-        final AbstractComponentHandler handler =
-            (AbstractComponentHandler)this.componentMapping.get( component );
+        final ComponentHandler handler =
+            (ComponentHandler)this.componentMapping.get( component );
 
         if ( handler != null ) {
             // ThreadSafe components will always be using a 
ThreadSafeComponentHandler,
@@ -312,8 +312,8 @@
         super.initialize();
 
         for( int i = 0; i < this.newComponentHandlers.size(); i++ ) {
-            final AbstractComponentHandler handler =
-                (AbstractComponentHandler)this.newComponentHandlers.get( i );
+            final ComponentHandler handler =
+                (ComponentHandler)this.newComponentHandlers.get( i );
             try {
                 handler.initialize();
             } catch( Exception e ) {
@@ -332,8 +332,8 @@
 
         for( int i = 0; i < keys.size(); i++ ) {
             final Object key = keys.get( i );
-            final AbstractComponentHandler handler =
-                (AbstractComponentHandler)this.componentHandlers.get( key );
+            final ComponentHandler handler =
+                (ComponentHandler)this.componentHandlers.get( key );
 
             if( !this.newComponentHandlers.contains( handler ) ) {
                 try {
@@ -366,8 +366,8 @@
                  iterator.hasNext(); ) {
                 final Object role = iterator.next();
 
-                final AbstractComponentHandler handler =
-                    (AbstractComponentHandler)componentHandlers.get( role );
+                final ComponentHandler handler =
+                    (ComponentHandler)componentHandlers.get( role );
 
                 if( forceDisposal || handler.canBeDisposed() ) {
                     if( forceDisposal && getLogger().isWarnEnabled() ) {
@@ -416,7 +416,7 @@
                 this.getLogger().debug( "Attempting to get handler for role [" 
+ role + "]" );
             }
 
-            final AbstractComponentHandler handler = this.getComponentHandler( 
component,
+            final ComponentHandler handler = this.getComponentHandler( 
component,
                                                                   
configuration,
                                                                   this);
 

Modified: 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
==============================================================================
--- 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
      (original)
+++ 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
      Mon Nov  1 10:21:13 2004
@@ -19,7 +19,6 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -83,7 +82,7 @@
                 "You cannot select a component from a disposed service 
selector." );
         }
 
-        AbstractComponentHandler handler = 
(AbstractComponentHandler)this.componentHandlers.get( key );
+        ComponentHandler handler = 
(ComponentHandler)this.componentHandlers.get( key );
 
         // Retrieve the instance of the requested component
         if( null == handler ) {
@@ -152,7 +151,7 @@
         boolean exists = false;
 
         try {
-            AbstractComponentHandler handler = 
(AbstractComponentHandler)this.componentHandlers.get( key );
+            ComponentHandler handler = 
(ComponentHandler)this.componentHandlers.get( key );
             exists = (handler != null);
         } catch( Throwable t ) {
             // We can safely ignore all exceptions
@@ -178,8 +177,8 @@
             this.parentSelector.release(component);
 
         } else {
-            final AbstractComponentHandler handler =
-                (AbstractComponentHandler)this.componentMapping.get( component 
);
+            final ComponentHandler handler =
+                (ComponentHandler)this.componentMapping.get( component );
     
             if( null == handler ) {
                 this.getLogger().warn( "Attempted to release a " + 
component.getClass().getName()
@@ -281,8 +280,8 @@
 
         for( int i = 0; i < keys.size(); i++ ) {
             final Object key = keys.get( i );
-            final AbstractComponentHandler handler =
-                (AbstractComponentHandler)this.componentHandlers.get( key );
+            final ComponentHandler handler =
+                (ComponentHandler)this.componentHandlers.get( key );
 
             try {
                 handler.initialize();
@@ -305,8 +304,8 @@
 
         while( keys.hasNext() ) {
             Object key = keys.next();
-            AbstractComponentHandler handler =
-                (AbstractComponentHandler)this.componentHandlers.get( key );
+            ComponentHandler handler =
+                (ComponentHandler)this.componentHandlers.get( key );
 
             handler.dispose();
 
@@ -330,15 +329,6 @@
         super.dispose();
     }
 
-    /**
-     * Makes the ComponentHandlers available to subclasses.
-     *
-     * @return A reference to the componentHandler Map.
-     */
-    protected Map getComponentHandlers() {
-        return this.componentHandlers;
-    }
-
     /** Add a new component to the manager.
      * @param key the key for the new component.
      * @param component the class of this component.
@@ -354,7 +344,7 @@
         }
 
         try {
-            final AbstractComponentHandler handler = getComponentHandler( 
component,
+            final ComponentHandler handler = getComponentHandler( component,
                                                                   
configuration,
                                                                   
this.serviceManager);
 
@@ -460,7 +450,5 @@
         }
         return this.componentMapping.containsKey( component );
     }
-
-    
 
 }

Added: 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentHandler.java
==============================================================================
--- (empty file)
+++ 
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentHandler.java
   Mon Nov  1 10:21:13 2004
@@ -0,0 +1,64 @@
+/* 
+ * Copyright 2002-2004 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.container;
+
+/**
+ * This class acts like a Factory to instantiate the correct version
+ * of the component handler that you need.
+ *
+ * @version CVS $Id: AbstractComponentHandler.java 55144 2004-10-20 12:26:09Z 
ugo $
+ */
+public interface ComponentHandler {
+
+    /**
+     * Get an instance of the type of component handled by this handler.
+     * 
+     * @return an instance
+     * @exception Exception if an error occurs
+     */
+    Object get() throws Exception;
+
+    /**
+     * Put back an instance of the type of component handled by this handler.
+     *
+     * @param component a service
+     * @exception Exception if an error occurs
+     */
+    void put( Object component ) 
+    throws Exception;
+
+    /**
+     * Returns <code>true</code> if this component handler can safely be
+     * disposed (i.e. none of the components it is handling are still
+     * being used).
+     *
+     * @return <code>true</code> if this component handler can safely be
+     *         disposed; <code>false</code> otherwise
+     */
+    boolean canBeDisposed();
+
+    /**
+     * Dispose of the component handler and any associated Pools and Factories.
+     */
+    public void dispose();
+    
+    /**
+     * Initialize this handler
+     */
+    void initialize() throws Exception;
+
+}

Reply via email to