Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1396 - in development/main: central/site/src/docs/products/metro/composition/descriptors/tags metro/composition/impl/src/main/net/dpml/composition/model/impl metro/composition/test/src/test/net/dpml/composition/util metro/testing/testschema/src/main/net/dpml/test/testschema

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: pneubauer AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1396 - in development/main: central/site/src/docs/products/metro/composition/descriptors/tags metro/composition/impl/src/main/net/dpml/composition/model/impl metro/composition/test/src/test/net/dpml/composition/util metro/testing/testschema/src/main/net/dpml/test/testschema
  • Date: Thu, 06 Jan 2005 20:46:56 +0100

Author: pneubauer
Date: Thu Jan 6 20:46:56 2005
New Revision: 1396

Modified:

development/main/central/site/src/docs/products/metro/composition/descriptors/tags/configuration.xml

development/main/metro/composition/impl/src/main/net/dpml/composition/model/impl/DefaultComponentModel.java

development/main/metro/composition/test/src/test/net/dpml/composition/util/SchemaValidationTestCase.java

development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableA.java

development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableB.java
Log:
Change schema tag value to "xmlschema" and updated the docs


Modified:
development/main/central/site/src/docs/products/metro/composition/descriptors/tags/configuration.xml
==============================================================================
---
development/main/central/site/src/docs/products/metro/composition/descriptors/tags/configuration.xml
(original)
+++
development/main/central/site/src/docs/products/metro/composition/descriptors/tags/configuration.xml
Thu Jan 6 20:46:56 2005
@@ -21,21 +21,34 @@
<tr>
<td>schema</td><td>yes</td>
<td>
- The validate schema name.
+ The validation schema type. At the moment, only
<code>@configuration schema="xmlschema"</code>
+ is supported.
+
+ xmlschema definitions are placed in the same package as the
component, and have a
+ .xschema extension (same location as the .xinfo, .xconfig etc
files).
</td>
</tr>
</table>
</subsection>

- <subsection name="Example">
+ <subsection name="Example (xmlschema)">

<source><![CDATA[

+.....
+package test
+
+.
+.
+.
+
+public class TestComponent implements Configurable
+
/**
* Configuration of the component by the container.
* @param config the configuration instance
* @exception ConfigurationException if error occurs
- * @metro.configuration schema="your-schema-spec"
+ * @metro.configuration schema="xmlschema"
*/
public void configure( Configuration config ) throws ConfigurationException
{
@@ -43,16 +56,37 @@
}
]]></source>

-<p>Generated meta-info type descriptor:</p>
+<p>Generated meta-info type descriptor (test.TestComponent.xinfo):</p>

<source><![CDATA[
<type>
<info>
- <schema>your-schema-spec</schema>
+ <schema>xmlschema</schema>
</info>
</type>
]]></source>

+<p>Example contents of the validation schema (test.TestComponent.xschema)</p>
+
+<source><![CDATA[
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
+ <xs:element name="configuration">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="child1" type="xs:string"/>
+ </xs:sequence>
+ <xs:attribute name="attr1" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+]]></source>
+which decribes a configuration like this:
+<source><![CDATA[
+<configuration attr1="foo">
+ <child1/>
+</configuration>
+]]></source>
</subsection>
</section>
</body>

Modified:
development/main/metro/composition/impl/src/main/net/dpml/composition/model/impl/DefaultComponentModel.java
==============================================================================
---
development/main/metro/composition/impl/src/main/net/dpml/composition/model/impl/DefaultComponentModel.java
(original)
+++
development/main/metro/composition/impl/src/main/net/dpml/composition/model/impl/DefaultComponentModel.java
Thu Jan 6 20:46:56 2005
@@ -59,204 +59,201 @@

