mcconnell 2004/03/13 15:26:59
Modified: merlin/activation/impl/src/java/org/apache/avalon/activation/impl
ApplianceInvocationHandler.java
DefaultAppliance.java DefaultComponentFactory.java
merlin/activation/impl/src/test/org/apache/avalon/activation/impl/test
CodeSecurityDisabledTestCase.java
merlin/composition/api/src/java/org/apache/avalon/composition/model
ComponentModel.java ContainmentModel.java
ContextModel.java DeploymentModel.java
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultComponentModel.java
DefaultContainmentModel.java
DefaultContainmentModelAssemblyHelper.java
DefaultContextModel.java
merlin/platform/tutorials/context/avalon/src/java/tutorial
HelloComponent.java
merlin/platform/tutorials/context/custom/src/java/tutorial
HelloComponent.java
merlin/platform/tutorials/main/conf demo.block
Added: merlin/platform/tutorials/mixed WARNING.txt project.xml
merlin/composition/api/src/java/org/apache/avalon/composition/info
DeliveryDescriptor.java
InjectorDeliveryDescriptor.java
NativeDeliveryDescriptor.java
NullDeliveryDescriptor.java
StagedDeliveryDescriptor.java package.html
merlin/platform/tutorials/security WARNING.txt
Log:
Progress on cleaning up the context management model. Updating of a couple of
tutorials.
Revision Changes Path
1.7 +12 -1
avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/ApplianceInvocationHandler.java
Index: ApplianceInvocationHandler.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/ApplianceInvocationHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ApplianceInvocationHandler.java 4 Mar 2004 03:42:30 -0000 1.6
+++ ApplianceInvocationHandler.java 13 Mar 2004 23:26:56 -0000 1.7
@@ -73,6 +73,9 @@
*/
protected ApplianceInvocationHandler( DefaultAppliance appliance, Logger
logger, boolean secure )
{
+ assertNotNull( appliance, "appliance" );
+ assertNotNull( logger, "logger" );
+
m_appliance = appliance;
m_logger = logger;
m_secure = secure;
@@ -217,5 +220,13 @@
}
}
return e;
+ }
+
+ private void assertNotNull( Object object, String key )
+ {
+ if( null == object )
+ {
+ throw new NullPointerException( key );
+ }
}
}
1.6 +1 -19
avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultAppliance.java
Index: DefaultAppliance.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultAppliance.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultAppliance.java 8 Mar 2004 11:28:35 -0000 1.5
+++ DefaultAppliance.java 13 Mar 2004 23:26:56 -0000 1.6
@@ -182,24 +182,6 @@
model.getInterfaces(),
handler );
}
- //catch( AccessControlException e )
- //{
- // Permission p = e.getPermission();
- // if( null != p )
- // {
- // final String warning =
- // "Proxy creation disabled due to insufficient permission: ["
- // + p.getName()
- // + "].";
- // getLogger().warn( warning );
- // }
- // else
- // {
- // final String warning =
- // "Proxy creation disabled due to access control
restriction.";
- // getLogger().warn( warning );
- // }
- //}
catch( Throwable e )
{
final String error =
1.9 +31 -15
avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultComponentFactory.java
Index: DefaultComponentFactory.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultComponentFactory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultComponentFactory.java 12 Mar 2004 18:12:35 -0000 1.8
+++ DefaultComponentFactory.java 13 Mar 2004 23:26:56 -0000 1.9
@@ -32,6 +32,11 @@
import org.apache.avalon.activation.RuntimeFactory;
import org.apache.avalon.activation.LifecycleException;
+import org.apache.avalon.composition.info.DeliveryDescriptor;
+import org.apache.avalon.composition.info.NativeDeliveryDescriptor;
+import org.apache.avalon.composition.info.StagedDeliveryDescriptor;
+import org.apache.avalon.composition.info.InjectorDeliveryDescriptor;
+import org.apache.avalon.composition.info.NullDeliveryDescriptor;
import org.apache.avalon.composition.model.ModelException;
import org.apache.avalon.composition.model.ModelRuntimeException;
import org.apache.avalon.composition.model.DeploymentModel;
@@ -253,7 +258,6 @@
final Parameters params = m_model.getParameters();
final ServiceManager manager = new DefaultServiceManager( m_model );
final Object context = getTargetContext();
-
final Class contextClass = getContextCastingClass();
final Object instance =
@@ -284,7 +288,18 @@
}
}
- applyContext( instance, context );
+ if( m_model.getContextModel().isEnabled() )
+ {
+ DeliveryDescriptor delivery =
+ m_model.getContextModel().getDeliveryDescriptor();
+ if( !( delivery instanceof NullDeliveryDescriptor ) )
+ {
+ if( !( delivery instanceof InjectorDeliveryDescriptor ) )
+ {
+ applyContext( instance, delivery, context );
+ }
+ }
+ }
if( instance instanceof Serviceable )
{
@@ -441,14 +456,7 @@
private Class getContextCastingClass()
{
- if( null == m_model.getContextModel() )
- {
- return null;
- }
- else
- {
- return m_model.getContextModel().getCastingClass();
- }
+ return m_model.getContextModel().getCastingClass();
}
private Object getTargetContext()
@@ -814,16 +822,15 @@
}
}
- private void applyContext( final Object instance, final Object context )
+ private void applyContext(
+ final Object instance, DeliveryDescriptor delivery, final Object context )
throws LifecycleException
{
if( null == context ) return;
final ContextModel model = m_model.getContextModel();
- if( model == null ) return;
- final DeploymentModel provider = model.getProvider();
- if(( null == provider ) && (instance instanceof Contextualizable ))
+ if( delivery instanceof NativeDeliveryDescriptor )
{
getLogger().debug( "applying context" );
@@ -872,9 +879,10 @@
throw new LifecycleException( error );
}
}
- else if( null != provider )
+ else if( delivery instanceof StagedDeliveryDescriptor )
{
getLogger().debug( "applying custom context" );
+ final DeploymentModel provider = model.getProvider();
try
{
ContextualizationHandler handler =
@@ -890,6 +898,14 @@
provider.toString() );
throw new LifecycleException( error, e );
}
+ }
+ else
+ {
+ final String error =
+ "Unrecognized delivery strategy: ["
+ + delivery.getClass().getName()
+ + "].";
+ throw new IllegalStateException( error );
}
}
}
1.3 +2 -0
avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/impl/test/CodeSecurityDisabledTestCase.java
Index: CodeSecurityDisabledTestCase.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/impl/test/CodeSecurityDisabledTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CodeSecurityDisabledTestCase.java 23 Feb 2004 13:30:00 -0000 1.2
+++ CodeSecurityDisabledTestCase.java 13 Mar 2004 23:26:56 -0000 1.3
@@ -91,6 +91,8 @@
{
TestService test = getTestService();
+ assertNotNull( "test", test );
+
try
{
test.createDirectory();
1.8 +3 -12
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ComponentModel.java
Index: ComponentModel.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ComponentModel.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ComponentModel.java 10 Mar 2004 10:52:17 -0000 1.7
+++ ComponentModel.java 13 Mar 2004 23:26:56 -0000 1.8
@@ -150,19 +150,10 @@
Parameters getParameters();
/**
- * Rest if the component type backing the model requires the
- * establishment of a runtime context.
- *
- * @return TRUE if the component type requires a runtime
- * context otherwise FALSE
- */
- boolean isContextDependent();
-
- /**
* 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
+ * @see ContextModel#isEnabled
*/
ContextModel getContextModel();
1.22 +14 -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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ContainmentModel.java 25 Feb 2004 22:54:09 -0000 1.21
+++ ContainmentModel.java 13 Mar 2004 23:26:56 -0000 1.22
@@ -18,6 +18,7 @@
package org.apache.avalon.composition.model;
import java.net.URL;
+import java.util.List;
import org.apache.avalon.composition.data.DeploymentProfile;
import org.apache.avalon.composition.data.ServiceDirective;
@@ -81,6 +82,18 @@
* @exception Exception if an error occurs during model assembly
*/
void assemble() throws AssemblyException;
+
+ /**
+ * Assemble the model.
+ * @param subjects a list of deployment models that make up the assembly chain
+ * @exception Exception if an error occurs during model assembly
+ */
+ void assemble( List subjects ) throws AssemblyException;
+
+ /**
+ * Disassemble the model.
+ */
+ void disassemble();
/**
* Return the set of models nested within this model.
1.7 +16 -2
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContextModel.java
Index: ContextModel.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContextModel.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ContextModel.java 11 Mar 2004 18:13:15 -0000 1.6
+++ ContextModel.java 13 Mar 2004 23:26:56 -0000 1.7
@@ -17,7 +17,7 @@
package org.apache.avalon.composition.model;
-import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.composition.info.DeliveryDescriptor;
/**
* <p>Specification of a context model from which a
@@ -33,6 +33,20 @@
*/
public static final String DEFAULT_STRATEGY_CLASSNAME =
"org.apache.avalon.framework.context.Contextualizable";
+
+ /**
+ * Return the enabled state of the context model.
+ *
+ * @return TRUE if enabled else FALSE
+ */
+ boolean isEnabled();
+
+ /**
+ * Return the delivery descriptor.
+ *
+ * @return the descriptor
+ */
+ DeliveryDescriptor getDeliveryDescriptor();
/**
* Return the class that the context is castable to.
1.19 +1 -13
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- DeploymentModel.java 29 Feb 2004 22:25:26 -0000 1.18
+++ DeploymentModel.java 13 Mar 2004 23:26:56 -0000 1.19
@@ -138,13 +138,6 @@
*/
boolean isAssembled();
- /**
- * Assemble the model.
- * @param subjects a list of deployment models that make up the assembly chain
- * @exception Exception if an error occurs during model assembly
- */
- void assemble( List subjects ) throws AssemblyException;
-
/**
* Return the set of models consuming this model.
* @return the consumers
@@ -156,11 +149,6 @@
* @return the providers
*/
DeploymentModel[] getProviderGraph();
-
- /**
- * Disassemble the model.
- */
- void disassemble();
/**
* Return the set of models assigned as providers.
1.16 +25 -138
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DefaultComponentModel.java 11 Mar 2004 13:17:44 -0000 1.15
+++ DefaultComponentModel.java 13 Mar 2004 23:26:57 -0000 1.16
@@ -29,6 +29,9 @@
import org.apache.avalon.composition.data.StageDirective;
import org.apache.avalon.composition.data.ContextDirective;
import org.apache.avalon.composition.data.Mode;
+import org.apache.avalon.composition.info.DeliveryDescriptor;
+import org.apache.avalon.composition.info.NativeDeliveryDescriptor;
+import org.apache.avalon.composition.info.StagedDeliveryDescriptor;
import org.apache.avalon.composition.model.AssemblyException;
import org.apache.avalon.composition.model.ContextModel;
import org.apache.avalon.composition.model.DependencyModel;
@@ -78,7 +81,7 @@
//--------------------------------------------------------------
private static final Resources REZ =
- ResourceManager.getPackageResources( DefaultComponentModel.class );
+ ResourceManager.getPackageResources( DefaultComponentModel.class );
private static final String CONTEXTUALIZABLE =
"org.apache.avalon.framework.context.Contextualizable";
@@ -95,8 +98,6 @@
private final ContextModel m_contextModel;
- private final boolean m_contextDependent;
-
private final DependencyModel[] m_dependencies;
private final StageModel[] m_stages;
@@ -169,22 +170,14 @@
}
}
- m_contextDependent = getContextDependentState();
-
- if( m_contextDependent )
- {
- 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 );
- }
- else
- {
- m_contextModel = null;
- }
+ 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
@@ -280,12 +273,17 @@
private boolean isContextAssembled()
{
- if( null == getContextModel() ) return true;
- Class clazz = getContextModel().getStrategyClass();
- if( clazz.getName().equals(
- ContextModel.DEFAULT_STRATEGY_CLASSNAME ) )
- return true;
- return ( null != getContextModel().getProvider() );
+ ContextModel model = getContextModel();
+ if( model.isEnabled() )
+ {
+ DeliveryDescriptor delivery =
+ getContextModel().getDeliveryDescriptor();
+ if( delivery instanceof StagedDeliveryDescriptor )
+ {
+ return ( null != getContextModel().getProvider() );
+ }
+ }
+ return true;
}
private boolean isStageAssembled()
@@ -309,23 +307,6 @@
}
/**
- * Assemble the model.
- * @exception Exception if an error occurs during model assembly
- */
- public void assemble( List subjects ) throws AssemblyException
- {
- getLogger().warn( "## component assembly request in : " + this + " with " +
subjects );
- }
-
- /**
- * Disassemble the model.
- */
- public void disassemble()
- {
- // nothing to do
- }
-
- /**
* 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
@@ -340,7 +321,7 @@
}
final ArrayList list = new ArrayList();
- if( null != getContextModel() )
+ if( getContextModel().isEnabled() )
{
DeploymentModel provider = getContextModel().getProvider();
if( provider != null )
@@ -699,18 +680,6 @@
}
/**
- * Test if the component type backing the model requires the
- * establishment of a runtime context.
- *
- * @return TRUE if the component type requires a runtime
- * context otherwise FALSE
- */
- public boolean isContextDependent()
- {
- return m_contextDependent;
- }
-
- /**
* Return the context model for this deployment model.
*
* @return the context model if this model is context dependent, else
@@ -721,7 +690,6 @@
return m_contextModel;
}
-
/**
* Return the dependency models for this component type.
*
@@ -863,87 +831,6 @@
//==============================================================
// implementation
//==============================================================
-
- /**
- * Test if the component type backing the model requires the
- * establishment of a runtime context.
- *
- * @param return TRUE if the component type requires a runtime
- * context otherwise FALSE
- */
- private boolean getContextDependentState()
- {
- if( m_context.getType().getStages().length > 0 )
- {
- return true;
- }
-
- Class base = m_context.getDeploymentClass();
- String strategy =
- m_context.getType().getContext().getAttribute(
- ContextDescriptor.STRATEGY_KEY, null );
- ClassLoader classLoader = m_context.getClassLoader();
-
- if( strategy != null )
- {
- Class contextualizable =
- getComponentClass( classLoader, strategy );
-
- if( contextualizable == null )
- {
- final String error =
- REZ.getString(
- "deployment.missing-strategy.error",
- strategy, base.getName() );
- throw new IllegalStateException( error );
- }
- else
- {
- if( contextualizable.isAssignableFrom( base ) )
- {
- return true;
- }
- else
- {
- final String error =
- REZ.getString(
- "deployment.inconsitent-strategy.error",
- contextualizable, base );
- throw new IllegalStateException( error );
- }
- }
- }
- else
- {
- //
- // its either classic avalon 4.1 or its 4.2 constructor
- // based - first off check the constructor for a type
- // corresponding to the base class
- //
-
- String contextClassname =
- m_context.getType().getContext().getContextInterfaceClassname();
- Class contextClass =
- getComponentClass( classLoader, contextClassname );
- boolean isConstructorBased = isaConstructorArg( contextClass );
- if( isConstructorBased ) return true;
-
- //
- // otherwise check for classic avalon Contextualizable
- //
-
- Class contextualizable =
- getComponentClass( classLoader, CONTEXTUALIZABLE );
- if( contextualizable != null )
- {
- if( contextualizable.isAssignableFrom( base ) )
- {
- return true;
- }
- }
- }
- return false;
- }
/**
* Test to determin if the first constructor supports the context
1.42 +16 -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.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- DefaultContainmentModel.java 11 Mar 2004 01:30:38 -0000 1.41
+++ DefaultContainmentModel.java 13 Mar 2004 23:26:57 -0000 1.42
@@ -445,10 +445,24 @@
for( int i=0; i<models.length; i++ )
{
DeploymentModel model = models[i];
- model.disassemble();
+ if( model instanceof ContainmentModel )
+ {
+ ContainmentModel containment = (ContainmentModel) model;
+ containment.disassemble();
+ }
+ else
+ {
+ ComponentModel component = (ComponentModel) model;
+ dissasemble( component );
+ }
}
m_assembly.setEnabled( false );
}
+ }
+
+ private void dissasemble( ComponentModel model )
+ {
+ // TODO
}
/**
1.7 +13 -7
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultContainmentModelAssemblyHelper.java 8 Mar 2004 11:28:36 -0000
1.6
+++ DefaultContainmentModelAssemblyHelper.java 13 Mar 2004 23:26:57 -0000
1.7
@@ -21,6 +21,8 @@
import java.util.ArrayList;
import org.apache.avalon.composition.data.DeploymentProfile;
+import org.apache.avalon.composition.info.DeliveryDescriptor;
+import org.apache.avalon.composition.info.StagedDeliveryDescriptor;
import org.apache.avalon.composition.model.ContainmentModel;
import org.apache.avalon.composition.model.ComponentModel;
import org.apache.avalon.composition.model.DeploymentModel;
@@ -119,7 +121,8 @@
}
else
{
- model.assemble( subjects );
+ ContainmentModel containment = (ContainmentModel) model;
+ containment.assemble( subjects );
}
}
@@ -131,15 +134,18 @@
// locate and assemble the component context handler
//
- if( model.getContextModel() != null )
+ ContextModel context = model.getContextModel();
+ DeliveryDescriptor delivery = context.getDeliveryDescriptor();
+ if( context.isEnabled() )
{
- ContextModel context = model.getContextModel();
- Class clazz = context.getStrategyClass();
- if( !clazz.getName().equals(
- ContextModel.DEFAULT_STRATEGY_CLASSNAME ) )
+ if( delivery instanceof StagedDeliveryDescriptor )
{
if( null == context.getProvider() )
{
+ StagedDeliveryDescriptor phased =
+ (StagedDeliveryDescriptor) delivery;
+ Class clazz = phased.getDeliveryInterfaceClass();
+
try
{
subjects.add( model );
1.15 +150 -13
avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContextModel.java
Index: DefaultContextModel.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContextModel.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DefaultContextModel.java 11 Mar 2004 18:13:15 -0000 1.14
+++ DefaultContextModel.java 13 Mar 2004 23:26:57 -0000 1.15
@@ -25,6 +25,11 @@
import org.apache.avalon.composition.data.EntryDirective;
import org.apache.avalon.composition.data.ImportDirective;
import org.apache.avalon.composition.data.ConstructorDirective;
+import org.apache.avalon.composition.info.DeliveryDescriptor;
+import org.apache.avalon.composition.info.NullDeliveryDescriptor;
+import org.apache.avalon.composition.info.StagedDeliveryDescriptor;
+import org.apache.avalon.composition.info.InjectorDeliveryDescriptor;
+import org.apache.avalon.composition.info.NativeDeliveryDescriptor;
import org.apache.avalon.composition.model.EntryModel;
import org.apache.avalon.composition.model.ContextModel;
import org.apache.avalon.composition.model.ComponentModel;
@@ -33,6 +38,7 @@
import org.apache.avalon.composition.provider.ComponentContext;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
@@ -93,6 +99,8 @@
private final Class m_castingClass;
+ private final DeliveryDescriptor m_delivery;
+
//==============================================================
// constructor
//==============================================================
@@ -126,6 +134,7 @@
throw new NullPointerException( "context" );
}
+
m_descriptor = descriptor;
m_directive = directive;
m_context = context;
@@ -134,6 +143,7 @@
m_strategy = loadStrategyClass( descriptor, classLoader );
Class impl = loadContextClass( directive, classLoader );
m_castingClass = getContextCastingClass( descriptor, classLoader, impl );
+ m_delivery = createDeliveryDescriptor( descriptor, context, m_castingClass
);
//
// get the set of context entries declared by the component type
@@ -225,12 +235,131 @@
classLoader, impl, descriptor, directive, m_map );
}
+ public boolean isEnabled()
+ {
+ return m_delivery != null;
+ }
+
+ /**
+ * Return the delivery descriptor for the context model. If
+ * the component is non-contextualizable the method return null.
+ *
+ * @param return the delivery descriptor
+ */
+ private DeliveryDescriptor createDeliveryDescriptor(
+ ContextDescriptor descriptor, ComponentContext context, Class casting )
throws ModelException
+ {
+ Class base = context.getDeploymentClass();
+ ClassLoader classLoader = context.getClassLoader();
+ String strategy =
+ context.getType().getContext().getAttribute(
+ ContextDescriptor.STRATEGY_KEY, null );
+
+ if( Contextualizable.class.isAssignableFrom( base ) )
+ {
+ //
+ // Its's classic Avalon 4.1
+ //
+
+ return new NativeDeliveryDescriptor( casting );
+ }
+ else if( isaConstructorArg( casting, base ) )
+ {
+ //
+ // use constructor injection via Avalon 4.2
+ //
+
+ return new InjectorDeliveryDescriptor( casting );
+ }
+ else if( null != strategy )
+ {
+ //
+ // A custom strategy has been declared so we need to
+ // make sure the strategy class exists and declare a
+ // staged delivery mechanism.
+ //
+
+ Class contextualizable =
+ loadClass( classLoader, strategy );
+ if( contextualizable == null )
+ {
+ final String error =
+ REZ.getString(
+ "deployment.missing-strategy.error",
+ strategy, base.getName() );
+ throw new IllegalStateException( error );
+ }
+ else
+ {
+ //
+ // Verify that the base class implements the
+ // stage delivery interface.
+ //
+
+ if( contextualizable.isAssignableFrom( base ) )
+ {
+ return new StagedDeliveryDescriptor(
+ casting, contextualizable );
+ }
+ else
+ {
+ final String error =
+ REZ.getString(
+ "deployment.inconsitent-strategy.error",
+ contextualizable, base );
+ throw new IllegalStateException( error );
+ }
+ }
+ }
+ else
+ {
+ if( context.getType().getStages().length > 0 )
+ {
+ return new NullDeliveryDescriptor( Context.class );
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ private Class loadClass( ClassLoader classLoader, String classname )
+ {
+ if( classLoader == null )
+ {
+ throw new NullPointerException( "classLoader" );
+ }
+ if( classname == null )
+ {
+ throw new NullPointerException( "classname" );
+ }
+
+ try
+ {
+ return classLoader.loadClass( classname );
+ }
+ catch( ClassNotFoundException e )
+ {
+ return null;
+ }
+ }
//==============================================================
// ContextModel
//==============================================================
/**
+ * Return the delivery descriptor.
+ *
+ * @return the descriptor
+ */
+ public DeliveryDescriptor getDeliveryDescriptor()
+ {
+ return m_delivery;
+ }
+
+ /**
* Return the set of entry models associated with this context model.
*
* @return the entry models
@@ -502,18 +631,7 @@
}
else
{
- try
- {
- castingClass =
- classLoader.loadClass( Context.class.getName() );
- }
- catch( Throwable e )
- {
- final String error =
- "Cannot load standard Avalon context interface class: "
- + Context.class.getName();
- throw new ModelException( error, e );
- }
+ castingClass = Context.class;
}
if( !castingClass.isAssignableFrom( clazz ) )
@@ -528,5 +646,24 @@
}
return castingClass;
+ }
+
+ /**
+ * Test to determin if the constructor supports the context
+ * base class as a parameter type.
+ * @return TRUE or FALSE
+ */
+ private boolean isaConstructorArg( Class clazz, Class base )
+ {
+ if( null == base ) return false;
+ Constructor[] constructors = clazz.getConstructors();
+ if( constructors.length == 0 ) return false;
+ Constructor constructor = constructors[0];
+ Class[] types = constructor.getParameterTypes();
+ for( int i=0; i<types.length; i++ )
+ {
+ if( base.isAssignableFrom( types[i] ) ) return true;
+ }
+ return false;
}
}
1.3 +1 -1
avalon/merlin/platform/tutorials/context/avalon/src/java/tutorial/HelloComponent.java
Index: HelloComponent.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/platform/tutorials/context/avalon/src/java/tutorial/HelloComponent.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HelloComponent.java 24 Jan 2004 23:25:33 -0000 1.2
+++ HelloComponent.java 13 Mar 2004 23:26:58 -0000 1.3
@@ -26,7 +26,7 @@
/**
* Component demonstrating access to standard context entries.
- * @avalon.component name="demo"
+ * @avalon.component name="demo" lifestyle="singleton"
*/
public class HelloComponent extends AbstractLogEnabled
implements Contextualizable
1.3 +1 -1
avalon/merlin/platform/tutorials/context/custom/src/java/tutorial/HelloComponent.java
Index: HelloComponent.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/platform/tutorials/context/custom/src/java/tutorial/HelloComponent.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HelloComponent.java 24 Jan 2004 23:25:34 -0000 1.2
+++ HelloComponent.java 13 Mar 2004 23:26:58 -0000 1.3
@@ -24,7 +24,7 @@
/**
* Demonstration of a component that uses a constructed context entry.
*
- * @avalon.component name="demo"
+ * @avalon.component name="demo" lifestyle="singleton"
*/
public class HelloComponent extends AbstractLogEnabled
implements Contextualizable
1.2 +1 -1 avalon/merlin/platform/tutorials/main/conf/demo.block
Index: demo.block
===================================================================
RCS file: /home/cvs/avalon/merlin/platform/tutorials/main/conf/demo.block,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- demo.block 4 Mar 2004 07:28:19 -0000 1.1
+++ demo.block 13 Mar 2004 23:26:58 -0000 1.2
@@ -9,6 +9,6 @@
</classpath>
</classloader>
- <component name="hello" class="tutorial.HelloComponent"/>
+ <component name="hello" class="tutorial.HelloComponent" activation="startup"/>
</container>
1.1 avalon/merlin/platform/tutorials/mixed/WARNING.txt
Index: WARNING.txt
===================================================================
TUTORIAL IS NOT READY FOR PRIMETIME
RELATED PROFILE SELECTOR MECHANISMS ARE NOT CURRENTLY AVAILABLE
1.1 avalon/merlin/platform/tutorials/mixed/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<extend>${basedir}/../project.xml</extend>
<id>tutorial-classic</id>
<name>Avalon Classic Tutorial</name>
<package>org.apache.avalon.playground</package>
<currentVersion>1.0</currentVersion>
<inceptionYear>2003</inceptionYear>
<shortDescription>Classic multicomponent scenario.</shortDescription>
<dependencies>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
</project>
1.1
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/info/DeliveryDescriptor.java
Index: DeliveryDescriptor.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.info;
/**
* Abstract base class for a descriptor of a lifecycle
* artifact delivery strategy.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/03/13 23:26:58 $
*/
public abstract class DeliveryDescriptor
{
private final Class m_casting;
public DeliveryDescriptor( Class casting )
{
m_casting = casting;
}
public Class getCastingInterfaceClass()
{
return m_casting;
}
}
1.1
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/info/InjectorDeliveryDescriptor.java
Index: InjectorDeliveryDescriptor.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.info;
/**
* Descriptor used to mark a lifecycle artifact handler a
* using a injection by constructor delivery strategy.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/03/13 23:26:58 $
*/
public class InjectorDeliveryDescriptor extends DeliveryDescriptor
{
public InjectorDeliveryDescriptor( final Class casting )
{
super( casting );
}
}
1.1
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/info/NativeDeliveryDescriptor.java
Index: NativeDeliveryDescriptor.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.info;
/**
* Descriptor used to mark a lifecycle artifact handler a
* using a injection by constructor delivery strategy.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/03/13 23:26:58 $
*/
public class NativeDeliveryDescriptor extends DeliveryDescriptor
{
public NativeDeliveryDescriptor( Class casting )
{
super( casting );
}
}
1.1
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/info/NullDeliveryDescriptor.java
Index: NullDeliveryDescriptor.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.info;
/**
* Descriptor used to mark a lifecycle artifact as non-deliverable. This
* is used in the special case of a component that is not itself context
* dependent, but is dependent on a lifecycle stage extension handler which
* is dependent on the component context.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/03/13 23:26:58 $
*/
public class NullDeliveryDescriptor extends DeliveryDescriptor
{
public NullDeliveryDescriptor( Class casting )
{
super( casting );
}
}
1.1
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/info/StagedDeliveryDescriptor.java
Index: StagedDeliveryDescriptor.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.info;
/**
* Descriptor used to mark a lifecycle artifact handler a
* using a injection by constructor delivery strategy.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/03/13 23:26:58 $
*/
public class StagedDeliveryDescriptor extends DeliveryDescriptor
{
private final Class m_delivery;
public StagedDeliveryDescriptor( Class casting, Class delivery )
{
super( casting );
m_delivery = delivery;
}
public Class getDeliveryInterfaceClass()
{
return m_delivery;
}
}
1.1
avalon/merlin/composition/api/src/java/org/apache/avalon/composition/info/package.html
Index: package.html
===================================================================
<body>
<p>
The <code>info</code> a series of descriptors dealing with lifecycle artifact
delivery semantics.</p>
</source>
</body>
1.1 avalon/merlin/platform/tutorials/security/WARNING.txt
Index: WARNING.txt
===================================================================
TUTORIAL IS NOT READY FOR PRIMETIME
RELATED SECURITY SERVICES ARE EVOLVING AND INCOMPLETE
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]