You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/11/07 06:00:17 UTC

cvs commit: jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl WrapperComponentManager.java SourceResolverImpl.java

donaldp     2002/11/06 21:00:17

  Modified:    sourceresolve/src/java/org/apache/excalibur/source/impl
                        SourceResolverImpl.java
  Added:       sourceresolve/src/java/org/apache/excalibur/source/impl
                        WrapperComponentManager.java
  Log:
  Move to Serviceable while still supporting Composable Resolvers.
  
  Revision  Changes    Path
  1.12      +32 -40    jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java
  
  Index: SourceResolverImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SourceResolverImpl.java	9 Aug 2002 05:30:02 -0000	1.11
  +++ SourceResolverImpl.java	7 Nov 2002 05:00:17 -0000	1.12
  @@ -13,18 +13,18 @@
   import java.net.URL;
   import java.util.Map;
   import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.ComponentSelector;
  -import org.apache.avalon.framework.component.Composable;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.ServiceSelector;
  +import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.excalibur.source.Recyclable;
   import org.apache.excalibur.source.Source;
  @@ -58,18 +58,18 @@
    */
   public class SourceResolverImpl
       extends AbstractLogEnabled
  -    implements Composable,
  +    implements Serviceable,
       Contextualizable,
       Disposable,
       Parameterizable,
       SourceResolver,
       ThreadSafe
   {
  -    /** The component manager */
  -    protected ComponentManager m_manager;
  +    /** The component m_manager */
  +    protected ServiceManager m_manager;
   
       /** The special Source factories */
  -    protected ComponentSelector m_factorySelector;
  +    protected ServiceSelector m_factorySelector;
   
       /** The context */
       protected Context m_context;
  @@ -121,12 +121,14 @@
       /**
        * Set the current <code>ComponentLocator</code> instance used by this
        * <code>Composable</code>.
  +     *
  +     * @avalon.service interface="org.apache.excalibur.source.SourceFactorySelector"
        */
  -    public void compose( ComponentManager manager )
  -        throws ComponentException
  +    public void service( final ServiceManager manager )
  +        throws ServiceException
       {
           m_manager = manager;
  -        m_factorySelector = (ComponentSelector)m_manager.lookup( SourceFactory.ROLE + "Selector" );
  +        m_factorySelector = (ServiceSelector)m_manager.lookup( SourceFactory.ROLE + "Selector" );
       }
   
       public void dispose()
  @@ -254,7 +256,7 @@
           if( protocolPos != -1 )
           {
               final String protocol = systemID.substring( 0, protocolPos );
  -            if( m_factorySelector.hasComponent( protocol ) )
  +            if( m_factorySelector.isSelectable( protocol ) )
               {
                   SourceFactory factory = null;
                   try
  @@ -262,7 +264,7 @@
                       factory = (SourceFactory)m_factorySelector.select( protocol );
                       source = factory.getSource( systemID, parameters );
                   }
  -                catch( ComponentException ce )
  +                catch( final ServiceException ce )
                   {
                       throw new SourceException( "ComponentException.", ce );
                   }
  @@ -320,32 +322,25 @@
                   }
               }
           }
  -        if( source instanceof LogEnabled )
  +        ContainerUtil.enableLogging( source, getLogger() );
  +
  +        try
           {
  -            ( (LogEnabled)source ).enableLogging( getLogger() );
  +            ContainerUtil.contextualize( source, m_context );
           }
  -        if( source instanceof Contextualizable )
  +        catch( ContextException ce )
           {
  -            try
  -            {
  -                ( (Contextualizable)source ).contextualize( m_context );
  -            }
  -            catch( ContextException ce )
  -            {
  -                throw new SourceException( "ContextException occured during source resolving.", ce );
  -            }
  +            throw new SourceException( "ContextException occured during source resolving.", ce );
           }
   
  -        if( source instanceof Composable )
  +        try
           {
  -            try
  -            {
  -                ( (Composable)source ).compose( m_manager );
  -            }
  -            catch( ComponentException ce )
  -            {
  -                throw new SourceException( "ComponentException occured during source resolving.", ce );
  -            }
  +            ContainerUtil.compose( source, new WrapperComponentManager( m_manager ) );
  +            ContainerUtil.service( source, m_manager );
  +        }
  +        catch( Exception ce )
  +        {
  +            throw new SourceException( "ComponentException occured during source resolving.", ce );
           }
           return source;
       }
  @@ -353,16 +348,13 @@
       /**
        * Releases a resolved resource
        */
  -    public void release( Source source )
  +    public void release( final Source source )
       {
           if( source == null ) return;
           if( source instanceof Recyclable )
           {
               ( (Recyclable)source ).recycle();
           }
  -        if( source instanceof Disposable )
  -        {
  -            ( (Disposable)source ).dispose();
  -        }
  +        ContainerUtil.dispose(source );
       }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/WrapperComponentManager.java
  
  Index: WrapperComponentManager.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.excalibur.source.impl;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  
  /**
   * An adapting class for ComponentManager.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/07 05:00:17 $
   */
  class WrapperComponentManager implements ComponentManager
  {
      private final ServiceManager m_manager;
  
      public WrapperComponentManager( final ServiceManager manager )
      {
          m_manager = manager;
      }
  
      public Component lookup( String role )
          throws ComponentException
      {
          try
          {
              final Object object = m_manager.lookup( role );
              if( object instanceof Component )
              {
                  return (Component)object;
              }
          }
          catch( ServiceException e )
          {
              throw new ComponentException( e.getRole(), e.getMessage(), e.getCause() );
          }
  
          final String message = "Role does not implement the Component " +
              "interface and can not be accessed via ComponentManager";
          throw new ComponentException( role, message );
      }
  
      public boolean hasComponent( final String role )
      {
          return m_manager.hasService( role );
      }
  
      public void release( final Component component )
      {
          m_manager.release( component );
      }
  }
  
  
  

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