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 2004/02/22 00:54:43 UTC
cvs commit: avalon/merlin/platform/tutorials/dynamics/src/java/tutorial DefaultGizmo.java DefaultWidget.java Gizmo.java HelloFacility.java Widget.java
mcconnell 2004/02/21 15:54:43
Modified: logging/logkit/plugins/syslog/src/java/org/apache/avalon/logging/logkit/factory/syslog
package.html
merlin/composition/api/src/java/org/apache/avalon/composition/model
ContainmentModel.java DeploymentModel.java
ModelRepository.java ModelSelector.java
ProfileSelector.java TypeRepository.java
merlin/composition/impl maven.xml
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultComponentModel.java
DefaultContainmentModel.java
DefaultContainmentModelAssemblyHelper.java
DefaultModelRepository.java
DefaultModelSelector.java
DefaultProfileSelector.java
DefaultTypeRepository.java
merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl
SimpleDeploymentModel.java
merlin/composition/impl/src/test/org/apache/avalon/composition/model/test
AbstractTestCase.java ContextTestCase.java
DependencyTestCase.java IncludesTestCase.java
TargetsTestCase.java
merlin/kernel/impl/conf merlin.template
Added: merlin/composition/impl/src/test/org/apache/avalon/composition/model/test
DynamicsTestCase.java
merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/dynamics
DefaultGizmo.java DefaultWidget.java Gizmo.java
Widget.java
merlin/platform/tutorials/dynamics .cvsignore project.xml
merlin/platform/tutorials/dynamics/conf block.xml
merlin/platform/tutorials/dynamics/src/java/tutorial
DefaultGizmo.java DefaultWidget.java Gizmo.java
HelloFacility.java Widget.java
Log:
Add an operation to the containment model to support the resolution of a model based on a depedency descriptor or a reference descriptor. Addition of test case, and initial cut on tutorial content.
Revision Changes Path
1.2 +1 -1 avalon/logging/logkit/plugins/syslog/src/java/org/apache/avalon/logging/logkit/factory/syslog/package.html
Index: package.html
===================================================================
RCS file: /home/cvs/avalon/logging/logkit/plugins/syslog/src/java/org/apache/avalon/logging/logkit/factory/syslog/package.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- package.html 20 Feb 2004 22:44:11 -0000 1.1
+++ package.html 21 Feb 2004 23:54:42 -0000 1.2
@@ -1,3 +1,3 @@
<body>
-<p>The <code>socket</code> package contains a plugin socket log target.</p>
+<p>The <code>syslog</code> package contains a plugin syslog log target factory.</p>
</body>
1.19 +22 -1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContainmentModel.java
Index: ContainmentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContainmentModel.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ContainmentModel.java 12 Feb 2004 05:59:41 -0000 1.18
+++ ContainmentModel.java 21 Feb 2004 23:54:42 -0000 1.19
@@ -24,6 +24,7 @@
import org.apache.avalon.logging.data.CategoriesDirective;
import org.apache.avalon.composition.data.TargetDirective;
import org.apache.avalon.composition.event.CompositionListener;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
@@ -118,6 +119,26 @@
* @exception IllegalArgumentException if the path if badly formed
*/
DeploymentModel getModel( String path );
+
+ /**
+ * Resolve a model capable of supporting the supplied service reference.
+ *
+ * @param descriptor a service reference descriptor
+ * @return the model or null if unresolvable
+ * @exception AssemblyException if an assembly error occurs
+ */
+ DeploymentModel getModel( ReferenceDescriptor descriptor )
+ throws AssemblyException;
+
+ /**
+ * Resolve a model capable of supporting the supplied service reference.
+ *
+ * @param dependency a service dependency descriptor
+ * @return the model or null if unresolvable
+ * @exception AssemblyException if an assembly error occurs
+ */
+ DeploymentModel getModel( DependencyDescriptor dependency )
+ throws AssemblyException;
/**
* Addition of a new subsidiary containment model
1.15 +11 -1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java
Index: DeploymentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DeploymentModel.java 12 Feb 2004 05:59:41 -0000 1.14
+++ DeploymentModel.java 21 Feb 2004 23:54:42 -0000 1.15
@@ -26,6 +26,7 @@
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.framework.logger.Logger;
@@ -94,6 +95,15 @@
* @return true if this model can fulfill the dependency
*/
boolean isaCandidate( StageDescriptor stage );
+
+ /**
+ * Return TRUE is this model is capable of supporting a supplied
+ * service.
+ *
+ * @param reference the service reference descriptor
+ * @return true if this model can fulfill the service
+ */
+ boolean isaCandidate( ReferenceDescriptor reference );
//-----------------------------------------------------------
// composite assembly
1.4 +21 -2 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ModelRepository.java
Index: ModelRepository.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ModelRepository.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ModelRepository.java 24 Jan 2004 23:25:25 -0000 1.3
+++ ModelRepository.java 21 Feb 2004 23:54:42 -0000 1.4
@@ -18,6 +18,7 @@
package org.apache.avalon.composition.model;
import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
/**
@@ -47,6 +48,14 @@
DeploymentModel getModel( DependencyDescriptor dependency );
/**
+ * Locate a model meeting the supplied service criteria.
+ *
+ * @param reference a version interface descriptor
+ * @return the model
+ */
+ DeploymentModel getModel( ReferenceDescriptor reference );
+
+ /**
* Locate all models meeting the supplied dependency criteria.
*
* @param dependency a component service dependency
@@ -61,7 +70,17 @@
* @param stage a component stage dependency
* @return the candidate models
*/
- DeploymentModel[] getCandidateProviders( StageDescriptor stage );
+ DeploymentModel[] getCandidateProviders(
+ StageDescriptor stage );
+
+ /**
+ * Locate all models meeting the supplied service reference criteria.
+ *
+ * @param reference a service reference
+ * @return the candidate models
+ */
+ public DeploymentModel[] getCandidateProviders(
+ ReferenceDescriptor reference );
/**
* Locate a model meeting the supplied criteria.
1.5 +11 -1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ModelSelector.java
Index: ModelSelector.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ModelSelector.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ModelSelector.java 24 Jan 2004 23:25:25 -0000 1.4
+++ ModelSelector.java 21 Feb 2004 23:54:42 -0000 1.5
@@ -18,6 +18,7 @@
package org.apache.avalon.composition.model;
import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
/**
@@ -53,4 +54,13 @@
* can be established
*/
DeploymentModel select( DeploymentModel[] models, StageDescriptor stage );
+
+ /**
+ * Returns the preferred model from an available selection of candidates
+ * @param models the set of candidate models
+ * @param reference the versioned service reference
+ * @return the preferred provider or null if no satisfactory provider
+ * can be established
+ */
+ DeploymentModel select( DeploymentModel[] models, ReferenceDescriptor reference );
}
1.4 +16 -2 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ProfileSelector.java
Index: ProfileSelector.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ProfileSelector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ProfileSelector.java 24 Jan 2004 23:25:25 -0000 1.3
+++ ProfileSelector.java 21 Feb 2004 23:54:42 -0000 1.4
@@ -17,9 +17,11 @@
package org.apache.avalon.composition.model;
+import org.apache.avalon.composition.data.DeploymentProfile;
+
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
-import org.apache.avalon.composition.data.DeploymentProfile;
/**
* Interface defining the contract for profile selection.
@@ -50,4 +52,16 @@
* no satisfactory profile can be established
*/
DeploymentProfile select( DeploymentProfile[] profiles, StageDescriptor stage );
+
+ /**
+ * Returns the preferred profile from an available selection of
+ * candidates profiles.
+ *
+ * @param profiles the set of candidate profiles
+ * @param reference a service reference
+ * @return the preferred profile or null if
+ * no satisfactory profile can be established
+ */
+ DeploymentProfile select( DeploymentProfile[] profiles, ReferenceDescriptor reference );
+
}
1.6 +23 -5 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/TypeRepository.java
Index: TypeRepository.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/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 24 Jan 2004 23:25:25 -0000 1.5
+++ TypeRepository.java 21 Feb 2004 23:54:42 -0000 1.6
@@ -21,6 +21,7 @@
import org.apache.avalon.composition.data.DeploymentProfile;
import org.apache.avalon.composition.model.ProfileUnknownException;
import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
import org.apache.avalon.meta.info.Type;
@@ -73,13 +74,30 @@
*/
Type[] getTypes( DependencyDescriptor dependency );
+ /**
+ * Locate the set of component types capable of services the supplied
+ * dependency.
+ * @param dependency a service dependency descriptor
+ * @param search if TRUE then search for solution using the parent repository
+ * @return a set of types capable of servicing the supplied dependency
+ */
+ Type[] getTypes( DependencyDescriptor dependency, boolean search );
+
+ /**
+ * Locate the set of component types capable of services the supplied
+ * reference.
+ * @param reference a service reference descriptor
+ * @return a set of types capable of servicing the supplied service reference
+ */
+ Type[] getTypes( ReferenceDescriptor reference );
+
/**
* Locate the set of component types capable of services the supplied
- * dependency.
- * @param dependency a service dependency descriptor
- * @return a set of types capable of servicing the supplied dependency
+ * reference.
+ * @param reference a service reference descriptor
+ * @return a set of types capable of servicing the supplied service reference
*/
- Type[] getTypes( DependencyDescriptor dependency, boolean search );
+ Type[] getTypes( ReferenceDescriptor reference, boolean search );
/**
* Locate the set of component types that provide the supplied extension.
1.6 +4 -0 avalon/merlin/composition/impl/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/maven.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- maven.xml 10 Feb 2004 16:23:33 -0000 1.5
+++ maven.xml 21 Feb 2004 23:54:42 -0000 1.6
@@ -5,6 +5,10 @@
xmlns:util="jelly:util"
xmlns:ant="jelly:ant">
+ <preGoal name="java:compile">
+ <attainGoal name="avalon:meta"/>
+ </preGoal>
+
<postGoal name="test:compile">
<mkdir dir="${basedir}/target/test/repository/test/jars"/>
1.8 +15 -2 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java
Index: DefaultComponentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultComponentModel.java 12 Feb 2004 05:59:41 -0000 1.7
+++ DefaultComponentModel.java 21 Feb 2004 23:54:42 -0000 1.8
@@ -54,6 +54,7 @@
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.InfoDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
import org.apache.avalon.meta.info.Type;
@@ -353,7 +354,7 @@
*/
public boolean isaCandidate( DependencyDescriptor dependency )
{
- return m_context.getType().getService( dependency.getReference() ) != null;
+ return isaCandidate( dependency.getReference() );
}
/**
@@ -366,6 +367,18 @@
public boolean isaCandidate( StageDescriptor stage )
{
return m_context.getType().getExtension( stage ) != null;
+ }
+
+ /**
+ * Return TRUE is this model is capable of supporting a supplied
+ * service.
+ *
+ * @param reference the service reference descriptor
+ * @return true if this model can fulfill the service
+ */
+ public boolean isaCandidate( ReferenceDescriptor reference )
+ {
+ return m_context.getType().getService( reference ) != null;
}
//==============================================================
1.34 +44 -2 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
Index: DefaultContainmentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- DefaultContainmentModel.java 14 Feb 2004 21:33:56 -0000 1.33
+++ DefaultContainmentModel.java 21 Feb 2004 23:54:42 -0000 1.34
@@ -87,6 +87,7 @@
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
import org.apache.avalon.meta.info.Type;
@@ -355,11 +356,23 @@
*/
public boolean isaCandidate( DependencyDescriptor dependency )
{
+ return isaCandidate( dependency.getReference() );
+ }
+
+ /**
+ * Return TRUE is this model is capable of supporting a supplied
+ * service.
+ *
+ * @param reference the service reference descriptor
+ * @return true if this model can fulfill the service
+ */
+ public boolean isaCandidate( ReferenceDescriptor reference )
+ {
ServiceDescriptor[] services = getServices();
for( int i=0; i<services.length; i++ )
{
ServiceDescriptor service = services[i];
- if( service.getReference().matches( dependency.getReference() ) )
+ if( service.getReference().matches( reference ) )
{
return true;
}
@@ -763,6 +776,35 @@
DefaultContainmentModelNavigationHelper helper =
new DefaultContainmentModelNavigationHelper( m_context, this );
return helper.getModel( path );
+ }
+
+ /**
+ * Resolve a model capable of supporting the supplied service reference.
+ *
+ * @param descriptor a service reference descriptor
+ * @return the model or null if unresolvable
+ */
+ public DeploymentModel getModel( ReferenceDescriptor descriptor )
+ throws AssemblyException
+ {
+ DefaultContainmentModelAssemblyHelper helper =
+ new DefaultContainmentModelAssemblyHelper( m_context, this );
+ return helper.findServiceProvider( descriptor );
+ }
+
+ /**
+ * Resolve a model capable of supporting the supplied service reference.
+ *
+ * @param dependency a dependency descriptor
+ * @return the model or null if unresolvable
+ * @exception AssemblyException if an assembly error occurs
+ */
+ public DeploymentModel getModel( DependencyDescriptor dependency )
+ throws AssemblyException
+ {
+ DefaultContainmentModelAssemblyHelper helper =
+ new DefaultContainmentModelAssemblyHelper( m_context, this );
+ return helper.findDependencyProvider( dependency );
}
/**
1.4 +92 -1 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModelAssemblyHelper.java
Index: DefaultContainmentModelAssemblyHelper.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModelAssemblyHelper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultContainmentModelAssemblyHelper.java 12 Feb 2004 05:59:41 -0000 1.3
+++ DefaultContainmentModelAssemblyHelper.java 21 Feb 2004 23:54:42 -0000 1.4
@@ -43,6 +43,7 @@
import org.apache.avalon.meta.info.Type;
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
/**
@@ -252,6 +253,14 @@
}
}
+ DeploymentModel findDependencyProvider( DependencyDescriptor dependency )
+ throws AssemblyException
+ {
+ ArrayList list = new ArrayList();
+ ModelRepository repository = m_context.getModelRepository();
+ return findDependencyProvider( repository, dependency, list );
+ }
+
private DeploymentModel findDependencyProvider(
ModelRepository repository, DependencyDescriptor dependency, List subjects )
throws AssemblyException
@@ -309,6 +318,72 @@
}
}
+ DeploymentModel findServiceProvider( ReferenceDescriptor reference )
+ throws AssemblyException
+ {
+ ArrayList list = new ArrayList();
+ ModelRepository repository = m_context.getModelRepository();
+ return findServiceProvider( repository, reference, list );
+ }
+
+ private DeploymentModel findServiceProvider(
+ ModelRepository repository, ReferenceDescriptor reference, List subjects )
+ throws AssemblyException
+ {
+ DeploymentModel[] candidates =
+ repository.getCandidateProviders( reference );
+ ModelSelector selector = new DefaultModelSelector();
+ DeploymentModel model = selector.select( candidates, reference );
+ if( model != null )
+ {
+ assembleModel( model, subjects );
+ return model;
+ }
+
+ //
+ // otherwise, check for any packaged profiles that
+ // we could use to construct the model
+ //
+
+ DeploymentProfile[] profiles = findServiceProfiles( reference );
+ ProfileSelector profileSelector = new DefaultProfileSelector();
+ DeploymentProfile profile = profileSelector.select( profiles, reference );
+ if( profile != null )
+ {
+ try
+ {
+ DeploymentModel solution = m_model.createDeploymentModel( profile );
+ assembleModel( solution, subjects );
+ m_model.addModel( solution );
+ return solution;
+ }
+ catch( AssemblyException ae )
+ {
+ final String error =
+ "Nested assembly failure while attempting to construct model"
+ + " for the profile: [" + profile + "] for the reference: ["
+ + reference + "].";
+ throw new AssemblyException( error, ae );
+ }
+ catch( ModelException me )
+ {
+ final String error =
+ "Nested model failure while attempting to add model"
+ + " for the profile: [" + profile + "] for the reference: ["
+ + reference + "].";
+ throw new AssemblyException( error, me );
+ }
+ }
+ else
+ {
+ final String error =
+ "Unable to locate a service provider for the reference: [ "
+ + reference + "].";
+ throw new AssemblyException( error );
+ }
+ }
+
+
private DeploymentModel findExtensionProvider(
ModelRepository repository, StageModel stage, List subjects )
throws AssemblyException
@@ -412,6 +487,22 @@
{
TypeRepository repository = m_context.getClassLoaderModel().getTypeRepository();
Type[] types = repository.getTypes( dependency );
+ try
+ {
+ return getProfiles( repository, types );
+ }
+ catch( TypeUnknownException tue )
+ {
+ // will not happen
+ final String error = "An irrational condition has occured.";
+ throw new ModelRuntimeException( error, tue );
+ }
+ }
+
+ private DeploymentProfile[] findServiceProfiles( ReferenceDescriptor reference )
+ {
+ TypeRepository repository = m_context.getClassLoaderModel().getTypeRepository();
+ Type[] types = repository.getTypes( reference );
try
{
return getProfiles( repository, types );
1.5 +46 -3 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultModelRepository.java
Index: DefaultModelRepository.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultModelRepository.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultModelRepository.java 24 Jan 2004 23:25:27 -0000 1.4
+++ DefaultModelRepository.java 21 Feb 2004 23:54:42 -0000 1.5
@@ -28,6 +28,7 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
@@ -80,6 +81,17 @@
*/
public DeploymentModel getModel( DependencyDescriptor dependency )
{
+ return getModel( dependency.getReference() );
+ }
+
+ /**
+ * Locate an model meeting the supplied criteria.
+ *
+ * @param reference a component service reference
+ * @return the model or null if no matching model is resolved
+ */
+ public DeploymentModel getModel( ReferenceDescriptor reference )
+ {
//
// attempt to locate a solution locally
//
@@ -88,7 +100,7 @@
while( iterator.hasNext() )
{
DeploymentModel model = (DeploymentModel) iterator.next();
- if( model.isaCandidate( dependency ) )
+ if( model.isaCandidate( reference ) )
{
return model;
}
@@ -100,7 +112,7 @@
if( m_parent != null )
{
- return m_parent.getModel( dependency );
+ return m_parent.getModel( reference );
}
return null;
@@ -159,6 +171,37 @@
if( m_parent != null )
{
DeploymentModel[] models = m_parent.getCandidateProviders( dependency );
+ for( int i=0; i<models.length; i++ )
+ {
+ list.add( models[i] );
+ }
+ }
+ return (DeploymentModel[]) list.toArray( new DeploymentModel[0] );
+ }
+
+ /**
+ * Locate all models meeting the supplied service reference criteria.
+ *
+ * @param reference a service reference
+ * @return the candidate models
+ */
+ public DeploymentModel[] getCandidateProviders(
+ ReferenceDescriptor reference )
+ {
+ ArrayList list = new ArrayList();
+ Iterator iterator = m_models.values().iterator();
+ while( iterator.hasNext() )
+ {
+ DeploymentModel model = (DeploymentModel) iterator.next();
+ if( model.isaCandidate( reference ) )
+ {
+ list.add( model );
+ }
+ }
+
+ if( m_parent != null )
+ {
+ DeploymentModel[] models = m_parent.getCandidateProviders( reference );
for( int i=0; i<models.length; i++ )
{
list.add( models[i] );
1.5 +31 -1 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultModelSelector.java
Index: DefaultModelSelector.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultModelSelector.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultModelSelector.java 10 Feb 2004 16:23:33 -0000 1.4
+++ DefaultModelSelector.java 21 Feb 2004 23:54:42 -0000 1.5
@@ -24,6 +24,7 @@
import org.apache.avalon.composition.model.ModelSelector;
import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
@@ -70,9 +71,38 @@
return select( candidates );
}
+ /**
+ * Returns the preferred model from an available selection of candidates
+ * @param models the set of candidate models
+ * @param reference the versioned service reference
+ * @return the preferred provider or null if no satisfactory provider
+ * can be established
+ */
+ public DeploymentModel select( DeploymentModel[] models, ReferenceDescriptor reference )
+ {
+ DeploymentModel[] candidates = filterCandidateProviders( models, reference );
+ return select( candidates );
+ }
+
+
//==============================================================
// implementation
//==============================================================
+
+ private DeploymentModel[] filterCandidateProviders(
+ DeploymentModel[] models, ReferenceDescriptor reference )
+ {
+ ArrayList list = new ArrayList();
+ for( int i = 0; i < models.length; i++ )
+ {
+ DeploymentModel model = models[i];
+ if( model.isaCandidate( reference ) )
+ {
+ list.add( model );
+ }
+ }
+ return (DeploymentModel[]) list.toArray( new DeploymentModel[0] );
+ }
private DeploymentModel[] filterCandidateProviders(
DeploymentModel[] models, DependencyDescriptor dependency )
1.6 +16 -1 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultProfileSelector.java
Index: DefaultProfileSelector.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultProfileSelector.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultProfileSelector.java 10 Feb 2004 16:23:33 -0000 1.5
+++ DefaultProfileSelector.java 21 Feb 2004 23:54:42 -0000 1.6
@@ -23,6 +23,7 @@
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
/**
* Default profile selector class. The default selector selects profiles based
@@ -63,6 +64,20 @@
* no satisfactory profile can be established
*/
public DeploymentProfile select( DeploymentProfile[] profiles, StageDescriptor stage )
+ {
+ return select( profiles );
+ }
+
+ /**
+ * Returns the preferred profile from an available selection of
+ * candidates profiles.
+ *
+ * @param profiles the set of candidate profiles
+ * @param reference a service reference
+ * @return the preferred profile or null if
+ * no satisfactory profile can be established
+ */
+ public DeploymentProfile select( DeploymentProfile[] profiles, ReferenceDescriptor reference )
{
return select( profiles );
}
1.8 +37 -12 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultTypeRepository.java
Index: DefaultTypeRepository.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultTypeRepository.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultTypeRepository.java 10 Feb 2004 16:23:34 -0000 1.7
+++ DefaultTypeRepository.java 21 Feb 2004 23:54:42 -0000 1.8
@@ -263,23 +263,47 @@
return getTypes( dependency, true );
}
- /**
- * 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
- */
+ /**
+ * Locate the set of component types in the local repository
+ * capable of servicing the supplied dependency.
+ *
+ * @param dependency a service dependency descriptor
+ * @param search if TRUE then search for solution using the parent repository
+ * @return a set of types capable of servicing the supplied dependency
+ */
public Type[] getTypes( DependencyDescriptor dependency, boolean search )
{
- if( dependency == null )
+ return getTypes( dependency.getReference(), search );
+ }
+
+ /**
+ * Locate the set of component types capable of services the supplied
+ * reference.
+ * @param reference a service reference descriptor
+ * @return a set of types capable of servicing the supplied service reference
+ */
+ public Type[] getTypes( ReferenceDescriptor reference )
+ {
+ return getTypes( reference, true );
+ }
+
+ /**
+ * Locate the set of component types capable of services the supplied
+ * reference.
+ * @param reference a service reference descriptor
+ * @param search if TRUE then search for solution using the parent repository
+ * @return a set of types capable of servicing the supplied service reference
+ */
+ public Type[] getTypes( ReferenceDescriptor reference, boolean search )
+ {
+ if( reference == null )
{
- throw new NullPointerException( "dependency" );
+ throw new NullPointerException( "reference" );
}
ArrayList list = new ArrayList();
- ReferenceDescriptor reference = dependency.getReference();
Type[] types = getTypes( false );
+
for( int i=0; i<types.length; i++ )
{
Type type = types[i];
@@ -291,7 +315,7 @@
if( search && m_parent != null )
{
- Type[] suppliment = m_parent.getTypes( dependency );
+ Type[] suppliment = m_parent.getTypes( reference );
for( int i=0; i<suppliment.length; i++ )
{
list.add( suppliment[i] );
@@ -300,6 +324,7 @@
return (Type[]) list.toArray( new Type[0] );
}
+
/**
* Locate the set of local component types that provide the
1.3 +12 -0 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl/SimpleDeploymentModel.java
Index: SimpleDeploymentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl/SimpleDeploymentModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SimpleDeploymentModel.java 12 Feb 2004 05:59:42 -0000 1.2
+++ SimpleDeploymentModel.java 21 Feb 2004 23:54:42 -0000 1.3
@@ -26,6 +26,7 @@
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
import org.apache.avalon.framework.logger.Logger;
@@ -120,6 +121,17 @@
{
return true;
}
+
+ /**
+ * Return TRUE is this model is capable of supporting a supplied
+ * service.
+ * @return true if this model can fulfill the service
+ */
+ public boolean isaCandidate( ReferenceDescriptor reference )
+ {
+ return true;
+ }
+
//-----------------------------------------------------------
// composite assembly
1.3 +16 -0 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/AbstractTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractTestCase.java 19 Feb 2004 08:58:04 -0000 1.2
+++ AbstractTestCase.java 21 Feb 2004 23:54:42 -0000 1.3
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004 Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.avalon.composition.model.test;
1.7 +16 -0 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/ContextTestCase.java
Index: ContextTestCase.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/ContextTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ContextTestCase.java 14 Feb 2004 21:33:56 -0000 1.6
+++ ContextTestCase.java 21 Feb 2004 23:54:42 -0000 1.7
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004 Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.avalon.composition.model.test;
1.7 +16 -0 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/DependencyTestCase.java
Index: DependencyTestCase.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/DependencyTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DependencyTestCase.java 14 Feb 2004 21:33:56 -0000 1.6
+++ DependencyTestCase.java 21 Feb 2004 23:54:42 -0000 1.7
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004 Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.avalon.composition.model.test;
1.7 +16 -0 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/IncludesTestCase.java
Index: IncludesTestCase.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/IncludesTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- IncludesTestCase.java 14 Feb 2004 21:33:56 -0000 1.6
+++ IncludesTestCase.java 21 Feb 2004 23:54:42 -0000 1.7
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004 Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.avalon.composition.model.test;
1.7 +16 -0 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/TargetsTestCase.java
Index: TargetsTestCase.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/TargetsTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TargetsTestCase.java 14 Feb 2004 21:33:56 -0000 1.6
+++ TargetsTestCase.java 21 Feb 2004 23:54:42 -0000 1.7
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004 Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.avalon.composition.model.test;
1.1 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/DynamicsTestCase.java
Index: DynamicsTestCase.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.composition.model.test;
import org.apache.avalon.composition.model.DeploymentModel;
import org.apache.avalon.composition.model.ContainmentModel;
import org.apache.avalon.composition.model.ComponentModel;
import org.apache.avalon.composition.model.DependencyModel;
import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.util.exception.ExceptionHelper;
import org.apache.avalon.composition.model.test.dynamics.Widget;
import org.apache.avalon.composition.model.test.dynamics.Gizmo;
public class DynamicsTestCase extends AbstractTestCase
{
//-------------------------------------------------------
// constructor
//-------------------------------------------------------
public DynamicsTestCase()
{
super( "dynamics.xml" );
}
//-------------------------------------------------------
// tests
//-------------------------------------------------------
/**
* Validate resolution of a widget.
*/
public void testDynamicWidget() throws Exception
{
try
{
m_model.assemble();
String spec = Widget.class.getName();
ReferenceDescriptor ref = new ReferenceDescriptor( spec );
DeploymentModel widget =
m_model.getModel( ref );
}
catch( Throwable e )
{
final String message = "Assembly test failure";
final String error = ExceptionHelper.packException( message, e, true );
System.err.println( error );
fail( error );
}
}
/**
* Validate resolution of a gizmo.
*/
public void testDynamicGizmo() throws Exception
{
try
{
m_model.assemble();
String spec = Gizmo.class.getName();
ReferenceDescriptor ref = new ReferenceDescriptor( spec );
DeploymentModel widget =
m_model.getModel( ref );
}
catch( Throwable e )
{
final String message = "Assembly test failure";
final String error = ExceptionHelper.packException( message, e, true );
System.err.println( error );
fail( error );
}
}
}
1.2 +4 -0 avalon/merlin/kernel/impl/conf/merlin.template
Index: merlin.template
===================================================================
RCS file: /home/cvs/avalon/merlin/kernel/impl/conf/merlin.template,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- merlin.template 21 Feb 2004 10:21:46 -0000 1.1
+++ merlin.template 21 Feb 2004 23:54:42 -0000 1.2
@@ -25,5 +25,9 @@
merlin.runtime.csi.implementation = @SECURE_RUNTIME@
#
+# server mode
+merlin.server = true
+
+#
# EOF
#
1.1 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/dynamics/DefaultGizmo.java
Index: DefaultGizmo.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.composition.model.test.dynamics;
import org.apache.avalon.framework.logger.Logger;
/**
* A component that implements the Gizmo service.
*
* @avalon.component name="gizmo" lifestyle="singleton"
* @avalon.service type="org.apache.avalon.composition.model.test.dynamics.Gizmo"
*/
public class DefaultGizmo implements Gizmo
{
//---------------------------------------------------------
// immutable state
//---------------------------------------------------------
/**
* The logging channel supplied by the container.
*/
private final Logger m_logger;
//---------------------------------------------------------
// constructor
//---------------------------------------------------------
/**
* Creation of a new hello facility.
* @param logger a logging channel
*/
public DefaultGizmo( Logger logger )
{
m_logger = logger;
m_logger.info( "I've been created" );
}
}
1.1 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/dynamics/DefaultWidget.java
Index: DefaultWidget.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.composition.model.test.dynamics;
import org.apache.avalon.framework.logger.Logger;
/**
* A component that implements the Gizmo service.
*
* @avalon.component name="widget" lifestyle="singleton"
* @avalon.service type="org.apache.avalon.composition.model.test.dynamics.Widget"
*/
public class DefaultWidget implements Widget
{
//---------------------------------------------------------
// immutable state
//---------------------------------------------------------
/**
* The logging channel supplied by the container.
*/
private final Logger m_logger;
//---------------------------------------------------------
// constructor
//---------------------------------------------------------
/**
* Creation of a new hello facility.
* @param logger a logging channel
*/
public DefaultWidget( Logger logger )
{
m_logger = logger;
m_logger.info( "I've been created" );
}
}
1.1 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/dynamics/Gizmo.java
Index: Gizmo.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.composition.model.test.dynamics;
/**
* The Gizmo service interface.
*/
public interface Gizmo
{
}
1.1 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/dynamics/Widget.java
Index: Widget.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.composition.model.test.dynamics;
/**
* The Widget service interface.
*/
public interface Widget
{
}
1.1 avalon/merlin/platform/tutorials/dynamics/.cvsignore
Index: .cvsignore
===================================================================
maven.log
velocity.log
build
target
tutorial.jar
1.1 avalon/merlin/platform/tutorials/dynamics/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<extend>${basedir}/../project.xml</extend>
<id>merlin-tutorial-dynamics</id>
<name>Merlin Dynamics Tutorial</name>
<package>tutorial</package>
<currentVersion>1.0</currentVersion>
<inceptionYear>2003</inceptionYear>
<shortDescription>Example of dyanamic model interaction.</shortDescription>
<dependencies>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>avalon-composition</groupId>
<artifactId>avalon-composition-api</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>avalon-meta</groupId>
<artifactId>avalon-meta-api</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
1.1 avalon/merlin/platform/tutorials/dynamics/conf/block.xml
Index: block.xml
===================================================================
<container name="tutorial">
<component name="hello" class="tutorial.HelloFacility" activation="startup"/>
</container>
1.1 avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/DefaultGizmo.java
Index: DefaultGizmo.java
===================================================================
package tutorial;
import org.apache.avalon.framework.logger.Logger;
/**
* A component that implements the Gizmo service.
*
* @avalon.component name="gizmo" lifestyle="singleton"
* @avalon.service type="tutorial.Gizmo"
*/
public class DefaultGizmo implements Gizmo
{
//---------------------------------------------------------
// immutable state
//---------------------------------------------------------
/**
* The logging channel supplied by the container.
*/
private final Logger m_logger;
//---------------------------------------------------------
// constructor
//---------------------------------------------------------
/**
* Creation of a new hello facility.
* @param logger a logging channel
*/
public DefaultGizmo( Logger logger )
{
m_logger = logger;
m_logger.info( "I've been created" );
}
}
1.1 avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/DefaultWidget.java
Index: DefaultWidget.java
===================================================================
package tutorial;
import org.apache.avalon.framework.logger.Logger;
/**
* A component that implements the Gizmo service.
*
* @avalon.component name="widget" lifestyle="singleton"
* @avalon.service type="tutorial.Widget"
*/
public class DefaultWidget implements Widget
{
//---------------------------------------------------------
// immutable state
//---------------------------------------------------------
/**
* The logging channel supplied by the container.
*/
private final Logger m_logger;
//---------------------------------------------------------
// constructor
//---------------------------------------------------------
/**
* Creation of a new hello facility.
* @param logger a logging channel
*/
public DefaultWidget( Logger logger )
{
m_logger = logger;
m_logger.info( "I've been created" );
}
}
1.1 avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/Gizmo.java
Index: Gizmo.java
===================================================================
package tutorial;
/**
* The Gizmo service interface.
*/
public interface Gizmo
{
}
1.1 avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/HelloFacility.java
Index: HelloFacility.java
===================================================================
package tutorial;
import org.apache.avalon.composition.model.ContainmentModel;
import org.apache.avalon.composition.model.DeploymentModel;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.activity.Executable;
import org.apache.avalon.meta.info.ReferenceDescriptor;
/**
* A demonstration of a facility that invoces the runtime creation
* and deployment of other components.
*
* @avalon.component name="hello" lifestyle="singleton"
*/
public class HelloFacility
implements Contextualizable, Executable
{
//---------------------------------------------------------
// immutable state
//---------------------------------------------------------
/**
* The logging channel supplied by the container.
*/
private final Logger m_logger;
//---------------------------------------------------------
// mutable state
//---------------------------------------------------------
/**
* The containment model (establish via contexualization)
*/
private ContainmentModel m_model;
//---------------------------------------------------------
// constructor
//---------------------------------------------------------
/**
* Creation of a new hello facility.
* @param logger a logging channel
*/
public HelloFacility( Logger logger )
{
m_logger = logger;
}
//---------------------------------------------------------
// Contextualizable
//---------------------------------------------------------
/**
* Contextulaization of the facility by the container during
* which we are supplied with the root containment model.
*
* @param context the supplied context
* @avalon.entry key="urn:composition:containment.model"
* type="org.apache.avalon.composition.model.ContainmentModel"
* @exception ContextException if a contextualization error occurs
*/
public void contextualize( Context context ) throws ContextException
{
m_model =
(ContainmentModel) context.get(
"urn:composition:containment.model" );
}
//---------------------------------------------------------
// Executable
//---------------------------------------------------------
public void execute() throws Exception
{
//
// create a reference to the widget service
//
ReferenceDescriptor reference = new ReferenceDescriptor( Widget.class.getName() );
//
// get hold of a model representing a widget deployment scenario
//
DeploymentModel model = m_model.getModel( reference );
getLogger().info( "got the widget model: " + model );
//
// commission the model and resolve a component instance
//
model.commission();
Widget widget = (Widget) model.resolve();
getLogger().info( "got the widget instance: " + widget );
}
//---------------------------------------------------------
// private
//---------------------------------------------------------
private Logger getLogger()
{
return m_logger;
}
}
1.1 avalon/merlin/platform/tutorials/dynamics/src/java/tutorial/Widget.java
Index: Widget.java
===================================================================
package tutorial;
/**
* The Widget service interface.
*/
public interface Widget
{
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org