mcconnell    2003/07/31 15:52:47

  Modified:    merlin/composition maven.xml
               merlin/composition/src/java/org/apache/avalon/composition/model/impl
                        DefaultClassLoaderModel.java
                        DefaultContainmentContext.java
                        DefaultContainmentModel.java
                        DefaultModelFactory.java DefaultSystemContext.java
               merlin/composition/src/test/org/apache/avalon/composition/model
                        AbstractTestCase.java
               merlin/composition-spi/src/java/org/apache/avalon/composition/model
                        ClassLoaderModel.java ContainmentContext.java
  Log:
  Add implementation of block include semantics supporting inclusion from a repository 
based jar file (test case included).
  
  Revision  Changes    Path
  1.4       +10 -0     avalon-sandbox/merlin/composition/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/maven.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- maven.xml 14 Jul 2003 04:49:36 -0000      1.3
  +++ maven.xml 31 Jul 2003 22:52:47 -0000      1.4
  @@ -15,21 +15,31 @@
         manifest="${basedir}/src/test/etc/a.mf"
         includes="**/testa/*.*" basedir="${basedir}/target/test-classes">
       </ant:jar>
  +
       <ant:jar jarfile="${basedir}/target/test-classes/ext/test-b.jar"
         manifest="${basedir}/src/test/etc/b.mf"
         includes="**/testb/*.*" basedir="${basedir}/target/test-classes">
       </ant:jar>
  +
       <ant:jar jarfile="${basedir}/target/test-classes/lib/test-c.jar"
         manifest="${basedir}/src/test/etc/c.mf"
         includes="**/testc/*.*" basedir="${basedir}/target/test-classes">
       </ant:jar>
  +
       <ant:jar 
jarfile="${basedir}/target/test-classes/repository/test/jars/test-d.jar"
         manifest="${basedir}/src/test/etc/d.mf"
         includes="**/testd/*.*" basedir="${basedir}/target/test-classes">
       </ant:jar>
  +
       <ant:jar 
jarfile="${basedir}/target/test-classes/repository/test/jars/test-e.jar"
         manifest="${basedir}/src/test/etc/e.mf"
         includes="**/teste/*.*" basedir="${basedir}/target/test-classes">
  +    </ant:jar>
  +
  +    <ant:jar 
jarfile="${basedir}/target/test-classes/repository/test/jars/includes.jar">
  +      <zipfileset dir="${basedir}/src/test/conf" prefix="BLOCK-INF/">
  +        <include name="block.xml"/>
  +      </zipfileset>
       </ant:jar>
   
       <ant:delete>
  
  
  
  1.14      +3 -3      
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultClassLoaderModel.java      22 Jul 2003 04:11:57 -0000      1.13
  +++ DefaultClassLoaderModel.java      31 Jul 2003 22:52:47 -0000      1.14
  @@ -273,9 +273,9 @@
       * @param profile the profile directive
       * @return a new classloader context
       */
  -    public ClassLoaderContext createChildContext( ContainmentProfile profile )
  +    public ClassLoaderContext createChildContext( ContainmentProfile profile, 
String name )
       {
  -        Logger logger = getLogger().getChildLogger( profile.getName() );
  +        Logger logger = getLogger().getChildLogger( name );
           Repository repository = m_context.getRepository();
           File base = m_context.getBaseDirectory();
           OptionalPackage[] packages = getOptionalPackages();
  
  
  
  1.4       +16 -3     
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentContext.java
  
  Index: DefaultContainmentContext.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentContext.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultContainmentContext.java    17 Jul 2003 21:21:57 -0000      1.3
  +++ DefaultContainmentContext.java    31 Jul 2003 22:52:47 -0000      1.4
  @@ -98,6 +98,8 @@
   
       private final SystemContext m_system;
   
  +    private final String m_name;
  +
       //==============================================================
       // constructor
       //==============================================================
  @@ -121,7 +123,7 @@
       {
           this( logger, system, model, 
             system.getHomeDirectory(), system.getTempDirectory(), 
  -          profile, null );
  +          profile, null, "" );
       }
   
      /**
  @@ -139,7 +141,7 @@
       */
       public DefaultContainmentContext( 
         Logger logger, SystemContext system, ClassLoaderModel model, 
  -      File home, File temp, ContainmentProfile profile, String partition )
  +      File home, File temp, ContainmentProfile profile, String partition, String 
