You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/08/28 05:28:54 UTC

cvs commit: jakarta-avalon-excalibur/container/src/java/org/apache/excalibur/container/legacy LegacyComponentManager.java LegacyComponentSelector.java

bloritsch    2002/08/27 20:28:54

  Modified:    container/src/java/org/apache/excalibur/container/legacy
                        LegacyComponentManager.java
                        LegacyComponentSelector.java
  Log:
  Update the Javadocs to make sense, and ensure the componentmanager obeyed the naming semantics
  
  Revision  Changes    Path
  1.3       +54 -15    jakarta-avalon-excalibur/container/src/java/org/apache/excalibur/container/legacy/LegacyComponentManager.java
  
  Index: LegacyComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/container/src/java/org/apache/excalibur/container/legacy/LegacyComponentManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LegacyComponentManager.java	27 Aug 2002 21:04:52 -0000	1.2
  +++ LegacyComponentManager.java	28 Aug 2002 03:28:54 -0000	1.3
  @@ -13,7 +13,30 @@
   import java.util.HashMap;
   
   /**
  - * Create a Component proxy.  Requires JDK 1.3+
  + * The <code>LegacyComponentManager</code> is a convenient wrapper to any
  + * <code>ServiceManager</code>.  It uses the {@link ComponentProxyGenerator}
  + * to ensure that all services available to the <code>ServiceManager</code>
  + * are available to the component requiring the <code>ComponentManager</code>.
  + *
  + * <p>
  + *  IMPORTANT: In order for this to work, the services have to be bound by
  + *  the legacy naming scheme outlined in the
  + *  <a href="http://jakarta.apache.org/avalon/developing/index.html">Developing
  + *  with Avalon</a> whitepaper.  The reason is that it uses the role name as
  + *  the fully qualified name of the component's work interface.  There is
  + *  nothing else that this simple wrapper class can do without intimate
  + *  knowledge of your Container's internals.  As a review, the naming
  + *  convention is listed below:
  + * </p>
  + *
  + * <ul>
  + *  <li>The role name is the Fully Qualified Class Name (FQCN) of the component's
  + *      work interface.</li>
  + *  <li>If we are expecting a <code>ComponentSelector</code>, the phrase
  + *      "Selector" is added to the end of the FQCN</li>
  + *  <li>Another alternative is to append a "/" and the purpose of the component
  + *      such as "org.apache.example.Processor/food" for a "food" Processor.</li>
  + * </ul>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    */
  @@ -24,8 +47,9 @@
       private final HashMap                 m_map;
   
       /**
  -     * Initialize the ComponentProxyGenerator with the default classloader.
  -     * The default classloader is the Thread context classloader.
  +     * Initialize the LegacyComponentManager with the ServiceManager
  +     * being wrapped.  We will automatically create a new
  +     * ComponentProxyGenerator with the default constructor.
        */
       public LegacyComponentManager(final ServiceManager manager)
       {
  @@ -33,9 +57,8 @@
       }
   
       /**
  -     * Initialize the ComponentProxyGenerator with the supplied classloader.
  -     * If the supplied class loader is null, we use the Thread context class
  -     * loader.  If that is null, we use this class's classloader.
  +     * Initialize the LegacyComponentManager with the ServiceManager
  +     * being wrapped and the specified ComponentProxyGenerator.
        */
       public LegacyComponentManager( final ComponentProxyGenerator generator,
                                       final ServiceManager manager )
  @@ -55,16 +78,35 @@
           m_map = new HashMap();
       }
   
  +    /**
  +     * Checks to see if we have a component by a role name
  +     */
       public boolean hasComponent( String role )
       {
           return m_manager.hasService( role );
       }
   
  -    public Component lookup( String role )
  +    /**
  +     * Find a component by a role name.
  +     */
  +    public Component lookup( final String role )
           throws ComponentException
       {
           Component component = null;
           Object service = null;
  +        String interfaceName = role;
  +
  +        if ( interfaceName.endsWith("Selector") )
  +        {
  +            interfaceName.subSequence( 0, interfaceName.length() -
  +                                         "Selector".length() );
  +        }
  +
  +        int index = interfaceName.indexOf("/");
  +        if ( index > 0 )
  +        {
  +            interfaceName.substring( 0, index );
  +        }
   
           try
           {
  @@ -72,18 +114,12 @@
   
               if ( service instanceof ServiceSelector )
               {
  -                String roleName = role;
  -                if ( roleName.endsWith("Selector") )
  -                {
  -                    roleName.substring(0, "Selector".length());
  -                }
  -
                   component =
  -                    new LegacyComponentSelector( roleName, m_proxyGen, (ServiceSelector)service );
  +                    new LegacyComponentSelector( interfaceName, m_proxyGen, (ServiceSelector)service );
               }
               else
               {
  -                component = m_proxyGen.getProxy( role, service );
  +                component = m_proxyGen.getProxy( interfaceName, service );
               }
           }
           catch (ComponentException ce)
  @@ -103,6 +139,9 @@
           return component;
       }
   
  +    /**
  +     * Release a used component
  +     */
       public void release( Component component )
       {
           Object service = null;
  
  
  
  1.2       +22 -9     jakarta-avalon-excalibur/container/src/java/org/apache/excalibur/container/legacy/LegacyComponentSelector.java
  
  Index: LegacyComponentSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/container/src/java/org/apache/excalibur/container/legacy/LegacyComponentSelector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LegacyComponentSelector.java	27 Aug 2002 21:04:52 -0000	1.1
  +++ LegacyComponentSelector.java	28 Aug 2002 03:28:54 -0000	1.2
  @@ -12,8 +12,12 @@
   import org.apache.avalon.framework.service.*;
   import java.util.HashMap;
   
  +
   /**
  - * Create a Component proxy.  Requires JDK 1.3+
  + * The <code>LegacyComponentSelector</code> is a convenient wrapper to any
  + * <code>ServiceSelector</code>.  It uses the {@link ComponentProxyGenerator}
  + * to ensure that all services available to the <code>ServiceSelector</code>
  + * are available to the component requiring the <code>ComponentSelector</code>.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    */
  @@ -25,22 +29,22 @@
       private final HashMap                 m_map;
   
       /**
  -     * Initialize the ComponentProxyGenerator with the default classloader.
  -     * The default classloader is the Thread context classloader.
  +     * Initialize the LegacyComponentSelector with the ServiceSelector
  +     * being wrapped and the interface name.  We will automatically create a new
  +     * ComponentProxyGenerator with the default constructor.
        */
  -    public LegacyComponentSelector(final String role, final ServiceSelector selector)
  +    public LegacyComponentSelector( final String role, final ServiceSelector selector )
       {
           this( role, new ComponentProxyGenerator(), selector );
       }
   
       /**
  -     * Initialize the ComponentProxyGenerator with the supplied classloader.
  -     * If the supplied class loader is null, we use the Thread context class
  -     * loader.  If that is null, we use this class's classloader.
  +     * Initialize the LegacyComponentManager with the ServiceManager
  +     * being wrapped, the interface name and the specified ComponentProxyGenerator.
        */
       public LegacyComponentSelector( final String role,
  -                                   final ComponentProxyGenerator generator,
  -                                   final ServiceSelector selector )
  +                                    final ComponentProxyGenerator generator,
  +                                    final ServiceSelector selector )
       {
           if ( null == role )
           {
  @@ -63,11 +67,17 @@
           m_map = new HashMap();
       }
   
  +    /**
  +     * Determine if the component exists for the hint
  +     */
       public boolean hasComponent( Object hint )
       {
           return m_selector.isSelectable( hint );
       }
   
  +    /**
  +     * Choose the component by hint
  +     */
       public Component select( Object hint )
           throws ComponentException
       {
  @@ -96,6 +106,9 @@
           return component;
       }
   
  +    /**
  +     * Release the component
  +     */
       public void release( Component component )
       {
           Object service = null;
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>