Author: cziegeler
Date: Tue Oct 19 12:30:22 2004
New Revision: 55088

Added:
   
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/AbstractServiceManager.java
Modified:
   
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
   
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceSelector.java
Log:
Remove unused code, Refactoring

Added: 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/AbstractServiceManager.java
==============================================================================
--- (empty file)
+++ 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/AbstractServiceManager.java
       Tue Oct 19 12:30:22 2004
@@ -0,0 +1,121 @@
+/* 
+ * 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.components.container;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+/**
+ * Base class for all component managers: ServiceManager and ServiceSelector
+ *
+ * @version CVS $Revision: 1.6 $ $Date: 2004/02/28 11:47:14 $
+ */
+public class AbstractServiceManager
+extends AbstractLogEnabled
+implements Contextualizable, ThreadSafe {
+    
+    /** The classloader used for this system. */
+    protected final ClassLoader loader;
+
+    /** The application context for components */
+    protected Context context;
+
+    /** Static component mapping handlers. */
+    protected final Map componentMapping = Collections.synchronizedMap(new 
HashMap());
+
+    /** Used to map roles to ComponentHandlers. */
+    protected final Map componentHandlers = Collections.synchronizedMap(new 
HashMap());
+
+    /** Is the Manager disposed or not? */
+    protected boolean disposed;
+
+    /** Is the Manager initialized? */
+    protected boolean initialized;
+
+    /** RoleInfos. */
+    protected RoleManager roleManager;
+
+    /** LoggerManager. */
+    protected LoggerManager loggerManager;
+
+    
+    /** 
+     * Create the ComponentLocator with a Classloader
+     */
+    public AbstractServiceManager( final ClassLoader loader ) {
+        if( null == loader ) {
+            this.loader = Thread.currentThread().getContextClassLoader();
+        } else {
+            this.loader = loader;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see 
org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize( final Context context ) {
+        this.context = context;
+    }
+
+    public void setRoleManager( final RoleManager roles ) {
+        this.roleManager = roles;
+    }
+
+    /**
+     * Configure the LoggerManager.
+     */
+    public void setLoggerManager( final LoggerManager manager ) {
+        this.loggerManager = manager;
+    }
+    
+    /**
+     * Obtain a new ComponentHandler for the specified component. 
+     * 
+     * @param role The role
+     * @param componentClass Class of the component for which the handle is
+     *                       being requested.
+     * @param configuration The configuration for this component.
+     * @param serviceManager The service manager which will be managing the 
Component.
+     *
+     * @throws Exception If there were any problems obtaining a 
ComponentHandler
+     */
+    protected AbstractComponentHandler getComponentHandler( final String role,
+                                                    final Class componentClass,
+                                                    final Configuration 
configuration,
+                                                    final ServiceManager 
serviceManager)
+    throws Exception {
+        return AbstractComponentHandler.getComponentHandler( role,
+                                                     componentClass,
+                                                     configuration,
+                                                     serviceManager,
+                                                     this.context,
+                                                     this.getLogger(),
+                                                     this.loggerManager,
+                                                     this.roleManager);
+    }
+
+    
+}

Modified: 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
==============================================================================
--- 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
 (original)
+++ 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
 Tue Oct 19 12:30:22 2004
@@ -17,13 +17,11 @@
 package org.apache.cocoon.components.container;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.configuration.Configurable;
@@ -31,8 +29,6 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.components.SitemapConfigurable;
@@ -44,45 +40,17 @@
  * @version CVS $Revision: 1.6 $ $Date: 2004/02/28 11:47:14 $
  */
 public class CocoonServiceManager
-    extends AbstractLogEnabled
-    implements ServiceManager,
-    Configurable,
-    Contextualizable,
-    Initializable,
-    Disposable {
+extends AbstractServiceManager
+implements ServiceManager, Configurable, Initializable, Disposable {
     
     /** The parent ComponentLocator */
     private final ServiceManager parentManager;
 
-    /** The classloader used for this system. */
-    private final ClassLoader loader;
-
-    /** The application context for components */
-    private Context context;
-
-    /** Static component mapping handlers. */
-    private final Map componentMapping = Collections.synchronizedMap(new 
HashMap());
-
-    /** Used to map roles to ComponentHandlers. */
-    private final Map componentHandlers = Collections.synchronizedMap(new 
HashMap());
-
     /** added component handlers before initialization to maintain
      *  the order of initialization
      */
     private final List newComponentHandlers = new ArrayList();
 
-    /** RoleInfos. */
-    private RoleManager roleManager;
-
-    /** LogKitManager. */
-    private LoggerManager loggerManager;
-
-    /** Is the Manager disposed or not? */
-    private boolean disposed;
-
-    /** Is the Manager initialized? */
-    private boolean initialized;
-
     /** The [EMAIL PROTECTED] SitemapConfigurationHolder}s */
     private Map sitemapConfigurationHolders = new HashMap(15);
 
@@ -93,12 +61,7 @@
     /** Create the ComponentLocator with a Classloader and parent 
ComponentLocator */
     public CocoonServiceManager( final ServiceManager parent, 
                                  final ClassLoader loader ) {
-        if( null == loader ) {
-            this.loader = Thread.currentThread().getContextClassLoader();
-        } else {
-            this.loader = loader;
-        }
-
+        super(loader);
         this.parentManager = parent;
     }
 
@@ -162,14 +125,10 @@
 
                         final Configuration configuration = new 
DefaultConfiguration( "", "-" );
 
-                        handler = 
AbstractComponentHandler.getComponentHandler( role,
+                        handler = this.getComponentHandler( role,
                                                        componentClass,
                                                        configuration,
-                                                       this,
-                                                       context,
-                                                       this.getLogger(),
-                                                       this.loggerManager,
-                                                       this.roleManager);
+                                                       this);
 
                         handler.initialize();
                     } catch (ServiceException se) {
@@ -521,28 +480,6 @@
         }
     }
 
-    /*---------------------------------------------------------------
-     * RoleManageable Methods
-     *-------------------------------------------------------------*/
-    /**
-     * Configure the RoleManager
-     */
-    public void setRoleManager( final RoleManager roles )
-    {
-        if( null == roleManager )
-        {
-            roleManager = roles;
-        }
-    }
-
-
-    /**
-     * Configure the LoggerManager.
-     */
-    public void setLoggerManager( final LoggerManager loggerManager ) {
-        this.loggerManager = loggerManager;
-    }
-
     /**
      * Add a new component to the manager.
      *
@@ -564,14 +501,10 @@
                 this.getLogger().debug( "Attempting to get handler for role [" 
+ role + "]" );
             }
 
-            final AbstractComponentHandler handler = 
AbstractComponentHandler.getComponentHandler( role,
+            final AbstractComponentHandler handler = this.getComponentHandler( 
role,
                                                                   component,
                                                                   
configuration,
-                                                                  this,
-                                                                  context,
-                                                                  
this.getLogger(),
-                                                                  
this.loggerManager,
-                                                                  
this.roleManager);
+                                                                  this);
 
             if( this.getLogger().isDebugEnabled() ) {
                 this.getLogger().debug( "Handler type = " + 
handler.getClass().getName() );

Modified: 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceSelector.java
==============================================================================
--- 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceSelector.java
        (original)
+++ 
cocoon/whiteboard/ecmplus/src/java/org/apache/cocoon/components/container/CocoonServiceSelector.java
        Tue Oct 19 12:30:22 2004
@@ -17,27 +17,20 @@
 package org.apache.cocoon.components.container;
 
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.avalon.excalibur.logger.LoggerManager;
 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.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
 
 /**
  * Default component selector for Cocoon's components.
@@ -45,56 +38,13 @@
  * @version CVS $Revision: 1.6 $ $Date: 2004/02/28 11:47:14 $
  */
 public class CocoonServiceSelector
-    extends AbstractLogEnabled
-    implements Contextualizable,
-    ServiceSelector,
-    Serviceable,
-    Configurable,
-    Initializable,
-    ThreadSafe,
-    Disposable {
+extends AbstractServiceManager
+implements ServiceSelector, Serviceable, Configurable, Initializable, 
Disposable {
     
-    /** The classloader used for this system. */
-    protected final ClassLoader loader;
-
-    /** The role name for this instance
-     */
-    private String rolename;
-
-    /** The application context for components
-     */
-    protected Context context;
-
     /** The application context for components
      */
     private ServiceManager serviceManager;
 
-    /** Static configuraiton object.
-     */
-    private Configuration configuration;
-
-    /** Static component handlers.
-     */
-    private Map componentHandlers = Collections.synchronizedMap(new HashMap());
-
-    /** Dynamic component handlers mapping.
-     */
-    private Map componentMapping = Collections.synchronizedMap(new HashMap());
-
-    /** Flag for if this is disposed or not.
-     */
-    private boolean disposed;
-
-    /** Flag for if this is initialized or not.
-     */
-    private boolean initialized;
-
-    /** The RoleManager to get hint shortcuts
-     */
-    protected RoleManager roleManager;
-
-    private LoggerManager loggerManager;
-
     /** The parent selector, if any */
     protected CocoonServiceSelector parentSelector;
 
@@ -113,14 +63,7 @@
     
     /** Create the ComponentSelector */
     public CocoonServiceSelector() {
-        this.loader = Thread.currentThread().getContextClassLoader();
-    }
-
-    /* (non-Javadoc)
-     * @see 
org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
-     */
-    public void contextualize( final Context context ) {
-        this.context = context;
+        super(null);
     }
 
     /* (non-Javadoc)
@@ -152,7 +95,7 @@
            if ( this.parentSelector != null ) {
                 return this.parentSelector.select(hint);                
             }
-            final String message = getName()
+            final String message = this.roleName
                 + ": ComponentSelector could not find the component for hint 
[" + hint + "]";
             if( this.getLogger().isDebugEnabled() ) {
                 this.getLogger().debug( message );
@@ -168,7 +111,7 @@
             //rethrow
             throw ce;
         } catch( final Exception e ) {
-            final String message = getName()
+            final String message = this.roleName
                 + ": ComponentSelector could not access the Component for hint 
[" + hint + "]";
 
             if( this.getLogger().isDebugEnabled() ) {
@@ -182,7 +125,7 @@
             if ( this.parentSelector != null ) {
                 component = this.parentSelector.select(hint);
             } else {
-                final String message = getName()
+                final String message = this.roleName
                     + ": ComponentSelector could not find the component for 
hint [" + hint + "]";
                 if( this.getLogger().isDebugEnabled() ) {
                     this.getLogger().debug( message );
@@ -282,76 +225,15 @@
     throws ConfigurationException {
         // Store location
         this.location = config.getLocation();
-
         this.roleName = getRoleName(config);
 
-        // Pass a copy of the top-level object to superclass so that
-        // our name is properly initialized
-        // FIXME : could be avoided if parent m_role was protected or had 
protected accessors
-        DefaultConfiguration temp = new DefaultConfiguration(config.getName(), 
this.location);
-        if (config.getAttribute("role", null) != null) {
-            temp.setAttribute("role", this.roleName);
-        }
-
-        this.configuration = temp;
-
-        if( this.getLogger().isDebugEnabled() ) {
-            this.getLogger().debug( "ComponentSelector setting up with root 
element: " +
-                    this.configuration.getName() );
-        }
-
-        final String name = configuration.getName();
-        if( name.equals( "component" ) ) {
-            this.rolename = this.configuration.getAttribute( "role" );
-        } else {
-            this.rolename = this.roleManager.getRoleForName( name );
-        }
-
-        Configuration[] instances = this.configuration.getChildren();
-
-        for( int i = 0; i < instances.length; i++ ) {
-            final Object hint = instances[ i ].getAttribute( "name" ).trim();
-            String className;
-
-            if( "component-instance".equals( instances[ i ].getName() ) ) {
-                className = (String)instances[ i ].getAttribute( "class" 
).trim();
-            } else {
-                className = this.roleManager.getDefaultClassNameForHint( 
this.rolename,
-                                                                instances[ i 
].getName() );
-            }
-
-            if ( 
"org.apache.cocoon.components.ExtendedComponentSelector".equals(className)) {
-                className = CocoonServiceSelector.class.getName();
-            } else if 
("org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector".equals(className)
 ) {
-                className = ComponentsSelector.class.getName();
-            }
-            
-            try {
-                final Class clazz = this.loader.loadClass( className );
-                this.addComponent( hint, clazz, instances[ i ] );
-            } catch( final ClassNotFoundException cnfe ) {
-                final String message =
-                    "The component instance for hint [" + hint
-                    + "] has an invalid class name (" + className + ").";
-                if( this.getLogger().isErrorEnabled() ) {
-                    this.getLogger().error( message, cnfe );
-                }
-
-                throw new ConfigurationException( message, cnfe );
-            } catch( final Exception e ) {
-                if( this.getLogger().isErrorEnabled() ) {
-                    this.getLogger().error( "Unexpected exception for hint [" 
+ hint + "]", e );
-                }
-                throw new ConfigurationException( "Unexpected exception", e );
-            }
-        }
         // Get default hint
         this.defaultHint = 
config.getAttribute(this.getDefaultHintAttributeName(), null);
 
         // Add components
         String compInstanceName = getComponentInstanceName();
 
-        instances = config.getChildren();
+        Configuration[] instances = config.getChildren();
 
         for (int i = 0; i < instances.length; i++) {
 
@@ -471,50 +353,6 @@
         }
     }
 
-    public void setRoleManager( final RoleManager roles ) {
-        this.roleManager = roles;
-    }
-
-    /**
-     * Configure the LoggerManager.
-     */
-    public void setLoggerManager( final LoggerManager manager ) {
-        this.loggerManager = manager;
-    }
-
-    /**
-     * Obtain a new ComponentHandler for the specified component.  This method
-     *  allows classes which extend the ExcaliburComponentSelector to use their
-     *  own ComponentHandlers.
-     *
-     * @param componentClass Class of the component for which the handle is
-     *                       being requested.
-     * @param configuration The configuration for this component.
-     * @param componentManager The ComponentLocator which will be managing
-     *                         the Component.
-     * @param context The current context object.
-     * @param roleManager The current RoleManager.
-     * @param logkitManager The current LogKitManager.
-     *
-     * @throws Exception If there were any problems obtaining a 
ComponentHandler
-     */
-    protected AbstractComponentHandler getComponentHandler( final String role,
-                                                    final Class componentClass,
-                                                    final Configuration 
configuration,
-                                                    final ServiceManager 
componentManager,
-                                                    final Context context,
-                                                    final LoggerManager 
logkitManager )
-    throws Exception {
-        return AbstractComponentHandler.getComponentHandler( role,
-                                                     componentClass,
-                                                     configuration,
-                                                     this.serviceManager,
-                                                     context,
-                                                     this.getLogger(),
-                                                     this.loggerManager,
-                                                     this.roleManager);
-    }
-
     /**
      * Makes the ComponentHandlers available to subclasses.
      *
@@ -539,12 +377,10 @@
         }
 
         try {
-            final AbstractComponentHandler handler = getComponentHandler( 
this.rolename,
+            final AbstractComponentHandler handler = getComponentHandler( 
this.roleName,
                                                                   component,
                                                                   
configuration,
-                                                                  
this.serviceManager,
-                                                                  this.context,
-                                                                  
this.loggerManager );
+                                                                  
this.serviceManager);
 
             handler.initialize();
             this.componentHandlers.put( hint, handler );
@@ -562,21 +398,6 @@
 
             throw new ServiceException( hint.toString(), message, e );
         }
-    }
-
-    /**
-     * Return this selector's configuration name or a default name if no such
-     * configuration was provided. This accounts for the case when a static
-     * component instance has been added through
-     * <code>addComponentInstance</code> with no associated configuration
-     */
-    private String getName() {
-        if( null != this.configuration &&
-            !this.configuration.getName().equals( "" ) ) {
-            return this.configuration.getName();
-        }
-
-        return "Unnamed service selector";
     }
 
     /**

Reply via email to