avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data test1.xconf
Date Tue, 04 Feb 2003 19:39:37 GMT
bloritsch    2003/02/04 11:39:37

  Modified:    fortress/src/java/org/apache/avalon/fortress/impl
                        AbstractContainer.java
               fortress/src/java/org/apache/avalon/fortress/impl/lookup
                        FortressServiceManager.java
               fortress/src/test/org/apache/avalon/fortress/test/data
                        test1.xconf
  Log:
  fix some errors in component lookup contracts that I expected to be there
  
  Revision  Changes    Path
  1.6       +15 -19    jakarta-avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractContainer.java	30 Jan 2003 17:37:12 -0000	1.5
  +++ AbstractContainer.java	4 Feb 2003 19:39:36 -0000	1.6
  @@ -100,9 +100,9 @@
       implements Contextualizable, Serviceable, Initializable, Disposable, Container
   {
       /** The hint map's entry to get the default component type */
  -    protected static final String DEFAULT_ENTRY = "*";
  +    public static final String DEFAULT_ENTRY = "*";
       /** The component map's entry to get a ServiceSelector */
  -    protected static final String SELECTOR_ENTRY = "$";
  +    public static final String SELECTOR_ENTRY = "$";
   
       /** contains the impl's context passed in through contextualize() */
       protected Context m_context;
  @@ -280,29 +280,25 @@
           {
               Map hintMap = (StaticBucketMap)m_mapper.get( role );
   
  -
  -            if( null == hintMap ) // never heard of this role before.
  +            // Initialize the hintMap if it doesn't exist yet.
  +            if( null == hintMap )
               {
                   hintMap = new StaticBucketMap();
                   hintMap.put( DEFAULT_ENTRY, handler );
                   m_mapper.put( role, hintMap );
               }
  -            else // know it already. add something to the hintmap
  +
  +            hintMap.put( metaData.getName(), handler );
  +
  +            if( (! hintMap.containsKey( SELECTOR_ENTRY )) && (hintMap.size() >
1) )
               {
  -                hintMap.put( metaData.getName(), handler );
  +                hintMap.put( SELECTOR_ENTRY,
  +                             new FortressServiceSelector( this, role ) );
  +            }
   
  -                if( hintMap.containsKey( DEFAULT_ENTRY ) )
  -                {
  -                    if( !hintMap.containsKey( SELECTOR_ENTRY ) )
  -                    {
  -                        hintMap.put( SELECTOR_ENTRY,
  -                                     new FortressServiceSelector( this, role ) );
  -                    }
  -                }
  -                else
  -                {
  -                    hintMap.put( DEFAULT_ENTRY, handler );
  -                }
  +            if ( metaData.getConfiguration().getAttributeAsBoolean( "default", false )
)
  +            {
  +                hintMap.put( DEFAULT_ENTRY, handler );
               }
           }
       }
  
  
  
  1.2       +46 -11    jakarta-avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/lookup/FortressServiceManager.java
  
  Index: FortressServiceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/lookup/FortressServiceManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FortressServiceManager.java	27 Jan 2003 16:55:42 -0000	1.1
  +++ FortressServiceManager.java	4 Feb 2003 19:39:36 -0000	1.2
  @@ -58,6 +58,7 @@
   import org.apache.commons.collections.StaticBucketMap;
   import org.apache.avalon.fortress.Container;
   import org.apache.avalon.fortress.impl.handler.ComponentHandler;
  +import org.apache.avalon.fortress.impl.AbstractContainer;
   
   /**
    * This is the Default ServiceManager for the Container.  It provides
  @@ -99,15 +100,17 @@
           m_used = new StaticBucketMap();
       }
   
  -    public Object lookup( final String key )
  +    public Object lookup( final String role )
           throws ServiceException
       {
  -        if( !m_container.has( key, null ) )
  +        Lookup lookup = parseRole(role);
  +
  +        if( !m_container.has( lookup.role, lookup.hint ) )
           {
  -            return m_parent.lookup( key );
  +            return m_parent.lookup( role );
           }
   
  -        final Object result = m_container.get( key, null );
  +        final Object result = m_container.get( lookup.role, lookup.hint );
           if( result instanceof ServiceSelector )
           {
               return result;
  @@ -115,13 +118,13 @@
   
           if( result instanceof ComponentSelector )
           {
  -            return new WrapperServiceSelector( key, (ComponentSelector)result );
  +            return new WrapperServiceSelector( lookup.role, (ComponentSelector)result );
           }
   
           if( !( result instanceof ComponentHandler ) )
           {
               final String message = "Invalid entry in component manager";
  -            throw new ServiceException( key, message );
  +            throw new ServiceException( role, message );
           }
   
           try
  @@ -139,19 +142,21 @@
           {
               final String message =
                   "Could not return a reference to the Component";
  -            throw new ServiceException( key, message, e );
  +            throw new ServiceException( role, message, e );
           }
       }
   
  -    public boolean hasService( final String key )
  +    public boolean hasService( final String role )
       {
  -        if( m_container.has( key, null ) )
  +        Lookup lookup = parseRole( role );
  +
  +        if( m_container.has( lookup.role, lookup.hint ) )
           {
               return true;
           }
           else
           {
  -            return null != m_parent ? m_parent.hasService( key ) : false;
  +            return null != m_parent ? m_parent.hasService( role ) : false;
           }
       }
   
  @@ -181,5 +186,35 @@
           {
               handler.put( component );
           }
  +    }
  +
  +    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.2       +4 -8      jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/test1.xconf
  
  Index: test1.xconf
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/test1.xconf,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test1.xconf	27 Jan 2003 17:04:48 -0000	1.1
  +++ test1.xconf	4 Feb 2003 19:39:37 -0000	1.2
  @@ -1,19 +1,15 @@
   <test>
  -    <component id="component1"
  -        class="org.apache.avalon.fortress.test.data.Component1"
  +    <component1 id="component1"
           logger="component1"
           activation="startup"/>
  -    <component id="component2"
  -        class="org.apache.avalon.fortress.test.data.Component2"
  +    <component2 id="component2"
           logger="component2"
           pool-min="2"
           activation="startup"/>
  -    <component id="component3"
  -        class="org.apache.avalon.fortress.test.data.Component3"
  +    <component3 id="component3"
           logger="component3"
           activation="startup"/>
  -    <component id="component4"
  -        class="org.apache.avalon.fortress.test.data.Component4"
  +    <component4 id="component4"
           logger="component4"
           activation="startup"/>
   </test>
  
  
  

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


Mime
View raw message