You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/07/08 15:47:07 UTC

cvs commit: avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/repository LocalRepositoryTestCase.java

mcconnell    2003/07/08 06:47:07

  Modified:    merlin/composition/src/java/org/apache/avalon/composition/model/impl
                        DefaultClassLoaderModel.java
                        DefaultContainmentModel.java
                        DefaultDeploymentModel.java
                        DefaultSystemContext.java Resources.properties
                        Scanner.java
               merlin/composition/src/java/org/apache/avalon/composition/repository/impl
                        FileRepository.java
               merlin/composition/src/test/conf block.xml
               merlin/composition/src/test/org/apache/avalon/composition/model
                        AbstractTestCase.java CompositionTestCase.java
               merlin/composition/src/test/org/apache/avalon/composition/repository
                        LocalRepositoryTestCase.java
  Added:       merlin/composition/src/java/org/apache/avalon/composition/model/impl
                        DefaultContainmentContext.java
                        DefaultContextModel.java
                        DefaultDeploymentContext.java
                        DefaultModelFactory.java
  Removed:     merlin/composition/src/java/org/apache/avalon/composition/model/impl
                        DefaultContainmentModelFactory.java
                        DefaultDeploymentModelFactory.java
  Log:
  Incorporating classloader seperation !!!!!
  
  Revision  Changes    Path
  1.9       +2 -2      avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultClassLoaderModel.java
  
  Index: DefaultClassLoaderModel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultClassLoaderModel.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultClassLoaderModel.java	7 Jul 2003 18:45:34 -0000	1.8
  +++ DefaultClassLoaderModel.java	8 Jul 2003 13:47:03 -0000	1.9
  @@ -276,7 +276,7 @@
   
           ArrayList types = new ArrayList();
           ArrayList services = new ArrayList();
  -        Scanner scanner = new Scanner( classLoader );
  +        Scanner scanner = new Scanner( m_classLoader );
           scanner.enableLogging( logger.getChildLogger( "scanner" ) );
           scanner.scan( m_urls, types, services );
           Logger typeLogger = logger.getChildLogger( "types" );
  
  
  
  1.9       +47 -21    avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
  
  Index: DefaultContainmentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultContainmentModel.java	7 Jul 2003 18:45:34 -0000	1.8
  +++ DefaultContainmentModel.java	8 Jul 2003 13:47:05 -0000	1.9
  @@ -59,6 +59,7 @@
   
   import org.apache.avalon.composition.model.ClassLoaderModel;
   import org.apache.avalon.composition.model.ContainmentModel;
  +import org.apache.avalon.composition.model.ContainmentContext;
   import org.apache.avalon.composition.model.DeploymentModel;
   import org.apache.avalon.composition.model.Model;
   import org.apache.avalon.composition.model.ModelException;
  @@ -74,6 +75,7 @@
   import org.apache.avalon.meta.info.ServiceDescriptor;
   import org.apache.avalon.meta.info.DependencyDescriptor;
   import org.apache.avalon.meta.info.StageDescriptor;
  +import org.apache.avalon.meta.info.Type;
   
   
   /**
  @@ -97,7 +99,7 @@
       // state
       //==============================================================
   
  -    private SystemContext m_system;
  +    private ContainmentContext m_context;
   
       private String m_partition;
   
  @@ -124,14 +126,14 @@
       * @param profile the composition profile
       */
       public DefaultContainmentModel( 
  -      final Logger logger, SystemContext system, ClassLoaderModel classLoaderModel, 
  +      final ContainmentContext context, ClassLoaderModel classLoaderModel, 
         ContainmentProfile profile )
         throws Exception
       {
  -        super( logger, SEPERATOR, "", profile.getMode() );
  +        super( context.getLogger(), SEPERATOR, "", profile.getMode() );
           m_partition = SEPERATOR;
           m_profile = profile;
  -        m_system = system;
  +        m_context = context;
           m_classLoaderModel = classLoaderModel;
           expandContainmentModel();
       }
  @@ -149,14 +151,16 @@
       * @param directive the containment profile
       */
       public DefaultContainmentModel( 
  -      final Logger logger, ContainmentModel parent, 
  +      final ContainmentContext context, ContainmentModel parent, 
         ClassLoaderModel classLoaderModel, ContainmentProfile profile )
         throws Exception
       {
  -        super( logger, parent.getPartition(), profile.getName(), profile.getMode() );
  +        super( 
  +          context.getLogger(), parent.getPartition(), 
  +          profile.getName(), profile.getMode() );
   
           m_profile = profile;
  -        m_system = parent.getContext();
  +        m_context = context;
           m_classLoaderModel = classLoaderModel;
   
           m_partition = getPath() + getName() + SEPERATOR;
  @@ -206,15 +210,6 @@
       }
   
      /**
  -    * Return the containment context object.
  -    * @return the system context
  -    */
  -    public SystemContext getContext()
  -    {
  -        return m_system;
  -    }
  -
  -   /**
       * Return TRUE is this model is capable of supporting a supplied 
       * depedendency.
       * @return true if this model can fulfill the dependency
  @@ -263,8 +258,19 @@
   
           try
           {
  -            final DeploymentModel model = new DefaultDeploymentModel( 
  -              logger, m_system, m_classLoaderModel, profile, partition );
  +
  +            ClassLoader classLoader = m_classLoaderModel.getClassLoader();
  +            Class base = classLoader.loadClass( profile.getClassname() );
  +            Type type = m_classLoaderModel.getTypeRepository().getType( base );
  +
  +            DefaultDeploymentContext context = 
  +              new DefaultDeploymentContext( 
  +                logger, m_context, profile, type, base,
  +                new File( m_context.getHomeDirectory(), name ),
  +                new File( m_context.getTempDirectory(), name ),
  +                partition );
  +
  +            final DeploymentModel model = new DefaultDeploymentModel( context );
               m_models.add( model );
               return model;
           }
  @@ -297,8 +303,19 @@
           {
               final ClassLoaderModel classLoaderModel = 
                 m_classLoaderModel.createChild( profile );
  -            final ContainmentModel model = new DefaultContainmentModel( 
  -              logger, this, classLoaderModel, profile );
  +            final ClassLoader classLoader = classLoaderModel.getClassLoader();
  +            final SystemContext system = m_context.getSystemContext();
  +            final File home = new File( m_context.getHomeDirectory(), name );
  +            final File temp = new File( m_context.getTempDirectory(), name );
  +
  +            DefaultContainmentContext context = 
  +              new DefaultContainmentContext( 
  +                logger, system, classLoader, home, temp );
  +
  +            final ContainmentModel model = 
  +              new DefaultContainmentModel( 
  +                context, this, classLoaderModel, profile );
  +
               m_models.add( model );
               return model;
           }
  @@ -320,6 +337,15 @@
       public String getPartition()
       {
           return m_partition;
  +    }
  +
  +   /**
  +    * Return the classloader model.
  +    * @return the classloader model
  +    */
  +    public ContainmentContext getContainmentContext()
  +    {
  +        return m_context;
       }
   
      /**
  
  
  
  1.9       +51 -60    avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java
  
  Index: DefaultDeploymentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultDeploymentModel.java	7 Jul 2003 18:45:34 -0000	1.8
  +++ DefaultDeploymentModel.java	8 Jul 2003 13:47:06 -0000	1.9
  @@ -57,7 +57,9 @@
   import java.util.Hashtable;
   import java.util.Map;
   
  +import org.apache.avalon.composition.model.ContextModel;
   import org.apache.avalon.composition.model.DeploymentModel;
  +import org.apache.avalon.composition.model.DeploymentContext;
   import org.apache.avalon.composition.model.ClassLoaderModel;
   import org.apache.avalon.composition.model.SystemContext;
   import org.apache.avalon.composition.repository.Repository;
  @@ -70,12 +72,14 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.meta.data.ContextDirective;
   import org.apache.avalon.meta.data.DeploymentProfile;
   import org.apache.avalon.meta.data.Mode;
   import org.apache.avalon.meta.info.Type;
   import org.apache.avalon.meta.info.ServiceDescriptor;
   import org.apache.avalon.meta.info.StageDescriptor;
   import org.apache.avalon.meta.info.DependencyDescriptor;
  +import org.apache.avalon.meta.info.ContextDescriptor;
   import org.apache.avalon.meta.info.builder.TypeBuilder;
   import org.apache.excalibur.configuration.CascadingConfiguration;
   
  @@ -102,17 +106,9 @@
       // immutable state
       //==============================================================
   
  -    private final SystemContext m_system; 
  +    private final DeploymentContext m_context;
   
  -    private final ClassLoaderModel m_classLoaderModel;
  -
  -    private final DeploymentProfile m_profile;
  -
  -    private final Type m_type;
  -
  -    private final Class m_class;
  -
  -    private final Map m_map;
  +    private final ContextModel m_contextModel;
   
       //==============================================================
       // mutable state
  @@ -136,41 +132,23 @@
       * @param profile the deployment profile
       * @param path the partition name
       */
  -    public DefaultDeploymentModel( 
  -      final Logger logger, SystemContext system, ClassLoaderModel classLoaderModel,
  -      final DeploymentProfile profile, String path )
  +    public DefaultDeploymentModel( DeploymentContext context )
         throws Exception
       {
  -        super( logger, path, profile.getName(), profile.getMode() );
  -        if( classLoaderModel == null )
  -        {
  -            throw new NullPointerException( "classLoaderModel" );
  -        }
  -        if( path == null )
  -        {
  -            throw new NullPointerException( "path" );
  -        }
  +        super( 
  +          context.getLogger(), 
  +          context.getPartitionName(), 
  +          context.getProfile().getName(), 
  +          context.getProfile().getMode() );
   
  -        m_system = system;
  -        m_profile = profile;
  -        m_classLoaderModel = classLoaderModel;
  +        m_context = context;
   
  -        if( profile.getClassname() == null )
  -        {
  -            m_class = NullComponent.class;
  -        }
  -        else
  -        {
  -            m_class = m_classLoaderModel.getClassLoader().loadClass( 
  -              profile.getClassname() );
  -        }
  -
  -        m_type = m_classLoaderModel.getTypeRepository().getType( m_class );
  +        ClassLoader classLoader = m_context.getClassLoader();
   
           if( isConfigurable() )
           {
  -            final Configuration defaults = m_type.getConfiguration();
  -            final Configuration explicit = m_profile.getConfiguration();
  +            final Configuration defaults = m_context.getType().getConfiguration();
  +            final Configuration explicit = m_context.getProfile().getConfiguration();
               final Configuration consolidated = 
                 consolidateConfigurations( explicit, defaults );
               if( consolidated != null )
  @@ -185,7 +163,8 @@
   
           if( isParameterizable() )
           {
  -            final Parameters parameters = m_profile.getParameters();
  +            final Parameters parameters = 
  +              m_context.getProfile().getParameters();
               if( parameters != null )
               {
                   m_parameters = parameters;
  @@ -198,12 +177,19 @@
   
           if( isContextDependent() )
           {
  +            final ContextDescriptor contextDescriptor = 
  +              m_context.getType().getContext();
  +            final ContextDirective contextDirective = 
  +              m_context.getProfile().getContext();
  +            final Logger log = getLogger().getChildLogger( "context" );
  +            final SystemContext system = 
  +              m_context.getContainmentContext().getSystemContext();
  +
  +            m_contextModel = new DefaultContextModel( 
  +              log, contextDescriptor, contextDirective, 
  +              classLoader, system, getPath(), getName() );
   
  -            Map map = new Hashtable();
  -            map.put( "urn:avalon:name", getName() );
  -            map.put( "urn:avalon:partition", getPath() );
  -            map.put( "urn:avalon:classloader", m_classLoaderModel.getClassLoader() );
  -
  +            /*
               //
               // setup the home and working directory for the component but don't
               // actually create the directories - that needs to be handled in a 
  @@ -231,10 +217,11 @@
               //ContextBuilder.buildMap( this );
   
               m_map = map;
  +            */
           }
           else
           {
  -            m_map = null;
  +            m_contextModel = null;
           }
       }
   
  @@ -248,7 +235,7 @@
       */
       public ServiceDescriptor[] getServices()
       {
  -        return getType().getServices();
  +        return m_context.getType().getServices();
       }
   
      /**
  @@ -258,7 +245,7 @@
       */
       public boolean isaCandidate( DependencyDescriptor dependency )
       {
  -        return getType().getService( dependency.getReference() ) != null;
  +        return m_context.getType().getService( dependency.getReference() ) != null;
       }
   
      /**
  @@ -268,7 +255,7 @@
       */
       public boolean isaCandidate( StageDescriptor stage )
       {
  -        return getType().getExtension( stage ) != null;
  +        return m_context.getType().getExtension( stage ) != null;
       }
   
      /**
  @@ -277,7 +264,7 @@
       */
       public DependencyDescriptor[] getDependencies()
       {
  -        return getType().getDependencies();
  +        return m_context.getType().getDependencies();
       }
   
       //==============================================================
  @@ -286,7 +273,7 @@
   
       public Type getType()
       {
  -        return m_type;
  +        return m_context.getType();
       }
   
      /**
  @@ -295,7 +282,7 @@
       */
       public Class getDeploymentClass()
       {
  -        return m_class;
  +        return m_context.getDeploymentClass();
       }
   
      /**
  @@ -476,7 +463,7 @@
       }
   
      /**
  -    * Rest if the component type backing the model requires the 
  +    * Test if the component type backing the model requires the 
       * establishment of a runtime context.
       *
       * @param return TRUE if the component type requires a runtime
  @@ -484,28 +471,32 @@
       */
       public boolean isContextDependent()
       {
  -        if( getType().getStages().length > 0 )
  +        if( m_context.getType().getStages().length > 0 )
           {
               return true;
           }
  -        else if( Contextualizable.class.isAssignableFrom( m_class ) )
  +        else if( 
  +          Contextualizable.class.isAssignableFrom( 
  +            m_context.getDeploymentClass() ) )
           {
               return true;
           }
           else
           {
  -            return false;
  +            return m_context.getType().getContext().getAttribute( 
  +              ContextDescriptor.STRATEGY_KEY, null ) != null;
           }
       }
   
      /**
  -    * Return the context map established for the component.
  +    * Return the context model for this deployment model.
       * 
  -    * @return the context map
  +    * @return the context model if this model is context dependent, else
  +    *   the return value is null
       */
  -    public Map getContextMap()
  +    public ContextModel getContextModel()
       {
  -        return m_map;
  +        return m_contextModel;
       }
   
       //==============================================================
  
  
  
  1.5       +97 -9     avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContext.java
  
  Index: DefaultSystemContext.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultSystemContext.java	7 Jul 2003 18:45:34 -0000	1.4
  +++ DefaultSystemContext.java	8 Jul 2003 13:47:06 -0000	1.5
  @@ -55,6 +55,7 @@
   
   import org.apache.avalon.composition.model.SystemContext;
   import org.apache.avalon.composition.repository.Repository;
  +import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  @@ -66,7 +67,8 @@
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    * @version $Revision$ $Date$
    */
  -public class DefaultSystemContext implements SystemContext
  +public class DefaultSystemContext extends DefaultContext 
  +  implements SystemContext
   {
       //==============================================================
       // static
  @@ -87,6 +89,16 @@
   
       private final Repository m_repository;
   
  +    private final ClassLoader m_classLoader;
  +
  +    private final Logger m_logger;
  +
  +    //==============================================================
  +    // mutable state
  +    //==============================================================
  +
  +    private boolean m_trace;
  +
       //==============================================================
       // constructor
       //==============================================================
  @@ -94,31 +106,35 @@
      /**
       * Creation of a new system context.
       *
  +    * @param system the system classloader
       * @param base the base directory from which relative references 
       *   within a classpath or library directive shall be resolved
       * @param repository a resource repository to be used when resolving 
       *   resource directives
       */
  -    public DefaultSystemContext( File base, Repository repository )
  +    public DefaultSystemContext( 
  +      Logger logger, ClassLoader system, File base, Repository repository )
       {
           this( 
  -          base, 
  -          new File( System.getProperty( "user.work" ), "working" ), 
  +          logger, system, base, 
  +          new File( System.getProperty( "user.dir" ), "working" ), 
             repository );
       }
   
      /**
       * Creation of a new system context.
       *
  +    * @param system the system classloader
       * @param base the base directory from which relative references 
       *   within a classpath or library directive shall be resolved
       * @param repository a resource repository to be used when resolving 
       *   resource directives
       */
  -    public DefaultSystemContext( File base, File work, Repository repository )
  +    public DefaultSystemContext( 
  +      Logger logger, ClassLoader system, File base, File work, Repository repository )
       {
           this( 
  -          base, 
  +          logger, system, base, 
             new File( work, "home" ), 
             new File( work, "temp" ), 
             repository );
  @@ -127,12 +143,38 @@
      /**
       * Creation of a new system context.
       *
  +    * @param system the system classloader
  +    * @param base the base directory from which relative references 
  +    *   within a classpath or library directive shall be resolved
  +    * @param home the directory from which persistent content may be created
  +    * @param temp a temporary directory that will be destroyed on completion 
  +    *   of the session
  +    * @param repository a resource repository to be used when resolving 
  +    *   resource directives
  +    */
  +    public DefaultSystemContext( 
  +      Logger logger, ClassLoader system, File base, File home, File temp, 
  +      Repository repository )
  +    {
  +        this( logger, system, base, home, temp, repository, false );
  +    }
  +
  +   /**
  +    * Creation of a new system context.
  +    *
  +    * @param system the system classloader
       * @param base the base directory from which relative references 
       *   within a classpath or library directive shall be resolved
  +    * @param home the directory from which persistent content may be created
  +    * @param temp a temporary directory that will be destroyed on completion 
  +    *   of the session
       * @param repository a resource repository to be used when resolving 
       *   resource directives
  +    * @param trace flag indicating if internal logging is enabled
       */
  -    public DefaultSystemContext( File base, File home, File temp, Repository repository )
  +    public DefaultSystemContext( 
  +      Logger logger, ClassLoader system, File base, File home, File temp, 
  +      Repository repository, boolean trace )
       {
           if( base == null )
           {
  @@ -142,6 +184,10 @@
           {
               throw new NullPointerException( "repository" );
           }
  +        if( logger == null )
  +        {
  +            throw new NullPointerException( "logger" );
  +        }
           if( !base.isDirectory() )
           {
               final String error = 
  @@ -152,8 +198,10 @@
           m_base = base;
           m_home = home;
           m_temp = temp;
  -        
  +        m_trace = trace;
           m_repository = repository;
  +        m_classLoader = system;
  +        m_logger = logger;
       }
   
       //==============================================================
  @@ -202,6 +250,46 @@
       public Repository getRepository()
       {
           return m_repository;
  +    }
  +
  +   /**
  +    * Return the system classloader.
  +    *
  +    * @return the system classloader
  +    */
  +    public ClassLoader getSystemClassLoader()
  +    {
  +        return m_classLoader;
  +    }
  +
  +   /**
  +    * Return the system trace flag.
  +    *
  +    * @return the trace flag
  +    */
  +    public boolean isTraceEnabled()
  +    {
  +        return m_trace;
  +    }
  +
  +   /**
  +    * Set the system trace flag.
  +    *
  +    * @param trace the trace flag
  +    */
  +    public void setTraceEnabled( boolean trace )
  +    {
  +        m_trace = trace;
  +    }
  +
  +   /**
  +    * Return the system logging channel.
  +    *
  +    * @return the system logging channel
  +    */
  +    public Logger getLogger()
  +    {
  +        return m_logger;
       }
   
   }
  
  
  
  1.7       +5 -1      avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/Resources.properties,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Resources.properties	7 Jul 2003 08:31:18 -0000	1.6
  +++ Resources.properties	8 Jul 2003 13:47:06 -0000	1.7
  @@ -15,10 +15,14 @@
   containment.container.create.error=Unable to create containment model: {1} in {0}.
   containment.deployment.create.error=Unable to create deployment model: {1} in {0}.
   containment.unknown-profile-class.error=Unknown profile class: {1} in {0}.
  +containment.context.home.not-a-directory.error=Supplied home dir is not a directory: {0}
  +containment.context.temp.not-a-directory.error=Supplied temp dir is not a directory: {0}
   
   # DefaultDeploymentModel
   deployment.parameters.irrational=Illegal attempt to set a parameter value for a component type '{0}' that is not parameterizable in the model: {1}.
   deployment.configuration.irrational=Illegal attempt to set a configuration value for a component type '{0}' that is not configurable in the model: {1}.
  +deployment.context.home.not-a-directory.error=Supplied home dir is not a directory: {0}
  +deployment.context.temp.not-a-directory.error=Supplied temp dir is not a directory: {0}
   
   # DefaultModel
   created=created: {0}
  @@ -34,7 +38,7 @@
   
   #Scanner
   scanner.scanning=scanning: {0}
  -scanner.dir-scan.error.=Unexpected error while attempting to scan directory: {0}
  +scanner.dir-scan.error=Unexpected error while attempting to scan directory: {0}
   scanner.nested-jar-unsupported.error=Embeded jar file loading not supported: {0}
   scanner.stream.unrecognized-content.warning=Unrecognized content: {0}
   scanner.stream.content.error=Content related error while scanning url: {0}
  
  
  
  1.5       +23 -2     avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/Scanner.java
  
  Index: Scanner.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/Scanner.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Scanner.java	7 Jul 2003 18:45:34 -0000	1.4
  +++ Scanner.java	8 Jul 2003 13:47:06 -0000	1.5
  @@ -371,7 +371,28 @@
       private void addType( List types, String name ) throws Exception
       {
           String classname = parseResourceName( name );
  -        Class clazz = m_classloader.loadClass( classname );
  +        Class clazz = null;
  +        try
  +        {
  +            clazz = m_classloader.loadClass( classname );
  +        }
  +        catch( NoClassDefFoundError ncdf )
  +        {
  +            String ref = parseResourceName( ncdf.getMessage() );
  +            final String error = 
  +              "Component type: " + classname 
  +              + " references the class: " + ref
  +              + " which does not exist in the classloader.";
  +            throw new ModelException( error );
  +        }
  +        catch( ClassNotFoundException cnfe )
  +        {
  +            final String error = 
  +              "Component type: " + classname 
  +              + " does not exist in the classloader.";
  +            throw new ModelException( error, cnfe );
  +        }
  +
           Type type = TYPE_BUILDER.build( clazz );
   
           try
  
  
  
  1.1                  avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentContext.java
  
  Index: DefaultContainmentContext.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 apache@apache.org.
  
   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.composition.model.impl;
  
  import java.io.File;
  import java.util.Map;
  
  import org.apache.avalon.composition.model.SystemContext;
  import org.apache.avalon.composition.model.ContainmentContext;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  
  /**
   * Implementation of a system context that exposes a system wide set of parameters.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/07/08 13:47:05 $
   */
  public class DefaultContainmentContext extends DefaultContext 
    implements ContainmentContext
  {
      //==============================================================
      // static
      //==============================================================
  
      private static final Resources REZ =
              ResourceManager.getPackageResources( DefaultContainmentContext.class );
  
      //==============================================================
      // immutable state
      //==============================================================
  
      private final SystemContext m_system;
  
      private final File m_home;
  
      private final File m_temp;
  
      private final ClassLoader m_classLoader;
  
      private final Logger m_logger;
  
      //==============================================================
      // constructor
      //==============================================================
  
     /**
      * Creation of a new containment context.
      *
      * @param system the system context
      * @param classLoader the containment classloader
      * @param home the directory for the container
      * @param temp a temporary directory for the container
      * @param repository a resource repository to be used when resolving 
      *   resource directives
      */
      public DefaultContainmentContext( 
        Logger logger, SystemContext system, ClassLoader classLoader, File home, File temp )
      {
          if( system == null )
          {
              throw new NullPointerException( "system" );
          }
          if( classLoader == null )
          {
              throw new NullPointerException( "classLoader" );
          }
          if( logger == null )
          {
              throw new NullPointerException( "logger" );
          }
  
          /*
          if( !home.isDirectory() )
          {
              final String error = 
                REZ.getString( 
                  "containment.context.home.not-a-directory.error", home.toString() );
              throw new IllegalArgumentException( error );
          }
          if( !temp.isDirectory() )
          {
              final String error = 
                REZ.getString( 
                  "containment.context.temp.not-a-directory.error", temp.toString() );
              throw new IllegalArgumentException( error );
          }
          */
  
          m_home = home;
          m_temp = temp;
          m_system = system;
          m_classLoader = classLoader;
          m_logger = logger;
      }
  
      //==============================================================
      // ContainmentContext
      //==============================================================
  
     /**
      * Return the system context.
      *
      * @return the system context
      */
      public SystemContext getSystemContext()
      {
          return m_system;
      }
  
     /**
      * Return the working directory from which containers may 
      * establish persistent content.
      *
      * @return the working directory
      */
      public File getHomeDirectory()
      {
          return m_home;
      }
  
     /**
      * Return the temporary directory from which a container 
      * may use to establish a transient content directory. 
      *
      * @return the temporary directory
      */
      public File getTempDirectory()
      {
          return m_temp;
      }
  
     /**
      * Return the containment classloader.
      *
      * @return the classloader
      */
      public ClassLoader getClassLoader()
      {
          return m_classLoader;
      }
  
     /**
      * Return the system logging channel.
      *
      * @return the system logging channel
      */
      public Logger getLogger()
      {
          return m_logger;
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContextModel.java
  
  Index: DefaultContextModel.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 apache@apache.org.
  
   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.composition.model.impl;
  
  import java.util.Map;
  import java.util.Hashtable;
  
  import org.apache.avalon.composition.model.ContextModel;
  import org.apache.avalon.composition.model.ModelException;
  import org.apache.avalon.composition.model.SystemContext;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.meta.info.ContextDescriptor;
  import org.apache.avalon.meta.data.ContextDirective;
  
  /**
   * <p>Specification of a context model from which a 
   * a fully qualifed context can be established.</p>
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/07/08 13:47:06 $
   */
  public class DefaultContextModel extends AbstractLogEnabled implements ContextModel
  {
      //==============================================================
      // static
      //==============================================================
  
      /**
       * The default context implementation class to be used if
       * no context class is defined.
       */
      public static final Class DEFAULT_CONTEXT_CLASS = DefaultContext.class;
  
      /**
       * The default context strategy interface class.
       */
      public static final Class DEFAULT_STRATEGY_CLASS = Contextualizable.class;
  
      /**
       * The standard context entry key for the partition name.
       */
      public static final String PARTITION_KEY = "urn:avalon:partition.name";
  
      /**
       * The standard context entry key for the partition name.
       */
      public static final String NAME_KEY = "urn:avalon:name";
  
      /**
       * The standard context entry key for the partition name.
       */
      public static final String CLASSLOADER_KEY = "urn:avalon:classloader";
  
      /**
       * The standard context entry key for the partition name.
       */
      public static final String HOME_KEY = "urn:avalon:home.dir";
  
      /**
       * The standard context entry key for the partition name.
       */
      public static final String TEMP_KEY = "urn:avalon:temp.dir";
  
      //==============================================================
      // immutable state
      //==============================================================
  
      private final ContextDescriptor m_descriptor;
  
      private final ContextDirective m_directive;
  
      private final SystemContext m_system;
  
      private final ClassLoader m_classLoader;
  
      private final Class m_strategy;
  
      private final Class m_contextClass;
  
      private final Map m_map;
  
      //==============================================================
      // constructor
      //==============================================================
  
     /**
      * <p>Default implementation of the context model.  The implementation
      * takes an inital system context as the base for context value 
      * establishment and uses this to set standard context entries.</p>
      *
      * @param descriptor the contextualization stage descriptor
      * @param directive the contextualization directive
      * @param classLoader the classloader
      * @param system the system context
      */
      public DefaultContextModel( 
        Logger logger, ContextDescriptor descriptor, ContextDirective directive, 
        ClassLoader classLoader, SystemContext system, String partition, String name )
        throws ModelException
      {
          enableLogging( logger );
  
          m_descriptor = descriptor;
          m_directive = directive;
          m_classLoader = classLoader;
          m_system = system;
  
          m_strategy = loadStrategyClass( descriptor, classLoader );
          m_contextClass = loadContextClass( directive, classLoader );
  
          validateCastingConstraint( 
           descriptor, classLoader, m_contextClass );
  
          m_map = buildContextMap( system, classLoader, partition, name );
  
          if( getLogger().isDebugEnabled() )
          {
              getLogger().debug( "context: " + m_map );
          }
      }
      
      private Map buildContextMap( 
        SystemContext system, ClassLoader classLoader, String partition, String name )
      {
          Map map = new Hashtable();
          map.put( PARTITION_KEY, partition );
          map.put( NAME_KEY, name );
          map.put( CLASSLOADER_KEY, classLoader );
          map.put( HOME_KEY, system.getHomeDirectory() );
          map.put( TEMP_KEY, system.getTempDirectory() );
  
          //
          // TODO: build any entries based on imports or constructed arguments
          //
  
          return map;
      }
  
      //==============================================================
      // ContextModel
      //==============================================================
  
     /**
      * Return the class representing the contextualization stage interface.
      * 
      * @return the class representing the contextualization interface
      */
      public Class getStrategyClass()
      {
          return m_strategy;
      }
  
     /**
      * Return the context implementation class.
      * 
      * @return the class representing the context implementation.
      */
      public Class getContextClass()
      {
          return m_contextClass;
      }
  
     /**
      * Return the context map established for the component.
      * 
      * @return the context map
      */
      public Map getContextMap()
      {
          return m_map;
      }
  
      //==============================================================
      // implementation
      //==============================================================
  
     /**
      * Load the contextualization strategy class.
      * @param descriptor the context descriptor
      * @param classLoader the classloader 
      * @return the strategy class
      */
      private Class loadStrategyClass( 
         ContextDescriptor descriptor, ClassLoader classLoader )
        throws ModelException
      {
          final String strategy = m_descriptor.getAttribute( 
            ContextDescriptor.STRATEGY_KEY, null );
          if( strategy != null )
          {
              try
              {
                  Class clazz = classLoader.loadClass( strategy );
                  if( getLogger().isDebugEnabled() )
                  {
                      final String message = 
                        "Custom strategy: " + clazz.getName();
                      getLogger().debug( message );
                  }
                  return clazz;
              }
              catch( Throwable e )
              {
                  final String error = 
                    "Cannot load custom contextualization strategy class: "
                    + strategy;
                  throw new ModelException( error, e );
              }
          }
          else
          {
              if( getLogger().isDebugEnabled() )
              {
                  final String message = "classic strategy";
                  getLogger().debug( message );
              }
              return DEFAULT_STRATEGY_CLASS;
          }
      }
  
     /**
      * Load the context implementation class.
      * @param directive the context directive
      * @param classLoader the classloader 
      * @return the strategy class
      */
      private Class loadContextClass( 
         ContextDirective directive, ClassLoader classLoader )
        throws ModelException
      {
          final String classname = m_directive.getClassname();
          if( classname == null )
          {
              return DefaultContext.class;
          }
          else
          {
              try
              {
                  return classLoader.loadClass( classname );
              }
              catch( Throwable e )
              {
                  final String error = 
                    "Cannot load custom context implementation class: "
                    + classname;
                  throw new ModelException( error, e );
              }
          }
      }
  
     /**
      * Validate that the context implememtation class implements
      * any casting constraint declared or implied by the context 
      * descriptor.
      * 
      * @param descriptor the context descriptor
      * @param classLoader the classloader
      * @param clazz the context implementation class
      * @exception if a validation failure occurs
      */
      private void validateCastingConstraint( 
        ContextDescriptor descriptor, ClassLoader classLoader, Class clazz )
        throws ModelException
      {
  
          Class castingClass = Context.class;
  
          final String castingClassName = 
            descriptor.getReference().getClassname();
  
          if( castingClassName != null )
          {
              try
              {
                  castingClass =
                    classLoader.loadClass( castingClassName );
              }
              catch( Throwable e )
              {
                  final String error = 
                    "Cannot load custom context interface class: "
                    + castingClassName;
                  throw new ModelException( error, e );
              }
          }
  
          if( !castingClass.isAssignableFrom( clazz ) )
          {
              final String error = 
                "Supplied context implementation class: " 
                + clazz.getName() 
                + " does not implement the interface: " 
                + castingClass.getName()
                + ".";
              throw new ModelException( error );
          }
      }
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentContext.java
  
  Index: DefaultDeploymentContext.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 apache@apache.org.
  
   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.composition.model.impl;
  
  import java.io.File;
  import java.util.Map;
  
  import org.apache.avalon.composition.model.ContainmentContext;
  import org.apache.avalon.composition.model.DeploymentContext;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.meta.info.Type;
  import org.apache.avalon.meta.data.DeploymentProfile;
  
  
  /**
   * Default implementation of a deployment context.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/07/08 13:47:06 $
   */
  public class DefaultDeploymentContext extends DefaultContext 
    implements DeploymentContext
  {
      //==============================================================
      // static
      //==============================================================
  
      private static final Resources REZ =
              ResourceManager.getPackageResources( DefaultDeploymentContext.class );
  
      //==============================================================
      // immutable state
      //==============================================================
  
      private final ContainmentContext m_context;
  
      private final DeploymentProfile m_profile;
  
      private final Type m_type;
  
      private final Class m_class;
  
      private final File m_home;
  
      private final File m_temp;
  
      private final Logger m_logger;
  
      private final String m_partition;
  
      //==============================================================
      // constructor
      //==============================================================
  
     /**
      * Creation of a new deployment context.
      *
      * @param context the containment context
      * @param home the directory
      * @param temp a temporary directory 
      */
      public DefaultDeploymentContext( 
        Logger logger, ContainmentContext context, 
        DeploymentProfile profile, Type type, Class clazz, 
        File home, File temp, String partition )
      {
          if( context == null )
          {
              throw new NullPointerException( "context" );
          }
          if( logger == null )
          {
              throw new NullPointerException( "logger" );
          }
          if( clazz == null )
          {
              throw new NullPointerException( "clazz" );
          }
          if( type == null )
          {
              throw new NullPointerException( "type" );
          }
          if( profile == null )
          {
              throw new NullPointerException( "profile" );
          }
          if( partition == null )
          {
              throw new NullPointerException( "partition" );
          }
  
          /*
          if( !home.isDirectory() )
          {
              final String error = 
                REZ.getString( "deployment.context.home.not-a-directory.error", home  );
              throw new IllegalArgumentException( error );
          }
          if( !temp.isDirectory() )
          {
              final String error = 
                REZ.getString( "deployment.context.temp.not-a-directory.error", temp  );
              throw new IllegalArgumentException( error );
          }
          */
  
          m_home = home;
          m_temp = temp;
          m_context = context;
          m_type = type;
          m_logger = logger;
          m_profile = profile;
          m_partition = partition;
          m_class = clazz;
      }
  
      //==============================================================
      // ContainmentContext
      //==============================================================
  
     /**
      * Return the partition name that the component will execute within.
      *
      * @return the partition name
      */
      public String getPartitionName()
      {
          return m_partition;
      }
  
     /**
      * Return the containment context.
      *
      * @return the containment context
      */
      public ContainmentContext getContainmentContext()
      {
          return m_context;
      }
  
     /**
      * Return the working directory.
      *
      * @return the working directory
      */
      public File getHomeDirectory()
      {
          return m_home;
      }
  
     /**
      * Return the temporary directory.
      *
      * @return the temporary directory
      */
      public File getTempDirectory()
      {
          return m_temp;
      }
  
     /**
      * Return the logging channel.
      *
      * @return the logging channel
      */
      public Logger getLogger()
      {
          return m_logger;
      }
  
     /**
      * Return the deployment profile.
      *
      * @return the profile
      */
      public DeploymentProfile getProfile()
      {
          return m_profile;
      }
  
     /**
      * Return the component type.
      *
      * @return the type defintion
      */
      public Type getType()
      {
          return m_type;
      }
  
     /**
      * Return the component class.
      *
      * @return the class
      */
      public Class getDeploymentClass()
      {
          return m_class;
      }
  
     /**
      * Return the classloader for the component.
      *
      * @return the classloader
      */
      public ClassLoader getClassLoader()
      {
          return m_context.getClassLoader();
      }
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultModelFactory.java
  
  Index: DefaultModelFactory.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 apache@apache.org.
  
   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.composition.model.impl;
  
  import java.io.File;
  
  import org.apache.avalon.composition.model.ClassLoaderModel;
  import org.apache.avalon.composition.model.ContainmentModel;
  import org.apache.avalon.composition.model.ContainmentContext;
  import org.apache.avalon.composition.model.ModelFactory;
  import org.apache.avalon.composition.model.ModelException;
  import org.apache.avalon.composition.model.SystemContext;
  import org.apache.avalon.composition.repository.Repository;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.meta.data.ContainmentProfile;
  import org.apache.avalon.meta.data.ClassLoaderDirective;
  
  /**
   * A factory enabling the establishment of new composition model instances.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/07/08 13:47:06 $
   */
  public class DefaultModelFactory extends AbstractLogEnabled 
    implements ModelFactory
  {
      //==============================================================
      // static
      //==============================================================
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( DefaultModelFactory.class );
  
      private static ClassLoader getClassLoader( final ClassLoader classloader )
      {
          if( classloader == null )
          {
              return Thread.currentThread().getContextClassLoader();
          }
          else
          {
              return classloader;
          }
      }
  
      //==============================================================
      // immutable state
      //==============================================================
  
      final SystemContext m_system;
  
      //==============================================================
      // constructor
      //==============================================================
  
      public DefaultModelFactory( final SystemContext system )
      {
          if( system == null )
          {
              throw new NullPointerException( "system" );
          }
          m_system = system;
          enableLogging( system.getLogger() );
      }
  
      //==============================================================
      // ContainmentModelFactory
      //==============================================================
  
     /**
      * Creation of a new root containment model using 
      * a supplied system context and containment profile
      * using the context classloader.
      *
      * @param system the system context
      * @param profile a composition profile 
      * @return the containment model
      */
      public ContainmentModel createContainmentModel( ContainmentProfile profile ) 
        throws ModelException
      {
          if( profile == null )
          {
              throw new NullPointerException( "profile" );
          }
  
          final Logger logger = getLogger();
  
          try
          {
              ClassLoader root = ClassLoader.getSystemClassLoader();
  
              ClassLoaderDirective classLoaderDirective = 
                profile.getClassLoaderDirective();
              ClassLoaderModel classLoaderModel = 
                new DefaultClassLoaderModel( 
                  logger, m_system, root, classLoaderDirective );
  
              DefaultContainmentContext context = 
                new DefaultContainmentContext( 
                  logger, m_system, 
                  classLoaderModel.getClassLoader(),
                  m_system.getHomeDirectory(),
                  m_system.getTempDirectory() );
  
              return new DefaultContainmentModel(
                context, classLoaderModel, profile );
          }
          catch( Throwable e )
          {
              final String error = 
                REZ.getString( "factory.containment.create.error", profile.getName() );
              throw new ModelException( error, e );
          }
      }
  
     /**
      * Creation of a new nested containment model.
      *
      * @param parent the containment model into which the new 
      *   containment model is to be added
      * @param profile the containment profile
      * @return the containment model
      */
      public ContainmentModel createContainmentModel( 
        final ContainmentModel parent, ContainmentProfile profile )
        throws ModelException
      {
          throw new IllegalStateException( "I'm not implmented" );
       
          /*
          Logger logger = getLogger().getChildLogger( profile.getName() );
          final String name = profile.getName();
  
          try
          {
              ClassLoaderModel classLoaderModel = 
                parent.getClassLoaderModel().createChild( profile );
              ClassLoader classLoader = classLoaderModel.getClassLoader();
              ContainmentContext parentContext = parent.getContainmentContext();
              SystemContext system = parentContext.getSystemContext();
              final File home = new File( parentContext.getHomeDirectory(), name );
              final File temp = new File( parentContext.getTempDirectory(), name );
  
              DefaultContainmentContext context = 
                new DefaultContainmentContext( 
                  logger, system, classLoader, home, temp );
  
              return new DefaultContainmentModel( 
                  context, parent, classLoaderModel, profile );
          }
          catch( Throwable e )
          {
              final String error = 
                REZ.getString( "factory.containment.create.error", profile.getName() );
              throw new ModelException( error, e );
          }
          */
      }
  }
  
  
  
  1.2       +37 -5     avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/repository/impl/FileRepository.java
  
  Index: FileRepository.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/repository/impl/FileRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileRepository.java	4 Jul 2003 07:27:41 -0000	1.1
  +++ FileRepository.java	8 Jul 2003 13:47:07 -0000	1.2
  @@ -91,6 +91,8 @@
   
       public static final String BASE_KEY = "urn:avalon:repository.base";
   
  +    public static final String HOSTS_KEY = "urn:avalon:repository.hosts";
  +
       //------------------------------------------------------------------
       // state 
       //------------------------------------------------------------------
  @@ -105,7 +107,6 @@
       */
       private URL[] m_hosts;
   
  -
       //------------------------------------------------------------------
       // lifecycle 
       //------------------------------------------------------------------
  @@ -121,6 +122,29 @@
       public void contextualize( final Context context ) throws ContextException
       {
           m_base = (File) context.get( BASE_KEY );
  +        URL[] hosts = (URL[]) context.get( HOSTS_KEY );
  +        m_hosts = new URL[ hosts.length ];
  +        for( int i=0; i<hosts.length; i++ )
  +        {
  +            final String path = hosts[i].toString();
  +            if( !path.endsWith( "/" ) ) 
  +            {
  +                try
  +                {
  +                    m_hosts[i] = new URL( path + "/" );
  +                }
  +                catch( Throwable e )
  +                {
  +                    final String error = 
  +                      "Could not coerce supplied URL to a directory reference: " + path;
  +                    throw new IllegalArgumentException( error );
  +                }
  +            }
  +            else
  +            {
  +                m_hosts[i] = hosts[i];
  +            }
  +        }
       }
   
      /**
  @@ -176,7 +200,12 @@
               Configuration host = hosts[i];
               try
               {
  -                URL url = new URL( host.getValue() );
  +                String path = host.getValue();
  +                if( !path.endsWith( "/" ) )
  +                {
  +                    path = path + "/";
  +                }
  +                URL url = new URL( path );
                   final String protocol = url.getProtocol();
                   if( url.getProtocol().equals( "http" ) )
                   { 
  @@ -278,6 +307,10 @@
         final String group, final String name, final String version, final String type )
         throws RepositoryException
       {
  +        if( m_hosts == null )
  +        {
  +            throw new IllegalStateException( "hosts" );
  +        }
           if( group == null )
           {
               throw new NullPointerException( "group" );
  @@ -290,13 +323,11 @@
           {
               throw new NullPointerException( "type" );
           }
  -
           String path = group + "/" + type + "s/" + name;
           if( ( version != null ) && ( version.length() != 0 ) ) 
           {
               path = path + "-" + version;
           }
  -
           path = path + "." + type;
   
           RepositoryException repositoryException = null;
  @@ -332,6 +363,7 @@
           }
           catch( Throwable e )
           {
  +System.out.println( "7" );
               final String error =
                 "Unexpected error while attempting to resolve artifact: " + path;
               throw new RepositoryException( error, e );
  
  
  
  1.4       +4 -0      avalon-sandbox/merlin/composition/src/test/conf/block.xml
  
  Index: block.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/test/conf/block.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- block.xml	6 Jul 2003 10:08:17 -0000	1.3
  +++ block.xml	8 Jul 2003 13:47:07 -0000	1.4
  @@ -27,6 +27,10 @@
          <repository>
            <resource id="test:test-d"/>
          </repository>
  +       <repository>
  +         <resource id="avalon-framework:avalon-framework-api" version="4.1.5-dev"/>
  +         <resource id="avalon-framework:avalon-framework-impl" version="4.1.5-dev"/>
  +       </repository>
        </classpath>
      </classloader>
   
  
  
  
  1.3       +2 -0      avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/model/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/model/AbstractTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractTestCase.java	6 Jul 2003 10:08:17 -0000	1.2
  +++ AbstractTestCase.java	8 Jul 2003 13:47:07 -0000	1.3
  @@ -109,10 +109,12 @@
   
       protected FileRepository setUpRepository( File root ) throws Exception
       {
  +        URL ibiblio = new URL( "http://www.ibiblio.org/maven" );
           FileRepository repository = new FileRepository();
           repository.enableLogging( new ConsoleLogger() );
           DefaultContext context = new DefaultContext();
           context.put( FileRepository.BASE_KEY, root );
  +        context.put( FileRepository.HOSTS_KEY, new URL[]{ ibiblio } );
           context.makeReadOnly();
           repository.contextualize( context );
           return repository;
  
  
  
  1.4       +9 -16     avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/model/CompositionTestCase.java
  
  Index: CompositionTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/model/CompositionTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CompositionTestCase.java	7 Jul 2003 18:45:35 -0000	1.3
  +++ CompositionTestCase.java	8 Jul 2003 13:47:07 -0000	1.4
  @@ -6,7 +6,7 @@
   import java.io.IOException;
   import java.net.URL;
   
  -import org.apache.avalon.composition.model.impl.DefaultContainmentModelFactory;
  +import org.apache.avalon.composition.model.impl.DefaultModelFactory;
   import org.apache.avalon.composition.model.impl.DefaultSystemContext;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.meta.data.ServiceDirective;
  @@ -83,7 +83,7 @@
       */
       public void testImplementation( ContainmentModel model ) throws Exception
       {
  -        assertEquals( 4, model.getClassLoaderModel().getQualifiedClassPath().length );
  +        assertEquals( 6, model.getClassLoaderModel().getQualifiedClassPath().length );
           assertEquals( 2, model.getModels().length );
           testFirstDeploymentModel( (DeploymentModel) model.getModels()[0] );
           testFirstContainmentModel( (ContainmentModel) model.getModels()[1] );
  @@ -105,8 +105,8 @@
       {
           assertEquals( "my-component", model.getName() );
           assertEquals( 
  -          org.apache.avalon.composition.model.testd.TestD.class, 
  -          model.getDeploymentClass() );
  +          org.apache.avalon.composition.model.testd.TestD.class.getName(), 
  +          model.getDeploymentClass().getName() );
       }
   
      //-------------------------------------------------------
  @@ -131,17 +131,10 @@
       {
           super.setUp();
   
  -        //
  -        // create the composition model
  -        //
  -
  -        //
  -        // create the model
  -        //
  -
  -        SystemContext system = new DefaultSystemContext( m_base, m_repository );
  -        DefaultContainmentModelFactory factory = new DefaultContainmentModelFactory();
  -        factory.enableLogging( getLogger() );
  -        m_model = factory.createContainmentModel( system, m_profile );
  +        ClassLoader loader = Thread.currentThread().getContextClassLoader();
  +        SystemContext system = 
  +          new DefaultSystemContext( getLogger(), loader, m_base, m_repository );
  +        DefaultModelFactory factory = new DefaultModelFactory( system );
  +        m_model = factory.createContainmentModel( m_profile );
       }
   }
  
  
  
  1.2       +2 -0      avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/repository/LocalRepositoryTestCase.java
  
  Index: LocalRepositoryTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/repository/LocalRepositoryTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalRepositoryTestCase.java	4 Jul 2003 07:27:43 -0000	1.1
  +++ LocalRepositoryTestCase.java	8 Jul 2003 13:47:07 -0000	1.2
  @@ -51,6 +51,7 @@
   package org.apache.avalon.composition.repository;
   
   import java.io.File;
  +import java.net.URL;
   
   import org.apache.avalon.composition.repository.Repository;
   import org.apache.avalon.composition.repository.impl.FileRepository;
  @@ -94,6 +95,7 @@
           repository.enableLogging( new ConsoleLogger() );
           DefaultContext context = new DefaultContext();
           context.put( FileRepository.BASE_KEY, root );
  +        context.put( FileRepository.HOSTS_KEY, new URL[0] );
           context.makeReadOnly();
           repository.contextualize( context );
           return repository;
  
  
  

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