mcconnell    2003/02/03 21:42:34

  Modified:    assembly .cvsignore build.xml
               assembly/src/java/org/apache/avalon/assembly/appliance
                        DefaultAppliance.java DefaultApplianceFactory.java
               assembly/src/java/org/apache/avalon/assembly/engine
                        DefaultRepositoryManager.java Engine.java
                        EngineClassLoader.java
               assembly/src/java/org/apache/avalon/assembly/logging
                        LoggingManager.java
               assembly/src/test/org/apache/avalon/assembly/engine
                        EngineTestCase.java
  Added:       assembly/src/java/org/apache/avalon/assembly/appliance
                        ApplianceRepository.java
                        ApplianceURLConnection.java
                        DefaultApplianceRepository.java Handler.java
               assembly/src/test/org/apache/avalon/assembly/engine
                        ApplianceTestCase.java
               assembly/src/test/org/apache/avalon/assembly/engine/profile
                        ProfileManagerTestCase.java
               assembly/src/test/org/apache/avalon/assembly/engine/service
                        DefaultServiceRepositoryTestCase.java
               assembly/src/test/org/apache/avalon/assembly/engine/type
                        TypeManagerTestCase.java
  Removed:     assembly/src/java/org/apache/avalon/assembly/appliance
                        ApplianceManager.java DefaultApplianceManager.java
               assembly/src/test/org/apache/avalon/assembly/profile
                        ProfileManagerTestCase.java
               assembly/src/test/org/apache/avalon/assembly/service
                        DefaultServiceRepositoryTestCase.java
               assembly/src/test/org/apache/avalon/assembly/type
                        TypeManagerTestCase.java
  Log:
  Correcting some package name errors in the test case, introduction of an improved 
appliance url handling scheme, anf renaming og appliace manager to appliance 
repository.
  
  Revision  Changes    Path
  1.2       +4 -0      avalon-sandbox/assembly/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/.cvsignore,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- .cvsignore        24 Nov 2002 12:50:44 -0000      1.1
  +++ .cvsignore        4 Feb 2003 05:42:32 -0000       1.2
  @@ -5,3 +5,7 @@
   kernel.log
   extensions
   distributions
  +maven.log
  +project.xml
  +project.properties
  +
  
  
  
  1.15      +3 -13     avalon-sandbox/assembly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/build.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- build.xml 29 Jan 2003 17:49:36 -0000      1.14
  +++ build.xml 4 Feb 2003 05:42:32 -0000       1.15
  @@ -444,19 +444,9 @@
   
     <target name="patch">
       <replace dir="src" summary="true"
  -       token="org.apache.avalon.assembly.profile"
  -       value="org.apache.avalon.assembly.engine.profile" >
  -     <include name="**/*.*"/>
  -    </replace>
  -    <replace dir="src" summary="true"
  -       token="org.apache.avalon.assembly.type"
  -       value="org.apache.avalon.assembly.engine.type" >
  -     <include name="**/*.*"/>
  -    </replace>
  -    <replace dir="src" summary="true"
  -       token="org.apache.avalon.assembly.service"
  -       value="org.apache.avalon.assembly.engine.service" >
  -     <include name="**/*.*"/>
  +       token="assembly:appliance.manager"
  +       value="assembly:appliance.repository" >
  +     <include name="**/*.java"/>
       </replace>
     </target>
   
  
  
  
  1.30      +21 -14    
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java
  
  Index: DefaultAppliance.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- DefaultAppliance.java     29 Jan 2003 13:50:39 -0000      1.29
  +++ DefaultAppliance.java     4 Feb 2003 05:42:32 -0000       1.30
  @@ -254,6 +254,11 @@
       */ 
       private boolean m_disassembled = false;
   
  +   /**
  +    * The appliance manager.
  +    */ 
  +    private ApplianceRepository m_repository;
  +
       //=====================================================================
       // Contextualizable
       //=====================================================================
  @@ -269,6 +274,7 @@
           m_lifestyle = (LifestyleService) context.get( 
"urn:assembly:lifestyle.service" );
           m_applianceContext = (ApplianceContext) context.get( 
"urn:assembly:appliance.context" );
           m_system = (Locator) context.get( "urn:assembly:appliance.system" );
  +        m_repository = (ApplianceRepository) context.get( 
"urn:assembly:appliance.repository" );
       }
   
       //=====================================================================
  @@ -320,6 +326,20 @@
                 "Unexpected lifestyle handler establishment failure in appliance: " + 
this;
               throw new ApplianceException( error, e );
           }
  +
  +        try
  +        {
  +            getLogger().debug( "creating appliance URL from base repository: " + 
m_repository.getURL() + 
  +              " for name: " + m_name );
  +            m_url = new URL( m_repository.getURL(), m_name );
  +            getLogger().debug( "created URL: " + m_url );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Unexpected lifestyle handler establishment failure in appliance: " + 
this;
  +            throw new ApplianceException( error, e );
  +        }
       }
   
       //=====================================================================
  @@ -390,19 +410,6 @@
       */
       public URL getURL()
       {
  -        if( m_url == null )
  -        {
  -            try
  -            {
  -                m_url = new URL( PROTOCOL, m_domain, -1, getPath() );
  -            }
  -            catch( Throwable e )
  -            {
  -                final String error = 
  -                  "Protocol handler for protocol '" + PROTOCOL + "' has not been 
established.";
  -                throw new IllegalStateException( error );
  -            }
  -        }
           return m_url;
       }
   
  
  
  
  1.7       +44 -51    
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceFactory.java
  
  Index: DefaultApplianceFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultApplianceFactory.java      27 Jan 2003 07:11:56 -0000      1.6
  +++ DefaultApplianceFactory.java      4 Feb 2003 05:42:32 -0000       1.7
  @@ -60,6 +60,7 @@
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.assembly.lifestyle.LifestyleException;
  @@ -102,14 +103,14 @@
   {
   
       public static ApplianceFactory createApplianceFactory( 
  -       ClassLoader loader, Logger logger, Locator system ) 
  +       ClassLoader loader, Logger logger, ApplianceRepository repository, Locator 
system ) 
          throws ApplianceException
       {
  -        return createApplianceFactory( loader, 
DefaultApplianceFactory.class.getName(), logger, system );
  +        return createApplianceFactory( loader, 
DefaultApplianceFactory.class.getName(), logger, repository, system );
       }
   
       public static ApplianceFactory createApplianceFactory( 
  -      ClassLoader loader, String classname, Logger logger, Locator system ) 
  +      ClassLoader loader, String classname, Logger logger, ApplianceRepository 