name )
       {
           if( logger == null )
           {
  @@ -188,11 +190,22 @@
           m_temp = temp;
           m_profile = profile;
           m_partition = partition;
  +        m_name = name;
       }
   
       //==============================================================
       // ContainmentContext
       //==============================================================
  +
  +   /**
  +    * Return the name that the container has been assigned.
  +    *
  +    * @return the container name
  +    */
  +    public String getName()
  +    {
  +        return m_name;
  +    }
   
      /**
       * Return the partition name that the container is 
  
  
  
  1.20      +110 -43   
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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DefaultContainmentModel.java      31 Jul 2003 17:42:38 -0000      1.19
  +++ DefaultContainmentModel.java      31 Jul 2003 22:52:47 -0000      1.20
  @@ -51,6 +51,9 @@
   package org.apache.avalon.composition.model.impl;
   
   import java.io.File;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLClassLoader;
   import java.util.Hashtable;
  @@ -63,6 +66,7 @@
   import org.apache.avalon.composition.data.ContainmentProfile;
   import org.apache.avalon.composition.data.DeploymentProfile;
   import org.apache.avalon.composition.data.Profile;
  +import org.apache.avalon.composition.data.ResourceDirective;
   import org.apache.avalon.composition.data.ServiceDirective;
   import org.apache.avalon.composition.data.builder.ContainmentProfileBuilder;
   import org.apache.avalon.composition.model.ClassLoaderContext;
  @@ -77,6 +81,7 @@
   import org.apache.avalon.composition.model.ProfileSelector;
   import org.apache.avalon.composition.model.TypeRepository;
   import org.apache.avalon.composition.repository.Repository;
  +import org.apache.avalon.composition.repository.RepositoryException;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  @@ -106,18 +111,6 @@
       private static final ContainmentProfileBuilder BUILDER = 
         new ContainmentProfileBuilder();
   
  -    private static String getName( ContainmentContext context )
  -    {
  -        if( context.getPartitionName() == null )
  -        {
  -            return "";
  -        }
  -        else
  -        {
  -            return context.getContainmentProfile().getName();
  -        }
  -    }
  -
       private static String getPath( ContainmentContext context )
       {
           if( context.getPartitionName() == null )
  @@ -154,7 +147,7 @@
       public DefaultContainmentModel( final ContainmentContext context )
         throws ModelException
       {
  -        super( context.getLogger(), getPath( context ), getName( context ), 
  +        super( context.getLogger(), getPath( context ), context.getName(), 
             context.getContainmentProfile().getMode() );
   
           m_context = context;
  @@ -174,7 +167,6 @@
           }
       }
   
  -
       //==============================================================
       // Model
       //==============================================================
  @@ -241,25 +233,28 @@
   
       public Model addModel( Profile profile ) throws ModelException
       {
  +        Model model = null;
  +        final String name = profile.getName();
  +
           if( profile instanceof ContainmentProfile )
           {
               ContainmentProfile containment = (ContainmentProfile) profile;
  -            return addContainmentProfile( containment );
  +            model = createContainmentModel( containment );
           }
           else if( profile instanceof DeploymentProfile ) 
           {
               DeploymentProfile deployment = (DeploymentProfile) profile;
  -            return addDeploymentProfile( deployment );
  +            model = createDeploymentModel( deployment );
           }
           else if( profile instanceof BlockIncludeDirective ) 
           {
               BlockIncludeDirective directive = (BlockIncludeDirective) profile;
  -            return addBlockIncludeDirective( directive );
  +            model = createContainmentModel( directive );
           }
           else if( profile instanceof BlockCompositionDirective ) 
           {
               BlockCompositionDirective directive = (BlockCompositionDirective) 
profile;
  -            return addBlockCompositionDirective( directive );
  +            model = createContainmentModel( directive );
           }
           else
           {
  @@ -275,6 +270,9 @@
                   profile.getClass().getName() );
               throw new ModelException( error );
           }
  +
  +        m_models.put( name, model );
  +        return model;
       }
   
      /**
  @@ -284,7 +282,7 @@
       * @param profile a containment profile 
       * @return the composition model
       */
  -    private DeploymentModel addDeploymentProfile( final DeploymentProfile profile ) 
  +    private DeploymentModel createDeploymentModel( final DeploymentProfile profile 
) 
         throws ModelException
       {
           final String name = profile.getName();
  @@ -315,10 +313,7 @@
               // the argument.
               //
   
  -            final DeploymentModel model = new DefaultDeploymentModel( context );
  -            m_models.put( name, model );
  -
  -            return model;
  +            return new DefaultDeploymentModel( context );
           }
           catch( Throwable e )
           {
  @@ -338,13 +333,28 @@
       * @param profile a containment profile 
       * @return the composition model
       */
  -    private ContainmentModel addContainmentProfile( final ContainmentProfile 
profile ) 
  +    private ContainmentModel createContainmentModel( 
  +      final ContainmentProfile profile ) 
         throws ModelException
       {
           final String name = profile.getName();
  +        return createContainmentModel( name, profile );
  +    }
  +
  +   /**
  +    * Creation of a new instance of a containment model within
  +    * this containment context.
  +    *
  +    * @param name the containment name
  +    * @param profile a containment profile 
  +    * @return the composition model
  +    */
  +    private ContainmentModel createContainmentModel( 
  +      final String name, final ContainmentProfile profile ) 
  +      throws ModelException
  +    {
           final String partition = getPartition();
           final Logger logger = getLogger().getChildLogger( name );
  -
           if( getLogger().isDebugEnabled() )
           {
               final String message = REZ.getString( "containment.add", name );
  @@ -354,7 +364,7 @@
           try
           {
               ClassLoaderContext cntx = 
  -              m_context.getClassLoaderModel().createChildContext( profile );
  +              m_context.getClassLoaderModel().createChildContext( profile, name );
               final ClassLoaderModel classLoaderModel = 
                 DefaultClassLoaderModel.createClassLoaderModel( cntx );
               final File home = new File( m_context.getHomeDirectory(), name );
  @@ -363,7 +373,7 @@
               DefaultContainmentContext context = 
                 new DefaultContainmentContext( 
                   logger, m_context.getSystemContext(), 
  -                classLoaderModel, home, temp, profile, getPartition() );
  +                classLoaderModel, home, temp, profile, getPartition(), name );
   
               //
               // TODO: lookup the profile for a factory declaration, then 
  @@ -371,11 +381,7 @@
               // the argument.
               //
   
  -            final ContainmentModel model = 
  -              new DefaultContainmentModel( context );
  -            m_models.put( name, model );
  -
  -            return model;
  +            return new DefaultContainmentModel( context );
           }
           catch( Throwable e )
           {
  @@ -393,24 +399,77 @@
       * @param directive the block composition directive
       * @return the containment model established by the include
       */
  -    private ContainmentModel addBlockCompositionDirective( 
BlockCompositionDirective directive )
  +    private ContainmentModel createContainmentModel( 
  +      BlockCompositionDirective directive ) throws ModelException
       {
  -        //
  -        // TODO
  -        // construct an input stream from the repository resource
  -        // jar file /BLOCK_INF/block.xml and use this to create the 
  -        // containment profile and use the profile to create the model
  -        //
  +        final String name = directive.getName();
  +        final ResourceDirective resource = directive.getResource();
  +        final String id = resource.getId();
  +        final String version = resource.getVersion();
  +        
  +        try
  +        {
  +            Repository repository = m_context.getSystemContext().getRepository();
  +            final URL url = repository.getArtifact( id, version, "jar" );
  +            final URL jarURL = convertToJarURL( url );
  +            final URL blockURL = new URL( jarURL, "/BLOCK-INF/block.xml" );
  +            final InputStream stream = blockURL.openStream();
  +            final ContainmentProfile profile = 
  +              BUILDER.createContainmentProfile( stream );
   
  -        throw new UnsupportedOperationException();
  +            final String message = 
  +              "including composite block: " + blockURL.toString();
  +            getLogger().debug( message );
  +
  +            return createContainmentModel( name, profile );
  +
  +        }
  +        catch( RepositoryException e )
  +        {
  +            final String error = 
  +              "Unable to include block [" + name 
  +              + "] into the containmment model [" 
  +              + getQualifiedName() 
  +              + "] because of a repository related error.";
  +            throw new ModelException( error, e );
  +        }
  +        catch( MalformedURLException e )
  +        {
  +            final String error = 
  +              "Unable to include block [" + name 
  +              + "] into the containmment model [" 
  +              + getQualifiedName() 
  +              + "] because of a url related error.";
  +            throw new ModelException( error, e );
  +        }
  +        catch( IOException e )
  +        {
  +            final String error = 
  +              "Unable to include block [" + name 
  +              + "] into the containmment model [" 
  +              + getQualifiedName() 
  +              + "] because of a io related error.";
  +            throw new ModelException( error, e );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Unable to include block [" + name 
  +              + "] into the containmment model [" 
  +              + getQualifiedName() 
  +              + "] because of an unexpected error.";
  +            throw new ModelException( error, e );
  +        }
       }
   
      /**
  -    * Add a containment profile that is derived from an external source.
  +    * Create a containment model that is derived from an external 
  +    * source profile defition.
  +    *
       * @param directive the block include directive
       * @return the containment model established by the include
       */
  -    private ContainmentModel addBlockIncludeDirective( BlockIncludeDirective 
directive )
  +    private ContainmentModel createContainmentModel( BlockIncludeDirective 
directive )
       {
           //
           // TODO
  @@ -591,8 +650,16 @@
           return m_context.getContainmentProfile().getServiceDirectives();
       }
   
  +    private URL convertToJarURL( URL url ) throws MalformedURLException
  +    {
  +        if( url.getProtocol().equals( "jar" ) ) return url;
  +        return new URL( "jar:" + url.toString() + "!/" );
  +    }
  +
       public String toString()
       {
           return "[containment model: " + getQualifiedName() + "]";
       }
  +
  +
   }
  
  
  
  1.7       +3 -4      
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultModelFactory.java
  
  Index: DefaultModelFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultModelFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultModelFactory.java  31 Jul 2003 17:42:38 -0000      1.6
  +++ DefaultModelFactory.java  31 Jul 2003 22:52:47 -0000      1.7
  @@ -133,7 +133,8 @@
           {
               final URLConnection connection = url.openConnection();
               final InputStream stream = connection.getInputStream();
  -            final ContainmentProfile profile = BUILDER.createContainmentProfile( 
stream );
  +            final ContainmentProfile profile = 
  +              BUILDER.createContainmentProfile( stream );
               return createContainmentModel( profile );
           }
           catch( Throwable e )
  @@ -168,9 +169,7 @@
               Repository repository = m_system.getRepository();
               File base = m_system.getBaseDirectory();
   
  -            //ClassLoader root = ClassLoader.getSystemClassLoader();
               ClassLoader root = m_system.getCommonClassLoader();
  -
               ClassLoaderDirective classLoaderDirective = 
                 profile.getClassLoaderDirective();
   
  
  
  
  1.8       +41 -5     
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultSystemContext.java 17 Jul 2003 21:21:57 -0000      1.7
  +++ DefaultSystemContext.java 31 Jul 2003 22:52:47 -0000      1.8
  @@ -64,6 +64,7 @@
   import org.apache.avalon.composition.repository.Repository;
   import org.apache.avalon.composition.repository.impl.FileRepository;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.logger.ConsoleLogger;
   import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  @@ -96,9 +97,9 @@
       * @return a system context
       */
       public static SystemContext createSystemContext( 
  -      File base, File root ) throws Exception
  +      File base, File root, int priority ) throws Exception
       {
  -        LoggingManager logging = createLoggingManager( base );
  +        LoggingManager logging = createLoggingManager( base, priority );
           Logger logger = logging.getSystemLoggerForCategory( "" );
           Repository repository = createRepository( root, logger );
           return new DefaultSystemContext( logging, base, repository );
  @@ -117,17 +118,52 @@
           return repository;
       }
   
  -    private static LoggingManager createLoggingManager( File base ) throws Exception
  +    private static LoggingManager createLoggingManager( File base, int priority ) 
throws Exception
       {
  +        final String level = getStringPriority( priority );
           LoggingDescriptor logging =
                   new LoggingDescriptor(
  -                        "", "DEBUG", null,
  +                        "", level, null,
                           new TargetDescriptor[0],
                           new CategoryDirective( "logging", "WARN" ) );
   
           DefaultLoggingManager manager = 
             new DefaultLoggingManager( base, "sys", logging );
           return manager;
  +    }
  +
  +    private static String getStringPriority( int priority )
  +    {
  +        if( priority == ConsoleLogger.LEVEL_DISABLED )
  +        {
  +            return "NONE";
  +        }
  +        else if( priority == ConsoleLogger.LEVEL_DEBUG )
  +        {
  +            return "DEBUG";
  +        }
  +        else if( priority == ConsoleLogger.LEVEL_INFO )
  +        {
  +            return "INFO";
  +        }
  +        else if( priority == ConsoleLogger.LEVEL_WARN )
  +        {
  +            return "WARN";
  +        }
  +        else if( priority == ConsoleLogger.LEVEL_ERROR )
  +        {
  +            return "ERROR";
  +        }
  +        else if( priority == ConsoleLogger.LEVEL_FATAL )
  +        {
  +            return "FATAL";
  +        }
  +        else
  +        {
  +            final String error = 
  +             "Unrecognized logging priority: " + priority;
  +            throw new IllegalArgumentException( error );
  +        }
       }
   
       //==============================================================
  
  
  
  1.7       +5 -2      
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractTestCase.java     17 Jul 2003 21:21:58 -0000      1.6
  +++ AbstractTestCase.java     31 Jul 2003 22:52:47 -0000      1.7
  @@ -32,13 +32,15 @@
   
   public abstract class AbstractTestCase extends TestCase
   {
  +    public int PRIORITY = ConsoleLogger.LEVEL_WARN;
  +
      //-------------------------------------------------------
      // state
      //-------------------------------------------------------
   
       public ContainmentModel m_model;
   
  -    private Logger m_logger = new ConsoleLogger();
  +    private Logger m_logger = new ConsoleLogger( PRIORITY );
   
       private String m_path;
   
  @@ -76,7 +78,8 @@
               File confDir = new File( base, "conf" );
               File source = new File( confDir, m_path );
   
  -            SystemContext system = DefaultSystemContext.createSystemContext( base, 
repository );
  +            SystemContext system = 
  +              DefaultSystemContext.createSystemContext( base, repository, PRIORITY 
);
               m_model = system.getFactory().createContainmentModel( source.toURL() );
           }
       }
  
  
  
  1.8       +3 -2      
avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ClassLoaderModel.java
  
  Index: ClassLoaderModel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ClassLoaderModel.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ClassLoaderModel.java     17 Jul 2003 21:22:00 -0000      1.7
  +++ ClassLoaderModel.java     31 Jul 2003 22:52:47 -0000      1.8
  @@ -130,7 +130,8 @@
       * relative parent.
       *
       * @param profile the containment profile
  +    * @param name the container name
       * @return a new classloader context
       */
  -    ClassLoaderContext createChildContext( ContainmentProfile profile );
  +    ClassLoaderContext createChildContext( ContainmentProfile profile, String name 
);
   }
  
  
  
  1.4       +8 -1      
avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ContainmentContext.java
  
  Index: ContainmentContext.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ContainmentContext.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ContainmentContext.java   17 Jul 2003 21:22:00 -0000      1.3
  +++ ContainmentContext.java   31 Jul 2003 22:52:47 -0000      1.4
  @@ -107,6 +107,13 @@
       ContainmentProfile getContainmentProfile();
   
      /**
  +    * Return the name that the container has been assigned.
  +    *
  +    * @return the container name
  +    */
  +    String getName();
  +
  +   /**
       * Return the partition name that the container is 
       * established with.
       *
  
  
  

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

Reply via email to