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/10/04 13:53:04 UTC
cvs commit: avalon/merlin/composition/spi/src/java/org/apache/avalon/composition/data/builder ContainmentProfileCreator.java
mcconnell 2003/10/04 04:53:04
Modified: merlin/composition/api/src/java/org/apache/avalon/composition/data
DeploymentProfile.java
merlin/composition/api/src/java/org/apache/avalon/composition/model
TypeRepository.java
merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder
ContainmentProfileBuilder.java
XMLContainmentProfileCreator.java
XMLDeploymentProfileCreator.java
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultContainmentModel.java
DefaultModelFactory.java DefaultTypeRepository.java
merlin/composition/spi/src/java/org/apache/avalon/composition/data/builder
ContainmentProfileCreator.java
Log:
Add support for the declaration of a component using a profile template.
Revision Changes Path
1.2 +21 -1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/data/DeploymentProfile.java
Index: DeploymentProfile.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/data/DeploymentProfile.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DeploymentProfile.java 24 Sep 2003 09:31:06 -0000 1.1
+++ DeploymentProfile.java 4 Oct 2003 11:53:03 -0000 1.2
@@ -192,6 +192,26 @@
null, null, Mode.IMPLICIT );
}
+ /**
+ * Creation of a new deployment profile using a supplied template profile.
+ * @param name the name to assign to the created profile
+ * @param template the template deployment profile
+ */
+ public DeploymentProfile( String name, DeploymentProfile template )
+ {
+ this(
+ name,
+ template.getActivationPolicy(),
+ template.m_classname,
+ template.m_categories,
+ template.m_context,
+ template.m_dependencies,
+ template.m_stages,
+ template.m_parameters,
+ template.m_configuration,
+ Mode.EXPLICIT );
+ }
+
public DeploymentProfile(
final String name,
final boolean activation,
1.2 +10 -11 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TypeRepository.java 24 Sep 2003 09:31:23 -0000 1.1
+++ TypeRepository.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -51,6 +51,7 @@
package org.apache.avalon.composition.model;
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.StageDescriptor;
import org.apache.avalon.meta.info.Type;
@@ -122,17 +123,15 @@
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
+ * Return a deployment profile for the supplied type and key.
+ * @param type the type
+ * @param key the profile name
+ * @return a profile matching the supplied key
+ * @exception TypeUnknownException if the supplied type is unknown
+ * @exception ProfileUnknownException if the supplied key is unknown
*/
- //Profile[] getProfiles( DependencyDescriptor dependency );
+ DeploymentProfile getProfile( Type type, String key )
+ throws TypeUnknownException, ProfileUnknownException;
- /**
- * Return the set of profiles matching the supplied stage.
- * @param stage the stage descriptor
- * @return the set of extension profiles
- */
- //Profile[] getProfiles( StageDescriptor stage );
}
1.2 +7 -7 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/ContainmentProfileBuilder.java
Index: ContainmentProfileBuilder.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/ContainmentProfileBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContainmentProfileBuilder.java 24 Sep 2003 09:31:25 -0000 1.1
+++ ContainmentProfileBuilder.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -87,7 +87,6 @@
private final SerializedContainmentProfileCreator m_serial =
new SerializedContainmentProfileCreator();
-
/**
* Create a {@link ContainmentProfile} from a stream.
*
@@ -95,7 +94,7 @@
* @return the containment profile
* @exception Exception if a error occurs during profile creation
*/
- public ContainmentProfile createContainmentProfile( InputStream inputStream )
+ public ContainmentProfile createContainmentProfile( InputStream inputStream )
throws Exception
{
// we backup the inputstream content in a bytearray
@@ -106,6 +105,7 @@
baos.write( buffer, 0, read );
read = inputStream.read( buffer );
}
+
inputStream = new ByteArrayInputStream( baos.toByteArray() );
try
@@ -146,14 +146,14 @@
/**
* Build ContainmentProfile from an XML descriptor.
- *
+ * @param stream the input stream
* @throws Exception if an error occurs
*/
- private ContainmentProfile buildFromXMLDescriptor( InputStream inputStream )
+ private ContainmentProfile buildFromXMLDescriptor( InputStream stream )
throws Exception
{
- final InputSource inputSource = new InputSource( inputStream );
- Configuration config = ConfigurationBuilder.build( inputSource );
+ final InputSource source = new InputSource( stream );
+ Configuration config = ConfigurationBuilder.build( source );
return m_xml.createContainmentProfile( config );
}
1.2 +40 -18 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLContainmentProfileCreator.java
Index: XMLContainmentProfileCreator.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLContainmentProfileCreator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLContainmentProfileCreator.java 24 Sep 2003 09:31:37 -0000 1.1
+++ XMLContainmentProfileCreator.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -60,32 +60,33 @@
import java.net.URL;
import java.util.ArrayList;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.meta.info.DependencyDescriptor;
-import org.apache.avalon.meta.info.ServiceDescriptor;
import org.apache.avalon.composition.data.BlockCompositionDirective;
import org.apache.avalon.composition.data.BlockIncludeDirective;
+import org.apache.avalon.composition.data.ClassLoaderDirective;
import org.apache.avalon.composition.data.CategoriesDirective;
+import org.apache.avalon.composition.data.ClasspathDirective;
import org.apache.avalon.composition.data.ContainmentProfile;
import org.apache.avalon.composition.data.DeploymentProfile;
import org.apache.avalon.composition.data.FilesetDirective;
-import org.apache.avalon.composition.data.LibraryDirective;
-import org.apache.avalon.composition.data.ClasspathDirective;
import org.apache.avalon.composition.data.IncludeDirective;
-import org.apache.avalon.composition.data.ClassLoaderDirective;
-import org.apache.avalon.composition.data.RepositoryDirective;
-import org.apache.avalon.composition.data.ResourceDirective;
+import org.apache.avalon.composition.data.LibraryDirective;
import org.apache.avalon.composition.data.Mode;
-import org.apache.avalon.composition.data.Profile;
-import org.apache.avalon.composition.data.ServiceDirective;
import org.apache.avalon.composition.data.MetaDataException;
import org.apache.avalon.composition.data.MetaDataRuntimeException;
+import org.apache.avalon.composition.data.NamedDeploymentProfile;
+import org.apache.avalon.composition.data.Profile;
+import org.apache.avalon.composition.data.RepositoryDirective;
+import org.apache.avalon.composition.data.ResourceDirective;
+import org.apache.avalon.composition.data.ServiceDirective;
import org.apache.avalon.composition.data.Targets;
import org.apache.avalon.composition.data.TargetDirective;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.ServiceDescriptor;
import org.apache.avalon.meta.info.builder.XMLTypeCreator;
import org.apache.excalibur.configuration.ConfigurationUtil;
@@ -398,9 +399,15 @@
}
else if( child.getName().equals( "component" ) )
{
- DeploymentProfile profile =
- DEPLOYMENT_CREATOR.createDeploymentProfile( child );
- list.add( profile );
+ if( child.getAttribute( "profile", null ) != null )
+ {
+ list.add( createNamedDeploymentProfile( child ) );
+ }
+ else
+ {
+ list.add(
+ DEPLOYMENT_CREATOR.createDeploymentProfile( child ) );
+ }
}
else if( child.getName().equals( "include" ) )
{
@@ -409,6 +416,21 @@
}
}
return (Profile[]) list.toArray( new Profile[0] );
+ }
+
+ /**
+ * Create a profile using a packaged deployment profile.
+ * @param config the component configuration
+ * @return the named profile
+ */
+ private NamedDeploymentProfile createNamedDeploymentProfile( Configuration config )
+ throws Exception
+ {
+ final String name = config.getAttribute( "name" );
+ final String classname = config.getAttribute( "class" );
+ final String key = config.getAttribute( "profile" );
+ final boolean activation = getActivationPolicy( config );
+ return new NamedDeploymentProfile( name, classname, key, activation );
}
/**
1.2 +7 -5 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLDeploymentProfileCreator.java
Index: XMLDeploymentProfileCreator.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLDeploymentProfileCreator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLDeploymentProfileCreator.java 24 Sep 2003 09:31:38 -0000 1.1
+++ XMLDeploymentProfileCreator.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -71,7 +71,7 @@
/**
* Creation of a {@link DeploymentProfile} from an XML configuration.
*
- * @param config the configuration
+ * @param config the configuration instance describing the component deployment scenario
* @return the deployment profile
*/
public DeploymentProfile createDeploymentProfile( Configuration config )
@@ -84,7 +84,8 @@
/**
* Creation of a {@link DeploymentProfile} from an XML configuration.
*
- * @param config the configuration
+ * @param base the default name
+ * @param config the configuration describing the component deployment scenario
* @return the deployment profile
*/
public DeploymentProfile createDeploymentProfile(
@@ -98,7 +99,8 @@
/**
* Creation of a {@link DeploymentProfile} from an XML configuration.
*
- * @param config the configuration
+ * @param classname the name of the class identifying the underlying component type
+ * @param config the configuration describing the component deployment scenario
* @return the deployment profile
*/
public DeploymentProfile createDeploymentProfile(
@@ -243,7 +245,7 @@
final String error =
"The 'context' tag format has changed."
+ " Please check Merlin home for details "
- + "http://avalon.apache.org/sandbox/merlin/resources";
+ + "http://avalon.apache.org/merlin";
throw new ConfigurationException( error );
}
1.2 +15 -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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultContainmentModel.java 24 Sep 2003 09:31:59 -0000 1.1
+++ DefaultContainmentModel.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -67,6 +67,7 @@
import org.apache.avalon.composition.data.CategoriesDirective;
import org.apache.avalon.composition.data.ContainmentProfile;
import org.apache.avalon.composition.data.DeploymentProfile;
+import org.apache.avalon.composition.data.NamedDeploymentProfile;
import org.apache.avalon.composition.data.Profile;
import org.apache.avalon.composition.data.ResourceDirective;
import org.apache.avalon.composition.data.ServiceDirective;
@@ -288,6 +289,18 @@
DeploymentProfile deployment = (DeploymentProfile) profile;
model = createDeploymentModel( deployment );
}
+ else if( profile instanceof NamedDeploymentProfile )
+ {
+ NamedDeploymentProfile holder = (NamedDeploymentProfile) profile;
+ final String classname = holder.getClassname();
+ final String key = holder.getKey();
+ TypeRepository repository =
+ m_context.getClassLoaderModel().getTypeRepository();
+ Type type = repository.getType( classname );
+ DeploymentProfile template = repository.getProfile( type, key );
+ DeploymentProfile deployment = new DeploymentProfile( profile.getName(), template );
+ model = createDeploymentModel( deployment );
+ }
else if( profile instanceof BlockIncludeDirective )
{
BlockIncludeDirective directive = (BlockIncludeDirective) profile;
@@ -578,7 +591,7 @@
/**
* Create a containment model that is derived from an external
- * source profile defintion.
+ * source containment profile defintion.
*
* @param directive the block include directive
* @return the containment model established by the include
1.2 +2 -2 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultModelFactory.java
Index: DefaultModelFactory.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultModelFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultModelFactory.java 24 Sep 2003 09:32:10 -0000 1.1
+++ DefaultModelFactory.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -214,7 +214,7 @@
* Creation of a new root containment context.
*
* @param profile a containment profile
- * @return the containment model
+ * @return the containment context
*/
public ContainmentContext createContainmentContext( ContainmentProfile profile )
throws ModelException
1.2 +37 -1 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultTypeRepository.java 24 Sep 2003 09:32:15 -0000 1.1
+++ DefaultTypeRepository.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -61,6 +61,7 @@
import org.apache.avalon.composition.model.TypeRuntimeException;
import org.apache.avalon.composition.model.TypeDuplicateException;
import org.apache.avalon.composition.model.TypeUnknownException;
+import org.apache.avalon.composition.model.ProfileUnknownException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.logger.Logger;
@@ -373,6 +374,27 @@
}
/**
+ * Return a deployment profile for the supplied type and key.
+ * @param type the type
+ * @param key the profile name
+ * @return a profile matching the supplied key
+ * @exception TypeUnknownException if the supplied type is unknown
+ * @exception ProfileUnknownException if the supplied key is unknown
+ */
+ public DeploymentProfile getProfile( Type type, String key )
+ throws TypeUnknownException, ProfileUnknownException
+ {
+ DeploymentProfile[] profiles = getProfiles( type );
+ for( int i=0; i<profiles.length; i++ )
+ {
+ DeploymentProfile profile = profiles[i];
+ final String name = getProfileName( type, key );
+ if( profile.getName().equals( name ) ) return profile;
+ }
+ throw new ProfileUnknownException( key );
+ }
+
+ /**
* Return the set of local profiles.
* @return a profile or null if a profile connot be resolve
*/
@@ -388,6 +410,20 @@
protected Logger getLogger()
{
return m_logger;
+ }
+
+ /**
+ * Return the name of a packaged profile given the type and the
+ * packaged profile key. The key corresponds to the name attribute
+ * declared under the profile definition.
+ *
+ * @param type the component type
+ * @param key the profile name
+ * @return the composite name
+ */
+ private String getProfileName( Type type, String key )
+ {
+ return type.getInfo().getName() + "-" + key;
}
}
1.2 +3 -3 avalon/merlin/composition/spi/src/java/org/apache/avalon/composition/data/builder/ContainmentProfileCreator.java
Index: ContainmentProfileCreator.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/spi/src/java/org/apache/avalon/composition/data/builder/ContainmentProfileCreator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContainmentProfileCreator.java 24 Sep 2003 09:32:29 -0000 1.1
+++ ContainmentProfileCreator.java 4 Oct 2003 11:53:04 -0000 1.2
@@ -65,11 +65,11 @@
/**
* Create a {@link ContainmentProfile} from a stream.
*
- * @param inputStream the stream that the resource is loaded from
+ * @param stream the stream that the resource is loaded from
* @return the containment profile
* @exception Exception if a error occurs during profile creation
*/
- ContainmentProfile createContainmentProfile( InputStream inputStream )
+ ContainmentProfile createContainmentProfile( InputStream stream )
throws Exception;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org