You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by do...@apache.org on 2001/04/18 15:01:34 UTC

cvs commit: jakarta-avalon/src/java/org/apache/avalon/component Component.java ComponentManager.java ComponentSelector.java Composable.java Recomposable.java ComponentException.java DefaultComponentManager.java DefaultComponentSelector.java DefaultComponentFactory.java DefaultComponentHandler.java DefaultComponentPool.java DefaultComponentPoolController.java DefaultRoleManager.java RoleManager.java

donaldp     01/04/18 06:01:34

  Modified:    src/java/org/apache/avalon/component ComponentException.java
                        DefaultComponentManager.java
                        DefaultComponentSelector.java
  Added:       src/java/org/apache/avalon/component Component.java
                        ComponentManager.java ComponentSelector.java
                        Composable.java Recomposable.java
  Removed:     src/java/org/apache/avalon/component
                        DefaultComponentFactory.java
                        DefaultComponentHandler.java
                        DefaultComponentPool.java
                        DefaultComponentPoolController.java
                        DefaultRoleManager.java RoleManager.java
  Log:
  Update component sub-package
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-avalon/src/java/org/apache/avalon/component/ComponentException.java
  
  Index: ComponentException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/component/ComponentException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComponentException.java	2001/04/11 04:18:09	1.1
  +++ ComponentException.java	2001/04/18 13:01:30	1.2
  @@ -7,7 +7,7 @@
    */
   package org.apache.avalon.component;
   
  -import org.apache.avalon.ComponentManagerException;
  +import org.apache.avalon.CascadingException;
   
   /**
    * The exception thrown by ComponentManager.
  @@ -18,7 +18,7 @@
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
    */
   public class ComponentException 
  -    extends ComponentManagerException
  +    extends CascadingException
   {
       /**
        * Construct a new <code>ComponentException</code> instance.
  
  
  
  1.7       +32 -283   jakarta-avalon/src/java/org/apache/avalon/component/DefaultComponentManager.java
  
  Index: DefaultComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/component/DefaultComponentManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultComponentManager.java	2001/04/11 16:39:13	1.6
  +++ DefaultComponentManager.java	2001/04/18 13:01:31	1.7
  @@ -2,332 +2,81 @@
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
    * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included  with this distribution in
  + * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    */
   package org.apache.avalon.component;
   
  -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.AbstractLoggable;
  -import org.apache.avalon.Component;
  -import org.apache.avalon.ComponentManager;
  -import org.apache.avalon.ComponentManagerException;
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.Context;
  -import org.apache.avalon.Contextualizable;
  -import org.apache.avalon.Disposable;
  -import org.apache.avalon.Initializable;
  -import org.apache.avalon.configuration.Configurable;
  -import org.apache.avalon.configuration.Configuration;
  -import org.apache.avalon.configuration.ConfigurationException;
  -import org.apache.avalon.configuration.DefaultConfiguration;
   
   /**
  - * Default component manager for Avalon's components.
  + * This class is a static implementation of a ComponentManager. Allow ineritance
  + * and extention so you can generate a tree of ComponentManager each defining
  + * Component scope.
    *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
  - * @version CVS $Revision: 1.6 $ $Date: 2001/04/11 16:39:13 $
  + * @author <a href="mailto:scoobie@pop.systemy.it">Federico Barbieri</a>
  + * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public class DefaultComponentManager
  -    extends AbstractLoggable
  -    implements ComponentManager, Configurable, Contextualizable, Disposable
  +    implements ComponentManager
   {
  -    /** The application context for components
  -     */
  -    private Context      m_context;
  -
  -    /** Static component mapping handlers.
  -     */
  -    private Map          m_componentMapping;
  -
  -    /** Static component handlers.
  -     */
  -    private Map          m_componentHandlers;
  -
  -    /** RoleInfos.
  -     */
  -    private RoleManager  m_roles;
  +    protected final HashMap               m_components = new HashMap();
  +    protected final ComponentManager      m_parent;
   
  -    /** Is the Manager disposed or not? */
  -    private boolean      m_disposed;
  -
       public DefaultComponentManager()
       {
  -        // Setup the maps.
  -        m_componentHandlers = Collections.synchronizedMap( new HashMap() );
  -        m_componentMapping = Collections.synchronizedMap( new HashMap() );
  +        this( null );
       }
   
  -    /** Set up the Component's Context.
  -     */
  -    public void contextualize( final Context context )
  +    public DefaultComponentManager( final ComponentManager parent )
       {
  -        //HACK: Is this really needed ??? (Isn't a symtom of fault elsewhere in system)
  -        if( null == m_context )
  -        {
  -            m_context = context;
  -        }
  +        m_parent = parent;
       }
   
  -    /** Properly dispose of the Child handlers.
  -     */
  -    public synchronized void dispose( )
  -    {
  -        m_disposed = true;
  -
  -        Iterator keys = m_componentHandlers.keySet().iterator();
  -        final List keyList = new ArrayList();
  -
  -        while( keys.hasNext() )
  -        {
  -            final Object key = keys.next();
  -            final DefaultComponentHandler handler =
  -                (DefaultComponentHandler)m_componentHandlers.get( key );
  -
  -            handler.dispose();
  -            keyList.add( key );
  -        }
  -
  -        keys = keyList.iterator();
  -
  -        while( keys.hasNext() )
  -        {
  -            m_componentHandlers.remove( keys.next() );
  -        }
  -
  -        keyList.clear();
  -    }
  -
  -    /**
  -     * Return an instance of a component based on a Role.  The Role is usually the Interface's
  -     * Fully Qualified Name(FQN)--unless there are multiple Components for the same Role.  In that
  -     * case, the Role's FQN is appended with "Selector", and we return a ComponentSelector.
  -     */
       public Component lookup( final String role )
           throws ComponentException
       {
  -
  -        if( m_disposed )
  -        {
  -            throw new IllegalStateException( "You cannot lookup components " +
  -                                             "on a disposed ComponentManager" );
  -        }
  -
  -        if( null == role )
  -        {
  -            final String message =
  -                "ComponentManager Attempted to retrieve component with null role.";
  -            getLogger().error( message );
  -            throw new ComponentException( message );
  -        }
  -
  -        DefaultComponentHandler handler = (DefaultComponentHandler)m_componentHandlers.get( role );
  -
  -        // Retrieve the instance of the requested component
  -        if( null == handler )
  -        {
  -            getLogger().debug( "Could not find ComponentHandler, " +
  -                               "attempting to create one for role: " + role );
  -
  -            try
  -            {
  -                final String className = m_roles.getDefaultClassNameForRole( role );
  -                final Class componentClass =
  -                    getClass().getClassLoader().loadClass( className );
  -
  -                final Configuration configuration = new DefaultConfiguration( "", "-" );
  -
  -                handler =
  -                    new DefaultComponentHandler( componentClass,
  -                                                 configuration,
  -                                                 this,
  -                                                 m_context,
  -                                                 m_roles );
  -
  -                handler.setLogger( getLogger() );
  -                handler.init();
  -            }
  -            catch( final Exception e )
  -            {
  -                final String message =
  -                    "ComponentManager Could not find component for role: " + role;
  -                getLogger().error( message, e );
  -                throw new ComponentException( message, e );
  -            }
  -
  -            m_componentHandlers.put( role, handler );
  -        }
  -
  -        Component component = null;
  +        final Component component = (Component)m_components.get( role );
   
  -        try
  +        if( null != component )
           {
  -            component = handler.get();
  -
  -            if( component instanceof DefaultComponentSelector )
  -            {
  -                ((DefaultComponentSelector)component).setRoleManager( m_roles );
  -            }
  +            return component;
           }
  -        catch( final IllegalStateException ise )
  +        else if( null != m_parent )
           {
  -            handler.init();
  -
  -            try
  -            {
  -                component = handler.get();
  -            }
  -            catch( final Exception e )
  -            {
  -                final String message = "Could not access the Component for role: " + role;
  -                throw new ComponentException( message, e );
  -            }
  +            return m_parent.lookup( role );
           }
  -        catch( final Exception e )
  +        else
           {
  -            final String message = "Could not access the Component for role: " + role;
  -            throw new ComponentException( message, e );
  +            throw new ComponentException( "Unable to provide implementation for " + role );
           }
  -
  -        m_componentMapping.put(component, handler);
  -        return component;
       }
   
  -    /**
  -     * Configure the ComponentManager.
  -     */
  -    public void configure( final Configuration configuration )
  -        throws ConfigurationException
  +    public void put( final String name, final Component component )
       {
  -        if( null == m_roles )
  -        {
  -            DefaultRoleManager role_info = new DefaultRoleManager();
  -            role_info.setLogger( getLogger() );
  -            role_info.configure( configuration );
  -            m_roles = role_info;
  -        }
  -
  -        // Set components
  -
  -        final Configuration[] configurations = configuration.getChildren();
  -
  -        for( int i = 0; i < configurations.length; i++ )
  -        {
  -            String type = configurations[i].getName(); // types are already trimmed
  -
  -            if( !type.equals( "role" ) )
  -            {
  -                String role = configurations[ i ].getAttribute( "role", "" );
  -                String className = configurations[ i ].getAttribute( "class", "" );
  -
  -                if( role.equals( "" ) )
  -                {
  -                    role = m_roles.getRoleForName( type );
  -                }
  -
  -                if( null != role && !role.equals( "" ) )
  -                {
  -                    if( className.equals( "" ) )
  -                    {
  -                        className = m_roles.getDefaultClassNameForRole( role );
  -                    }
  -
  -                    try
  -                    {
  -                        getLogger().debug( "Adding component (" + role + " = " + className + ")" );
  -                        final Class clazz =
  -                            getClass().getClassLoader().loadClass( className );
  -                        addComponent( role, clazz, configurations[ i ] );
  -                    }
  -                    catch( final Exception e )
  -                    {
  -                        final String message =
  -                            "Could not get class " + className + " for role " + role +
  -                            " on configuration element " + configurations[ i ].getName();
  -
  -                        getLogger().error( message, e );
  -                        throw new ConfigurationException( message, e );
  -                    }
  -                }
  -            }
  -        }
  +        m_components.put( name, component );
       }
   
  -    /**
  -     * Configure the RoleManager
  -     */
  -    public void setRoleManager( final RoleManager roles )
  -    {
  -        //HACK: Is this really necessary???
  -        if( null == m_roles )
  -        {
  -            m_roles = roles;
  -        }
  -    }
  -
  -    /**
  -     * Release a Component.  This implementation makes sure it has a handle on the propper
  -     * ComponentHandler, and let's the ComponentHandler take care of the actual work.
  -     */
       public void release( final Component component )
       {
  -        if( null == component ) return;
  -
  -        final DefaultComponentHandler handler =
  -            (DefaultComponentHandler)m_componentMapping.get( component );
  -
  -        if( null != handler )
  -        {
  -            handler.put( component );
  -            m_componentMapping.remove( component );
  -        }
  +        // if the ComponentManager handled pooling, it would be
  +        // returned to the pool here.
       }
   
  -    /** Add a new component to the manager.
  -     * @param role the role name for the new component.
  -     * @param component the class of this component.
  -     * @param Configuration the configuration for this component.
  -     */
  -    public void addComponent( final String role,
  -                              final Class component,
  -                              final Configuration configuration )
  -        throws ComponentException
  +    public String toString()
       {
  -        try
  -        {
  -            final DefaultComponentHandler handler =
  -                new DefaultComponentHandler( component, configuration, this, m_context, m_roles );
  +        final StringBuffer buffer = new StringBuffer();
  +        final Iterator components = m_components.keySet().iterator();
  +        buffer.append( "Components:" );
   
  -            handler.setLogger( getLogger() );
  -            m_componentHandlers.put( role, handler );
  -        }
  -        catch( final Exception e )
  +        while( components.hasNext() )
           {
  -            throw new ComponentException( "Could not set up Component for role: " + role, e );
  +            buffer.append( "[" );
  +            buffer.append( components.next() );
  +            buffer.append( "]" );
           }
  -    }
   
  -    /** Add a static instance of a component to the manager.
  -     * @param role the role name for the component.
  -     * @param instance the instance of the component.
  -     */
  -    public void addComponentInstance( final String role, final Object instance )
  -    {
  -        try
  -        {
  -            DefaultComponentHandler handler = new DefaultComponentHandler( (Component)instance );
  -            handler.setLogger( getLogger() );
  -            m_componentHandlers.put( role, handler );
  -        }
  -        catch( final Exception e )
  -        {
  -            getLogger().warn( "Could not set up Component for role: " + role, e );
  -        }
  +        return buffer.toString();
       }
   }
  
  
  
  1.7       +17 -306   jakarta-avalon/src/java/org/apache/avalon/component/DefaultComponentSelector.java
  
  Index: DefaultComponentSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/component/DefaultComponentSelector.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultComponentSelector.java	2001/04/14 05:49:36	1.6
  +++ DefaultComponentSelector.java	2001/04/18 13:01:32	1.7
  @@ -2,341 +2,52 @@
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
    * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included  with this distribution in
  + * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    */
   package org.apache.avalon.component;
   
  -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.AbstractLoggable;
  -import org.apache.avalon.Component;
  -import org.apache.avalon.ComponentManager;
  -import org.apache.avalon.ComponentManagerException;
  -import org.apache.avalon.ComponentSelector;
  -import org.apache.avalon.Composer;
  -import org.apache.avalon.Context;
  -import org.apache.avalon.Contextualizable;
  -import org.apache.avalon.Disposable;
  -import org.apache.avalon.ThreadSafe;
  -import org.apache.avalon.configuration.Configurable;
  -import org.apache.avalon.configuration.Configuration;
  -import org.apache.avalon.configuration.ConfigurationException;
  -import org.apache.avalon.configuration.DefaultConfiguration;
   
   /**
  - * Default component manager for Avalon's components.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
  - * @version CVS $Revision: 1.6 $ $Date: 2001/04/14 05:49:36 $
  + * This is the default implementation of the ComponentSelector
    */
   public class DefaultComponentSelector
  -    extends AbstractLoggable
  -    implements Contextualizable, ComponentSelector, Composer, Configurable, ThreadSafe, Disposable
  +    implements ComponentSelector
   {
  -    private static final String DEFAULT_NAME = "UnnamedSelector";
  +    protected final HashMap m_components = new HashMap();
   
  -    /** The role name for this instance
  -     */
  -    private String           m_rolename;
  -
  -    /** The application context for components
  -     */
  -    protected Context        m_context;
  -
  -    /** The application context for components
  -     */
  -    private ComponentManager m_componentManager;
  -
  -    /** Dynamic component handlers mapping.
  -     */
  -    private Map              m_componentMapping;
  -
  -    /** Static configuraiton object.
  -     */
  -    private Configuration    m_configuration;
  -
  -    /** Static component handlers.
  -     */
  -    private Map              m_componentHandlers;
  -
  -    /** Flag for if this is disposed or not.
  -     */
  -    private boolean          m_disposed;
  -
  -    /** Shorthand for hints
  -     */
  -    private Map              m_hints;
  -
  -    /** The RoleManager to get hint shortcuts
  -     */
  -    private RoleManager      m_roles;
  -
  -    /** Construct a new default component manager.
  -     */
  -    public DefaultComponentSelector()
  -    {
  -        // Setup the maps.
  -        m_componentHandlers = Collections.synchronizedMap( new HashMap() );
  -        m_componentMapping = Collections.synchronizedMap( new HashMap() );
  -    }
  -
  -    /** Provide the application Context.
  -     */
  -    public void contextualize( final Context context )
  -    {
  -        if( null == m_context )
  -        {
  -            m_context = context;
  -        }
  -    }
  -
  -    /** Compose the ComponentSelector so that we know what the parent ComponentManager is.
  -     */
  -    public void compose( final ComponentManager componentManager )
  -        throws ComponentManagerException
  -    {
  -        //HACK: Is this necessary???
  -        if( null == m_componentManager )
  -        {
  -            m_componentManager = componentManager;
  -        }
  -    }
  -
  -    /**
  -     * Properly dispose of all the ComponentHandlers.
  -     */
  -    public synchronized void dispose()
  -    {
  -        m_disposed = true;
  -
  -        Iterator keys = m_componentHandlers.keySet().iterator();
  -        List keyList = new ArrayList();
  -
  -        while( keys.hasNext() )
  -        {
  -            Object key = keys.next();
  -            DefaultComponentHandler handler =
  -                (DefaultComponentHandler)m_componentHandlers.get( key );
  -
  -            handler.dispose();
  -            keyList.add( key );
  -        }
  -
  -        keys = keyList.iterator();
  -
  -        while( keys.hasNext() )
  -        {
  -            m_componentHandlers.remove( keys.next() );
  -        }
  -
  -        keyList.clear();
  -    }
  -
       /**
  -     * Return an instance of a component based on a hint.  The Composer has already selected the
  -     * role, so the only part left it to make sure the Component is handled.
  +     * Select the desired component.  It does not cascade, neither
  +     * should it.
        */
  -    public Component select( final Object hint )
  +    public Component select( Object hint )
           throws ComponentException
       {
  -        if( m_disposed )
  -        {
  -            throw new IllegalStateException( "You cannot select a Component " +
  -                                             "from a disposed ComponentSelector" );
  -        }
  +        final Component component = (Component)m_components.get( hint );
   
  -        if( null == hint )
  +        if( null != component )
           {
  -            final String message =
  -                getName() + ": ComponentSelector Attempted to retrieve component with null hint.";
  -            getLogger().error( message );
  -            throw new ComponentException( message );
  +            return component;
           }
  -
  -        DefaultComponentHandler handler = (DefaultComponentHandler)m_componentHandlers.get( hint );
  -
  -        // Retrieve the instance of the requested component
  -        if( null == handler )
  -        {
  -            final String message =
  -                getName() + ": ComponentSelector could not find the component for hint: " + hint;
  -            throw new ComponentException( message );
  -        }
  -
  -        Component component = null;
  -
  -        try
  -        {
  -            component = handler.get();
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message =
  -                getName() + ": ComponentSelector could not access the Component for hint: " + hint;
  -            throw new ComponentException( message, e );
  -        }
  -
  -        if( null == component )
  -        {
  -            final String message =
  -                getName() + ": ComponentSelector could not find the component for hint: " + hint;
  -            throw new ComponentException( message );
  -        }
  -
  -        m_componentMapping.put( component, handler );
  -        return component;
  -    }
  -
  -    /**
  -     * Default Configuration handler for ComponentSelector.
  -     */
  -    public void configure( final Configuration configuration )
  -        throws ConfigurationException
  -    {
  -        m_configuration = configuration;
  -        getLogger().debug( "ComponentSelector setting up with root element: " +
  -                           m_configuration.getName() );
  -
  -        final String name = configuration.getName();
  -        if( name.equals( "component" ) )
  -        {
  -            m_rolename = m_configuration.getAttribute( "role" );
  -        }
           else
  -        {
  -            m_rolename = m_roles.getRoleForName( name );
  -        }
  -
  -        Configuration[] instances = m_configuration.getChildren();
  -
  -        for( int i = 0; i < instances.length; i++ )
  -        {
  -            final Object hint = instances[ i ].getAttribute( "name" ).trim();
  -            final String className;
  -
  -            if("component-instance".equals(instances[i].getName())) {
  -                className = (String)instances[i].getAttribute( "class" ).trim();
  -            } else {
  -                className = m_roles.getDefaultClassNameForHint(m_rolename, instances[i].getName());
  -            }
  -
  -            try
  -            {
  -                final Class clazz = getClass().getClassLoader().loadClass( className );
  -                addComponent( hint, clazz, instances[i]);
  -            }
  -            catch( final Exception e )
  -            {
  -                final String message =
  -                    "The component instance for '" + hint + "' has an invalid class name.";
  -                getLogger().error( message, e );
  -                throw new ConfigurationException( message, e );
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Configure the RoleManager
  -     */
  -    public void setRoleManager( final RoleManager roles )
  -    {
  -        if( null == m_roles )
           {
  -            m_roles = roles;
  +            throw new ComponentException( "Unable to provide implementation for " +
  +                                          hint.toString() );
           }
       }
   
  -    /**
  -     * Release the Component to the propper ComponentHandler.
  -     */
       public void release( final Component component )
  -    {
  -        if( null == component ) return;
  -
  -        final DefaultComponentHandler handler =
  -            (DefaultComponentHandler)m_componentMapping.get( component );
  -
  -        if( null == handler ) return;
  -
  -        handler.put( component );
  -
  -        m_componentMapping.remove( component );
  -    }
  -
  -    /** Add a new component to the manager.
  -     * @param hint the hint name for the new component.
  -     * @param component the class of this component.
  -     * @param Configuration the configuration for this component.
  -     */
  -    public void addComponent( final Object hint,
  -                              final Class component,
  -                              final Configuration configuration )
  -        throws ComponentException
  -    {
  -        try
  -        {
  -            final DefaultComponentHandler handler =
  -                new DefaultComponentHandler( component,
  -                                             configuration,
  -                                             m_componentManager,
  -                                             m_context,
  -                                             m_roles );
  -
  -            handler.setLogger( getLogger() );
  -            handler.init();
  -            m_componentHandlers.put( hint, handler );
  -            getLogger().debug( "Adding " + component.getName() + " for " + hint.toString() );
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message =
  -                "Could not set up Component for hint: " + hint;
  -            getLogger().error( message, e);
  -            throw new ComponentException( message, e );
  -        }
  -    }
  -
  -    /** Add a static instance of a component to the manager.
  -     * @param hint the hint name for the component.
  -     * @param instance the instance of the component.
  -     */
  -    public void addComponentInstance( final String hint, final Object instance )
       {
  -        try
  -        {
  -            final DefaultComponentHandler handler =
  -                new DefaultComponentHandler( (Component)instance );
  -            handler.setLogger( getLogger() );
  -            handler.init();
  -            m_componentHandlers.put( hint, handler );
  -            getLogger().debug( "Adding " + instance.getClass().getName() + " for " + hint.toString() );
  -        }
  -        catch( final Exception e )
  -        {
  -            getLogger().error( "Could not set up Component for hint: " + hint, e );
  -        }
  +        // if the ComponentManager handled pooling, it would be
  +        // returned to the pool here.
       }
   
       /**
  -     * 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
  +     * Populate the ComponentSelector.
        */
  -    private String getName()
  +    public void put( final Object hint, final Component component )
       {
  -        if( null != m_configuration &&
  -            !m_configuration.getName().equals( "" ) )
  -        {
  -            return m_configuration.getName();
  -        }
  -
  -        return DEFAULT_NAME;
  +        m_components.put( hint, component );
       }
   }
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/component/Component.java
  
  Index: Component.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.component;
  
  /**
   * This interface identifies classes that can be used as <code>Components</code>
   * by a <code>Composer</code>.
   * <br />
   *
   * The contract surrounding the <code>Component</code> is that it is
   * used, but not a user.  When a class implements this interface, it
   * is stating that other entities may use that class.  As part of the
   * contract with the system, a <code>Component</code> must always
   * declare an empty constructor.
   * <br />
   *
   * A <code>Component</code> is the basic building block of the Avalon.
   * When a class implements this interface, it allows itself to be
   * managed by a <code>ComponentManager</code> and used by an outside
   * element called a <code>Composer</code>.  The <code>Composer</code>
   * must know what type of <code>Component</code> it is accessing, so
   * it will re-cast the <code>Component</code> into the type it needs.
   * <br />
   *
   * In order for a <code>Component</code> to be useful you must either
   * extend this interface, or implement this interface in conjunction
   * with one that actually has methods.  The new interface is the contract
   * with the <code>Composer</code> that this is a particular type of
   * component, and as such it can perform those functions on that type
   * of component.
   * <br />
   *
   * For example, we want a component that performs a logging function
   * so we extend the <code>Component</code> to be a <code>LoggingComponent</code>.
   *
   * <pre>
   *   interface LoggingComponent extends Component {
   *       log(String message);
   *   }
   * </pre>
   *
   * Now all <code>Composer</code>s that want to use this type of component,
   * will re-cast the <code>Component</code> into a <code>LoggingComponent</code>
   * and the <code>Composer</code> will be able to use the <code>log</code>
   * method.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   * @author <a href="mailto:bloritsch@apache.org>Berin Loritsch</a>
   */
  public interface Component
  {
  }
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/component/ComponentManager.java
  
  Index: ComponentManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.component;
  
  /**
   * A <code>ComponentManager</code> selects <code>Component</code>s based on a
   * role.  The contract is that all the <code>Component</code>s implement the
   * differing roles and there is one <code>Component</code> per role.  If you
   * need to select on of many <code>Component</code>s that implement the same
   * role, then you need to use a <code>ComponentSelector</code>.  Roles are the
   * full interface name.
   *
   * A role is better understood by the analogy of a play.  There are many
   * different roles in a script.  Any actor or actress can play any given part
   * and you get the same results (phrases said, movements made, etc.).  The exact
   * nuances of the performance is different.
   *
   * Below is a list of things that might be considered the different roles:
   *
   * <ul>
   *   <li> InputAdaptor and OutputAdaptor</li>
   *   <li> Store and Spool</li>
   * </ul>
   *
   * The <code>ComponentManager</code> does not specify the methodology of
   * getting the <code>Component</code>, merely the interface used to get it.
   * Therefore the <code>ComponentManager</code> can be implemented with a
   * factory pattern, an object pool, or a simple Hashtable.
   *
   * @see org.apache.avalon.Component
   * @see org.apache.avalon.Composer
   * @see org.apache.avalon.ComponentSelector
   *
   * @author <a href="mailto:scoobie@betaversion.org">Federico Barbieri</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   * @author <a href="mailto:bloritsch@apache.org>Berin Loritsch</a>
   */
  public interface ComponentManager
  {
      /**
       * Get the <code>Component</code> associated with the given role.  For
       * instance, If the <code>ComponentManager</code> had a
       * <code>LoggerComponent</code> stored and referenced by role, I would use
       * the following call:
       * <pre>
       * try {
       *     LoggerComponent log;
       *     log = (LoggerComponent) manager.lookup("org.apache.avalon.blocks.Logger");
       * } catch (...) {
       *     ...
       * }
       * </pre>
       *
       * @param name The role name of the <code>Component</code> to retrieve.
       *
       * @exception ComponentNotFoundException If the given role is not associated
       *                                       with a <code>Component</code>.
       * @exception ComponentNotAccessibleException If a <code>Component</code>
       *                                            instance cannot be created.
       */
      Component lookup( String role )
          throws ComponentException;
  
      /**
       * Return the <code>Component</code> when you are finished with it.  This
       * allows the <code>ComponentManager</code> to handle the End-Of-Life Lifecycle
       * events associated with the Component.  Please note, that no Exceptions
       * should be thrown at this point.  This is to allow easy use of the
       * ComponentManager system without having to trap Exceptions on a release.
       *
       * @param component The Component we are releasing.
       */
      void release( Component component );
  }
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/component/ComponentSelector.java
  
  Index: ComponentSelector.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.component;
  
  /**
   * A <code>ComponentSelector</code> selects <code>Component</code>s based on a
   * hint.  The contract is that all the <code>Component</code>s implement the
   * same role.
   *
   * A role is better understood by the analogy of a play.  There are many
   * different roles in a script.  Any actor or actress can play any given part
   * and you get the same results (phrases said, movements made, etc.).  The exact
   * nuances of the performance is different.
   *
   * Below is a list of things that might be considered the same role:
   *
   * <ul>
   *   <li> XMLInputAdaptor and PropertyInputAdaptor</li>
   *   <li> FileGenerator   and SQLGenerator</li>
   * </ul>
   *
   * The <code>ComponentSelector</code> does not specify the methodology of
   * getting the <code>Component</code>, merely the interface used to get it.
   * Therefore the <code>ComponentSelector</code> can be implemented with a
   * factory pattern, an object pool, or a simple Hashtable.
   *
   * @see org.apache.avalon.Component
   * @see org.apache.avalon.Composer
   * @see org.apache.avalon.ComponentManager
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface ComponentSelector
      extends Component
  {
      /**
       * Select the <code>Component</code> associated with the given hint.
       * For instance, If the <code>ComponentSelector</code> has a
       * <code>Generator</code> stored and referenced by a URL, I would use the
       * following call:
       *
       * <pre>
       * try {
       *     Generator input;
       *     input = (Generator) selector.select(new URL("foo://demo/url"));
       * } catch (...) {
       *     ...
       * }
       * </pre>
       *
       * @param name A hint to retrieve the correct <code>Component</code>.
       *
       * @exception ComponentNotFoundException If the given role is not associated
       *                                       with a <code>Component</code>.
       * @exception ComponentNotAccessibleException If a <code>Component</code>
       *                                            instance cannot be created.
       */
      Component select( Object hint )
          throws ComponentException;
  
      /**
       * Return the <code>Component</code> when you are finished with it.  This
       * allows the <code>ComponentManager</code> to handle the End-Of-Life Lifecycle
       * events associated with the Component.  Please note, that no Exceptions
       * should be thrown at this point.  This is to allow easy use of the
       * ComponentManager system without having to trap Exceptions on a release.
       *
       * @param component The Component we are releasing.
       */
      void release( Component component );
  }
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/component/Composable.java
  
  Index: Composable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.component;
  
  /**
   * A composer is a class that need to connect to software components using
   * a "role" abstraction, thus not depending on particular implementations
   * but on behavioral interfaces.
   * <br />
   *
   * The contract surrounding a <code>Composer</code> is that it is a user.
   * The <code>Composer</code> is able to use <code>Components</code> managed
   * by the <code>ComponentManager</code> it was initialized with.  As part
   * of the contract with the system, the instantiating entity must call
   * the <code>setComponenetManager</code> method before the
   * <code>Composer</code> can be considered valid.  The
   * <code>setComponentManager</code> method must be called after the constructor
   * and before any user methods.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public interface Composable
  {
      /**
       * Pass the <code>ComponentManager</code> to the <code>composer</code>.
       * The <code>Composer</code> implementation should use the specified
       * <code>ComponentManager</code> to acquire the components it needs for
       * execution.
       *
       * @param manager The <code>ComponentManager</code> which this
       *                <code>Composer</code> uses.
       */
      void compose( ComponentManager componentManager )
          throws ComponentException;
  }
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/component/Recomposable.java
  
  Index: Recomposable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.component;
  
  /**
   * Extends composer to allow recomposing.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Recomposable
      extends Composable
  {
      void recompose( ComponentManager componentManager )
          throws ComponentException;
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org