mcconnell 2003/07/05 02:33:43
Modified: merlin/composition/src/java/org/apache/avalon/composition/model/impl
DefaultClassLoaderModel.java
DefaultContainmentModel.java
DefaultDeploymentModel.java
DefaultTypeRepository.java
merlin/meta project.xml
Log:
Update type management to make sure that we return a parent type defintion if it
exists before executing local evaluation.
Revision Changes Path
1.4 +8 -4
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultClassLoaderModel.java
Index: DefaultClassLoaderModel.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultClassLoaderModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultClassLoaderModel.java 5 Jul 2003 07:59:09 -0000 1.3
+++ DefaultClassLoaderModel.java 5 Jul 2003 09:33:42 -0000 1.4
@@ -63,6 +63,7 @@
import org.apache.avalon.composition.model.SystemContext;
import org.apache.avalon.composition.model.TypeRepository;
import org.apache.avalon.composition.model.ServiceRepository;
+import org.apache.avalon.composition.model.TypeUnknownException;
import org.apache.avalon.composition.repository.Repository;
import org.apache.avalon.composition.util.ExceptionHelper;
import org.apache.avalon.extension.Extension;
@@ -78,6 +79,10 @@
import org.apache.avalon.meta.data.ClasspathDirective;
import org.apache.avalon.meta.data.RepositoryDirective;
import org.apache.avalon.meta.data.ResourceDirective;
+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;
/**
* <p>Implementation of a classloader model within which a
@@ -108,7 +113,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision$ $Date$
*/
-public class DefaultClassLoaderModel implements ClassLoaderModel
+public class DefaultClassLoaderModel implements ClassLoaderModel
{
//==============================================================
// static
@@ -117,7 +122,6 @@
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultClassLoaderModel.class );
-
//==============================================================
// state
//==============================================================
@@ -289,7 +293,7 @@
}
//==============================================================
- // public implementation
+ // ClassLoaderModel
//==============================================================
/**
1.3 +4 -4
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultContainmentModel.java 4 Jul 2003 15:24:55 -0000 1.2
+++ DefaultContainmentModel.java 5 Jul 2003 09:33:42 -0000 1.3
@@ -121,7 +121,7 @@
final Logger logger, SystemContext system, ClassLoaderModel classLoaderModel,
ContainmentProfile profile )
throws Exception
{
- super( logger, system, classLoaderModel.getClassLoader(), profile,
SEPERATOR );
+ super( logger, system, classLoaderModel, profile, SEPERATOR );
m_profile = profile;
m_classLoaderModel = classLoaderModel;
expandContainmentModel( system );
@@ -144,7 +144,7 @@
ClassLoaderModel classLoaderModel, ContainmentProfile profile )
throws Exception
{
- super( logger, system, classLoaderModel.getClassLoader(), profile,
+ super( logger, system, classLoaderModel, profile,
parent.getPath() + profile.getName() + SEPERATOR );
m_profile = profile;
m_classLoaderModel = classLoaderModel;
@@ -228,7 +228,7 @@
new DefaultDeploymentModel(
getLogger().getChildLogger( profile.getName() ),
system,
- m_classLoaderModel.getClassLoader(),
+ m_classLoaderModel,
deployment,
getPath() );
m_models.add( model );
1.3 +113 -12
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java
Index: DefaultDeploymentModel.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultDeploymentModel.java 4 Jul 2003 15:24:55 -0000 1.2
+++ DefaultDeploymentModel.java 5 Jul 2003 09:33:42 -0000 1.3
@@ -53,15 +53,19 @@
import java.io.File;
import org.apache.avalon.composition.model.DeploymentModel;
+import org.apache.avalon.composition.model.ClassLoaderModel;
import org.apache.avalon.composition.model.SystemContext;
import org.apache.avalon.composition.repository.Repository;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.meta.data.DeploymentProfile;
-
+import org.apache.avalon.meta.info.Type;
+import org.apache.avalon.meta.info.builder.TypeBuilder;
+import org.apache.excalibur.configuration.CascadingConfiguration;
/**
* Deployment model defintion.
@@ -78,25 +82,48 @@
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultDeploymentModel.class );
+ private static final Configuration EMPTY_CONFIGURATION =
+ new DefaultConfiguration(
+ "configuration", DeploymentModel.class.getName() );
+
+ private static final Type NULL_TYPE;
+ static
+ {
+ try
+ {
+ NULL_TYPE = new TypeBuilder().build( NullComponent.class );
+ }
+ catch( Throwable e )
+ {
+ throw new RuntimeException(
+ "Internal error while creating NullComponent type defintion: "
+ + e.toString() );
+ }
+ }
+
+
//==============================================================
// immutable state
//==============================================================
private final SystemContext m_system;
+ private final ClassLoaderModel m_classLoaderModel;
+
private final DeploymentProfile m_profile;
- private final Class m_class;
+ private final Type m_type;
+ private final Class m_class;
//==============================================================
// mutable state
//==============================================================
- private ClassLoader m_classLoader;
-
private Configuration m_config = null;
+ private boolean m_configurationReplacementPolicy = false;
+
//==============================================================
// constructor
//==============================================================
@@ -112,7 +139,7 @@
* @param path the partition name
*/
public DefaultDeploymentModel(
- final Logger logger, final SystemContext system, ClassLoader classLoader,
+ final Logger logger, final SystemContext system, ClassLoaderModel
classLoaderModel,
final DeploymentProfile profile, String path )
throws Exception
{
@@ -121,9 +148,9 @@
{
throw new NullPointerException( "system" );
}
- if( classLoader == null )
+ if( classLoaderModel == null )
{
- throw new NullPointerException( "classLoader" );
+ throw new NullPointerException( "classLoaderModel" );
}
if( path == null )
{
@@ -132,15 +159,18 @@
m_system = system;
m_profile = profile;
- m_classLoader = classLoader;
+ m_classLoaderModel = classLoaderModel;
if( profile.getClassname() == null )
{
m_class = NullComponent.class;
+ //m_type = NULL_TYPE;
}
else
{
- m_class = m_classLoader.loadClass( profile.getClassname() );
+ m_class = m_classLoaderModel.getClassLoader().loadClass(
+ profile.getClassname() );
}
+ m_type = m_classLoaderModel.getTypeRepository().getType( m_class );
}
//==============================================================
@@ -149,6 +179,11 @@
// expose everything needed to create a new appliance instance
//==============================================================
+ public Type getType()
+ {
+ return m_type;
+ }
+
/**
* Return the class for the deployable target.
* @return the class
@@ -159,6 +194,33 @@
}
/**
+ * Set the configuration to the supplied value. The supplied
+ * configuration will replace the existing configuration.
+ *
+ * @param config the supplied configuration
+ */
+ public void setConfiguration( Configuration config )
+ {
+ setConfiguration( config, true );
+ }
+
+ /**
+ * Set the configuration to the supplied value. The supplied
+ * configuration may suppliment or replace the existing configuration.
+ *
+ * @param config the supplied configuration
+ * @param policy if TRUE the supplied configuration replaces the current
+ * configuration otherwise the resoved configuration shall be layed above
+ * the configuration supplied with the profile which in turn is layer above
+ * the type default configuration (if any)
+ */
+ public void setConfiguration( Configuration config, boolean policy )
+ {
+ m_config = config;
+ m_configurationReplacementPolicy = policy;
+ }
+
+ /**
* Return the configuration to be applied to the component.
* The implementation returns the current configuration state.
* If the the component type does not implementation the
@@ -170,9 +232,48 @@
{
if( Configurable.class.isAssignableFrom( getDeploymentClass() ) )
{
- //Configuration config = getType().getConfiguration();
+ if( m_configurationReplacementPolicy )
+ {
+ if( m_config != null )
+ {
+ return m_config;
+ }
+ else
+ {
+ return EMPTY_CONFIGURATION;
+ }
+ }
+ else
+ {
+ final Configuration defaults = m_type.getConfiguration();
+ final Configuration explicit = m_profile.getConfiguration();
+ Configuration consolidated = consolidateConfigurations( explicit,
defaults );
+ return consolidateConfigurations( m_config, consolidated );
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private Configuration consolidateConfigurations( final Configuration primary,
final Configuration defaults )
+ {
+ if( primary == null )
+ {
+ return defaults;
+ }
+ else
+ {
+ if( defaults == null )
+ {
+ return primary;
+ }
+ else
+ {
+ return new CascadingConfiguration( primary, defaults );
+ }
}
- return null;
}
//==============================================================
1.3 +57 -8
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultTypeRepository.java 5 Jul 2003 07:59:09 -0000 1.2
+++ DefaultTypeRepository.java 5 Jul 2003 09:33:42 -0000 1.3
@@ -82,6 +82,21 @@
class DefaultTypeRepository extends AbstractLogEnabled implements TypeRepository,
Initializable
{
+ private static final Type NULL_TYPE;
+ static
+ {
+ try
+ {
+ NULL_TYPE = new TypeBuilder().build( NullComponent.class );
+ }
+ catch( Throwable e )
+ {
+ throw new RuntimeException(
+ "Internal error while creating NullComponent type defintion: "
+ + e.toString() );
+ }
+ }
+
private final ClassLoader m_classloader;
/**
@@ -133,10 +148,32 @@
public void initialize() throws Exception
{
+ //
+ // If the parent is null then we are root so we add the
+ // NullComponent type as the default component type.
+ //
+
+ if( m_parent == null )
+ {
+ final String classname = NULL_TYPE.getInfo().getClassname();
+ m_types.put( classname , NULL_TYPE );
+ if( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "bootstrap: " + classname );
+ }
+ }
+
+ //
+ // Validate types before adding them to the repository.
+ // If a validation error occurs then abort the process
+ // which will result in classloader establishment failure.
+ //
+
if( getLogger().isDebugEnabled() )
{
- getLogger().debug( "type count: " + m_typesList.size() );
+ getLogger().debug( "validating: " + m_typesList.size() );
}
+
Iterator iterator = m_typesList.iterator();
while( iterator.hasNext() )
{
@@ -156,10 +193,17 @@
error, e, getLogger().isDebugEnabled() ) );
}
}
+
+ //
+ // we should add a test to make sure that the type is
+ // not already defined in parent or locally
+ //
+
if( getLogger().isDebugEnabled() )
{
getLogger().debug( "add: " + classname );
}
+
m_types.put( classname, type );
}
}
@@ -197,17 +241,22 @@
throw new NullPointerException( "classname" );
}
- Type type = (Type) m_types.get( classname );
- if( type == null )
+ if( m_parent != null )
{
- if( m_parent != null )
+ try
{
return m_parent.getType( classname );
- }
- else
+ }
+ catch( TypeUnknownException tue )
{
- throw new TypeUnknownException( classname );
+ // continue
}
+ }
+
+ Type type = (Type) m_types.get( classname );
+ if( type == null )
+ {
+ throw new TypeUnknownException( classname );
}
return type;
1.8 +1 -1 avalon-sandbox/merlin/meta/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/meta/project.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- project.xml 4 Jul 2003 09:02:01 -0000 1.7
+++ project.xml 5 Jul 2003 09:33:43 -0000 1.8
@@ -4,7 +4,7 @@
<extend>${basedir}/../project.xml</extend>
<groupId>avalon</groupId>
<id>avalon-meta</id>
- <name>Avalon Meta Model</name>
+ <name>Avalon Meta Model Implementation</name>
<package>org.apache.avalon.meta</package>
<currentVersion>1.0</currentVersion>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]