repository, Locator system ) 
         throws ApplianceException
       {
           if( classname == null )
  @@ -131,15 +132,28 @@
           {
               throw new NullPointerException( "system" );
           }
  +
  +        if( repository == null )
  +        {
  +            throw new NullPointerException( "repository" );
  +        }
  +
           Class clazz;
           try
           {
  -            clazz = loader.loadClass( classname );
  +            if( classname.equals( DefaultApplianceFactory.class.getName() ) )
  +            {
  +                clazz = DefaultApplianceFactory.class;
  +            }
  +            else
  +            {
  +                clazz = loader.loadClass( classname );
  +            }
           }
           catch( ClassNotFoundException cnfe )
           {
               throw new ApplianceException(
  -                "Could not find appliance class " + classname );
  +                "Could not find appliance factory class " + classname, cnfe );
           }
   
           ApplianceFactory factory;
  @@ -152,7 +166,9 @@
               }
               if( factory instanceof Contextualizable )
               {
  -                ((Contextualizable)factory).contextualize( system );
  +                DefaultLocator context = new DefaultLocator( system  );
  +                context.put( "urn:assembly:appliance.repository", repository );
  +                ((Contextualizable)factory).contextualize( context );
               }
               if( factory instanceof Initializable )
               {
  @@ -168,14 +184,28 @@
           }
       }
   
  +    //---------------------------------------------------------------------------
  +    // state
  +    //---------------------------------------------------------------------------
   
       private Context m_system;
   
  -    public void contextualize( Locator system )
  +    private ApplianceRepository m_repository;
  +
  +    //---------------------------------------------------------------------------
  +    // contextualization
  +    //---------------------------------------------------------------------------
  +
  +    public void contextualize( Locator context ) throws ContextException
       {
  -        m_system = system;
  +        m_system = context;
  +        m_repository = (ApplianceRepository) context.get( 
"urn:assembly:appliance.repository" );
       }
   
  +    //---------------------------------------------------------------------------
  +    // initialization
  +    //---------------------------------------------------------------------------
  +
       public void initialize() throws Exception
       {
           if( m_system == null )
  @@ -184,6 +214,10 @@
           }
       }
   
  +    //---------------------------------------------------------------------------
  +    // implementation
  +    //---------------------------------------------------------------------------
  +
      /**
       * Create a new appliance.
       * @param context the appliance creation context
  @@ -211,7 +245,6 @@
   
           appliance.enableLogging( logger );
   
  -
           try
           {
               PoolManager pool = (PoolManager) system.get( 
"urn:assembly:threads.manager" );
  @@ -220,6 +253,7 @@
               locator.put( "urn:assembly:lifestyle.service", createLifestyleService( 
engine, pool ) );
               locator.put( "urn:assembly:appliance.context", context );
               locator.put( "urn:assembly:appliance.system", system );
  +            locator.put( "urn:assembly:appliance.repository", m_repository );
               locator.makeReadOnly();
               appliance.contextualize( locator );
               appliance.initialize();
  @@ -304,45 +338,4 @@
           }
       }
   
  -/*
  -    private PoolManager getPoolManager( ) throws ApplianceException
  -    {
  -        try
  -        {
  -            //
  -            // Set up the ThreadManager that the CommandManager uses
  -            //
  -
  -            TPCThreadManager threadManager = new TPCThreadManager();
  -            threadManager.enableLogging( getLogger().getChildLogger( "threads" ) );
  -            Parameters params = new Parameters();
  -            params.setParameter( "threads-per-processor", "2" );
  -            params.setParameter( "sleep-time", "1000" );
  -            params.setParameter( "block-timeout", "250" );
  -            threadManager.parameterize( params );
  -            threadManager.initialize();
  -
  -            //
  -            // Set up the CommandManager that the PoolManager uses.
  -            //
  -
  -            CommandManager commandManager = new CommandManager();
  -            threadManager.register( commandManager );
  -
  -            //
  -            // Set up the PoolManager that the pooled lifecycle helper needs
  -            //
  -
  -            DefaultPoolManager poolManager = 
  -              new DefaultPoolManager( commandManager.getCommandSink() );
  -            return poolManager;
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = 
  -              "Internal error during establishment of the default pool manager.";
  -            throw new ApplianceException( error, e );
  -        }
  -    }
  -*/
   }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/ApplianceRepository.java
  
  Index: ApplianceRepository.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.assembly.appliance;
  
  import java.util.Map;
  import java.net.URL;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.meta.info.DependencyDescriptor;
  import org.apache.avalon.meta.info.StageDescriptor;
  import org.apache.avalon.meta.model.Profile;
  import org.apache.avalon.assembly.logging.LoggingManager;
  
  /**
   * An appliance manager implemetation provides support for the 
   * creation and retrival of appliance instances.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/02/04 05:42:32 $
   */
  public interface ApplianceRepository 
  {
     /**
      * Return the base URL for the repository.
      * @return the manager URL
      */
      URL getURL();
  
      /**
       * Add a appliance to the manager.
       * @param appliance the appliance to add to the manager
       * @exception DuplicateApplianceException if an appliance has already been 
registered
       *   for the underlying profile
       */
      void addAppliance( Appliance appliance ) throws DuplicateApplianceException, 
NullPointerException;
  
     /**
      * Return the set of appliance istances capable of supporting the supplied 
dependency.
      * @param dependency a service dependency descriptor
      * @return a matching appliance
      */
      Appliance[] getAppliances( DependencyDescriptor dependency );
  
     /**
      * Return the set of appliance instances that provide the supplied extension.
      * @param stage a stage descriptor
      * @return a set of candidate appliances
      */
      Appliance[] getAppliances( StageDescriptor stage );
  
     /**
      * Select an appliance supporting the supplied dependency using a supplied 
selector.
      * @param dependency a service depedency descriptor
      * @param selector the appliance selector
      * @return the selected appliance (possibly null)
      */
      Appliance getAppliance( DependencyDescriptor dependency, ApplianceSelector 
selector );
  
     /**
      * Select an appliance capable of supporting the supplied stage 
      * @param stage a lifecycle stage
      * @param selector an appliance selector
      * @return the selected appliance (possibly null)
      */
      Appliance getAppliance( StageDescriptor stage, ApplianceSelector selector );
  
     /**
      * Select an appliance supporting the supplied dependency using a default 
selector.
      * @param dependency a service depedency descriptor
      * @return the selected appliance (possibly null)
      */
      Appliance getAppliance( DependencyDescriptor dependency );
  
     /**
      * Select an appliance capable of supporting the supplied stage 
      * @param stage a lifecycle stage
      * @return the selected appliance (possibly null)
      */
      Appliance getAppliance( StageDescriptor stage );
  
  }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/ApplianceURLConnection.java
  
  Index: ApplianceURLConnection.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.assembly.appliance;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLConnection;
  
  /**
   * URL connection handler for the service protocol. New instances of
   * the <code>ServiceURLConnection</code> are created by a service
   * URL <code>Handler</code> class.
   * @see Handler
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   */
  public class ApplianceURLConnection extends URLConnection
  {
  
      /**
       * The appliance repository from which the appliance instance is resolved.
       */
      private ApplianceRepository m_repository;
  
      /**
       * The URL passed in during the creation of the URL Connection by the protocol 
handler.
       */
      private URL m_url;
  
      /**
       * Creation of a new <code>ApplianceURLConnection</code> handler.
       * @param url the base URL
       * @param registry the parent registry
       */
      public ApplianceURLConnection( URL url, ApplianceRepository repository )
      {
          super( url );
          m_repository = repository;
          m_url = url;
      }
  
      /**
       * Establishment of a connection to the object defined by the URL.
       *
       * @exception IOException if an error is raised while attempting to
       *  establish the connection.
       */
      public void connect() throws IOException
      {
          // nothing to do
      }
  
      /**
       * Returns the object referenced by the URL.
       * @return and appliance instance
       * @exception IOException if an error occurs while attempting to retireve
       *   the object reference.
       */
      public Object getContent() throws IOException
      {
          System.out.println( "CONNECTION: " + m_url + " from repository: " + 
m_repository.getURL() );
          return m_url;
      }
  
      /**
       * Retrieves the contents of this URL connection.
       *
       * @param classes the <code>Class</code> array
       * indicating the requested types
       * @return     the object fetched that is the first match of the type
       *               specified in the classes array. null if none of
       *               the requested types are supported.
       *               The <code>instanceOf</code> operation should be used to
       *               determine the specific kind of object returned.
       * @exception  IOException              if an I/O error occurs while
       *               getting the content.
       */
      public Object getContent( Class[] classes ) throws IOException
      {
          System.out.println( "CONNECTION[]: " + m_url + " from repository: " + 
m_repository.getURL() );
          return m_url;
      }
  }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceRepository.java
  
  Index: DefaultApplianceRepository.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.assembly.appliance;
  
  import java.util.Map;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.ArrayList;
  import java.net.URL;
  
  import org.apache.avalon.assembly.lifestyle.LifestyleService;
  import org.apache.avalon.assembly.lifestyle.DefaultLifestyleService;
  import org.apache.avalon.assembly.logging.DefaultLoggingManager;
  import org.apache.avalon.assembly.logging.LoggingManager;
  import org.apache.avalon.assembly.engine.Engine;
  import org.apache.avalon.framework.Version;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.DefaultServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.meta.info.DependencyDescriptor;
  import org.apache.avalon.meta.info.StageDescriptor;
  import org.apache.avalon.meta.info.ReferenceDescriptor;
  import org.apache.avalon.meta.model.Profile;
  import org.apache.avalon.meta.info.InfoDescriptor;
  
  /**
   * The default appliance manager provides support for {@link Appliance}
   * registration and retrival.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/02/04 05:42:32 $
   */
  public final class DefaultApplianceRepository 
    implements ApplianceRepository
  {
  
      //==================================================================
      // state
      //==================================================================
  
     /**
      * The parent appliance manager.
      */
      private ApplianceRepository m_parent;
  
      /**
       * Table of registered appliance instances keyed by profile name.
       */
      private final ArrayList m_appliances = new ArrayList();
          
     /**
      * The engine.
      */
      private Engine m_engine;
  
     /**
      * The name of the manager.
      */
      private String m_name;
  
     /**
      * The full manager path
      */
      private URL m_url;
  
      //==============================================================
      // constructor
      //==============================================================
  
      public DefaultApplianceRepository( Engine engine )
      {
          this( engine, null, null );
      }
  
      public DefaultApplianceRepository( Engine engine, ApplianceRepository parent, 
String name )
      {
          m_parent = parent;
          m_engine = engine;
          m_name = name;
          if( parent == null )
          {
              try
              {
                  m_url = new URL( "appliance", "localhost", -1, "/", new Handler( 
parent ) );
              }
              catch( Throwable e )
              {
                  // should not happen
                  final String error =
                    "Unexpected error while creating a root URL for repository: " + 
name;
                  throw new ApplianceRuntimeException( error, e );
              }
          }
          else
          {
  
              try
              {
                  if( name.endsWith("/") )
                  {
                      m_url = new URL( parent.getURL(), name );
                  }
                  else
                  {
                      m_url = new URL( parent.getURL(), name + "/" );
                  }
              }
              catch( Throwable e )
              {
                  final String error = 
                    "Unable to construct a valid URL from the base: " 
                      + parent.getURL() + " with the name: " + name;
                  throw new ApplianceRuntimeException( error, e );
              }
          }
      }
  
      //==================================================================
      // ApplianceRepository
      //==================================================================
  
     /**
      * Return the repository URL.
      * @return the URL for the repository.
      */
      public URL getURL()
      {
          return m_url;
      }
  
     /**
      * Return the set of appliance istances capable of supporting the supplied 
dependency.
      * @param dependency a service dependency descriptor
      * @return a matching appliance
      */
      public Appliance[] getAppliances( DependencyDescriptor dependency )
      {
          ArrayList list = new ArrayList();
          if( m_parent != null )
          {
              Appliance[] appliances = m_parent.getAppliances( dependency );
              for( int i=0; i<appliances.length; i++ )
              {
                  list.add( appliances[i] );
              }
          }
  
          ReferenceDescriptor reference = dependency.getReference();
          Iterator iterator = m_appliances.iterator();
          while( iterator.hasNext() )
          {
              Appliance appliance = (Appliance) iterator.next();
              Object service = appliance.getType().getService( reference );
              if( service != null )
              {
                  list.add( appliance );
              }
          }
  
          return (Appliance[]) list.toArray( new Appliance[0] );
      }
  
     /**
      * Return the set of appliance instances that provide the supplied extension.
      * @param stage a stage descriptor
      * @return a set of appliances capable of supporting the supplied stage
      */
      public Appliance[] getAppliances( StageDescriptor stage )
      {
          ArrayList list = new ArrayList();
          if( m_parent != null )
          {
              Appliance[] appliances = m_parent.getAppliances( stage );
              for( int i=0; i<appliances.length; i++ )
              {
                  list.add( appliances[i] );
              }
          }
  
          Iterator iterator = m_appliances.iterator();
          while( iterator.hasNext() )
          {
              Appliance appliance = (Appliance) iterator.next();
              
              if( appliance.isEnabled() 
                && ( appliance.getType().getExtension( stage ) != null ) )
              {
                  list.add( appliance );
              }
          }
  
          return (Appliance[]) list.toArray( new Appliance[0] );
      }
  
     /**
      * Select an appliance supporting the supplied dependency using a supplied 
selector.
      * @param dependency a service depedency descriptor
      * @param selector the applaice selector
      * @return the selected appliance (possibly null)
      */
      public Appliance getAppliance( DependencyDescriptor dependency, 
ApplianceSelector selector )
      {
          Appliance[] appliances = getAppliances( dependency );
          return selector.select( appliances, dependency );
      }
  
     /**
      * Select an appliance capable of supporting the supplied stage 
      * @param stage a lifecycle stage
      * @param selector an appliance selector
      * @return the selected appliance (possibly null)
      */
      public Appliance getAppliance( StageDescriptor stage, ApplianceSelector selector 
)
      {
          Appliance[] appliances = getAppliances( stage );
          return selector.select( appliances, stage );
      }
  
     /**
      * Select an appliance supporting the supplied dependency using a default 
selector.
      * @param dependency a service depedency descriptor
      * @return the selected appliance (possibly null)
      */
      public Appliance getAppliance( DependencyDescriptor dependency )
      {
          return getAppliance( dependency, new DefaultApplianceSelector() );
      }
  
     /**
      * Select an appliance capable of supporting the supplied stage 
      * @param stage a lifecycle stage
      * @return the selected appliance (possibly null)
      */
      public Appliance getAppliance( StageDescriptor stage )
      {
          return getAppliance( stage, new DefaultApplianceSelector() );
      }
  
      /**
       * Add a appliance to the manager.
       * @param appliance the appliance to add to the manager
       * @exception DuplicateApplianceException if an appliance has already been 
registered
       *   for the undrlying profile
       * @exception NullPointerException if the supplied appliance is null.
       */
      public void addAppliance( Appliance appliance ) throws 
DuplicateApplianceException, NullPointerException
      {
          if( appliance == null )
          {
              throw new NullPointerException( "appliance" );
          }
          if( m_appliances.contains( appliance ) )
          {
              throw new DuplicateApplianceException( appliance.toString() );
          }
          m_appliances.add( appliance );
      }
  }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/Handler.java
  
  Index: Handler.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.assembly.appliance;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLConnection;
  import java.net.URLStreamHandler;
  
  /**
   * <p>A URL handler for the appliance protocol.<p>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   */
  public class Handler extends URLStreamHandler
  {
  
      /**
       * The appliance manager.
       */
      private ApplianceRepository m_manager;
  
      private boolean debug = false;
  
      /**
       * Creation of a new handler.
       * @param host the host domain name
       * @param appliance the appliance
       */
      public Handler( ApplianceRepository manager )
      {
          m_manager = manager;
      }
  
      /**
       * Opens a connection to the specified URL.
       *
       * @param url A URL to open a connection to.
       * @return The established connection.
       * @throws IOException If a connection failure occurs.
       */
      protected URLConnection openConnection( final URL url )
          throws IOException
      {
          System.out.println( "HANDLER: opening connection for URL: " + url );
          return new ApplianceURLConnection( url, m_manager );
      }
  
      /**
       * Parses the string representation of a <code>URL</code> into a
       * <code>URL</code> object.
       * e.g. native:/root/myService
       * <p>
       * If there is any inherited context, then it has already been
       * copied into the <code>URL</code> argument.
       *
       * @param   url     the <code>URL</code> to receive the result of parsing
       *                  the spec.
       * @param   spec    the <code>String</code> representing the URL that
       *                  must be parsed.
       * @param   start   the character index at which to begin parsing. This is
       *                  just past the '<code>:</code>' (if there is one) that
       *                  specifies the determination of the protocol name.
       * @param   limit   the character position to stop parsing at. This is the
       *                  end of the string or the position of the
       *                  "<code>#</code>" character, if present. All information
       *                  after the sharp sign indicates an anchor.
       */
      protected void parseURL( URL url, String spec, int start, int limit )
      {
          //
          // get the ref component
          // (from # to the end of the spec)
          //
  
          String ref = url.getRef();
          String remainder = spec.substring( start, limit );
          int refLoc = spec.indexOf( "#", start );
          if( refLoc > -1 )
          {
              ref = spec.substring( refLoc + 1 );
              remainder = spec.substring( start, refLoc );
          }
  
          //
          // get the query component
          // (from ? to the end of the remainder)
          //
  
          String query = url.getQuery();
          int queryLoc = remainder.indexOf( "?" );
          if( queryLoc > -1 )
          {
              query = remainder.substring( queryLoc + 1, remainder.length() );
              remainder = remainder.substring( 0, queryLoc );
          }
  
          //
          // get the path component
          // (from / to the end of the remainder)
          //
  
          String path = url.getPath();
          if( remainder.startsWith( "//" ) )
          {
              remainder = remainder.substring( 2, remainder.length() );
          }
  
          int pathLoc = remainder.indexOf( "/" );
          if( pathLoc > -1 )
          {
              path = remainder.substring( pathLoc, remainder.length() );
              remainder = remainder.substring( 0, pathLoc );
          }
          else
          {
              path = path + remainder;
          }
  
          //
          // set the URL parameters
          //
  
          String user = url.getUserInfo();
  
          String host = url.getHost();
          if( host == null ) 
          {
              host = "localhost";
          }
  
          int port = url.getPort();
          if( port == -1 ) 
          {
              port = getDefaultPort();
          }
  
          //
          // create authority string dependending of non-default port reference
          //
  
          String authority = null;
          if( port == getDefaultPort() )
          {
              authority = host;
          }
          else
          {
              authority = host + ":" + port;
          }
  
          setURL( url, "appliance", host, port, authority, user, path, query, ref );
  
          if( debug )
          {
              System.out.println( "BASE: " + url );
              System.out.println( "HOST: " + host );
              System.out.println( "PORT: " + port );
              System.out.println( "AUTHORITY: " + authority );
              System.out.println( "USER: " + user );
              System.out.println( "PATH: " + path );
              System.out.println( "QUERY: " + query );
              System.out.println( "REF: " + ref );
          }
      }
  
      /**
       * Retuns the default port.
       * @return int the default port value of 0
       */
      protected int getDefaultPort()
      {
          return 0;
      }
  
      /**
       * Returns the URL in a string form.
       * @param url to the URL to externalize
       * @return String the external form of the URL
       */
      protected String toExternalForm( URL url )
      {
          StringBuffer result = new StringBuffer( url.getProtocol() );
          result.append( "://" );
          result.append( url.getHost() );
          if( url.getUserInfo() != null )
          {
              result.append( "@" );
              result.append( url.getUserInfo() );
          }
          if( url.getFile() != null )
          {
              result.append( url.getFile() );
          }
          if( url.getRef() != null )
          {
              result.append( "#" );
              result.append( url.getRef() );
          }
          return result.toString();
      }
  }
  
  
  
  
  1.10      +24 -32    
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/DefaultRepositoryManager.java
  
  Index: DefaultRepositoryManager.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/DefaultRepositoryManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultRepositoryManager.java     15 Jan 2003 09:09:24 -0000      1.9
  +++ DefaultRepositoryManager.java     4 Feb 2003 05:42:33 -0000       1.10
  @@ -158,6 +158,14 @@
           this( classloader, null );
       }
   
  +   /**
  +    * Creation of a new repository manager using a supplied classloader and parent 
  +    * repository.  The repository establishes and manages a type, service,  
  +    * profile repository.
  +    * @param classloader the classloader to be supplied to the type, service and 
  +    *        profile managers created by this repository
  +    * @param parent the parent repository
  +    */
       DefaultRepositoryManager( ClassLoader classloader, RepositoryManager parent )
       {
           if( classloader == null )
  @@ -230,52 +238,36 @@
        */
       public void install( URL url )
       {
  -        if( isDirectory( url ) )
  -        {
  -            return;
  -        }
  -
           if( m_scanned.contains( url ) )
           {
               return;
           }
   
  -        try
  +        if( isDirectory( url ) )
           {
  -            final URL resource = new URL( "jar:" + url.toString() + "!/" );
  -            final JarURLConnection jar = 
(JarURLConnection)resource.openConnection();
  -
  -            /*
  -
  -            //
  -            // commented out the manifest checking bacause Phoenix distributions 
  -            // no longer provide manifest level declaration of that fact that the 
  -            // jar is a componetn container wehich means that we need to scan 
  -            // everything
  -            //
  -
  -            Manifest manifest = jar.getManifest();
  -            if( manifest == null )
  +            if( getLogger().isWarnEnabled() )
               {
  -                m_scanned.add( url );
  -                return;
  +                getLogger().warn("directory scanning not supported: " + url );
               }
  +            return;
  +        }
   
  -            Attributes attributes = manifest.getAttributes( AVALON_BLOCK_KEY );
  -            if( attributes == null )
  -            {
  -                m_scanned.add( url );
  -                return;
  -            }
  -            */
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            getLogger().debug("scanning: " + url );
  +        }
   
  +        try
  +        {
               //
  -            // we are dealing with an Avalon Block so we need to scan the classes
  +            // we are dealing with a jar file so we need to scan the classes
               // for service and type defintions
               //
   
  +            final URL resource = new URL( "jar:" + url.toString() + "!/" );
  +            final JarURLConnection jar = 
(JarURLConnection)resource.openConnection();
  +            final JarFile base = jar.getJarFile();
               m_scanned.add( url );
  -            JarFile base = jar.getJarFile();
               load( base );
           }
           catch( IOException e )
  
  
  
  1.13      +3 -3      
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/Engine.java
  
  Index: Engine.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/Engine.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Engine.java       28 Jan 2003 13:26:55 -0000      1.12
  +++ Engine.java       4 Feb 2003 05:42:33 -0000       1.13
  @@ -84,11 +84,11 @@
   
      /**
       * Dynamic registration of a type and associated profiles with the container.
  -    * @param path the path to the appliance implementation class
  +    * @param classname the class name of the appliance implementation class
       * @return the appliance
       * @exception EngineRuntimeException if a registration error occurs
       */
  -    void register( String path ) throws EngineRuntimeException;
  +    void register( String classname ) throws EngineRuntimeException;
   
      /**
       * Create a new appliance.
  
  
  
  1.31      +28 -15    
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java
  
  Index: EngineClassLoader.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- EngineClassLoader.java    29 Jan 2003 17:49:36 -0000      1.30
  +++ EngineClassLoader.java    4 Feb 2003 05:42:33 -0000       1.31
  @@ -73,9 +73,9 @@
   import org.apache.avalon.assembly.appliance.ApplianceContext;
   import org.apache.avalon.assembly.appliance.DefaultApplianceContext;
   import org.apache.avalon.assembly.appliance.ApplianceException;
  -import org.apache.avalon.assembly.appliance.ApplianceManager;
  +import org.apache.avalon.assembly.appliance.ApplianceRepository;
   import org.apache.avalon.assembly.appliance.DefaultAppliance;
  -import org.apache.avalon.assembly.appliance.DefaultApplianceManager;
  +import org.apache.avalon.assembly.appliance.DefaultApplianceRepository;
   import org.apache.avalon.assembly.appliance.DependencyGraph;
   import org.apache.avalon.assembly.engine.model.LibraryDescriptor;
   import org.apache.avalon.assembly.engine.model.ClasspathDescriptor;
  @@ -171,7 +171,7 @@
       * component type, profile, lifestyle policy and service supporting 
       * component deployment.
       */
  -    private ApplianceManager m_appliances;
  +    private ApplianceRepository m_manager;
   
      /**
       * The repository maanger holds the service, types and profiels associated
  @@ -251,8 +251,7 @@
        */
       public EngineClassLoader()
       {
  -        super( new URL[ 0 ] );
  -        m_parsable = getParentURLs();
  +        this( Thread.currentThread().getContextClassLoader() );
       }
   
       /**
  @@ -369,6 +368,15 @@
               m_logging = (LoggingManager) context.get( key );
           }
   
  +        if( context.hasEntry( "urn:assembly:appliance.repository" ) )
  +        {
  +            m_manager = (ApplianceRepository) context.get( 
"urn:assembly:appliance.repository" );
  +        }
  +        else
  +        {
  +            m_manager = new DefaultApplianceRepository( this );
  +        }
  +
           if( context.hasEntry( "urn:assembly:threads.manager" ) )
           {
               m_pool = (PoolManager) context.get( "urn:assembly:threads.manager" );
  @@ -401,6 +409,11 @@
               throw new IllegalStateException("logger");
           }
   
  +        if( m_manager == null )
  +        {
  +            throw new IllegalStateException("manager");
  +        }
  +
           if( m_logging == null )
           {
               getLoggingManager();
  @@ -413,8 +426,7 @@
   
           m_repository = createRepositoryManager();
           m_factory = DefaultApplianceFactory.createApplianceFactory( 
  -           this, getLogger(), getSystemContext() );
  -        m_appliances = createApplianceManager( m_facilities );
  +           this, getLogger(), m_manager, getSystemContext() );
   
           //
           // install the set of extensions
  @@ -517,7 +529,6 @@
   
               String sep = System.getProperty( "path.separator" );
               String classpath = System.getProperty( "java.class.path" );
  -
               StringTokenizer tokenizer = new StringTokenizer( classpath, sep );
               while( tokenizer.hasMoreTokens() )
               {
  @@ -834,7 +845,7 @@
               getLogger().debug( "resolve: " + dependency );
           }
   
  -        Appliance appliance = m_appliances.getAppliance( dependency );
  +        Appliance appliance = m_manager.getAppliance( dependency );
           if( appliance == null )
           {
               Profile profile = getRepository().getProfileManager().getProfile( 
dependency );
  @@ -894,7 +905,7 @@
           {
               getLogger().debug( REZ.getString( "resolve.stage.notice", stage ) );
           }
  -        Appliance appliance = m_appliances.getAppliance( stage );
  +        Appliance appliance = m_manager.getAppliance( stage );
           if( appliance == null )
           {
               Profile profile = getRepository().getProfileManager().getProfile( stage 
);
  @@ -975,14 +986,14 @@
           {
               factory = 
                 DefaultApplianceFactory.createApplianceFactory( 
  -                this, classname, logger, getSystemContext() );
  +                this, classname, logger, m_manager, getSystemContext() );
           }
   
           Appliance appliance = factory.createAppliance( getSystemContext(), this, 
context, logger );
   
           if( shared )
           {
  -            m_appliances.addAppliance( appliance );
  +            m_manager.addAppliance( appliance );
           }
   
           return appliance;
  @@ -1056,7 +1067,8 @@
           return manager;
       }
   
  -    private ApplianceManager createApplianceManager( Map facilities ) 
  +   /*
  +    private ApplianceRepository createApplianceRepository( Map facilities ) 
         throws Exception
       {
           if( getLogger().isDebugEnabled() )
  @@ -1064,7 +1076,7 @@
               getLogger().debug( "creating appliance manager" );
           }
   
  -        DefaultApplianceManager manager = new DefaultApplianceManager();
  +        DefaultApplianceRepository manager = new DefaultApplianceRepository();
           manager.enableLogging( getLogger() );
           manager.contextualize( new DefaultContext() ); // <-- placeholder for 
parent manager
           DefaultServiceManager services = new DefaultServiceManager();
  @@ -1074,6 +1086,7 @@
           manager.initialize();
           return manager;
       }
  +    */
   
       private Locator getSystemContext()
       {
  
  
  
  1.3       +1 -2      
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/LoggingManager.java
  
  Index: LoggingManager.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/LoggingManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LoggingManager.java       27 Jan 2003 03:18:25 -0000      1.2
  +++ LoggingManager.java       4 Feb 2003 05:42:34 -0000       1.3
  @@ -50,7 +50,6 @@
   
   package org.apache.avalon.assembly.logging;
   
  -import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.meta.model.LoggingDirective;
   import org.apache.avalon.meta.model.Category;
  @@ -59,7 +58,7 @@
    * A <code>LoggerManager</code> that supports the management of a logging hierarchy.
    * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development 
Team</a>
    */
  -public interface LoggingManager extends LoggerManager
  +public interface LoggingManager 
   {
       /**
        * Add a set of category entries using the supplied categories descriptor.
  
  
  
  1.15      +79 -59    
avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/EngineTestCase.java
  
  Index: EngineTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/EngineTestCase.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- EngineTestCase.java       27 Jan 2003 07:11:56 -0000      1.14
  +++ EngineTestCase.java       4 Feb 2003 05:42:34 -0000       1.15
  @@ -54,72 +54,29 @@
       protected void setUp() throws Exception
       {
           super.setUp();
  -        setUpEngine( true );
  -    }
  +        m_engine = setUpEngine( true );
   
  -    protected void setUpEngine( boolean bootstrap ) throws Exception
  -    {
  -        try
  -        {
  -            EngineClassLoader engine = new EngineClassLoader();
  -            engine.enableLogging( getLogger() );
  -            DefaultLocator context = new DefaultLocator();
  -            context.put( "urn:assembly:engine.bootstrap", "" + bootstrap );
  -            context.put( "urn:assembly:logging.manager", m_logManager );
  -            context.put( "urn:assembly:threads.manager", getPoolManager() );
  -            context.makeReadOnly();
  -            engine.contextualize( context );
  -            engine.initialize();
  -            m_engine = engine;
  -        }
  -        catch( Throwable e )
  -        {
  -            ExceptionHelper.printException( "Engine setup failure.", e, this, true 
);
  -            assertTrue( false );
  -        }
  -    }
  -
  -    private PoolManager getPoolManager( ) throws Exception
  -    {
  -        try
  -        {
  -            //
  -            // Set up the ThreadManager that the CommandManager uses
  -            //
  -
  -            TPCThreadManager threadManager = new TPCThreadManager();
  -            threadManager.enableLogging( getLogger().getChildLogger( "threads" ) );
  -            Parameters params = new Parameters();
  -            params.setParameter( "threads-per-processor", "2" );
  -            params.setParameter( "sleep-time", "1000" );
  -            params.setParameter( "block-timeout", "250" );
  -            threadManager.parameterize( params );
  -            threadManager.initialize();
  -
  -            //
  -            // Set up the CommandManager that the PoolManager uses.
  -            //
  -
  -            CommandManager commandManager = new CommandManager();
  -            threadManager.register( commandManager );
  +        //
  +        // register the components types that we need for the demonstration
  +        // (note: the appliance package does not do stuff like location and 
pre-assement
  +        // of available compoennt types)
  +        //
   
  -            //
  -            // Set up the PoolManager that the pooled lifecycle helper needs
  -            //
  +        final String complex = "org.apache.avalon.playground.ComplexComponent";
  +        final String demo = "org.apache.avalon.playground.DemoManager";
  +        final String exploitation = 
"org.apache.avalon.playground.ExploitationManager";
  +        final String simple = "org.apache.avalon.playground.SimpleComponent";
  +        final String basic = "org.apache.avalon.playground.basic.BasicComponent";
  +        final String context = 
"org.apache.avalon.assembly.lifecycle.context.DefaultContextManager";
   
  -            DefaultPoolManager poolManager = 
  -              new DefaultPoolManager( commandManager.getCommandSink() );
  -            return poolManager;
  -        }
  -        catch( Throwable e )
  +        final String[] classnames = new String[]{
  +           complex, demo, exploitation, simple, basic, context };
  +        for( int i=0; i< classnames.length; i++ )
           {
  -            final String error = 
  -              "Internal error during establishment of the default pool manager. 
Cause: ";
  -            throw new Exception( error + e.toString() );
  +            m_engine.register( classnames[i] );
           }
       }
   
  -
      /**
       * Test a component with custom context type and profile based import and 
       * entry creation directives and no service dependencies.
  @@ -270,6 +227,69 @@
                 "failure for create type using : " + classname, e );
               getLogger().error( error );
               assertTrue( false );
  +        }
  +    }
  +
  +    protected EngineClassLoader setUpEngine( boolean bootstrap ) throws Exception
  +    {
  +        try
  +        {
  +            EngineClassLoader engine = new EngineClassLoader();
  +            engine.enableLogging( getLogger() );
  +            DefaultLocator context = new DefaultLocator();
  +            context.put( "urn:assembly:engine.bootstrap", "" + bootstrap );
  +            context.put( "urn:assembly:logging.manager", m_logManager );
  +            context.put( "urn:assembly:threads.manager", getPoolManager() );
  +            context.makeReadOnly();
  +            engine.contextualize( context );
  +            engine.initialize();
  +            return engine;
  +        }
  +        catch( Exception e )
  +        {
  +            ExceptionHelper.printException( "Engine setup failure.", e, this, true 
);
  +            assertTrue( false );
  +            throw e;
  +        }
  +    }
  +
  +    private PoolManager getPoolManager( ) throws Exception
  +    {
  +        try
  +        {
  +            //
  +            // Set up the ThreadManager that the CommandManager uses
  +            //
  +
  +            TPCThreadManager threadManager = new TPCThreadManager();
  +            threadManager.enableLogging( getLogger().getChildLogger( "threads" ) );
  +            Parameters params = new Parameters();
  +            params.setParameter( "threads-per-processor", "2" );
  +            params.setParameter( "sleep-time", "1000" );
  +            params.setParameter( "block-timeout", "250" );
  +            threadManager.parameterize( params );
  +            threadManager.initialize();
  +
  +            //
  +            // Set up the CommandManager that the PoolManager uses.
  +            //
  +
  +            CommandManager commandManager = new CommandManager();
  +            threadManager.register( commandManager );
  +
  +            //
  +            // Set up the PoolManager that the pooled lifecycle helper needs
  +            //
  +
  +            DefaultPoolManager poolManager = 
  +              new DefaultPoolManager( commandManager.getCommandSink() );
  +            return poolManager;
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Internal error during establishment of the default pool manager. 
Cause: ";
  +            throw new Exception( error + e.toString() );
           }
       }
   }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/ApplianceTestCase.java
  
  Index: ApplianceTestCase.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.avalon.assembly.engine;
  
  import java.io.File;
  import java.util.Map;
  import java.util.Hashtable;
  import junit.framework.TestCase;
  import org.apache.avalon.framework.Version;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.assembly.locator.DefaultLocator;
  import org.apache.avalon.meta.info.*;
  import org.apache.avalon.meta.model.*;
  import org.apache.avalon.assembly.TestCaseBase;
  import org.apache.avalon.assembly.engine.Engine;
  import org.apache.avalon.assembly.engine.type.TypeManager;
  import org.apache.avalon.assembly.appliance.Appliance;
  import org.apache.avalon.assembly.appliance.ApplianceContext;
  import org.apache.avalon.assembly.appliance.DefaultApplianceContext;
  import org.apache.avalon.assembly.appliance.DependencyGraph;
  import org.apache.avalon.assembly.util.ExceptionHelper;
  import org.apache.excalibur.mpool.DefaultPoolManager;
  import org.apache.excalibur.mpool.PoolManager;
  import org.apache.excalibur.event.command.CommandManager;
  import org.apache.excalibur.event.command.TPCThreadManager;
  
  /**
   * A testcase for the {@link DefaultEngine} implementation.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   */
  public class ApplianceTestCase extends TestCaseBase
  {
      private TypeManager m_manager;
  
      protected EngineClassLoader m_engine;
  
      protected DependencyGraph m_graph = new DependencyGraph();
  
      protected ClassLoader m_loader = Thread.currentThread().getContextClassLoader();
  
      public ApplianceTestCase()
      {
          this( "ApplianceTestCase" );
      }
  
      public ApplianceTestCase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
  
          TypeManager manager = new TypeManager( m_loader );
          manager.enableLogging( getLogger().getChildLogger("types") );
          m_manager = manager;
  
          m_engine = setUpEngine( true );
      }
  
     /**
      * Test a component with custom context type and profile based import and 
      * entry creation directives and no service dependencies.
      */
      public void testTypeCreation()
      {
          try
          {
              final String classname = "org.apache.avalon.playground.DemoManager";
              final String stage = "org.apache.avalon.playground.Demonstratable";
              m_engine.register( classname );
              m_engine.register( stage );
              Appliance appliance = m_engine.resolve( m_graph, new StageDescriptor( 
stage ) );
                getLogger().info("appliance: " + appliance.getURL() );
              assertTrue( true );
          }
          catch( Throwable e )
          {
              ExceptionHelper.printException( "Resolution failure.", e, this, true );
              assertTrue( false );
          }
      }
  
      protected EngineClassLoader setUpEngine( boolean bootstrap ) throws Exception
      {
          try
          {
              EngineClassLoader engine = new EngineClassLoader();
              engine.enableLogging( getLogger() );
              DefaultLocator context = new DefaultLocator();
              context.put( "urn:assembly:engine.bootstrap", "" + bootstrap );
              context.put( "urn:assembly:logging.manager", m_logManager );
              context.put( "urn:assembly:threads.manager", getPoolManager() );
              context.makeReadOnly();
              engine.contextualize( context );
              engine.initialize();
              return engine;
          }
          catch( Exception e )
          {
              ExceptionHelper.printException( "Engine setup failure.", e, this, true );
              assertTrue( false );
              throw e;
          }
      }
  
      private PoolManager getPoolManager( ) throws Exception
      {
          try
          {
              //
              // Set up the ThreadManager that the CommandManager uses
              //
  
              TPCThreadManager threadManager = new TPCThreadManager();
              threadManager.enableLogging( getLogger().getChildLogger( "threads" ) );
              Parameters params = new Parameters();
              params.setParameter( "threads-per-processor", "2" );
              params.setParameter( "sleep-time", "1000" );
              params.setParameter( "block-timeout", "250" );
              threadManager.parameterize( params );
              threadManager.initialize();
  
              //
              // Set up the CommandManager that the PoolManager uses.
              //
  
              CommandManager commandManager = new CommandManager();
              threadManager.register( commandManager );
  
              //
              // Set up the PoolManager that the pooled lifecycle helper needs
              //
  
              DefaultPoolManager poolManager = 
                new DefaultPoolManager( commandManager.getCommandSink() );
              return poolManager;
          }
          catch( Throwable e )
          {
              final String error = 
                "Internal error during establishment of the default pool manager. 
Cause: ";
              throw new Exception( error + e.toString() );
          }
      }
  }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/profile/ProfileManagerTestCase.java
  
  Index: ProfileManagerTestCase.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.avalon.assembly.engine.profile;
  
  import java.io.File;
  import junit.framework.TestCase;
  import org.apache.avalon.framework.Version;
  import org.apache.avalon.framework.context.*;
  import org.apache.avalon.framework.logger.*;
  import org.apache.avalon.assembly.engine.service.*;
  import org.apache.avalon.assembly.engine.type.*;
  import org.apache.avalon.assembly.engine.profile.*;
  import org.apache.avalon.meta.info.*;
  import org.apache.avalon.meta.model.*;
  import org.apache.avalon.assembly.TestCaseBase;
  
  /**
   * A testcase for the @link{ProfileManager}.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   */
  public class ProfileManagerTestCase extends TestCaseBase
  {
  
      private ProfileManager m_manager;
      private TypeManager m_types;
      protected ClassLoader m_loader = Thread.currentThread().getContextClassLoader();
  
      public ProfileManagerTestCase()
      {
          this( "ProfileManagerTestCase" );
      }
  
      public ProfileManagerTestCase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          m_types = createTypeManager();
          m_manager = createProfileManager();
      }
  
      public void testPackagedProfileImport()
      {
          final String classname = "org.apache.avalon.playground.basic.BasicComponent";
            
          try
          {
              Type type = m_types.createType( classname );
              Profile[] profiles = m_manager.loadProfiles( type );
              assertTrue( profiles.length > 0 );
          }
          catch( Throwable e )
          {
              System.out.println("failure to create packaged profiles for : " + 
classname );
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testClassicProfileRegistrationAndRetrival() throws Exception
      {
          final String classname = "org.apache.avalon.playground.basic.BasicComponent";
          
          ReferenceDescriptor ref = 
            new ReferenceDescriptor(
              "org.apache.avalon.playground.basic.BasicService",
              Version.getVersion( "1.1" ) );
  
          DependencyDescriptor dep = 
            new DependencyDescriptor( "test", ref );
  
          try
          {
              Type type = m_types.createType( classname );
              Profile[] profiles = m_manager.loadProfiles( type );
              for( int i=0; i<profiles.length; i++ )
              {
                  m_manager.addProfile( profiles[i] );
              }
  
              Profile[] candidates = m_manager.getProfiles( dep );
              assertTrue( candidates.length > 0 );
          }
          catch( Throwable e )
          {
              System.out.println("failure to resolve profile for : " + ref );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testExtensionProfileRegistrationAndRetrival() throws Exception
      {
          final String classname = "org.apache.avalon.playground.ExploitationManager";
          
          ReferenceDescriptor reference = 
            new ReferenceDescriptor( "org.apache.avalon.playground.Exploitable" );
  
          StageDescriptor stage = new StageDescriptor( reference );
  
          try
          {
              Type type = m_types.createType( classname );
              Profile[] profiles = m_manager.loadProfiles( type );
              for( int i=0; i<profiles.length; i++ )
              {
                  m_manager.addProfile( profiles[i] );
              }
  
              Profile[] candidates = m_manager.getProfiles( stage );
              assertTrue( candidates.length > 0 );
          }
          catch( Throwable e )
          {
              System.out.println("failure to resolve extension handler profile for : " 
+ reference );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testServiceProviderSelection() throws Exception
      {
          final String classname = "org.apache.avalon.playground.basic.BasicComponent";
          
          ReferenceDescriptor ref = 
            new ReferenceDescriptor(
              "org.apache.avalon.playground.basic.BasicService",
              Version.getVersion( "1.1" ) );
  
          DependencyDescriptor dep = 
            new DependencyDescriptor( "test", ref );
  
          try
          {
              Type type = m_types.createType( classname );
              Profile[] profiles = m_manager.loadProfiles( type );
              for( int i=0; i<profiles.length; i++ )
              {
                  m_manager.addProfile( profiles[i] );
              }
  
              Profile selection = m_manager.getProfile( dep );
              assertTrue( selection != null );
          }
          catch( Throwable e )
          {
              System.out.println("failure to resolve profile for : " + ref );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testExtensionProviderSelection() throws Exception
      {
          final String classname = "org.apache.avalon.playground.ExploitationManager";
          
          ReferenceDescriptor reference = 
            new ReferenceDescriptor( "org.apache.avalon.playground.Exploitable" );
  
          StageDescriptor stage = new StageDescriptor( reference );
  
          try
          {
              Type type = m_types.createType( classname );
              Profile[] profiles = m_manager.loadProfiles( type );
              for( int i=0; i<profiles.length; i++ )
              {
                  m_manager.addProfile( profiles[i] );
              }
  
              Profile selection = m_manager.getProfile( stage );
              assertTrue( selection != null );
          }
          catch( Throwable e )
          {
              System.out.println("failure to resolve extension handler profile for : " 
+ reference );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      protected void tearDown() throws Exception
      {
          m_manager = null;
          m_types = null;
      }
  
      private TypeManager createTypeManager() throws Exception
      {
          TypeManager manager = new TypeManager( m_loader );
          manager.enableLogging( getLogger().getChildLogger("types") );
          return manager;
      }
  
      private ProfileManager createProfileManager() throws Exception
      {
          ProfileManager manager = new ProfileManager( m_loader );
          manager.enableLogging( getLogger().getChildLogger("profiles") );
          return manager;
      }
  
  }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/service/DefaultServiceRepositoryTestCase.java
  
  Index: DefaultServiceRepositoryTestCase.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.avalon.assembly.engine.service;
  
  import java.io.File;
  import junit.framework.TestCase;
  import org.apache.avalon.framework.Version;
  import org.apache.avalon.framework.context.*;
  import org.apache.avalon.framework.logger.*;
  import org.apache.avalon.assembly.engine.service.*;
  import org.apache.avalon.assembly.engine.type.*;
  import org.apache.avalon.meta.info.*;
  import org.apache.avalon.assembly.TestCaseBase;
  
  /**
   * A testcase for the @link{DefaultServiceRepository}.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   */
  public class DefaultServiceRepositoryTestCase extends TestCaseBase
  {
  
      private ServiceRepository m_manager;
      protected ClassLoader m_loader = Thread.currentThread().getContextClassLoader();
  
      public DefaultServiceRepositoryTestCase()
      {
          this( "DefaultServiceRepository" );
      }
  
      public DefaultServiceRepositoryTestCase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          ServiceRepository manager = new ServiceRepository( m_loader );
          manager.enableLogging( getLogger().getChildLogger("services") );
          m_manager = manager;
      }
  
      public void testCreateBasicService()
      {
          final String classname = "org.apache.avalon.playground.basic.BasicService";
            
          try
          {
              assertTrue( m_manager.createService( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("static operation failure for create type using : " + 
classname );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testCreateNull()
      {          
          try
          {
              m_manager.createService( (String) null );
              assertTrue( false );
          }
          catch( NullPointerException e )
          {
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println("static operation failure for create type using : " + 
null );
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testCreateBadService()
      {          
          final String classname = "org.something.else";
          try
          {
              Service service = m_manager.createService( classname );
              assertTrue( false );
          }
          catch( ServiceException e )
          {
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println(
                "static operation anti-failure for creation of invalid service using : 
" 
                + classname );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testServiceRegistrationAndRetrival() throws Exception
      {
          final String classname = "org.apache.avalon.playground.basic.BasicService";
  
          Service service = m_manager.createService( classname );
          try
          {
              m_manager.addService( service );
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "type addition failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // try to add the service again (which should fail)
          //
  
          try
          {
              m_manager.addService( service );
              System.out.println( "type replacement check failure" );
              assertTrue( false );
          }
          catch( Throwable e )
          {
              assertTrue( true );
          }
  
          //
          // validate service retrival by classname and version
          //
  
          try
          {
              service.equals( m_manager.getService( service.getClassname(), 
service.getVersion() ) );
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "service retrival by classname/version failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // validate service retrival by classname and version using a bad version
          //
  
          try
          {
              Version version = Version.getVersion( "111.111" );
              service.equals( m_manager.getService( service.getClassname(), version ) 
);
              System.out.println( "service retrival by classname/version failure on 
bad version" );
              assertTrue( false );
          }
          catch( Throwable e )
          {
              assertTrue( true );
          }
      }
  
      protected void tearDown() throws Exception
      {
          m_loader = null;
          m_manager = null;
      }
  
  }
  
  
  
  1.1                  
avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/type/TypeManagerTestCase.java
  
  Index: TypeManagerTestCase.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.avalon.assembly.engine.type;
  
  import java.io.File;
  import junit.framework.TestCase;
  import org.apache.avalon.framework.context.*;
  import org.apache.avalon.framework.logger.*;
  import org.apache.avalon.assembly.engine.service.*;
  import org.apache.avalon.assembly.engine.type.*;
  import org.apache.avalon.meta.info.*;
  import org.apache.avalon.assembly.TestCaseBase;
  
  /**
   * A testcase for the @link{TypeManager}.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development Team</a>
   */
  public class TypeManagerTestCase extends TestCaseBase
  {
  
      private TypeManager m_manager;
      protected ClassLoader m_loader = Thread.currentThread().getContextClassLoader();
  
      public TypeManagerTestCase()
      {
          this( "TypeManagerTestCase" );
      }
  
      public TypeManagerTestCase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          TypeManager manager = new TypeManager( m_loader );
          manager.enableLogging( getLogger().getChildLogger("types") );
          m_manager = manager;
      }
  
      public void testBasic()
      {
          final String classname = "org.apache.avalon.playground.basic.BasicComponent";
            
          try
          {
              assertTrue( m_manager.createType( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("failure to create type using : " + classname );
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testSimple()
      {
          final String classname = "org.apache.avalon.playground.SimpleComponent";
            
          try
          {
              assertTrue( m_manager.createType( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("failure for create type using : " + classname );
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testComplex()
      {
          final String classname = "org.apache.avalon.playground.ComplexComponent";
            
          try
          {
              assertTrue( m_manager.createType( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("failure for create type using : " + classname );
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testNull()
      {          
          try
          {
              m_manager.createType( (String) null );
              assertTrue( false );
          }
          catch( NullPointerException e )
          {
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println("failure for create type using : " + null );
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testBadType()
      {          
          final String classname = "org.something.else";
          try
          {
              Type type = m_manager.createType( classname );
              assertTrue( false );
          }
          catch( TypeException e )
          {
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println(
                "anti-failure for creation of invalid type using : " 
                + classname );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testTypeRegistrationAndRetrival() throws Exception
      {
          final String complex = "org.apache.avalon.playground.ComplexComponent";
          final String basic = "org.apache.avalon.playground.basic.BasicComponent";
          final String simple = "org.apache.avalon.playground.SimpleComponent";
  
          Type complexType = m_manager.createType( complex );
          Type basicType = m_manager.createType( basic );
          Type simpleType = m_manager.createType( simple );
          try
          {
  
              m_manager.addType( complexType );
              m_manager.addType( basicType );
              m_manager.addType( simpleType );
  
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "type addition failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // validate type retrival by classname
          //
  
          try
          {
              complexType.equals( m_manager.getType( complex ) );
              basicType.equals( m_manager.getType( basic ) );
              simpleType.equals( m_manager.getType( simple ) );
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "type retrival by classname failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // validate retrival by dependency
          //
  
          DependencyDescriptor constraint = complexType.getDependency( "simple" );
          Type[] solutions = m_manager.getTypes( constraint );
          assertTrue( solutions.length > 0 );
      }
  
      protected void tearDown() throws Exception
      {
          m_loader = null;
      }
  
  }
  
  
  

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

Reply via email to