mcconnell    2003/08/30 12:59:15

  Modified:    merlin/merlin-platform/tutorials/dependencies/auto/src/java/tutorial
                        HelloComponent.java
  Added:       merlin/merlin-platform/tutorials/dependencies/auto/src/java/tutorial
                        Identifiable.java IdentifiableComponent.java
  Log:
  Add example of keyless dependency resolution.
  
  Revision  Changes    Path
  1.2       +5 -0      
avalon-sandbox/merlin/merlin-platform/tutorials/dependencies/auto/src/java/tutorial/HelloComponent.java
  
  Index: HelloComponent.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/merlin-platform/tutorials/dependencies/auto/src/java/tutorial/HelloComponent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HelloComponent.java       28 Aug 2003 17:26:39 -0000      1.1
  +++ HelloComponent.java       30 Aug 2003 19:59:14 -0000      1.2
  @@ -15,6 +15,7 @@
     implements Initializable, Serviceable, Disposable
   {
       RandomGenerator m_random = null;
  +    Identifiable m_identifiable = null;
   
      /**
       * Servicing of the component by the container during 
  @@ -24,17 +25,21 @@
       * @param manager the service manager
       * @avalon.dependency type="tutorial.RandomGenerator:1.0"
       *    key="random"
  +    * @avalon.dependency type="tutorial.Identifiable"
       */
       public void service( ServiceManager manager )
         throws ServiceException
       {
           m_random = (RandomGenerator) manager.lookup( "random" );
  +        m_identifiable = 
  +          (Identifiable) manager.lookup( Identifiable.class.getName() );
       }
   
       public void initialize()
       {
           getLogger().info( "initialization" );
           getLogger().info( "received random value: " + m_random.getRandom() );
  +        getLogger().info( "using identifiable: " + m_identifiable.getIdentity() );
       }
   
       public void dispose()
  
  
  
  1.1                  
avalon-sandbox/merlin/merlin-platform/tutorials/dependencies/auto/src/java/tutorial/Identifiable.java
  
  Index: Identifiable.java
  ===================================================================
  
  package tutorial;
  
  /**
   * A service that provides access to a component identity.
   */
  public interface Identifiable
  {
  
     /**
      * Return a message indicating the component identify.
      * @return the identity
      */
      String getIdentity();
  
  }
  
  
  
  1.1                  
avalon-sandbox/merlin/merlin-platform/tutorials/dependencies/auto/src/java/tutorial/IdentifiableComponent.java
  
  Index: IdentifiableComponent.java
  ===================================================================
  package tutorial;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  
  /**
   * The IdentifiableComponent implements Identifiable.
   *
   * @avalon.component version="1.0" name="simple" lifestyle="singleton"
   * @avalon.service type="tutorial.Identifiable"
   */
  public class IdentifiableComponent extends AbstractLogEnabled 
    implements Identifiable, Contextualizable
  {
  
      private String m_identity = null;
  
     /**
      * Contextualization of the component during which we 
      * establish the component identity.
      *
      * @param context the component context
      * @avalon.entry key="urn:avalon:name"
      * @avalon.entry key="urn:avalon:partition"
      */
      public void contextualize( Context context )
        throws ContextException
      {
          getLogger().info( "contextualize" );
          String name = (String) context.get( "urn:avalon:name" );
          String partition = (String) context.get( "urn:avalon:partition" );
          m_identity = partition + name;
      }
  
      public String getIdentity()
      {
          return m_identity;
      }
  
  }
  
  
  

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

Reply via email to