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/merlin/composition/src/java/org/apache/avalon/composition/model/impl DefaultConstructorModel.java DefaultContainmentModel.java DefaultContextModel.java DefaultDeploymentContext.java DefaultDeploymentModel.java DefaultImportModel.java DefaultModelFactory.java DefaultSystemContext.java Resources.properties
Date Mon, 14 Jul 2003 04:46:24 GMT
mcconnell    2003/07/13 21:46:24

  Modified:    merlin/composition/src/java/org/apache/avalon/composition/model/impl
                        DefaultConstructorModel.java
                        DefaultContainmentModel.java
                        DefaultContextModel.java
                        DefaultDeploymentContext.java
                        DefaultDeploymentModel.java DefaultImportModel.java
                        DefaultModelFactory.java DefaultSystemContext.java
                        Resources.properties
  Log:
  Context management enhancements including support for alias management, and context building
using constructed, included and standard context entries.
  
  Revision  Changes    Path
  1.2       +7 -8      avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultConstructorModel.java
  
  Index: DefaultConstructorModel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultConstructorModel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultConstructorModel.java	11 Jul 2003 11:06:30 -0000	1.1
  +++ DefaultConstructorModel.java	14 Jul 2003 04:46:24 -0000	1.2
  @@ -71,7 +71,7 @@
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    * @version $Revision$ $Date$
    */
  -public class DefaultConstructorModel extends DefaultContextEntryModel
  +public class DefaultConstructorModel extends DefaultEntryModel
   {
       //==============================================================
       // static
  @@ -110,12 +110,11 @@
       * @param context the containment context
       */
       public DefaultConstructorModel( 
  -      EntryDescriptor descriptor, ConstructorDirective directive, DeploymentContext context,
Map map )
  +      EntryDescriptor descriptor, ConstructorDirective directive, 
  +      DeploymentContext context, Map map )
       {
  -        if( descriptor == null )
  -        {
  -            throw new NullPointerException( "descriptor" );
  -        }
  +        super( descriptor );
  +
           if( directive == null )
           {
               throw new NullPointerException( "directive" );
  @@ -131,7 +130,7 @@
       }
   
       //==============================================================
  -    // ContextEntryModel
  +    // EntryModel
       //==============================================================
   
      /**
  
  
  
  1.12      +22 -5     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultContainmentModel.java	11 Jul 2003 11:06:30 -0000	1.11
  +++ DefaultContainmentModel.java	14 Jul 2003 04:46:24 -0000	1.12
  @@ -56,6 +56,7 @@
   import java.util.Hashtable;
   import java.util.List;
   import java.util.ArrayList;
  +import java.util.Map;
   
   import org.apache.avalon.composition.model.ClassLoaderContext;
   import org.apache.avalon.composition.model.ClassLoaderModel;
  @@ -128,7 +129,7 @@
   
       private String m_partition;
   
  -    private final List m_models = new ArrayList();
  +    private final Map m_models = new Hashtable();
   
       //==============================================================
       // constructor
  @@ -287,7 +288,13 @@
               //
   
               final DeploymentModel model = new DefaultDeploymentModel( context );
  -            m_models.add( model );
  +            m_models.put( name, model );
  +
  +            if( getLogger().isDebugEnabled() )
  +            {
  +                final String message = REZ.getString( "containment.add", name );
  +                getLogger().debug( message );
  +            }
   
               return model;
           }
  @@ -338,7 +345,7 @@
   
               final ContainmentModel model = 
                 new DefaultContainmentModel( context );
  -            m_models.add( model );
  +            m_models.put( name, model );
   
               return model;
           }
  @@ -368,8 +375,18 @@
       */
       public Model[] getModels()
       {
  -        return (Model[]) m_models.toArray( new Model[0] );
  +        return (Model[]) m_models.values().toArray( new Model[0] );
       }
  +
  +   /**
  +    * Return a model relative to a supplied name.
  +    * @return the named model or null if the name is unknown
  +    */
  +    public Model getModel( String name )
  +    {
  +        return (Model) m_models.get( name );
  +    }
  +
   
       //==============================================================
       // implementation
  
  
  
  1.3       +126 -45   avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContextModel.java
  
  Index: DefaultContextModel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContextModel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultContextModel.java	11 Jul 2003 11:06:30 -0000	1.2
  +++ DefaultContextModel.java	14 Jul 2003 04:46:24 -0000	1.3
  @@ -52,6 +52,7 @@
   
   import java.util.Map;
   import java.util.Hashtable;
  +import java.lang.reflect.Constructor;
   
   import org.apache.avalon.composition.model.ContextModel;
   import org.apache.avalon.composition.model.ModelException;
  @@ -62,7 +63,6 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.context.ContextException;
  -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;
  @@ -97,7 +97,8 @@
       /**
        * The default context strategy interface class.
        */
  -    public static final Class DEFAULT_STRATEGY_CLASS = Contextualizable.class;
  +    public static final String DEFAULT_STRATEGY_CLASSNAME = 
  +      "org.apache.avalon.framework.context.Contextualizable";
   
       //==============================================================
       // immutable state
  @@ -109,16 +110,14 @@
   
       private final DeploymentContext m_context;
   
  -    // --
  -
       private final Class m_strategy;
   
  -    private final Class m_contextClass;
  -
       private final Map m_models = new Hashtable();
   
       private final Map m_map = new Hashtable();
   
  +    private final Context m_componentContext;
  +
       //==============================================================
       // constructor
       //==============================================================
  @@ -144,12 +143,7 @@
           m_context = context;
   
           ClassLoader classLoader = context.getClassLoader();
  -        m_strategy = 
  -          loadStrategyClass( descriptor, classLoader );
  -        m_contextClass = 
  -          loadContextClass( directive, classLoader );
  -        validateCastingConstraint( 
  -         descriptor, classLoader, m_contextClass );
  +        m_strategy = loadStrategyClass( descriptor, classLoader );
   
           //
           // get the set of context entries declared by the component type
  @@ -167,6 +161,7 @@
                   try
                   {
                       Object value = m_context.resolve( key );
  +                    m_map.put( key, value );
                   }
                   catch( ContextException e )
                   {
  @@ -206,7 +201,7 @@
                         (ImportDirective) entryDirective;
                       DefaultImportModel model = 
                         new DefaultImportModel( entry, importDirective, context, m_map );
  -                    m_context.register( key, model );
  +                    m_context.register( model );
                       m_map.put( key, model.getValue() );
                   }
                   else if( entryDirective instanceof ConstructorDirective )
  @@ -215,7 +210,7 @@
                         (ConstructorDirective) entryDirective;
                       DefaultConstructorModel model = 
                         new DefaultConstructorModel( entry, constructor, context, m_map );
  -                    m_context.register( key, model );
  +                    m_context.register( model );
                       m_map.put( key, model.getValue() );
                   }
                   else
  @@ -229,6 +224,8 @@
               }
           }
   
  +        m_componentContext = createComponentContext( m_context, descriptor, directive );
  +
           if( getLogger().isDebugEnabled() )
           {
               getLogger().debug( "context: " + m_map );
  @@ -250,28 +247,13 @@
       }
   
      /**
  -    * 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. The
  -    * map contains a set of keys corresponding to the context 
  -    * entries declared by the component type.  Each key maps to 
  -    * either the directly resolved stardard context key, or, 
  -    * an instance of ContextEntryModel from which a contest entry
  -    * value may be resolved at runtime.
  +    * Return the context objct established for the component.
       * 
  -    * @return the context map
  +    * @return the context object
       */
  -    public Map getContextMap()
  +    public Context getContext()
       {
  -        return m_map;
  +        return m_componentContext;
       }
   
       //==============================================================
  @@ -298,33 +280,107 @@
                   if( getLogger().isDebugEnabled() )
                   {
                       final String message = 
  -                      "Custom strategy: " + clazz.getName();
  +                      REZ.getString( "context.strategy.custom", strategy );
                       getLogger().debug( message );
                   }
                   return clazz;
               }
  +            catch( ClassNotFoundException e )
  +            {
  +                final String error = 
  +                  REZ.getString( "context.strategy.custom.missing.error", strategy );
  +                throw new ModelException( error );
  +            }
               catch( Throwable e )
               {
                   final String error = 
  -                  "Cannot load custom contextualization strategy class: "
  -                  + strategy;
  +                  REZ.getString( "context.strategy.custom.unexpected.error", strategy );
                   throw new ModelException( error, e );
               }
           }
           else
           {
  -            if( getLogger().isDebugEnabled() )
  +            try
  +            {
  +                Class clazz = classLoader.loadClass( DEFAULT_STRATEGY_CLASSNAME );
  +                if( getLogger().isDebugEnabled() )
  +                {
  +                    final String message = 
  +                      REZ.getString( "context.strategy.avalon" );
  +                    getLogger().debug( message );
  +                }
  +                return clazz;
  +            }
  +            catch( ClassNotFoundException e )
  +            {
  +                final String error = 
  +                  REZ.getString( 
  +                    "context.strategy.avalon.missing.error", 
  +                    DEFAULT_STRATEGY_CLASSNAME );
  +                throw new ModelException( error );
  +            }
  +            catch( Throwable e )
               {
  -                final String message = "classic strategy";
  -                getLogger().debug( message );
  +                final String error = 
  +                  REZ.getString( 
  +                    "context.strategy.avalon.unexpected.error",
  +                    DEFAULT_STRATEGY_CLASSNAME );
  +                throw new ModelException( error, e );
               }
  -            return DEFAULT_STRATEGY_CLASS;
  +        }
  +    }
  +
  +   /**
  +    * Creates a compoent context using a deployment context that 
  +    * has been pre-populated with constom context entry models.
  +    * 
  +    * @param context the deployment context
  +    * @param clazz the context implmentation class
  +    * @return the context object compliant with the context casting
  +    *   constraints declared by the component type
  +    * @exception ModelException if an error occurs while attempting to 
  +    *   construct the context instance
  +    */
  +    private Context createComponentContext( 
  +      DeploymentContext context, ContextDescriptor descriptor, ContextDirective directive
)
  +      throws ModelException
  +    {
  +        ClassLoader classLoader = context.getClassLoader();
  +        Class clazz = loadContextClass( directive, classLoader );
  +        validateCastingConstraint( descriptor, classLoader, clazz );
  +        Context base = new DefaultContext( context );
  +
  +        if( clazz.equals( DefaultContext.class ) ) return base; 
  +
  +        //
  +        // its a custom context object so we need to create it 
  +        // using the classic context object as the constructor 
  +        // argument
  +        //
  +
  +        try
  +        {
  +            Constructor constructor = clazz.getConstructor(
  +                new Class[]{ Context.class } );
  +            return (Context) constructor.newInstance( new Object[]{ base } );
  +        }
  +        catch( NoSuchMethodException e )
  +        {
  +            final String error =
  +              REZ.getString( "context.non-compliance-constructor.error", clazz.getName()
);
  +            throw new ModelException( error, e );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error =
  +              REZ.getString( "context.custom-unexpected.error", clazz.getName() );
  +            throw new ModelException( error, e );
           }
       }
   
      /**
       * Load the context implementation class.
  -    * @param directive the context directive
  +    * @param directive the context directive (possibly null)
       * @param classLoader the classloader 
       * @return the strategy class
       */
  @@ -332,10 +388,15 @@
          ContextDirective directive, ClassLoader classLoader )
         throws ModelException
       {
  +        if( directive == null )
  +        {
  +            return DEFAULT_CONTEXT_CLASS;
  +        }
  +
           final String classname = m_directive.getClassname();
           if( classname == null )
           {
  -            return DefaultContext.class;
  +            return DEFAULT_CONTEXT_CLASS;
           }
           else
           {
  @@ -368,7 +429,7 @@
         throws ModelException
       {
   
  -        Class castingClass = Context.class;
  +        Class castingClass = null;
   
           final String castingClassName = 
             descriptor.getReference().getClassname();
  @@ -388,11 +449,31 @@
                   throw new ModelException( error, e );
               }
           }
  +        else
  +        {
  +            try
  +            {
  +                castingClass =
  +                  classLoader.loadClass( Context.class.getName() );
  +            }
  +            catch( Throwable e )
  +            {
  +                final String error = 
  +                  "Cannot load standard Avalon context interface class: "
  +                  + Context.class.getName();
  +                throw new ModelException( error, e );
  +            }
  +        }
   
           if( !castingClass.isAssignableFrom( clazz ) )
           {
  +System.out.println( "CONTEXT CLASSLOADER: " + castingClass.getClassLoader() );
  +for( int i=0; i<clazz.getInterfaces().length; i++ )
  +{
  +System.out.println( "SYS CLASSLOADER: " + clazz.getInterfaces()[i].getClassLoader() );
  +}
               final String error = 
  -              "Supplied context implementation class: " 
  +              "### Supplied context implementation class: " 
                 + clazz.getName() 
                 + " does not implement the interface: " 
                 + castingClass.getName()
  
  
  
  1.4       +46 -32    avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentContext.java
  
  Index: DefaultDeploymentContext.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentContext.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultDeploymentContext.java	11 Jul 2003 11:06:30 -0000	1.3
  +++ DefaultDeploymentContext.java	14 Jul 2003 04:46:24 -0000	1.4
  @@ -55,7 +55,7 @@
   import java.util.Hashtable;
   
   import org.apache.avalon.composition.model.SystemContext;
  -import org.apache.avalon.composition.model.ContextEntryModel;
  +import org.apache.avalon.composition.model.EntryModel;
   import org.apache.avalon.composition.model.ContainmentContext;
   import org.apache.avalon.composition.model.DeploymentContext;
   import org.apache.avalon.composition.model.ModelException;
  @@ -65,8 +65,9 @@
   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;
  +import org.apache.avalon.meta.info.Type;
  +import org.apache.avalon.meta.info.EntryDescriptor;
   
   
   /**
  @@ -108,8 +109,8 @@
       private final String m_partition;
   
      /**
  -    * Map containing the supplimentary context entries 
  -    * key by context enty key.
  +    * Map containing context entry models 
  +    * keyed by entry key.
       */
       private final Map m_map = new Hashtable();
   
  @@ -298,8 +299,9 @@
       * @param key
       * @param value
       */
  -    public void register( String key, ContextEntryModel model )
  +    public void register( EntryModel model )
       {
  +        final String key = model.getKey();
           if( m_map.get( key ) == null )
           {
               m_map.put( key, model );
  @@ -307,22 +309,28 @@
           else
           {
               final String error = 
  -              "Illegal attempt to override an existing model entry: " + key;
  +              REZ.getString( "deployment.registration.override.error", key );
               throw new IllegalArgumentException( error );
           }
       }
   
      /**
       * Get a context entry from the deployment context.
  -    * @param key the entry lookup key
  +    * @param alias the entry lookup key
       * @return value the corresponding value
       * @exception ContextException if the key is unknown
  +    * @exception ModelRuntimeException if the key is unknown
       */
  -    public Object resolve( String key ) throws ContextException
  +    public Object resolve( final String alias ) throws ContextException
       {
  -        Object object = m_map.get( key );
  -        if( object == null )
  +        if( alias == null ) throw new NullPointerException( "alias" );
  +
  +        EntryDescriptor entry = 
  +          getType().getContext().getEntry( alias );
  +
  +        if( entry != null )
           {
  +            final String key = entry.getKey();
               if( key.equals( NAME_KEY ) )
               {
                   return getName();
  @@ -345,31 +353,37 @@
               }
               else
               {
  -                throw new ContextException( key );
  -            }
  -        }
  -
  -        if( object instanceof ContextEntryModel )
  -        {
  -            final String classname = object.getClass().getName();
  -            try
  -            {
  -                return ((ContextEntryModel)object).getValue();
  -            }
  -            catch( Throwable e )
  -            {
  -                final String error = 
  -                  REZ.getString( 
  -                    "deployment.context.runtime-get", 
  -                    key, classname );
  -                throw new ModelRuntimeException( error, e );
  +                Object object = m_map.get( key );
  +                if( null != object )
  +                {
  +                    final String classname = object.getClass().getName();
  +                    try
  +                    {
  +                        return ((EntryModel)object).getValue();
  +                    }
  +                    catch( Throwable e )
  +                    {
  +                        final String error = 
  +                          REZ.getString( 
  +                            "deployment.context.runtime-get", 
  +                            key, classname );
  +                        throw new ModelRuntimeException( error, e );
  +                    }
  +                }
  +                else
  +                {
  +                    final String error = 
  +                      REZ.getString( 
  +                        "deployment.context.runtime-get", key );
  +                    throw new ModelRuntimeException( error );
  +                }
               }
           }
           else
           {
  -            return object;
  +            final String error = 
  +              REZ.getString( "deployment.context.invalid-key-request", alias );
  +            throw new ContextException( error );
           }
       }
  -
  -
   }
  
  
  
  1.12      +85 -9     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultDeploymentModel.java	11 Jul 2003 11:06:30 -0000	1.11
  +++ DefaultDeploymentModel.java	14 Jul 2003 04:46:24 -0000	1.12
  @@ -99,6 +99,9 @@
       private static final Resources REZ =
               ResourceManager.getPackageResources( DefaultDeploymentModel.class );
   
  +   private static final String CONTEXTUALIZABLE = 
  +     "org.apache.avalon.framework.context.Contextualizable";
  +
       private static final Configuration EMPTY_CONFIGURATION =
         new DefaultConfiguration( 
           "configuration", DeploymentModel.class.getName() );
  @@ -111,6 +114,7 @@
   
       private final ContextModel m_contextModel;
   
  +    private final boolean m_contextDependent;
   
       //==============================================================
       // mutable state
  @@ -147,7 +151,6 @@
   
           m_context = context;
   
  -        
   
           ClassLoader classLoader = m_context.getClassLoader();
   
  @@ -181,7 +184,9 @@
               }
           }
   
  -        if( isContextDependent() )
  +        m_contextDependent = getContextDependentState();
  +
  +        if( m_contextDependent )
           {
               final ContextDescriptor contextDescriptor = 
                 m_context.getType().getContext();
  @@ -480,20 +485,91 @@
       */
       public boolean isContextDependent()
       {
  +        return m_contextDependent;
  +    }
  +
  +   /**
  +    * 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
  +    *   context otherwise FALSE
  +    */
  +    public boolean getContextDependentState()
  +    {
           if( m_context.getType().getStages().length > 0 )
           {
               return true;
           }
  -        else if( 
  -          Contextualizable.class.isAssignableFrom( 
  -            m_context.getDeploymentClass() ) )
  +
  +        Class base = m_context.getDeploymentClass();
  +        String strategy = 
  +          m_context.getType().getContext().getAttribute( 
  +              ContextDescriptor.STRATEGY_KEY, null );
  +        ClassLoader classLoader = m_context.getClassLoader();
  +
  +        if( strategy != null )
           {
  -            return true;
  +            Class contextualizable = 
  +              getComponentClass( classLoader, strategy );
  +
  +            if( contextualizable == null )
  +            {
  +                final String error = 
  +                  REZ.getString( 
  +                    "deployment.missing-strategy.error", 
  +                    strategy, base.getName() );
  +                throw new IllegalStateException( error );
  +            }
  +            else
  +            {
  +                if( contextualizable.isAssignableFrom( base ) )
  +                {
  +                    return true;
  +                }
  +                else
  +                {
  +                    final String error = 
  +                      REZ.getString( 
  +                        "deployment.inconsitent-strategy.error",
  +                        contextualizable, base );
  +                    throw new IllegalStateException( error );
  +                }
  +            }
           }
           else
           {
  -            return m_context.getType().getContext().getAttribute( 
  -              ContextDescriptor.STRATEGY_KEY, null ) != null;
  +            Class contextualizable = 
  +              getComponentClass( classLoader, CONTEXTUALIZABLE );
  +            if( contextualizable != null )
  +            {
  +                if( contextualizable.isAssignableFrom( base ) )
  +                {
  +                    return true;
  +                }
  +            }
  +        }
  +        return false;
  +    }
  +
  +    private Class getComponentClass( ClassLoader classLoader, String classname )
  +    {
  +        if( classLoader == null )
  +        {
  +            throw new NullPointerException( "classLoader" );
  +        }
  +        if( classname == null )
  +        {
  +            throw new NullPointerException( "classname" );
  +        }
  +
  +        try
  +        {
  +            return classLoader.loadClass( classname );
  +        }
  +        catch( ClassNotFoundException e )
  +        {
  +            return null;
           }
       }
   
  
  
  
  1.2       +3 -6      avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultImportModel.java
  
  Index: DefaultImportModel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultImportModel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultImportModel.java	11 Jul 2003 11:06:30 -0000	1.1
  +++ DefaultImportModel.java	14 Jul 2003 04:46:24 -0000	1.2
  @@ -71,7 +71,7 @@
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    * @version $Revision$ $Date$
    */
  -public class DefaultImportModel extends DefaultContextEntryModel
  +public class DefaultImportModel extends DefaultEntryModel
   {
       //==============================================================
       // static
  @@ -113,10 +113,7 @@
         EntryDescriptor descriptor, ImportDirective directive, 
         DeploymentContext context, Map map )
       {
  -        if( descriptor == null )
  -        {
  -            throw new NullPointerException( "descriptor" );
  -        }
  +        super( descriptor );
           if( directive == null )
           {
               throw new NullPointerException( "directive" );
  
  
  
  1.3       +37 -14    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultModelFactory.java	9 Jul 2003 05:02:05 -0000	1.2
  +++ DefaultModelFactory.java	14 Jul 2003 04:46:24 -0000	1.3
  @@ -51,6 +51,7 @@
   package org.apache.avalon.composition.model.impl;
   
   import java.io.File;
  +import java.net.URL;
   
   import org.apache.avalon.composition.model.ClassLoaderModel;
   import org.apache.avalon.composition.model.ClassLoaderContext;
  @@ -65,10 +66,13 @@
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.extension.manager.OptionalPackage;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   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;
  +import org.apache.avalon.meta.data.builder.XMLContainmentProfileCreator;
   
   /**
    * A factory enabling the establishment of new composition model instances.
  @@ -83,21 +87,12 @@
       // static
       //==============================================================
   
  +    private static final XMLContainmentProfileCreator CREATOR = 
  +      new XMLContainmentProfileCreator();
  +
       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
       //==============================================================
  @@ -124,6 +119,31 @@
   
      /**
       * Creation of a new root containment model using 
  +    * a URL referring to a containment profile.
  +    *
  +    * @param url a composition profile source
  +    * @return the containment model
  +    */
  +    public ContainmentModel createContainmentModel( URL url ) 
  +      throws ModelException
  +    {
  +        try
  +        {
  +            DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +            Configuration config = builder.build( url.toString() );
  +            ContainmentProfile profile = CREATOR.createContainmentProfile( config );
  +            return createContainmentModel( profile );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Unable to create a containment model from the url: " + url;
  +            throw new ModelException( error, e );
  +        }
  +    }
  +
  +   /**
  +    * Creation of a new root containment model using 
       * a supplied system context and containment profile
       * using the context classloader.
       *
  @@ -145,7 +165,10 @@
           {
               Repository repository = m_system.getRepository();
               File base = m_system.getBaseDirectory();
  -            ClassLoader root = ClassLoader.getSystemClassLoader();
  +
  +            //ClassLoader root = ClassLoader.getSystemClassLoader();
  +            ClassLoader root = m_system.getCommonClassLoader();
  +
               ClassLoaderDirective classLoaderDirective = 
                 profile.getClassLoaderDirective();
   
  
  
  
  1.6       +108 -23   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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultSystemContext.java	8 Jul 2003 13:47:06 -0000	1.5
  +++ DefaultSystemContext.java	14 Jul 2003 04:46:24 -0000	1.6
  @@ -52,13 +52,23 @@
   
   import java.io.File;
   import java.util.Map;
  +import java.net.URL;
  +import java.net.URLClassLoader;
   
  +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.impl.DefaultLoggingManager;
  +import org.apache.avalon.composition.model.ModelFactory;
   import org.apache.avalon.composition.model.SystemContext;
   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.context.DefaultContext;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.avalon.framework.context.DefaultContext;
  +import org.apache.avalon.meta.data.CategoryDirective;
   
   
   /**
  @@ -77,6 +87,49 @@
       private static final Resources REZ =
               ResourceManager.getPackageResources( DefaultSystemContext.class );
   
  +   /**
  +    * Creation of a new system context.
  +    *
  +    * @param base the base directory from which relative references 
  +    *   within a classpath or library directive shall be resolved
  +    * @param root a repository root directory
  +    * @return a system context
  +    */
  +    public static SystemContext createSystemContext( 
  +      File base, File root ) throws Exception
  +    {
  +        LoggingManager logging = createLoggingManager( base );
  +        Logger logger = logging.getSystemLoggerForCategory( "" );
  +        Repository repository = createRepository( root, logger );
  +        return new DefaultSystemContext( logging, base, repository );
  +    }
  +
  +    private static FileRepository createRepository( File root, Logger logger ) throws Exception
  +    {
  +        URL ibiblio = new URL( "http://www.ibiblio.org/maven" );
  +        FileRepository repository = new FileRepository();
  +        repository.enableLogging( logger );
  +        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;
  +    }
  +
  +    private static LoggingManager createLoggingManager( File base ) throws Exception
  +    {
  +        LoggingDescriptor logging =
  +                new LoggingDescriptor(
  +                        "", "DEBUG", null,
  +                        new TargetDescriptor[0],
  +                        new CategoryDirective( "logging", "WARN" ) );
  +
  +        DefaultLoggingManager manager = 
  +          new DefaultLoggingManager( base, "sys", logging );
  +        return manager;
  +    }
  +
       //==============================================================
       // immutable state
       //==============================================================
  @@ -89,10 +142,16 @@
   
       private final Repository m_repository;
   
  -    private final ClassLoader m_classLoader;
  +    private final ClassLoader m_system;
  +
  +    private final ClassLoader m_common;
  +
  +    private final LoggingManager m_logging;
   
       private final Logger m_logger;
   
  +    private ModelFactory m_factory;
  +
       //==============================================================
       // mutable state
       //==============================================================
  @@ -106,17 +165,18 @@
      /**
       * Creation of a new system context.
       *
  -    * @param system the system classloader
  +    * @param logger the logging channel
  +    * @param common the common 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( 
  -      Logger logger, ClassLoader system, File base, Repository repository )
  +      LoggingManager logging, File base, Repository repository )
       {
           this( 
  -          logger, system, base, 
  +          logging, base, 
             new File( System.getProperty( "user.dir" ), "working" ), 
             repository );
       }
  @@ -124,45 +184,45 @@
      /**
       * Creation of a new system context.
       *
  -    * @param system the system classloader
  +    * @param logger the logging channel
  +    * @param common the common 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( 
  -      Logger logger, ClassLoader system, File base, File work, Repository repository )
  +      LoggingManager logging, File base, File working, Repository repository )
       {
           this( 
  -          logger, system, base, 
  -          new File( work, "home" ), 
  -          new File( work, "temp" ), 
  +          logging, base, 
  +          new File( working, "home" ), 
  +          new File( working, "temp" ), 
             repository );
       }
   
      /**
       * Creation of a new system context.
       *
  -    * @param system the system classloader
  +    * @param logger the logging channel
  +    * @param common the common 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 )
  +      LoggingManager logging, File base, File home, 
  +      File temp, Repository repository )
       {
  -        this( logger, system, base, home, temp, repository, false );
  +        this( logging, base, home, temp, repository, false );
       }
   
  +
      /**
       * Creation of a new system context.
       *
  -    * @param system the system classloader
  +    * @param logger the logging channel
       * @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
  @@ -173,7 +233,7 @@
       * @param trace flag indicating if internal logging is enabled
       */
       public DefaultSystemContext( 
  -      Logger logger, ClassLoader system, File base, File home, File temp, 
  +      LoggingManager logging, File base, File home, File temp, 
         Repository repository, boolean trace )
       {
           if( base == null )
  @@ -184,7 +244,7 @@
           {
               throw new NullPointerException( "repository" );
           }
  -        if( logger == null )
  +        if( logging == null )
           {
               throw new NullPointerException( "logger" );
           }
  @@ -200,8 +260,13 @@
           m_temp = temp;
           m_trace = trace;
           m_repository = repository;
  -        m_classLoader = system;
  -        m_logger = logger;
  +        m_logging = logging;
  +        m_logger = m_logging.getSystemLoggerForCategory( "" );
  +
  +        m_system = DefaultSystemContext.class.getClassLoader();
  +        m_common = Logger.class.getClassLoader();
  +
  +        m_factory = new DefaultModelFactory( this );
       }
   
       //==============================================================
  @@ -209,6 +274,16 @@
       //==============================================================
   
      /**
  +    * Return the model factory.
  +    *
  +    * @return the factory
  +    */
  +    public ModelFactory getFactory()
  +    {
  +        return m_factory;
  +    }
  +
  +   /**
       * Return the base directory from which relative classloader 
       * references may be resolved.
       *
  @@ -257,9 +332,19 @@
       *
       * @return the system classloader
       */
  +    public ClassLoader getCommonClassLoader()
  +    {
  +        return m_common;
  +    }
  +
  +   /**
  +    * Return the system classloader.
  +    *
  +    * @return the system classloader
  +    */
       public ClassLoader getSystemClassLoader()
       {
  -        return m_classLoader;
  +        return m_system;
       }
   
      /**
  
  
  
  1.9       +19 -0     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Resources.properties	11 Jul 2003 11:06:30 -0000	1.8
  +++ Resources.properties	14 Jul 2003 04:46:24 -0000	1.9
  @@ -17,6 +17,7 @@
   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}
  +containment.add=added: {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}.
  @@ -24,6 +25,11 @@
   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}
   deployment.context.runtime-get="Unable to resolve context value for key {0} due to an unexpected
runtime error in: " {1}
  +deployment.inconsitent-strategy.error=The custom contextualization strategy interface class
[{0}] is not implemented by the component class [{1}].
  +deployment.missing-strategy.error=The custom contextualization strategy interface class
[{0}] declared by the class [{1}] is not present in the containment context classloader.
  +deployment.context.invalid-key-request=The requested context resolution for the key [{0}]
cannot be performed because the component type does declare entry declaration as a key or
alias.
  +deployment.context.internal.error=The context key [{0}] was recognized but could not be
fulfilled as no context entry model has be assigned to handle the request.
  +deployment.registration.override.error=Illegal attempt to override an existing model entry
[{0}].
   
   # DefaultModel
   created=created: {0}
  @@ -63,10 +69,23 @@
   import.null-object.error=Resolution of the include directive for the containment key {0}
undeer the component context entry {1) return a null object reference. 
   
   #DefaultContextModel
  +context.strategy.custom=custom strategy: {0}
  +context.strategy.avalon=avalon strategy
   context.non-standard-avalon-key.error=The component has requested a Avalon context entry
that is not know within the family of standard Avalon context keys.  The offending key is:
{0}.
   
   context.missing-directive.error=The component has requested a non-avalon context entry.
The container cannot resolve this request because no entry directive can be found the matches
the key: {0}.
   
   context.unsupported-directive.error=The component has requested a context entry under the
key [{0}]. The container cannot resolve this request because the entry directive type [{1}]
is not supported at this time.
   
  +context.non-compliance-constructor.error="Custom context class [{0}] does not implement
a constructor pattern <init>( org.apache.avalon.framework.Context ).
  +
  +context.custom-unexpected.error=Unexpected error occured while attempting to construct
a custom context using the class [{0}].
  +
  +context.strategy.custom.missing.error=Custom stategy class [{0}] is not present in the
classpath. 
  +context.strategy.custom.unexpected.error=Unable to load the custom stategy class [{0}]
due to an unexpected error. 
  +context.strategy.avalon.missing.error=Classic Avalon context stategy class [{0}] is not
present in the classpath. 
  +context.strategy.avalon.unexpected.error=Unable to load the classic Avalon stategy class
[{0}] due to an unexpected error. 
  +
  +# DefaultContext
  +context.entry.model.error=Cannot fulfill request due to an model-related error while attempting
to resolve a context entry for the key: {0}.
   
  
  
  

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


Mime
View raw message