donaldp     2002/06/20 19:58:20

  Modified:    container/src/conf ant-services.xml
  Added:       container/src/java/org/apache/myrmidon/components/service
                        DefaultAntServiceKernel.java
               container/src/java/org/apache/myrmidon/interfaces/service
                        AntServiceKernel.java
  Log:
  Introduce a basic service to cache instances of services
  
  Revision  Changes    Path
  1.2       +3 -0      jakarta-ant-myrmidon/container/src/conf/ant-services.xml
  
  Index: ant-services.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/conf/ant-services.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ant-services.xml  16 Jun 2002 04:15:26 -0000      1.1
  +++ ant-services.xml  21 Jun 2002 02:58:20 -0000      1.2
  @@ -44,4 +44,7 @@
       <service 
classname="org.apache.myrmidon.components.builder.MasterProjectBuilder">
           <role name="org.apache.myrmidon.interfaces.builder.ProjectBuilder"/>
       </service>
  +    <service 
classname="org.apache.myrmidon.components.service.DefaultAntServiceKernel">
  +        <role 
name="org.apache.myrmidon.interfaces.service.AntServiceKernel"/>
  +    </service>
   </services>
  
  
  
  1.1                  
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/service/DefaultAntServiceKernel.java
  
  Index: DefaultAntServiceKernel.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.txt file.
   */
  package org.apache.myrmidon.components.service;
  
  import java.util.HashMap;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.myrmidon.interfaces.service.AntServiceKernel;
  
  /**
   * Implementation of [EMAIL PROTECTED] AntServiceKernel} service.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/21 02:58:20 $
   */
  public class DefaultAntServiceKernel
      implements AntServiceKernel
  {
      private final HashMap m_objects = new HashMap();
      private final AntServiceKernel m_parent;
  
      public DefaultAntServiceKernel()
      {
          this( null );
      }
  
      public DefaultAntServiceKernel( final AntServiceKernel parent )
      {
          m_parent = parent;
      }
  
      /**
       * Registers a service.  All lifecycle management is handled by the 
caller.
       */
      public void registerService( String[] roles, Object service )
          throws ServiceException
      {
          for( int i = 0; i < roles.length; i++ )
          {
              final String role = roles[ i ];
              registerService( role, service );
          }
      }
  
      /**
       * Registers a service.  All lifecycle management is handled by the 
caller.
       */
      public void registerService( String role, Object service )
          throws ServiceException
      {
          m_objects.put( role, service );
      }
  
      public Object getService( String role )
          throws ServiceException
      {
          Object service = m_objects.get( role );
          if( null != service )
          {
              return service;
          }
          else if( null != m_parent )
          {
              return m_parent.getService( role );
          }
          else
          {
              return null;
          }
      }
  
      public AntServiceKernel createChild()
      {
          return new DefaultAntServiceKernel( this );
      }
  }
  
  
  
  1.1                  
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/service/AntServiceKernel.java
  
  Index: AntServiceKernel.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.txt file.
   */
  package org.apache.myrmidon.interfaces.service;
  
  import org.apache.avalon.framework.service.ServiceException;
  
  /**
   * The service interface via which services are registered
   * and provided to runtime.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/21 02:58:20 $
   */
  public interface AntServiceKernel
  {
      /** Role name for this interface. */
      String ROLE = AntServiceKernel.class.getName();
  
      /**
       * Registers a service.  All lifecycle management is handled by the 
caller.
       */
      void registerService( String[] roles, Object service )
          throws ServiceException;
  
      /**
       * Registers a service.  All lifecycle management is handled by the 
caller.
       */
      void registerService( String role, Object service )
          throws ServiceException;
  
      Object getService( String role )
          throws ServiceException;
  
      AntServiceKernel createChild();
  }
  
  
  

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

Reply via email to