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/27 05:15:36 UTC
cvs commit: avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model ContainmentModel.java ModelSelector.java TypeRepository.java
mcconnell 2003/07/26 20:15:36
Modified: merlin maven.xml project.properties
merlin/composition/src/java/org/apache/avalon/composition/model/impl
DefaultContainmentModel.java
DefaultTypeRepository.java Resources.properties
merlin/composition-spi/src/java/org/apache/avalon/composition/model
ContainmentModel.java ModelSelector.java
TypeRepository.java
Log:
Enhancing the composition system to meet auto-assembly requirements.
Revision Changes Path
1.30 +2 -1 avalon-sandbox/merlin/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/maven.xml,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- maven.xml 24 Jul 2003 13:14:52 -0000 1.29
+++ maven.xml 27 Jul 2003 03:15:36 -0000 1.30
@@ -232,9 +232,9 @@
<j:forEach var="packageGroup" items="${pom.packageGroups}">
<group title="${packageGroup.title}" packages="${packageGroup.packages}"/>
</j:forEach>
- <!--
<sourcepath path="${basedir}/../extension-spi/src/java"/>
<sourcepath path="${basedir}/../extension/src/java"/>
+ <!--
-->
<sourcepath path="${basedir}/../composition-spi/src/java"/>
<sourcepath path="${basedir}/../composition/src/java"/>
@@ -249,6 +249,7 @@
</classpath>
<link href="${sun.j2se.link}" />
<link href="${avalon.framework.link}" />
+ <link href="${avalon.meta.link}" />
<link href="${avalon.logkit.link}" />
<link href="${avalon.lifecycle.link}" />
<link href="${excalibur.configuration.link}" />
1.4 +2 -1 avalon-sandbox/merlin/project.properties
Index: project.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/project.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- project.properties 10 Jun 2003 02:47:14 -0000 1.3
+++ project.properties 27 Jul 2003 03:15:36 -0000 1.4
@@ -17,6 +17,7 @@
sun.j2se.link = http://java.sun.com/j2se/1.4/docs/api/
avalon.framework.link = http://avalon.apache.org/framework/api/
+avalon.meta.link = http://avalon.apache.org/sandbox/avalon-meta/api/
avalon.logkit.link = http://avalon.apache.org/logkit/api/
avalon.lifecycle.link = http://avalon.apache.org/sandbox/lifecycle/api/
excalibur.configuration.link = http://avalon.apache.org/excalibur/configuration/api/
@@ -25,4 +26,4 @@
excalibur.threadcontext.link = http://avalon.apache.org/excalibur/threadcontext/api/
excalibur.event.link = http://avalon.apache.org/excalibur/event/api/
-maven.javadoc.links = ${sun.j2se.link},${avalon.logkit.link},${avalon.framework.link},${avalon.lifecycle.link},${excalibur.configuration.link},${excalibur.pool.link},${excalibur.thread.link},${excalibur.threadcontext.link},${excalibur.event.link}
+maven.javadoc.links = ${sun.j2se.link},${avalon.logkit.link},${avalon.framework.link},${avalon.meta.link},${avalon.lifecycle.link},${excalibur.configuration.link},${excalibur.pool.link},${excalibur.thread.link},${excalibur.threadcontext.link},${excalibur.event.link}
1.16 +176 -35 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DefaultContainmentModel.java 26 Jul 2003 16:27:57 -0000 1.15
+++ DefaultContainmentModel.java 27 Jul 2003 03:15:36 -0000 1.16
@@ -66,6 +66,9 @@
import org.apache.avalon.composition.model.Model;
import org.apache.avalon.composition.model.ModelException;
import org.apache.avalon.composition.model.SystemContext;
+import org.apache.avalon.composition.model.ModelSelector;
+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.framework.logger.Logger;
import org.apache.avalon.excalibur.i18n.ResourceManager;
@@ -161,34 +164,11 @@
Profile[] profiles = context.getContainmentProfile().getProfiles();
for( int i=0; i<profiles.length; i++ )
{
- Profile profile = profiles[i];
- if( profile instanceof ContainmentProfile )
- {
- ContainmentProfile containment = (ContainmentProfile) profile;
- addContainmentProfile( containment );
- }
- else if( profile instanceof DeploymentProfile )
- {
- DeploymentProfile deployment = (DeploymentProfile) profile;
- addDeploymentProfile( deployment );
- }
- else
- {
- //
- // TODO: establish the mechanisms for the declaration
- // of a custom profile handler.
- //
-
- final String error =
- REZ.getString(
- "containment.unknown-profile-class.error",
- getPath(),
- profile.getClass().getName() );
- throw new ModelException( error );
- }
+ addProfile( profiles[i] );
}
}
+
//==============================================================
// Model
//==============================================================
@@ -219,11 +199,15 @@
*/
public boolean isaCandidate( DependencyDescriptor dependency )
{
- //
- // TODO: implementation - needs to check the request
- // egainst the set of exported services.
- //
-
+ ServiceDescriptor[] services = getServices();
+ for( int i=0; i<services.length; i++ )
+ {
+ ServiceDescriptor service = services[i];
+ if( service.getReference().matches( dependency.getReference() ) )
+ {
+ return true;
+ }
+ }
return false;
}
@@ -236,7 +220,8 @@
{
//
// TODO-LATER: requires declaration of extension handling
- // export within the container meta-data
+ // export within the container meta-data - for now a container
+ // only exports services
//
return false;
@@ -244,7 +229,7 @@
/**
* Return the set of services that this model consumes.
- * @return the cumsumed depedencies
+ * @return the consumed dependencies
*/
public DependencyDescriptor[] getDependencies()
{
@@ -255,6 +240,34 @@
// ContainmentModel
//==============================================================
+ public Model addProfile( Profile profile ) throws ModelException
+ {
+ if( profile instanceof ContainmentProfile )
+ {
+ ContainmentProfile containment = (ContainmentProfile) profile;
+ return addContainmentProfile( containment );
+ }
+ else if( profile instanceof DeploymentProfile )
+ {
+ DeploymentProfile deployment = (DeploymentProfile) profile;
+ return addDeploymentProfile( deployment );
+ }
+ else
+ {
+ //
+ // TODO: establish the mechanisms for the declaration
+ // of a custom profile handler.
+ //
+
+ final String error =
+ REZ.getString(
+ "containment.unknown-profile-class.error",
+ getPath(),
+ profile.getClass().getName() );
+ throw new ModelException( error );
+ }
+ }
+
/**
* Creation of a new instance of a deployment model within
* this containment context.
@@ -376,7 +389,9 @@
}
/**
- * Return the set of models nested within this model.
+ * Return the set of immediate child models nested
+ * within this model.
+ *
* @return the nested model
*/
public Model[] getModels()
@@ -385,7 +400,7 @@
}
/**
- * Return a model relative to a supplied name.
+ * Return a immediate child model relative to a supplied name.
* @return the named model or null if the name is unknown
*/
public Model getModel( String name )
@@ -393,6 +408,132 @@
return (Model) m_models.get( name );
}
+ /**
+ * Get a local model relative to a supplied service dependency.
+ * @param dependency the service dependency descriptor
+ * @exception ModelException if an error occurs during model creation
+ */
+ public Model getModel( DependencyDescriptor dependency ) throws ModelException
+ {
+ //
+ // if an existing model exists return it
+ //
+
+ Model[] models = getModels();
+ ModelSelector modelSelector = new DefaultModelSelector();
+ Model model = modelSelector.select( models, dependency );
+ if( model != null ) return model;
+
+ //
+ // otherwise, check for any packaged profiles that
+ // we could use to construct the model
+ //
+
+ TypeRepository repository =
+ m_context.getClassLoaderModel().getTypeRepository();
+ ArrayList list = new ArrayList();
+ try
+ {
+ Type[] types = repository.getTypes( dependency );
+ for( int i=0; i<types.length; i++ )
+ {
+ Profile[] profiles = repository.getProfiles( types[i] );
+ for( int j=0; j<profiles.length; j++ )
+ {
+ list.add( profiles[i] );
+ }
+ }
+
+ //
+ // TODO: update this to handle meta-data directed selector
+ // creation (e.g. an extension urn) - problem is that we either
+ // declare that this method is invoked when we are auto
+ // creating a model on demand - in effect what we need is a
+ // DependencyDirective instead of the descriptor.
+ //
+
+ Profile[] collection = (Profile[]) list.toArray( new Profile[0] );
+ ProfileSelector selector = new DefaultProfileSelector();
+ Profile profile = selector.select( collection, dependency );
+ if( profile != null ) return addProfile( profile );
+ return null;
+ }
+ catch( Throwable e )
+ {
+ // should not happen
+ final String error =
+ REZ.getString(
+ "containment.model.create.error",
+ getPath(),
+ dependency.toString() );
+ throw new ModelException( error, e );
+ }
+ }
+
+ /**
+ * Return a model relative to a supplied stage descriptor.
+ * @param stage the stage descriptor
+ * @return model of a an stage handler or null if the stage is unresolvable
+ * @exception ModelException if an error occurs during model establishment
+ */
+ public Model getModel( StageDescriptor stage )
+ throws ModelException
+ {
+ //
+ // if an existing model exists return it
+ //
+
+ Model[] models = getModels();
+ ModelSelector modelSelector = new DefaultModelSelector();
+ Model model = modelSelector.select( models, stage );
+ if( model != null ) return model;
+
+ //
+ // otherwise, check for any packaged profiles that
+ // we could use to construct the model
+ //
+
+ TypeRepository repository =
+ m_context.getClassLoaderModel().getTypeRepository();
+
+ ArrayList list = new ArrayList();
+ try
+ {
+ Type[] types = repository.getTypes( stage );
+ for( int i=0; i<types.length; i++ )
+ {
+ Profile[] profiles = repository.getProfiles( types[i] );
+ for( int j=0; j<profiles.length; j++ )
+ {
+ list.add( profiles[i] );
+ }
+ }
+
+ //
+ // TODO: update this to handle meta-data directed selector
+ // creation (e.g. an extension urn) - problem is that we either
+ // declare that this method is invoked when we are auto
+ // creating a model on demand - in effect what we need is a
+ // DependencyDirective instead of the descriptor.
+ //
+
+ Profile[] collection = (Profile[]) list.toArray( new Profile[0] );
+ ProfileSelector selector = new DefaultProfileSelector();
+ Profile profile = selector.select( collection, stage );
+ if( profile != null ) return addProfile( profile );
+ return null;
+ }
+ catch( Throwable e )
+ {
+ // should not happen
+ final String error =
+ REZ.getString(
+ "containment.model.create.error",
+ getPath(),
+ stage.toString() );
+ throw new ModelException( error, e );
+ }
+ }
//==============================================================
// implementation
1.11 +84 -33 avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultTypeRepository.java
Index: DefaultTypeRepository.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultTypeRepository.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DefaultTypeRepository.java 25 Jul 2003 06:14:05 -0000 1.10
+++ DefaultTypeRepository.java 27 Jul 2003 03:15:36 -0000 1.11
@@ -181,8 +181,10 @@
if( getLogger().isDebugEnabled() )
{
final String message =
- REZ.getString( "type.repository.addition", classname, new Integer( n ) );
- getLogger().debug( "add: " + classname );
+ REZ.getString(
+ "type.repository.addition", classname,
+ new Integer( n ).toString() );
+ getLogger().debug( message );
}
}
}
@@ -279,8 +281,9 @@
}
/**
- * Locate the set of component types capable of services the supplied
- * dependency.
+ * Locate the set of component types in the local repository
+ * capable of servicing the supplied dependency.
+ *
* @param dependency a service dependency descriptor
* @return a set of types capable of servicing the supplied dependency
*/
@@ -292,31 +295,23 @@
}
ArrayList list = new ArrayList();
- if( m_parent != null )
- {
- Type[] types = m_parent.getTypes( dependency );
- for( int i = 0; i < types.length; i++ )
- {
- list.add( types[i] );
- }
- }
-
ReferenceDescriptor reference = dependency.getReference();
- Enumeration enum = m_types.elements();
- while( enum.hasMoreElements() )
+ Type[] types = getTypes( false );
+ for( int i=0; i<types.length; i++ )
{
- Type type = (Type) enum.nextElement();
- Object service = type.getService( reference );
- if( service != null )
+ Type type = types[i];
+ if( type.getService( reference ) != null )
{
list.add( type );
}
}
+
return (Type[]) list.toArray( new Type[0] );
}
/**
- * Locate the set of component types that provide the supplied extension.
+ * Locate the set of local component types that provide the
+ * supplied extension.
* @param stage a stage descriptor
* @return a set of types that support the supplied stage
*/
@@ -328,25 +323,15 @@
}
ArrayList list = new ArrayList();
- if( m_parent != null )
+ Type[] types = getTypes( false );
+ for( int i=0; i<types.length; i++ )
{
- Type[] types = m_parent.getTypes( stage );
- for( int i = 0; i < types.length; i++ )
- {
- list.add( types[i] );
- }
- }
-
- Iterator iterator = m_types.entrySet().iterator();
- while( iterator.hasNext() )
- {
- Type type = (Type) iterator.next();
+ Type type = types[i];
if( type.getExtension( stage ) != null )
{
list.add( type );
}
}
-
return (Type[]) list.toArray( new Type[0] );
}
@@ -378,6 +363,72 @@
throw new TypeUnknownException( classname );
}
}
+ }
+
+ /**
+ * Return the set of profiles matching the supplied dependency.
+ * @param dependency the dependency descriptor
+ * @return the set of available profiles
+ */
+ /*
+ public Profile[] getProfiles( DependencyDescriptor dependency )
+ {
+ if( dependency == null )
+ {
+ throw new NullPointerException( "dependency" );
+ }
+
+ Profile[] profiles = getProfiles();
+ ArrayList list = new ArrayList();
+ for( int i=0; i<profiles.length; i++ )
+ {
+ Profile profile = profiles[i];
+ Type type = getType( profile.getClassname() );
+ if( type != null )
+ {
+ if( type.getService( dependency ) != null )
+ {
+ list.add( profile );
+ }
+ }
+ return (Profile[]) list.toArray( new Profile[0] );
+ }
+ */
+
+ /**
+ * Return the set of profiles matching the supplied stage.
+ * @param stage the stage descriptor
+ * @return the set of extension profiles
+ */
+ /*
+ public Profile[] getProfiles( StageDescriptor stage )
+ {
+ if( stage == null )
+ {
+ throw new NullPointerException( "stage" );
+ }
+
+ Profile[] profiles = getProfiles();
+ ArrayList list = new ArrayList();
+ for( int i=0; i<profiles.length; i++ )
+ {
+ Profile profile = profiles[i];
+ if( profile.getExtensions( stage ) != null )
+ {
+ list.add( profile );
+ }
+ }
+ return (Profile[]) list.toArray( new Profile[0] );
+ }
+ */
+
+ /**
+ * Return the set of local profiles.
+ * @return a profile or null if a profile connot be resolve
+ */
+ private Profile[] getProfiles()
+ {
+ return (Profile[]) m_profiles.values().toArray( new Profile[0] );
}
protected Logger getLogger()
1.15 +3 -3 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Resources.properties 24 Jul 2003 13:14:54 -0000 1.14
+++ Resources.properties 27 Jul 2003 03:15:36 -0000 1.15
@@ -22,8 +22,8 @@
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}
-
+containment.add=installing: {0}
+containment.model.create.error=Unexpected error while attempting to build a model within the containment context [{0}] for a dependency [{1}].
# DefaultDeploymentModel
# ======================
@@ -48,7 +48,7 @@
type.repository.null-create.error=Internal error while creating NullComponent type defintion. {0}
type.repository.bootstrap.error=bootstrap: {0}
type.repository.count=type install count: {0}
-type.repository.addition=add: {0}, ({1}).
+type.repository.addition=registered [type:{0}/{1}].
#Scanner
1.11 +30 -3 avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ContainmentModel.java
Index: ContainmentModel.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ContainmentModel.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ContainmentModel.java 17 Jul 2003 21:22:00 -0000 1.10
+++ ContainmentModel.java 27 Jul 2003 03:15:36 -0000 1.11
@@ -52,8 +52,10 @@
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.ServiceDirective;
import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.StageDescriptor;
/**
* Containment model is an extended deployment model that aggregates
@@ -94,6 +96,33 @@
Model getModel( String name );
/**
+ * Return a model relative to a supplied dependency.
+ * @return a matching model or null if the dependency is unresolvable
+ * @exception ModelException if an error occurs during model establishment
+ */
+ Model getModel( DependencyDescriptor dependency )
+ throws ModelException;
+
+ /**
+ * Return a model relative to a supplied stage descriptor.
+ * @param stage the stage descriptor
+ * @return model of a an stage handler or null if the stage is unresolvable
+ * @exception ModelException if an error occurs during model establishment
+ */
+ Model getModel( StageDescriptor stage )
+ throws ModelException;
+
+ /**
+ * Addition of a new subsidiary model within
+ * the containment context using the supplied profile.
+ *
+ * @param profile a containment of deployment profile
+ * @return the model created from the profile
+ * @exception ModelException if an error occurs during model establishment
+ */
+ Model addProfile( Profile profile ) throws ModelException;
+
+ /**
* Addition of a new instance of a deployment model within
* the containment context using the supplied profile.
*
@@ -105,7 +134,6 @@
throws ModelException;
// TODO: replaceDeploymentProfile
-
// TODO: removeDeploymentProfile
/**
@@ -120,6 +148,5 @@
throws ModelException;
// TODO: replaceContainmentProfile
-
// TODO: removeContainmentProfile
}
1.3 +5 -3 avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ModelSelector.java
Index: ModelSelector.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/ModelSelector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ModelSelector.java 17 Jul 2003 21:22:00 -0000 1.2
+++ ModelSelector.java 27 Jul 2003 03:15:36 -0000 1.3
@@ -74,7 +74,8 @@
*
* @param models the set of candidate models
* @param dependency a service dependency
- * @return the preferred model or null if no satisfactory provider can be established
+ * @return the preferred model or null if no satisfactory provider
+ * can be established
*/
Model select( Model[] models, DependencyDescriptor dependency );
@@ -82,7 +83,8 @@
* Returns the preferred model from an available selection of candidates
* @param models the set of candidate models
* @param stage the stage dependency
- * @return the preferred provider or null if no satisfactory provider can be established
+ * @return the preferred provider or null if no satisfactory provider
+ * can be established
*/
Model select( Model[] models, StageDescriptor stage );
}
1.6 +15 -1 avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/TypeRepository.java
Index: TypeRepository.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model/TypeRepository.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TypeRepository.java 17 Jul 2003 21:22:00 -0000 1.5
+++ TypeRepository.java 27 Jul 2003 03:15:36 -0000 1.6
@@ -121,4 +121,18 @@
*/
DeploymentProfile[] getProfiles( Type type ) throws TypeUnknownException;
+ /**
+ * Return the set of profiles matching the supplied dependency.
+ * @param dependency the dependency descriptor
+ * @return the set of available profiles
+ */
+ //Profile[] getProfiles( DependencyDescriptor dependency );
+
+ /**
+ * Return the set of profiles matching the supplied stage.
+ * @param stage the stage descriptor
+ * @return the set of extension profiles
+ */
+ //Profile[] getProfiles( StageDescriptor stage );
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org