bloritsch    2003/02/15 09:43:33

  Modified:    component/src/java/org/apache/avalon/excalibur/component
                        ComponentProxyGenerator.java
                        ExcaliburComponentManager.java
  Log:
  put the code in the right place for the proxy generator
  
  Revision  Changes    Path
  1.2       +32 -1     
avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentProxyGenerator.java
  
  Index: ComponentProxyGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentProxyGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComponentProxyGenerator.java      9 Nov 2002 08:41:03 -0000       1.1
  +++ ComponentProxyGenerator.java      15 Feb 2003 17:43:33 -0000      1.2
  @@ -99,7 +99,8 @@
        */
       public Component getProxy( String role, Object service ) throws Exception
       {
  -        Class serviceInterface = m_classLoader.loadClass( role );
  +     Lookup value = parseRole( role );
  +        Class serviceInterface = m_classLoader.loadClass( value.role );
   
           return (Component)Proxy.newProxyInstance( m_classLoader,
                                                     new 
Class[]{Component.class, serviceInterface},
  @@ -138,5 +139,35 @@
                   throw ite.getTargetException();
               }
           }
  +    }
  +
  +    private Lookup parseRole( String role )
  +    {
  +        Lookup lookup = new Lookup();
  +        lookup.role = role;
  +        lookup.hint = AbstractContainer.DEFAULT_ENTRY;
  +
  +        if ( role.endsWith("Selector") )
  +        {
  +            lookup.role = role.substring(0, role.length() - 
"Selector".length());
  +            lookup.hint = AbstractContainer.SELECTOR_ENTRY;
  +        }
  +
  +        int index = role.lastIndexOf("/");
  +
  +        // needs to be further than the first character
  +        if ( index > 0 )
  +        {
  +            lookup.role = role.substring(0, index);
  +            lookup.hint = role.substring(index + 1);
  +        }
  +
  +        return lookup;
  +    }
  +
  +    private final static class Lookup
  +    {
  +        public String role;
  +        public String hint;
       }
   }
  
  
  
  1.24      +3 -204    
avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentManager.java
  
  Index: ExcaliburComponentManager.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ExcaliburComponentManager.java    15 Feb 2003 17:34:16 -0000      1.23
  +++ ExcaliburComponentManager.java    15 Feb 2003 17:43:33 -0000      1.24
  @@ -1,175 +1,4 @@
  -/*
  - * 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.txt file.
  - */
  -package org.apache.avalon.excalibur.component;
  -
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.List;
  -import org.apache.commons.collections.StaticBucketMap;
  -import org.apache.avalon.excalibur.logger.LogKitManageable;
  -import org.apache.avalon.excalibur.logger.LogKitManager;
  -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.Component;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -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.excalibur.instrument.Instrument;
  -import org.apache.excalibur.instrument.InstrumentManageable;
  -import org.apache.excalibur.instrument.InstrumentManager;
  -import org.apache.excalibur.instrument.Instrumentable;
  -
  -/**
  - * Default component manager for Avalon's components.
  - *
  - * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]">Paul Russell</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.0
  - */
  -public class ExcaliburComponentManager
  -    extends AbstractDualLogEnabled
  -    implements ComponentManager,
  -    Configurable,
  -    Contextualizable,
  -    Initializable,
  -    Disposable,
  -    RoleManageable,
  -    LogKitManageable,
  -    InstrumentManageable,
  -    Instrumentable
  -{
  -    /** Instrumentable name used to represent the component-manager.
  -     *  Handlers reference this name to register themselves at the correct
  -     *  location under the ECM. */
  -    public static final String INSTRUMENTABLE_NAME = "component-manager";
  -
  -    /** The parent ComponentLocator */
  -    private final ComponentManager m_parentManager;
  -
  -    /** The classloader used for this system. */
  -    private final ClassLoader m_loader;
  -
  -    /** The application context for components */
  -    private Context m_context;
  -
  -    /** Static component mapping handlers. */
  -    private final StaticBucketMap m_componentMapping = new StaticBucketMap();
  -
  -    /** Used to map roles to ComponentHandlers. */
  -    private final StaticBucketMap m_componentHandlers = new 
StaticBucketMap();
  -
  -    /** added component handlers before initialization to maintain
  -     *  the order of initialization
  -     */
  -    private final List m_newComponentHandlers = new ArrayList();
  -
  -    /** RoleInfos. */
  -    private RoleManager m_roles;
  -
  -    /** LogKitManager. */
  -    private LogkitLoggerManager m_logkit;
  -
  -    /** Is the Manager disposed or not? */
  -    private boolean m_disposed;
  -
  -    /** Is the Manager initialized? */
  -    private boolean m_initialized;
  -
  -    /** Instrument Manager being used by the Component Manager. */
  -    private InstrumentManager m_instrumentManager;
  -
  -    /** Instrumentable Name assigned to this Instrumentable */
  -    private String m_instrumentableName = INSTRUMENTABLE_NAME;
  -
  -    /*---------------------------------------------------------------
  -     * Constructors
  -     *-------------------------------------------------------------*/
  -    /** Create a new ExcaliburComponentManager. */
  -    public ExcaliburComponentManager()
  -    {
  -        this( null, Thread.currentThread().getContextClassLoader() );
  -    }
  -
  -    /** Create a new ExcaliburComponentManager with uses a specific 
Classloader. */
  -    public ExcaliburComponentManager( final ClassLoader loader )
  -    {
  -        this( null, loader );
  -    }
  -
  -    /** Create the ComponentLocator with a Classloader and parent 
ComponentLocator */
  -    public ExcaliburComponentManager( final ComponentManager manager, final 
ClassLoader loader )
  -    {
  -        if( null == loader )
  -        {
  -            m_loader = Thread.currentThread().getContextClassLoader();
  -        }
  -        else
  -        {
  -            m_loader = loader;
  -        }
  -
  -        m_parentManager = manager;
  -    }
  -
  -    /** Create the ComponentLocator with a parent ComponentLocator */
  -    public ExcaliburComponentManager( final ComponentManager manager )
  -    {
  -        this( manager, Thread.currentThread().getContextClassLoader() );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * ComponentManager Methods
  -     *-------------------------------------------------------------*/
  -    /**
  -     * 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_initialized )
  -        {
  -            if( getLogger().isWarnEnabled() )
  -            {
  -                getLogger().warn(
  -                    "Looking up component on an uninitialized 
ComponentLocator [" + role + "]" );
  -            }
  -        }
  -
  -        if( m_disposed )
  -        {
  -            throw new IllegalStateException(
  -                "You cannot lookup components on a disposed 
ComponentLocator" );
  -        }
  -
  -        if( null == role )
  -        {
  -            final String message =
  -                "ComponentLocator Attempted to retrieve component with null 
role.";
  -
  -            if( getLogger().isErrorEnabled() )
  -            {
  -                getLogger().error( message );
  -            }
  -            throw new ComponentException( role, message );
  -        }
  -
  -        ComponentHandler handler = 
(ComponentHandler)m_componentHandlers.get( role );
  +g`"        ComponentHandler handler = 
(ComponentHandler)m_componentHandlers.get( role );
   
           // Retrieve the instance of the requested component
           if( null == handler )
  @@ -296,7 +125,7 @@
           //  In the case of a ThreadSafeComponentHandler, the same component 
will be mapped
           //  multiple times but because each put will overwrite the last, 
this is not a
           //  problem.  Checking to see if the put has already been done would 
be slower.
  -        m_componentMapping.put( component, handler );
  +        m_componentMapping.put( component.toString(), handler );
   
           return component;
       }
  @@ -338,7 +167,7 @@
           //  synchronization around the access to the map.
   
           final ComponentHandler handler =
  -            (ComponentHandler)m_componentMapping.get( component );
  +            (ComponentHandler)m_componentMapping.get( component.toString() );
   
           if( null != handler )
           {
  @@ -870,35 +699,5 @@
                   getLogger().warn( "Could not set up Component for role [" + 
role + "]", e );
               }
           }
  -    }
  -
  -    private Lookup parseRole( String role )
  -    {
  -        Lookup lookup = new Lookup();
  -        lookup.role = role;
  -        lookup.hint = AbstractContainer.DEFAULT_ENTRY;
  -
  -        if ( role.endsWith("Selector") )
  -        {
  -            lookup.role = role.substring(0, role.length() - 
"Selector".length());
  -            lookup.hint = AbstractContainer.SELECTOR_ENTRY;
  -        }
  -
  -        int index = role.lastIndexOf("/");
  -
  -        // needs to be further than the first character
  -        if ( index > 0 )
  -        {
  -            lookup.role = role.substring(0, index);
  -            lookup.hint = role.substring(index + 1);
  -        }
  -
  -        return lookup;
  -    }
  -
  -    private final static class Lookup
  -    {
  -        public String role;
  -        public String hint;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to