avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin MerlinEmbeddedTest.java
Date Thu, 27 Nov 2003 00:00:14 GMT
mcconnell    2003/11/26 16:00:14

  Modified:    kernel/impl project.xml
               kernel/impl/conf merlin.properties
               kernel/impl/src/java/org/apache/avalon/merlin/kernel
                        KernelCriteria.java
               kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl
                        DefaultCriteria.java DefaultFactory.java
               kernel/test/src/test/org/apache/avalon/merlin
                        MerlinEmbeddedTest.java
  Log:
  Bring the factory neart to completion - now includes root block establishment.
  
  Revision  Changes    Path
  1.10      +0 -17     avalon-sandbox/kernel/impl/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/project.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- project.xml	26 Nov 2003 21:46:52 -0000	1.9
  +++ project.xml	27 Nov 2003 00:00:13 -0000	1.10
  @@ -69,23 +69,6 @@
   
       <dependency>
         <groupId>avalon-repository</groupId>
  -      <artifactId>avalon-repository-main</artifactId>
  -      <version>1.2-dev</version>
  -      <properties>
  -        <avalon.classloader>api</avalon.classloader>
  -      </properties>
  -    </dependency>
  -
  -    <!--
  -    <dependency> 
  -      <groupId>avalon-repository</groupId>
  -      <artifactId>avalon-repository-impl</artifactId>
  -      <version>1.2-dev</version>
  -    </dependency>
  -    -->
  -
  -    <dependency>
  -      <groupId>avalon-repository</groupId>
         <artifactId>avalon-repository-api</artifactId>
         <version>1.2-dev</version>
         <properties>
  
  
  
  1.4       +1 -1      avalon-sandbox/kernel/impl/conf/merlin.properties
  
  Index: merlin.properties
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/conf/merlin.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- merlin.properties	26 Nov 2003 14:34:55 -0000	1.3
  +++ merlin.properties	27 Nov 2003 00:00:13 -0000	1.4
  @@ -50,7 +50,7 @@
   # The root anchor directory from which extension directory references
   # will be anchored to.
   #
  -merlin.ext = ${merlin.dir}/ext
  +merlin.ext = ${merlin.dir}
   
   #
   # The info generation policy.  If 'true' a short infomation header is 
  
  
  
  1.5       +2 -2      avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/KernelCriteria.java
  
  Index: KernelCriteria.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/KernelCriteria.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- KernelCriteria.java	26 Nov 2003 14:13:28 -0000	1.4
  +++ KernelCriteria.java	27 Nov 2003 00:00:14 -0000	1.5
  @@ -149,7 +149,7 @@
         new Parameter( 
           "merlin.ext",
           File.class.getName(),
  -        new File( USER_DIR, "ext" ) );
  +        USER_DIR );
   
      /**
       * Info policy parameter descriptor.
  
  
  
  1.10      +5 -6      avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java
  
  Index: DefaultCriteria.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultCriteria.java	26 Nov 2003 14:34:55 -0000	1.9
  +++ DefaultCriteria.java	27 Nov 2003 00:00:14 -0000	1.10
  @@ -68,11 +68,10 @@
   import org.apache.avalon.repository.criteria.ValidationException;
   import org.apache.avalon.repository.criteria.Parameter;
   
  -import org.apache.avalon.defaults.Defaults;
  -import org.apache.avalon.defaults.DefaultsFinder;
  -import org.apache.avalon.defaults.SimpleDefaultsFinder;
  -import org.apache.avalon.defaults.SystemDefaultsFinder;
  -
  +import org.apache.avalon.util.defaults.Defaults;
  +import org.apache.avalon.util.defaults.DefaultsFinder;
  +import org.apache.avalon.util.defaults.SimpleDefaultsFinder;
  +import org.apache.avalon.util.defaults.SystemDefaultsFinder;
   import org.apache.avalon.util.env.Env;
   import org.apache.avalon.util.env.EnvAccessException;
   import org.apache.avalon.util.exception.ExceptionHelper;
  
  
  
  1.9       +156 -6    avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultFactory.java	26 Nov 2003 21:46:52 -0000	1.8
  +++ DefaultFactory.java	27 Nov 2003 00:00:14 -0000	1.9
  @@ -23,21 +23,34 @@
   import org.apache.avalon.repository.criteria.ValidationException;
   import org.apache.avalon.repository.criteria.Factory;
   
  +import org.apache.avalon.composition.data.ContainmentProfile;
  +import org.apache.avalon.composition.data.CategoriesDirective;
  +import org.apache.avalon.composition.data.ContainmentProfile;
  +import org.apache.avalon.composition.data.TargetDirective;
  +import org.apache.avalon.composition.data.builder.XMLDeploymentProfileCreator;
  +import org.apache.avalon.composition.data.builder.XMLContainmentProfileCreator;
   import org.apache.avalon.composition.logging.LoggingManager;
   import org.apache.avalon.composition.logging.LoggingDescriptor;
   import org.apache.avalon.composition.logging.TargetDescriptor;
   import org.apache.avalon.composition.logging.TargetProvider;
   import org.apache.avalon.composition.logging.impl.DefaultLoggingManager;
   import org.apache.avalon.composition.logging.impl.FileTargetProvider;
  -import org.apache.avalon.composition.data.builder.XMLDeploymentProfileCreator;
  -import org.apache.avalon.composition.data.CategoriesDirective;
  -import org.apache.avalon.composition.data.ContainmentProfile;
  -import org.apache.avalon.composition.data.TargetDirective;
  +import org.apache.avalon.composition.model.ContainmentContext;
  +import org.apache.avalon.composition.model.ContainmentModel;
  +import org.apache.avalon.composition.model.ModelFactory;
  +import org.apache.avalon.composition.model.impl.DefaultSystemContext;
  +import org.apache.avalon.composition.model.impl.DefaultModelFactory;
  +
  +import org.apache.avalon.activation.appliance.Block;
  +import org.apache.avalon.activation.appliance.Composite;
  +import org.apache.avalon.activation.appliance.impl.AbstractBlock;
  +import org.apache.avalon.activation.appliance.impl.DefaultServiceContext;
   
   import org.apache.avalon.merlin.kernel.KernelException;
   import org.apache.avalon.merlin.kernel.KernelCriteria;
   
   import org.apache.excalibur.configuration.ConfigurationUtil;
  +import org.apache.excalibur.mpool.PoolManager;
   
   import org.xml.sax.InputSource;
   
  @@ -60,6 +73,9 @@
       private static final XMLDeploymentProfileCreator CREATOR = 
         new XMLDeploymentProfileCreator();
   
  +    private static final XMLContainmentProfileCreator CONTAINER_CREATOR = 
  +      new XMLContainmentProfileCreator();
  +
       //--------------------------------------------------------------------------
       // state
       //--------------------------------------------------------------------------
  @@ -73,11 +89,25 @@
       private Repository m_repository;
   
       private Factory m_factory;
  - 
  +
  +    private PoolManager m_pool;
  +
  +    private ContainmentContext m_root;
  +
  +    private ModelFactory m_modelFactory;
  +
  +    private ContainmentModel m_model;
  +
  +    private Block m_block;
  +
       //--------------------------------------------------------------------------
       // constructor
       //--------------------------------------------------------------------------
   
  +   /**
  +    * Creation of a new default factory.
  +    * @param factory the repository inital factory
  +    */
       public DefaultFactory( Factory factory )
       {
           m_factory = factory;
  @@ -87,16 +117,37 @@
       // Factory
       //--------------------------------------------------------------------------
   
  +   /**
  +    * Return of map containing the default parameters.
  +    *
  +    * @return the default parameters 
  +    */
       public Map createDefaultCriteria()
       {
           return new DefaultCriteria();
       }
   
  +   /**
  +    * Creation of the root block within the container heirachy using 
  +    * the default parameters.
  +    *
  +    * @param map the parameters 
  +    * @return the root block instance
  +    * @exception Exception if an error occurs during root block establishment
  +    */
       public Object create() throws Exception
       {
           return create( createDefaultCriteria() );
       }
   
  +   /**
  +    * Creation of the root block within the container heirachy using 
  +    * the supplied parameters.
  +    *
  +    * @param map the parameters 
  +    * @return the root block instance
  +    * @exception Exception if an error occurs during root block establishment
  +    */
       public Object create( Map map ) throws Exception
       {
           if( null == map ) 
  @@ -149,8 +200,107 @@
           m_repository = createRepository( m_factory, cache, repositoryConfig );
           getLogger().debug( "repository established: " + m_repository.getLocation() );
   
  +        //
  +        // setup the pool manager
  +        // TODO: an implementation following more thinking (pools should
  +        // probably be declared at the component directive level)
  +        //
  +
  +        m_pool = null;
  +
  +
  +        //
  +        // setup the model factory
  +        //
  +
  +        try
  +        {
  +            m_modelFactory = new DefaultModelFactory( 
  +              new DefaultSystemContext( 
  +                m_logging,
  +                criteria.getExtensionDirectory(),
  +                criteria.getContextDirectory(),
  +                criteria.getTempDirectory(),
  +                m_repository,
  +                loggingDescriptor.getName(),
  +                criteria.isDebugEnabled() ) );
  +            getLogger().info( "model factory established" );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Unexpected exception while creating internal model factory.";
  +            throw new KernelException( error, e );
  +        }
  +
  +        //
  +        // create the root containment context
  +        //
  +
  +        try
  +        {
  +            final ContainmentProfile profile = 
  +              CONTAINER_CREATOR.createContainmentProfile( 
  +                kernelConfig.getChild( "container" ) );
  +            m_root = m_modelFactory.createContainmentContext( profile );
  +            Thread.currentThread().setContextClassLoader( m_root.getClassLoader() );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Internal error while build default containment context.";
  +            throw new KernelException( error, e );
  +        }
  +
  +        //
  +        // create the root containment model
  +        //
  +
  +        try
  +        {
  +            getLogger().debug( "construction phase" );
  +            m_model = m_modelFactory.createContainmentModel( m_root );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Internal error while build default containment model.";
  +            throw new KernelException( error, e );
  +        }
  +
  +        //
  +        // we now have everything established such that we can add urls
  +        // to the root model
  +
  +        try
  +        {
  +            DefaultServiceContext services = new DefaultServiceContext();
  +            services.put( PoolManager.ROLE, m_pool );
  +            services.put( LoggingManager.KEY, m_logging );
  +            m_block = AbstractBlock.createRootBlock( services, m_model );
  +            if( m_block instanceof Composite )
  +            {
  +                try
  +                {
  +                    getLogger().debug( "assembly phase" );
  +                    ((Composite)m_block).assemble();
  +                }
  +                catch( Throwable e )
  +                {
  +                    final String error = 
  +                      "Assembly failure.";
  +                    throw new KernelException( error, e );
  +                }
  +            }
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Composition failure.";
  +            throw new KernelException( error, e );
  +        }
   
  -        return null;
  +        return m_block;
       }
   
       private Repository createRepository( Factory factory, File root, Configuration config
) 
  
  
  
  1.6       +2 -2      avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java
  
  Index: MerlinEmbeddedTest.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MerlinEmbeddedTest.java	26 Nov 2003 21:46:52 -0000	1.5
  +++ MerlinEmbeddedTest.java	27 Nov 2003 00:00:14 -0000	1.6
  @@ -151,7 +151,7 @@
           }
           catch( Throwable e )
           {
  -            final String error = ExceptionHelper.packException( e );
  +            final String error = ExceptionHelper.packException( e, true );
               System.out.println( error );
               throw new Exception( error );
           }
  
  
  

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


Mime
View raw message