mcconnell 2003/02/27 22:10:36
Modified: merlin/src/java/org/apache/avalon/merlin/block/impl
DefaultBlock.java DefaultBlockLoader.java
merlin/src/java/org/apache/avalon/merlin/kernel/impl
DefaultKernel.xinfo
merlin/src/test/org/apache/avalon/playground
ContextualizationHandler.java
StandardContextImp.java
Log:
Synchronization with the assembly framework.
Revision Changes Path
1.10 +4 -2
avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.java
Index: DefaultBlock.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DefaultBlock.java 27 Feb 2003 23:43:45 -0000 1.9
+++ DefaultBlock.java 28 Feb 2003 06:10:36 -0000 1.10
@@ -233,8 +233,9 @@
public void contextualize( Locator context ) throws ContextException
{
super.contextualize( context );
- m_engine = (EngineClassLoader) context.get( "urn:assembly:engine" );
m_applianceContext = (ApplianceContext) context.get(
"urn:assembly:appliance.context" );
+
+ m_engine = (EngineClassLoader) context.get( "urn:assembly:engine" );
m_descriptor = (ContainerDescriptor) context.get(
"urn:merlin:container.descriptor" );
m_library = (Library) context.get( "urn:merlin:container.library" );
m_blocks = (List) context.get( "urn:merlin:container.containers" );
@@ -269,7 +270,8 @@
Profile profile = profiles[i];
if( getLogger().isDebugEnabled() )
{
- final String message = "adding child profile: " + profile + " in "
+ this;
+ final String message =
+ "adding child profile: " + profile + " in " + this;
getLogger().debug( message );
}
1.13 +2 -6
avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlockLoader.java
Index: DefaultBlockLoader.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlockLoader.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DefaultBlockLoader.java 27 Feb 2003 23:45:09 -0000 1.12
+++ DefaultBlockLoader.java 28 Feb 2003 06:10:36 -0000 1.13
@@ -600,16 +600,12 @@
// to be applied to the block.
//
- //Map map = new Hashtable();
- //map.put("urn:merlin:container.descriptor", descriptor );
-
DefaultApplianceContext context = new DefaultApplianceContext( descriptor );
context.setName( name );
- context.setDeploymentContext( map );
context.setPartitionName( partition );
context.setApplianceClassname( DefaultBlock.class.getName() );
- context.put("urn:merlin:container.descriptor", descriptor );
+ context.put("urn:merlin:container.descriptor", descriptor );
context.put("urn:merlin:container.library", this );
context.put("urn:merlin:container.containers", containers );
context.makeReadOnly();
1.4 +1 -1
avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.xinfo
Index: DefaultKernel.xinfo
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.xinfo,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultKernel.xinfo 19 Feb 2003 11:58:25 -0000 1.3
+++ DefaultKernel.xinfo 28 Feb 2003 06:10:36 -0000 1.4
@@ -11,7 +11,7 @@
@author Stephen McConnell
@version 1.0 12/03/2001
-NOTE: usage of kernal as a component is completely untested. This file is provided
primarily for documetation of the context requirements of the kernel. This file may
be removed in the future.
+NOTE: usage of kernel as a component is completely untested. This file is provided
primarily for documetation of the context requirements of the kernel. This file may
be removed in the future.
-->
<type>
1.3 +72 -2
avalon-sandbox/merlin/src/test/org/apache/avalon/playground/ContextualizationHandler.java
Index: ContextualizationHandler.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/src/test/org/apache/avalon/playground/ContextualizationHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContextualizationHandler.java 7 Feb 2003 15:39:37 -0000 1.2
+++ ContextualizationHandler.java 28 Feb 2003 06:10:36 -0000 1.3
@@ -55,11 +55,14 @@
package org.apache.avalon.playground;
+import java.util.Map;
+import java.lang.reflect.Constructor;
+
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
-
import org.apache.avalon.assembly.appliance.Appliance;
import org.apache.avalon.assembly.lifecycle.context.Contextualization;
+import org.apache.avalon.meta.model.ContextDirective;
/**
* Definition of an extension handler that handles the Expoitable
@@ -80,11 +83,12 @@
* @exception ContextException if a contextualization error occurs
*/
public void contextualize(
- Object object, Context context )
+ ContextDirective directive, Object object, Map map )
throws ContextException
{
if( object instanceof Contextualizable )
{
+ Object context = createContextArgument( directive,
StandardContext.class, map );
if( context instanceof StandardContext )
{
( (Contextualizable)object ).contextualize( (StandardContext)
context );
@@ -104,4 +108,70 @@
throw new ContextException( error );
}
}
+
+ /**
+ * Returns a instance of a class established using the supplied map as a
+ * constructor argument.
+ *
+ * @param descriptor the context descriptor
+ * @param clazz the default class if no class defined in the descriptor
+ * @param map the context entry map
+ * @return the context argument value
+ */
+ public Object createContextArgument( ContextDirective directive, Class clazz,
Map map )
+ throws ContextException
+ {
+ if( directive == null )
+ {
+ throw new NullPointerException( "directive" );
+ }
+ if( clazz == null )
+ {
+ throw new NullPointerException( "clazz" );
+ }
+ if( map == null )
+ {
+ throw new NullPointerException( "map" );
+ }
+
+ String classname = directive.getClassname();
+ Class base;
+ if( classname != null )
+ {
+ try
+ {
+ base = Thread.currentThread().getContextClassLoader().loadClass(
classname );
+ }
+ catch( ClassNotFoundException cnfe )
+ {
+ throw new ContextException(
+ "Could not find context class: " + classname, cnfe );
+ }
+ }
+ else
+ {
+ base = clazz;
+ }
+
+ try
+ {
+ Constructor constructor = base.getConstructor(
+ new Class[]{ Map.class } );
+ return constructor.newInstance( new Object[]{ map } );
+ }
+ catch( NoSuchMethodException e )
+ {
+ final String error =
+ "Custom context class: [" + classname
+ + "] does not implement a constructor pattern <init>{ Map }.";
+ throw new ContextException( error, e );
+ }
+ catch( Throwable e )
+ {
+ throw new ContextException(
+ "Unexpected exception while creating context from "
+ + base.getName(), e );
+ }
+ }
+
}
1.3 +2 -2
avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardContextImp.java
Index: StandardContextImp.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardContextImp.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StandardContextImp.java 7 Feb 2003 15:39:37 -0000 1.2
+++ StandardContextImp.java 28 Feb 2003 06:10:36 -0000 1.3
@@ -80,9 +80,9 @@
* @param map the context name/value map
* @param parent a possibly parent context
*/
- public StandardContextImp( Map map, Context parent ) throws ContextException
+ public StandardContextImp( Map map ) throws ContextException
{
- super( map, parent );
+ super( map );
}
//-----------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]