/**
* Deployment model defintion.
- *
- * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta
+ * Library </a>
* @version $Id$
*/
-public class DefaultComponentModel extends DefaultDeploymentModel
- implements ComponentModel
+public class DefaultComponentModel extends DefaultDeploymentModel implements
+ ComponentModel
{
- //--------------------------------------------------------------
+ // --------------------------------------------------------------
// static
- //--------------------------------------------------------------
+ // --------------------------------------------------------------

- private static final Resources REZ =
- ResourceManager.getPackageResources( DefaultComponentModel.class );
+ private static final Resources REZ =
ResourceManager
+
.getPackageResources( DefaultComponentModel.class );

- private static final Configuration EMPTY_CONFIGURATION =
- new DefaultConfiguration(
- "configuration", ComponentModel.class.getName() );
-
- private static final String AVALON_CONFIGURABLE_CLASSNAME =
- "org.apache.avalon.framework.configuration.Configurable";
+ private static final Configuration EMPTY_CONFIGURATION =
new DefaultConfiguration(
+
"configuration",
+
ComponentModel.class
+
.getName() );

- private static final String AVALON_CONFIGURATION_CLASSNAME =
- "org.apache.avalon.framework.configuration.Configuration";
+ private static final String AVALON_CONFIGURABLE_CLASSNAME =
"org.apache.avalon.framework.configuration.Configurable";

- private static final String AVALON_PARAMETERIZABLE_CLASSNAME =
- "org.apache.avalon.framework.parameters.Parameterizable";
+ private static final String AVALON_CONFIGURATION_CLASSNAME =
"org.apache.avalon.framework.configuration.Configuration";

- private static final String AVALON_PARAMETERS_CLASSNAME =
- "org.apache.avalon.framework.parameters.Parameters";
+ private static final String AVALON_PARAMETERIZABLE_CLASSNAME =
"org.apache.avalon.framework.parameters.Parameterizable";

- //--------------------------------------------------------------
+ private static final String AVALON_PARAMETERS_CLASSNAME =
"org.apache.avalon.framework.parameters.Parameters";
+
+ // --------------------------------------------------------------
// immutable state
- //--------------------------------------------------------------
+ // --------------------------------------------------------------

- private final ComponentContext m_context;
+ private final ComponentContext m_context;

- private final ContextModel m_contextModel;
+ private final ContextModel m_contextModel;

- private final DependencyModel[] m_dependencies;
+ private final DependencyModel[] m_dependencies;

- private final StageModel[] m_stages;
+ private final StageModel[] m_stages;

- private final DefaultState m_assembly = new DefaultState();
+ private final DefaultState m_assembly =
new DefaultState();

- //--------------------------------------------------------------
+ // --------------------------------------------------------------
// mutable state
- //--------------------------------------------------------------
+ // --------------------------------------------------------------
+
+ private Configuration m_config;

- private Configuration m_config;
+ private Parameters m_parameters;

- private Parameters m_parameters;
+ private boolean m_activation;

- private boolean m_activation;
+ private int m_collection;

- private int m_collection;
+ private static final String SCHEMA_TAG_W3CSCHEMA =
"xmlschema";

- //--------------------------------------------------------------
+ // --------------------------------------------------------------
// constructor
- //--------------------------------------------------------------
+ // --------------------------------------------------------------

- /**
- * Creation of a new deployment model.
- *
- * @param context the deployment context
- */
- public DefaultComponentModel( ComponentContext context, SecurityModel
security )
- throws ModelException
- {
- super( context, security );
+ /**
+ * Creation of a new deployment model.
+ *
+ * @param context
+ * the deployment context
+ */
+ public DefaultComponentModel( ComponentContext context,
+ SecurityModel security ) throws ModelException
+ {
+ super( context, security );

- m_context = context;
+ m_context = context;

- m_activation = getDefaultActivationPolicy();
+ m_activation = getDefaultActivationPolicy();

- setCollectionPolicy(
m_context.getComponentProfile().getCollectionPolicy() );
+ setCollectionPolicy( m_context.getComponentProfile()
+ .getCollectionPolicy() );

- ClassLoader classLoader = m_context.getClassLoader();
+ ClassLoader classLoader = m_context.getClassLoader();

- if( isConfigurable() )
- {
- final Configuration defaults =
- m_context.getType().getConfiguration();
- final Configuration explicit =
- m_context.getComponentProfile().getConfiguration();
- final Configuration consolidated =
- consolidateConfigurations( explicit, defaults );
- if( consolidated != null )
+ if ( isConfigurable() )
{
- setConfiguration( consolidated );
- }
- else
- {
- setConfiguration( EMPTY_CONFIGURATION );
- }
- }
-
- if( isParameterizable() )
- {
- Parameters staticDefaults = m_context.getType().getParameters();
- final Parameters parameters =
- m_context.getComponentProfile().getParameters();
- if( parameters != null )
- {
- if( null == staticDefaults )
+ final Configuration defaults = m_context.getType()
+ .getConfiguration();
+ final Configuration explicit =
m_context.getComponentProfile()
+ .getConfiguration();
+ final Configuration consolidated = consolidateConfigurations(
+ explicit, defaults );
+ if ( consolidated != null )
{
- m_parameters = parameters;
+ setConfiguration( consolidated );
}
else
{
- m_parameters = new DefaultParameters();
- m_parameters.merge( staticDefaults );
- m_parameters.merge( parameters );
+ setConfiguration( EMPTY_CONFIGURATION );
}
}
- else
+
+ if ( isParameterizable() )
{
- if( null == staticDefaults )
+ Parameters staticDefaults =
m_context.getType().getParameters();
+ final Parameters parameters = m_context.getComponentProfile()
+ .getParameters();
+ if ( parameters != null )
{
- m_parameters = DefaultParameters.EMPTY_PARAMETERS;
+ if ( null == staticDefaults )
+ {
+ m_parameters = parameters;
+ }
+ else
+ {
+ m_parameters = new DefaultParameters();
+ m_parameters.merge( staticDefaults );
+ m_parameters.merge( parameters );
+ }
}
else
{
- m_parameters = staticDefaults;
+ if ( null == staticDefaults )
+ {
+ m_parameters = DefaultParameters.EMPTY_PARAMETERS;
+ }
+ else
+ {
+ m_parameters = staticDefaults;
+ }
}
}
- }
-
- final ContextDescriptor contextDescriptor =
- m_context.getType().getContext();
- final ContextDirective contextDirective =
- m_context.getComponentProfile().getContext();
- final Logger log = getLogger().getChildLogger( "context" );
- m_contextModel =
- new DefaultContextModel(
- log, contextDescriptor, contextDirective, context );
-
- //
- // create the dependency models for subsequent assembly
- // management
- //
-
- DependencyDescriptor[] dependencies =
- m_context.getType().getDependencies();
- m_dependencies = new DefaultDependencyModel[ dependencies.length ];
-
- for( int i=0; i<dependencies.length; i++ )
- {
- DependencyDescriptor descriptor = dependencies[i];
- DependencyDirective directive =
- context.getComponentProfile().getDependencyDirective(
descriptor.getKey() );
- m_dependencies[i] =
- new DefaultDependencyModel(
- context.getLogger().getChildLogger( "deps" ),
- context.getPartitionName(),
- context.getProfile().getName(),
- descriptor,
- directive );
- }
-
- //
- // create the stage models for subsequent assembly
- // management
- //
-
- StageDescriptor[] stages =
- m_context.getType().getStages();
- m_stages = new DefaultStageModel[ stages.length ];

- for( int i=0; i<stages.length; i++ )
- {
- StageDescriptor descriptor = stages[i];
- StageDirective directive =
- context.getComponentProfile().getStageDirective(
descriptor.getKey() );
- m_stages[i] =
- new DefaultStageModel(
- context.getLogger().getChildLogger( "stages" ),
- context.getPartitionName(), descriptor, directive );
+ final ContextDescriptor contextDescriptor = m_context.getType()
+ .getContext();
+ final ContextDirective contextDirective = m_context
+ .getComponentProfile().getContext();
+ final Logger log = getLogger().getChildLogger( "context" );
+ m_contextModel = new DefaultContextModel( log, contextDescriptor,
+ contextDirective, context );
+
+ //
+ // create the dependency models for subsequent assembly
+ // management
+ //
+
+ DependencyDescriptor[] dependencies = m_context.getType()
+ .getDependencies();
+ m_dependencies = new DefaultDependencyModel[dependencies.length];
+
+ for ( int i = 0; i < dependencies.length; i++ )
+ {
+ DependencyDescriptor descriptor = dependencies[i];
+ DependencyDirective directive = context.getComponentProfile()
+ .getDependencyDirective( descriptor.getKey() );
+ m_dependencies[i] = new DefaultDependencyModel( context
+ .getLogger().getChildLogger( "deps" ), context
+ .getPartitionName(), context.getProfile().getName(),
+ descriptor, directive );
+ }
+
+ //
+ // create the stage models for subsequent assembly
+ // management
+ //
+
+ StageDescriptor[] stages = m_context.getType().getStages();
+ m_stages = new DefaultStageModel[stages.length];
+
+ for ( int i = 0; i < stages.length; i++ )
+ {
+ StageDescriptor descriptor = stages[i];
+ StageDirective directive = context.getComponentProfile()
+ .getStageDirective( descriptor.getKey() );
+ m_stages[i] = new DefaultStageModel( context.getLogger()
+ .getChildLogger( "stages" ),
+ context.getPartitionName(), descriptor, directive );
+ }
}
- }

- /**
- * Get the default activation policy for the model.
- */
+ /**
+ * Get the default activation policy for the model.
+ */
public boolean getDefaultActivationPolicy()
{
- final int activation =
- m_context.getComponentProfile().getActivationDirective();
+ final int activation = m_context.getComponentProfile()
+ .getActivationDirective();

- if( activation != DeploymentProfile.DEFAULT )
+ if ( activation != DeploymentProfile.DEFAULT )
{
- return (activation == DeploymentProfile.ENABLED );
+ return ( activation == DeploymentProfile.ENABLED );
}
else
{
- if( m_context.getProfile().getMode() == Mode.EXPLICIT )
+ if ( m_context.getProfile().getMode() == Mode.EXPLICIT )
{
Type type = m_context.getType();
- if( type.getInfo().getLifestyle().equals(
InfoDescriptor.TRANSIENT ) )
+ if ( type.getInfo().getLifestyle().equals(
+ InfoDescriptor.TRANSIENT ) )
{
return false;
}
@@ -272,51 +269,50 @@
}
}

- //--------------------------------------------------------------
+ // --------------------------------------------------------------
// Commissionable
- //--------------------------------------------------------------
+ // --------------------------------------------------------------

- /**
- * Commission the model.
- *
- * @exception Exception if a commissioning error occurs
- */
+ /**
+ * Commission the model.
+ *
+ * @exception Exception
+ * if a commissioning error occurs
+ */
public void commission() throws Exception
{
- if( isAssembled() )
+ if ( isAssembled() )
{
super.commission();
}
else
{
- final String error =
- "Illegal attempt to commission a non-assembled component
model: "
- + this;
+ final String error = "Illegal attempt to commission a
non-assembled component model: "
+ + this;
throw new ModelException( error );
}
}

- //--------------------------------------------------------------
+ // --------------------------------------------------------------
// Composite
- //--------------------------------------------------------------
+ // --------------------------------------------------------------

/**
* Returns the assembled state of the model.
+ *
* @return true if this model is assembled
*/
public boolean isAssembled()
{
- return (
- isStageAssembled()
- && isServiceAssembled() );
+ return ( isStageAssembled() && isServiceAssembled() );
}

private boolean isStageAssembled()
{
StageModel[] stages = getStageModels();
- for( int i=0; i<stages.length; i++ )
+ for ( int i = 0; i < stages.length; i++ )
{
- if( null == stages[i].getProvider() )
+ if ( null == stages[i].getProvider() )
{
return false;
}
@@ -327,11 +323,10 @@
private boolean isServiceAssembled()
{
DependencyModel[] dependencies = getDependencyModels();
- for( int i=0; i<dependencies.length; i++ )
+ for ( int i = 0; i < dependencies.length; i++ )
{
DependencyModel dep = dependencies[i];
- if( null == dep.getProvider() &&
- dep.getDependency().isRequired() )
+ if ( null == dep.getProvider() &&
dep.getDependency().isRequired() )
{
return false;
}
@@ -341,106 +336,110 @@

/**
* Return the set of models assigned as providers.
+ *
* @return the providers consumed by the model
- * @exception IllegalStateException if the model is not in an assembled
state
+ * @exception IllegalStateException
+ * if the model is not in an assembled state
*/
public DeploymentModel[] getProviders()
{
- if( !isAssembled() )
+ if ( !isAssembled() )
{
- final String error =
- "Model is not assembled " + this;
- throw new IllegalStateException( error );
+ final String error = "Model is not assembled " + this;
+ throw new IllegalStateException( error );
}

- final ArrayList list = new ArrayList();
+ final ArrayList list = new ArrayList();
StageModel[] stages = getStageModels();
- for( int i=0; i<stages.length; i++ )
+ for ( int i = 0; i < stages.length; i++ )
{
StageModel stage = stages[i];
list.add( stage.getProvider() );
}
DependencyModel[] dependencies = getDependencyModels();
- for( int i=0; i<dependencies.length; i++ )
+ for ( int i = 0; i < dependencies.length; i++ )
{
DependencyModel dependency = dependencies[i];
DeploymentModel provider = dependency.getProvider();
- if( provider != null )
+ if ( provider != null )
+ {
list.add( provider );
+ }
}

return (DeploymentModel[]) list.toArray( new DeploymentModel[0] );
}

- //--------------------------------------------------------------
+ // --------------------------------------------------------------
// DeploymentModel
- //--------------------------------------------------------------
+ // --------------------------------------------------------------

- /**
- * Return the set of services produced by the model.
- *
- * @return the service descriptors
- */
+ /**
+ * Return the set of services produced by the model.
+ *
+ * @return the service descriptors
+ */
public ServiceDescriptor[] getServices()
{
return m_context.getType().getServices();
}

- /**
- * Return TRUE is this model is capable of supporting a supplied
- * depedendency.
- *
- * @param dependency the dependency descriptor
- * @return true if this model can fulfill the dependency
- */
+ /**
+ * Return TRUE is this model is capable of supporting a supplied
+ * depedendency.
+ *
+ * @param dependency
+ * the dependency descriptor
+ * @return true if this model can fulfill the dependency
+ */
public boolean isaCandidate( DependencyDescriptor dependency )
{
return isaCandidate( dependency.getReference() );
}

- /**
- * Return TRUE is this model is capable of supporting a supplied
- * stage dependency.
- *
- * @param stage the stage descriptor
- * @return TRUE if this model can fulfill the stage dependency
- */
+ /**
+ * Return TRUE is this model is capable of supporting a supplied stage
+ * dependency.
+ *
+ * @param stage
+ * the stage descriptor
+ * @return TRUE if this model can fulfill the stage dependency
+ */
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
- */
+ /**
+ * 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;
}

- //--------------------------------------------------------------
+ // --------------------------------------------------------------
// ComponentModel
- //--------------------------------------------------------------
+ // --------------------------------------------------------------

- /**
- * Return the collection policy for the model. If a profile
- * does not declare a collection policy, then the collection
- * policy declared by the underlying component type
- * will be used.
- *
- * @return the collection policy
- * @see InfoDescriptor#WEAK
- * @see InfoDescriptor#SOFT
- * @see InfoDescriptor#HARD
- * @see InfoDescriptor#UNDEFINED
- */
+ /**
+ * Return the collection policy for the model. If a profile does not
declare
+ * a collection policy, then the collection policy declared by the
+ * underlying component type will be used.
+ *
+ * @return the collection policy
+ * @see InfoDescriptor#WEAK
+ * @see InfoDescriptor#SOFT
+ * @see InfoDescriptor#HARD
+ * @see InfoDescriptor#UNDEFINED
+ */
public int getCollectionPolicy()
{
- if( m_collection == InfoDescriptor.UNDEFINED )
+ if ( m_collection == InfoDescriptor.UNDEFINED )
{
return getTypeCollectionPolicy();
}
@@ -450,33 +449,34 @@
}
}

- /**
- * Set the collection policy for the model.
- *
- * @param policy the collection policy
- * @see InfoDescriptor#WEAK
- * @see InfoDescriptor#SOFT
- * @see InfoDescriptor#HARD
- */
+ /**
+ * Set the collection policy for the model.
+ *
+ * @param policy
+ * the collection policy
+ * @see InfoDescriptor#WEAK
+ * @see InfoDescriptor#SOFT
+ * @see InfoDescriptor#HARD
+ */
public void setCollectionPolicy( int policy )
{
- if( policy == InfoDescriptor.UNDEFINED )
+ if ( policy == InfoDescriptor.UNDEFINED )
{
m_collection = InfoDescriptor.UNDEFINED;
}
else
{
int minimum = getTypeCollectionPolicy();
- if( policy >= minimum )
+ if ( policy >= minimum )
{
m_collection = policy;
}
else
{
- final String warning =
- "Ignoring collection policy override [" + policy
- + "] because the value is higher that type threshhold ["
- + minimum + "].";
+ final String warning = "Ignoring collection policy override
["
+ + policy
+ + "] because the value is higher that type
threshhold ["
+ + minimum + "].";
getLogger().warn( warning );
}
}
@@ -486,20 +486,21 @@
{
return m_context.getType().getInfo().getCollectionPolicy();
}
-
- /**
- * Return the proxy enabled policy for the model. If the system wide
- * proxy enabled is disabled the operation will return false otherwise
the
- * value returned is true unless overriden by the "urn:composition:proxy"
- * attribute.
- *
- * @return the proxy policy
- */
+
+ /**
+ * Return the proxy enabled policy for the model. If the system wide
proxy
+ * enabled is disabled the operation will return false otherwise the
value
+ * returned is true unless overriden by the "urn:composition:proxy"
+ * attribute.
+ *
+ * @return the proxy policy
+ */
public boolean getProxyPolicy()
{
- if( m_context.getSystemContext().isProxyEnabled() )
+ if ( m_context.getSystemContext().isProxyEnabled() )
{
- if( getType().getInfo().getAttribute( PROXY_KEY, "true"
).equals( "false" ) )
+ if ( getType().getInfo().getAttribute( PROXY_KEY, "true"
).equals(
+ "false" ) )
{
return false;
}
@@ -511,140 +512,137 @@
else
{
return false;
- }
+ }
}

- /**
- * Return the activation policy for the model.
- * @return the activaltion policy
- */
+ /**
+ * Return the activation policy for the model.
+ *
+ * @return the activaltion policy
+ */
public boolean getActivationPolicy()
{
return m_activation;
}

- /**
- * Set the activation policy for the model.
- *
- * @param policy the activaltion policy
- */
+ /**
+ * Set the activation policy for the model.
+ *
+ * @param policy
+ * the activaltion policy
+ */
public void setActivationPolicy( boolean policy )
{
m_activation = policy;
}

- /**
- * Return the component type descriptor.
- * @return the type descriptor
- */
+ /**
+ * Return the component type descriptor.
+ *
+ * @return the type descriptor
+ */
public Type getType()
{
return m_context.getType();
}

- /**
- * Return the class for the deployable target.
- * @return the class
- */
+ /**
+ * Return the class for the deployable target.
+ *
+ * @return the class
+ */
public Class getDeploymentClass()
{
return m_context.getDeploymentClass();
}

- /**
- * Rest if the component type backing the model is
- * parameterizable.
- *
- * @return TRUE if the compoent type is parameterizable
- * otherwise FALSE
- */
+ /**
+ * Rest if the component type backing the model is parameterizable.
+ *
+ * @return TRUE if the compoent type is parameterizable otherwise FALSE
+ */
public boolean isParameterizable()
{
- if( getType().getInfo().isNative() )
+ if ( getType().getInfo().isNative() )
{
- return (
- Parameterizable.class.isAssignableFrom( getDeploymentClass() )
- || isaConstructorArg( Parameters.class ) );
+ return ( Parameterizable.class
+ .isAssignableFrom( getDeploymentClass() ) ||
isaConstructorArg( Parameters.class ) );
}
else
{
try
{
ClassLoader loader = m_context.getClassLoader();
- Class parameterizable = loader.loadClass(
AVALON_PARAMETERIZABLE_CLASSNAME );
- Class parameters = loader.loadClass(
AVALON_PARAMETERS_CLASSNAME );
- return (
- parameterizable.isAssignableFrom( getDeploymentClass() )
- || isaConstructorArg( parameters ) );
- }
- catch( Throwable e )
- {
- final String error =
- "The component type "
- + getType()
- + " is based on the Avalon component model "
- + "however the required classes are not available "
- + "withing the containing classloader.";
+ Class parameterizable = loader
+ .loadClass( AVALON_PARAMETERIZABLE_CLASSNAME );
+ Class parameters = loader
+ .loadClass( AVALON_PARAMETERS_CLASSNAME );
+ return ( parameterizable
+ .isAssignableFrom( getDeploymentClass() ) ||
isaConstructorArg( parameters ) );
+ }
+ catch ( Throwable e )
+ {
+ final String error = "The component type " + getType()
+ + " is based on the Avalon component model "
+ + "however the required classes are not available "
+ + "withing the containing classloader.";
throw new ModelRuntimeException( error, e );
}
}
}

- /**
- * Set the parameters to the supplied value. The supplied
- * parameters value will replace the existing parameters value.
- *
- * @param parameters the supplied parameters value
- * @exception IllegalStateException if the component type backing the
- * model does not implement the parameteriazable interface
- * @exception NullPointerException if the supplied parameters are null
- */
+ /**
+ * Set the parameters to the supplied value. The supplied parameters
value
+ * will replace the existing parameters value.
+ *
+ * @param parameters
+ * the supplied parameters value
+ */
public void setParameters( Parameters parameters )
{
setParameters( parameters, true );
}

- /**
- * Set the parameters to the supplied value. The supplied
- * parameters value may suppliment or replace the existing
- * parameters value.
- *
- * @param parameters the supplied parameters
- * @param merge if TRUE the supplied parameters are merged with existing
- * parameters otherwise the supplied parameters replace any existing
- * parameters
- * @exception IllegalStateException if the component type backing the
- * model does not implement the parameteriazable interface
- * @exception NullPointerException if the supplied parameters are null
- */
+ /**
+ * Set the parameters to the supplied value. The supplied parameters
value
+ * may suppliment or replace the existing parameters value.
+ *
+ * @param parameters
+ * the supplied parameters
+ * @param merge
+ * if TRUE the supplied parameters are merged with existing
+ * parameters otherwise the supplied parameters replace any
+ * existing parameters
+ * @exception IllegalStateException
+ * if the component type backing the model does not
implement
+ * the parameteriazable interface
+ */
public void setParameters( Parameters parameters, boolean merge )
- throws IllegalStateException
+ throws IllegalStateException
{
- if( !isParameterizable() )
+ if ( !isParameterizable() )
{
- final String error =
- REZ.getString(
- "deployment.parameters.irrational",
- getDeploymentClass().getName(),
- this.toString() );
+ final String error = REZ.getString(
+ "deployment.parameters.irrational", getDeploymentClass()
+ .getName(), this.toString() );
throw new IllegalStateException( error );
}

- if( parameters == null )
+ if ( parameters == null )
{
throw new NullPointerException( "parameters" );
}

- if( merge )
+ if ( merge )
{
Properties props = DefaultParameters.toProperties( m_parameters
);
Properties suppliment = DefaultParameters.toProperties(
parameters );
Enumeration list = suppliment.propertyNames();
- while( list.hasMoreElements() )
+ while ( list.hasMoreElements() )
{
String name = (String) list.nextElement();
String value = suppliment.getProperty( name );
- if( value == null )
+ if ( value == null )
{
props.remove( name );
}
@@ -656,20 +654,20 @@
m_parameters = new DefaultParameters( props );
}
else
- {
+ {
m_parameters = parameters;
}
}

- /**
- * Return the parameters to be applied to the component.
- *
- * @return the assigned parameters
- */
+ /**
+ * Return the parameters to be applied to the component.
+ *
+ * @return the assigned parameters
+ */
public Parameters getParameters()
{
DefaultParameters params = new DefaultParameters();
- if( null != m_parameters )
+ if ( null != m_parameters )
{
params.merge( m_parameters );
}
@@ -677,172 +675,182 @@
return params;
}

- /**
- * Test if the component type backing the model is
- * configurable.
- *
- * @return TRUE if the component type is configurable
- * otherwise FALSE
- */
+ /**
+ * Test if the component type backing the model is configurable.
+ *
+ * @return TRUE if the component type is configurable otherwise FALSE
+ */
public boolean isConfigurable()
{
- if( getType().getInfo().isNative() )
+ if ( getType().getInfo().isNative() )
{
- return (
- Configurable.class.isAssignableFrom( getDeploymentClass() )
- || isaConstructorArg( Configuration.class ) );
+ return ( Configurable.class.isAssignableFrom(
getDeploymentClass() ) || isaConstructorArg( Configuration.class ) );
}
else
{
try
{
ClassLoader loader = m_context.getClassLoader();
- Class configurable = loader.loadClass(
AVALON_CONFIGURABLE_CLASSNAME );
- Class configuration = loader.loadClass(
AVALON_CONFIGURATION_CLASSNAME );
- return (
- configurable.isAssignableFrom( getDeploymentClass() )
- || isaConstructorArg( configuration ) );
- }
- catch( Throwable e )
- {
- final String error =
- "The component type "
- + getType()
- + " is based on the Avalon component model "
- + "however the required classes are not available "
- + "withing the containing classloader.";
+ Class configurable = loader
+ .loadClass( AVALON_CONFIGURABLE_CLASSNAME );
+ Class configuration = loader
+ .loadClass( AVALON_CONFIGURATION_CLASSNAME );
+ return ( configurable.isAssignableFrom( getDeploymentClass()
) || isaConstructorArg( configuration ) );
+ }
+ catch ( Throwable e )
+ {
+ final String error = "The component type " + getType()
+ + " is based on the Avalon component model "
+ + "however the required classes are not available "
+ + "withing the containing classloader.";
throw new ModelRuntimeException( error, e );
}
}
}

- /**
- * Set the configuration to the supplied value. The supplied
- * configuration will replace the existing configuration.
- *
- * @param config the supplied configuration
- * @exception IllegalStateException if the component type backing the
- * model does not implement the configurable interface
- * @exception ModelException if the supplied configuration is null or
- * not successfully validated (if requested)
- */
+ /**
+ * Set the configuration to the supplied value. The supplied
configuration
+ * will replace the existing configuration.
+ *
+ * @param config
+ * the supplied configuration
+ * @exception IllegalStateException
+ * if the component type backing the model does not
implement
+ * the configurable interface
+ * @exception ModelException
+ * if the supplied configuration is null or not
successfully
+ * validated (if requested)
+ */
public void setConfiguration( Configuration config )
- throws IllegalStateException, ModelException
+ throws IllegalStateException, ModelException
{
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 FALSE 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)
- * @exception IllegalStateException if the component type backing the
- * model does not implement the configurable interface
- * @exception NullPointerException if the supplied configuration is null
- */
- public void setConfiguration( Configuration config, boolean policy )
- throws IllegalStateException, ModelException
- {
- if( !isConfigurable() )
- {
- final String error =
- REZ.getString(
- "deployment.configuration.irrational",
- getDeploymentClass().getName(),
- this.toString() );
+ /**
+ * Set the configuration to the supplied value. The supplied
configuration
+ * may suppliment or replace the existing configuration.
+ *
+ * @param iConfig
+ * the supplied configuration
+ * @param policy
+ * if FALSE 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)
+ * @exception IllegalStateException
+ * if the component type backing the model does not
implement
+ * the configurable interface
+ * @exception ModelException
+ * if the supplied configuration is null or if validation
had
+ * errors
+ */
+ public void setConfiguration( Configuration iConfig, boolean policy )
+ throws IllegalStateException, ModelException
+ {
+ if ( !isConfigurable() )
+ {
+ final String error = REZ.getString(
+ "deployment.configuration.irrational",
getDeploymentClass()
+ .getName(), this.toString() );
throw new IllegalStateException( error );
}

- if( config == null )
+ if ( iConfig == null )
{
throw new NullPointerException( "config" );
}

- Configuration t_config = config;
- if( policy )
+ Configuration config = iConfig;
+ if ( policy )
{
- t_config = consolidateConfigurations( config, m_config );
+ iConfig = consolidateConfigurations( iConfig, m_config );
}
String schema = this.getType().getInfo().getConfigurationSchema();
- Boolean shouldWeValidate = Boolean.valueOf(schema);
- if( shouldWeValidate.booleanValue() )
+ if ( schema != null )
{
- //TODO: this is the only validator we have, this should be some
factory later on
- try
+ if ( schema.equals( SCHEMA_TAG_W3CSCHEMA ) )
{
- XercesSchemaValidator validator = new
XercesSchemaValidator();
- //TODO: we have just one policy to locate schemas yet :
Colocation to the component class
- String classname = this.getType().getInfo().getClassname();
- String iSchemaLocation =
- classname.replace( '.', '/' ) + ".xschema";
- InputStream schemaStream =
- this.getClass().getClassLoader().getResourceAsStream(
iSchemaLocation );
- validator.validate( t_config, schemaStream );
- }
- catch( Exception e )
- {
- final String error =
- "Configuration validation error.";
- throw new ModelException( error, e );
- }
- }
- m_config = t_config;
- }
-
- /**
- * 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
- * Configurable interface, the implementation returns null.
- *
- * @return the qualified configuration
- */
+ // TODO: this is the only validator we have, this should be
some
+ // factory later on
+ try
+ {
+ XercesSchemaValidator validator = new
XercesSchemaValidator();
+ // TODO: we have just one policy to locate schemas yet :
+ // Colocation to the component class
+ String classname =
this.getType().getInfo().getClassname();
+ String iSchemaLocation = classname.replace( '.', '/' )
+ + ".xschema";
+ InputStream schemaStream =
this.getClass().getClassLoader()
+ .getResourceAsStream( iSchemaLocation );
+ validator.validate( iConfig, schemaStream );
+ }
+ catch ( Exception e )
+ {
+ final String error = "Configuration validation error.";
+ throw new ModelException( error, e );
+ }
+ }
+ else
+ {
+ throw new ModelException( "validation method '" + schema
+ + "' is not supported. "
+ + "If you want validation, try '"
+ + SCHEMA_TAG_W3CSCHEMA + "'." );
+ }
+ }
+ m_config = iConfig;
+ }
+
+ /**
+ * 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 Configurable interface, the
+ * implementation returns null.
+ *
+ * @return the qualified configuration
+ */
public Configuration getConfiguration()
{
return m_config;
}

- /**
- * Return the context model for this deployment model.
- *
- * @return the context model if this model is context dependent, else
- * the return value is null
- */
+ /**
+ * Return the context model for this deployment model.
+ *
+ * @return the context model if this model is context dependent, else the
+ * return value is null
+ */
public ContextModel getContextModel()
{
return m_contextModel;
}

- /**
- * Return the dependency models for this component type.
- *
- * @return the dependency models
- */
+ /**
+ * Return the dependency models for this component type.
+ *
+ * @return the dependency models
+ */
public DependencyModel[] getDependencyModels()
{
return m_dependencies;
}

- /**
- * Return a dependency model matching the supplied descriptor. If
- * no model matches the supplied descriptor the implementation
- * will return null.
- *
- * @param dependency the dependency descriptor
- * @return the matching stage model
- */
+ /**
+ * Return a dependency model matching the supplied descriptor. If no
model
+ * matches the supplied descriptor the implementation will return null.
+ *
+ * @param dependency
+ * the dependency descriptor
+ * @return the matching stage model
+ */
public DependencyModel getDependencyModel( DependencyDescriptor
dependency )
{
DependencyModel[] models = getDependencyModels();
- for( int i=0; i<models.length; i++ )
+ for ( int i = 0; i < models.length; i++ )
{
DependencyModel model = models[i];
- if( dependency.equals( model.getDependency() ) )
+ if ( dependency.equals( model.getDependency() ) )
{
return model;
}
@@ -850,32 +858,31 @@
return null;
}

-
- /**
- * Return the stage models for this component type.
- *
- * @return the stage models
- */
+ /**
+ * Return the stage models for this component type.
+ *
+ * @return the stage models
+ */
public StageModel[] getStageModels()
{
return m_stages;
}

- /**
- * Return a stage model matching the supplied descriptor. If
- * no stage model matches the supplied descriptor the implementation
- * will return null.
- *
- * @param stage the stage descriptor
- * @return the matching stage model
- */
+ /**
+ * Return a stage model matching the supplied descriptor. If no stage
model
+ * matches the supplied descriptor the implementation will return null.
+ *
+ * @param stage
+ * the stage descriptor
+ * @return the matching stage model
+ */
public StageModel getStageModel( StageDescriptor stage )
{
StageModel[] stages = getStageModels();
- for( int i=0; i<stages.length; i++ )
+ for ( int i = 0; i < stages.length; i++ )
{
StageModel model = stages[i];
- if( stage.equals( model.getStage() ) )
+ if ( stage.equals( model.getStage() ) )
{
return model;
}
@@ -883,12 +890,11 @@
return null;
}

-
- /**
- * Return the set of services produced by the model as a array of classes.
- *
- * @return the service classes
- */
+ /**
+ * Return the set of services produced by the model as a array of
classes.
+ *
+ * @return the service classes
+ */
public Class[] getInterfaces()
{
//
@@ -899,7 +905,7 @@
ClassLoader classLoader = m_context.getClassLoader();
ArrayList list = new ArrayList();
ServiceDescriptor[] services = getServices();
- for( int i=0; i<services.length; i++ )
+ for ( int i = 0; i < services.length; i++ )
{
final ServiceDescriptor service = services[i];
final String classname = service.getReference().getClassname();
@@ -907,14 +913,14 @@
}

//
- // if the component is an extension then add all implemented
+ // if the component is an extension then add all implemented
// interfaces
//

- if( getType().getExtensions().length > 0 )
+ if ( getType().getExtensions().length > 0 )
{
Class[] interfaces = getDeploymentClass().getInterfaces();
- for( int i=0; i<interfaces.length; i++ )
+ for ( int i = 0; i < interfaces.length; i++ )
{
list.add( interfaces[i] );
}
@@ -923,30 +929,25 @@
return (Class[]) list.toArray( new Class[0] );
}

- /**
- * Return the deployment timeout value for the component.
- *
- * @return the default deployment timeout value
- */
+ /**
+ * Return the deployment timeout value for the component.
+ *
+ * @return the default deployment timeout value
+ */
public long getDeploymentTimeout()
{
- String value =
- m_context.getType().getInfo().getAttribute(
- DEPLOYMENT_TIMEOUT_KEY, null );
- if( null != value )
+ String value = m_context.getType().getInfo().getAttribute(
+ DEPLOYMENT_TIMEOUT_KEY, null );
+ if ( null != value )
{
try
{
return Long.parseLong( value );
}
- catch( NumberFormatException nfe )
+ catch ( NumberFormatException nfe )
{
- final String error =
- "Invalid timout parameter ["
- + value
- + "] in component type ["
- + m_context.getType()
- + "].";
+ final String error = "Invalid timout parameter [" + value
+ + "] in component type [" + m_context.getType() +
"].";
throw new ModelRuntimeException( error, nfe );
}
}
@@ -956,37 +957,41 @@
}
}

- //==============================================================
+ // ==============================================================
// implementation
- //==============================================================
+ // ==============================================================

- /**
- * Test to determin if the first constructor supports the context
- * base class as a parameter type.
- * @return TRUE or FALSE
- */
+ /**
+ * Test to determin if the first constructor supports the context base
class
+ * as a parameter type.
+ *
+ * @return TRUE or FALSE
+ */
private boolean isaConstructorArg( Class base )
{
- if( null == base ) return false;
+ if ( null == base )
+ return false;
Class clazz = getDeploymentClass();
Constructor[] constructors = clazz.getConstructors();
- if( constructors.length == 0 ) return false;
+ if ( constructors.length == 0 )
+ return false;
Constructor constructor = constructors[0];
Class[] types = constructor.getParameterTypes();
- for( int i=0; i<types.length; i++ )
+ for ( int i = 0; i < types.length; i++ )
{
- if( base.isAssignableFrom( types[i] ) ) return true;
+ if ( base.isAssignableFrom( types[i] ) )
+ return true;
}
return false;
}

private Class getComponentClass( ClassLoader classLoader, String
classname )
{
- if( classLoader == null )
+ if ( classLoader == null )
{
throw new NullPointerException( "classLoader" );
}
- if( classname == null )
+ if ( classname == null )
{
throw new NullPointerException( "classname" );
}
@@ -995,24 +1000,24 @@
{
return classLoader.loadClass( classname );
}
- catch( ClassNotFoundException e )
+ catch ( ClassNotFoundException e )
{
return null;
}
}

- private Configuration consolidateConfigurations(
- final Configuration primary, final Configuration defaults )
+ private Configuration consolidateConfigurations(
+ final Configuration primary, final Configuration defaults )
{
- if( primary == null )
+ if ( primary == null )
{
return defaults;
}
else
{
- if( defaults == null )
+ if ( defaults == null )
{
- return primary;
+ return primary;
}
else
{

Modified:
development/main/metro/composition/test/src/test/net/dpml/composition/util/SchemaValidationTestCase.java
==============================================================================
---
development/main/metro/composition/test/src/test/net/dpml/composition/util/SchemaValidationTestCase.java
(original)
+++
development/main/metro/composition/test/src/test/net/dpml/composition/util/SchemaValidationTestCase.java
Thu Jan 6 20:46:56 2005
@@ -22,15 +22,12 @@
import java.io.InputStream;
import java.util.Hashtable;

-import junit.framework.TestCase;
import net.dpml.composition.model.ContainmentModel;
import net.dpml.composition.model.ModelException;
-import net.dpml.composition.model.ModelRuntimeException;
import net.dpml.composition.test.CompositionTestCase;
import net.dpml.configuration.Configuration;
import net.dpml.configuration.impl.DefaultConfiguration;
import net.dpml.configuration.impl.DefaultConfigurationBuilder;
-import net.dpml.test.testschema.ConfigurableA;
import net.dpml.test.testschema.ConfigurableB;

import org.apache.xerces.parsers.SAXParser;
@@ -46,10 +43,11 @@
public class SchemaValidationTestCase extends CompositionTestCase
{

- private static final String PATH = "schemavalidation.xml";
- static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";;
+ private static final String PATH =
"schemavalidation.xml";

- static final String W3C_XML_SCHEMA =
"http://www.w3.org/2001/XMLSchema";;
+ static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";;
+
+ static final String W3C_XML_SCHEMA =
"http://www.w3.org/2001/XMLSchema";;

/**
*/
@@ -95,9 +93,10 @@

private Configuration m_config;

- private InputStream m_schema;
+ private InputStream m_schema;
+
+ private ContainmentModel m_model;

- private ContainmentModel m_model;
/**
* @see junit.framework.TestCase#setUp()
*/
@@ -111,8 +110,8 @@

ConfigurableB confB = new ConfigurableB();
String path = confB.getClass().getName().replace( '.', '/' )
- + ".xschema";
- m_schema = getClass().getClassLoader().getResourceAsStream(path);
+ + ".xschema";
+ m_schema = getClass().getClassLoader().getResourceAsStream( path );

}

@@ -126,10 +125,11 @@
}
catch ( Exception e )
{
- fail();
+ fail( e.toString() );
}

}
+
public void testValidatingAssemblyWithoutConfig() throws Exception
{

@@ -142,10 +142,11 @@
}
catch ( Exception e )
{
- assertTrue(true);
+ assertTrue( true );
}

}
+
public void testParsingOfValidatingXMLOKWhenUsingFiles() throws Exception
{
SAXParser saxParser = new SAXParser();
@@ -211,7 +212,8 @@
{
try
{
- m_validator.validate( m_config, new
ByteArrayInputStream("hej".getBytes()) );
+ m_validator.validate( m_config, new ByteArrayInputStream( "hej"
+ .getBytes() ) );
}
catch ( ModelException e )
{

Modified:
development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableA.java
==============================================================================
---
development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableA.java
(original)
+++
development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableA.java
Thu Jan 6 20:46:56 2005
@@ -33,7 +33,7 @@

/**
* @see
net.dpml.configuration.Configurable#configure(net.dpml.configuration.Configuration)
- * @metro.configuration schema="weird.xschema"
+ * @metro.configuration schema="somethingelse"
*/
public void configure( Configuration configuration ) throws
ConfigurationException
{

Modified:
development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableB.java
==============================================================================
---
development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableB.java
(original)
+++
development/main/metro/testing/testschema/src/main/net/dpml/test/testschema/ConfigurableB.java
Thu Jan 6 20:46:56 2005
@@ -32,7 +32,7 @@
private Logger m_logger;

/**
- * @metro.configuration schema="true"
+ * @metro.configuration schema="xmlschema"
*/
public void configure( Configuration configuration ) throws
ConfigurationException
{



  • svn commit: r1396 - in development/main: central/site/src/docs/products/metro/composition/descriptors/tags metro/composition/impl/src/main/net/dpml/composition/model/impl metro/composition/test/src/test/net/dpml/composition/util metro/testing/testschema/src/main/net/dpml/test/testschema, pneubauer, 01/06/2005

Archive powered by MHonArc 2.6.24.

Top of Page