mcconnell 2002/08/11 19:00:11
Modified: assembly/demo/src/java/org/apache/excalibur/playground
BasicComponent.xprofile CustomContainer.xinfo
DemoManager.xinfo EmbeddedDemo.java
ExploitationManager.xinfo
assembly/src/etc kernel.xml
assembly/src/java/org/apache/excalibur/merlin
DefaultController.java
assembly/src/java/org/apache/excalibur/merlin/assembly
AssemblyException.java ContainerManager.java
DefaultLoggerManager.java KernelManager.java
ProfileRegistry.java TypeManager.java
UnresolvedManagerException.java
UnresolvedProviderException.java
assembly/src/java/org/apache/excalibur/merlin/assembly/resource
LifecycleHelper.java ProfileDesignator.java
ResourceProvider.java
assembly/src/java/org/apache/excalibur/merlin/container
Container.java DefaultContainer.java
DefaultContainer.xinfo
assembly/src/java/org/apache/excalibur/merlin/kernel
DefaultKernel.java
assembly/src/java/org/apache/excalibur/merlin/model
ContainerDescriptor.java ContextDirective.java
Import.java Parameter.java Profile.java
Resource.java
assembly/src/java/org/apache/excalibur/merlin/model/builder
ContainerBuilder.java XMLContainerCreator.java
XMLContainerUtil.java XMLProfileCreator.java
assembly/src/java/org/apache/excalibur/meta/info
ExtensionDescriptor.java
assembly/src/java/org/apache/excalibur/meta/info/builder
XMLFacilityCreator.java
Added: assembly/demo/src/java/org/apache/excalibur/playground
CustomContainer.xprofile EmbeddedDemo.xconfig
Log:
General updates enabling management of a container as a pure component (i.e.
containers implementations may have thier own dependecies, extensions, etc. and
other components may declare dependencies on containers).
Revision Changes Path
1.7 +0 -1
jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.xprofile
Index: BasicComponent.xprofile
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.xprofile,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BasicComponent.xprofile 4 Aug 2002 14:58:30 -0000 1.6
+++ BasicComponent.xprofile 12 Aug 2002 02:00:08 -0000 1.7
@@ -13,7 +13,6 @@
<context class="org.apache.excalibur.playground.BasicContext">
<import key="home" name="avalon:home"/>
<entry key="location">Paris</entry>
- <entry key="test" class="java.io.File">../assembly</entry>
</context>
</component>
1.2 +26 -5
jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/CustomContainer.xinfo
Index: CustomContainer.xinfo
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/CustomContainer.xinfo,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CustomContainer.xinfo 5 Aug 2002 11:37:18 -0000 1.1
+++ CustomContainer.xinfo 12 Aug 2002 02:00:08 -0000 1.2
@@ -3,17 +3,38 @@
PUBLIC "-//AVALON/Component Info DTD Version 1.0//EN"
"http://jakarta.apache.org/avalon/componentinfo_1_0.dtd" >
-<component-info>
+<type>
<component>
<name>custom</name>
</component>
+ <context>
+ <entry key="merlin:container.descriptor"
+ type="org.apache.excalibur.merlin.model.ContainerDescriptor" />
+ <entry key="merlin:container.manager"
+ type="org.apache.excalibur.merlin.assembly.ContainerManager"/>
+ <entry key="merlin:container.state-listener"
+ type="org.apache.excalibur.merlin.container.StateListener"
+ optional="true"/>
+ <entry key="merlin:container.container-listener"
+ type="org.apache.excalibur.merlin.container.ContainerListener"
+ optional="true"/>
+ <entry key="merlin:container.logging"
+ type="org.apache.excalibur.merlin.assembly.DefaultLoggingManager"/>
+ </context>
+
<services>
- <service>
- <reference type="org.apache.excalibur.merlin.container.Container"/>
- </service>
+ <service>
+ <reference type="org.apache.excalibur.merlin.container.Container"
version="1.0"/>
+ </service>
</services>
-</component-info>
+ <phases>
+ <phase>
+ <reference type="org.apache.excalibur.merlin.container.Structural"/>
+ </phase>
+ </phases>
+
+</type>
1.4 +2 -2
jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/DemoManager.xinfo
Index: DemoManager.xinfo
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/DemoManager.xinfo,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DemoManager.xinfo 4 Aug 2002 11:49:35 -0000 1.3
+++ DemoManager.xinfo 12 Aug 2002 02:00:08 -0000 1.4
@@ -4,7 +4,7 @@
Definition of the extension type phase support.
-->
-<component-info>
+<facility>
<component>
<name>demonstratable</name>
@@ -29,5 +29,5 @@
</extensions>
-</component-info>
+</facility>
1.10 +24 -6
jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/EmbeddedDemo.java
Index: EmbeddedDemo.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/EmbeddedDemo.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EmbeddedDemo.java 9 Aug 2002 15:28:04 -0000 1.9
+++ EmbeddedDemo.java 12 Aug 2002 02:00:08 -0000 1.10
@@ -9,6 +9,8 @@
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.activity.Initializable;
@@ -22,6 +24,7 @@
import org.apache.excalibur.merlin.model.ClasspathDescriptor;
import org.apache.excalibur.merlin.model.Profile;
import org.apache.excalibur.merlin.assembly.ContainerManager;
+import org.apache.excalibur.merlin.container.ContainerFactory;
import org.apache.excalibur.meta.info.Type;
import org.apache.excalibur.meta.info.DependencyDescriptor;
import org.apache.excalibur.meta.info.ReferenceDescriptor;
@@ -33,20 +36,35 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public class EmbeddedDemo extends AbstractLogEnabled
-implements Contextualizable, Initializable, Startable, Disposable
+implements Contextualizable, Configurable, Initializable, Startable,
Disposable
{
private DefaultKernel m_kernel;
private File m_home;
private Context m_context;
+ private Configuration m_configuration;
+
private Container m_container;
+ //=======================================================================
+ // Contextualizable
+ //=======================================================================
+
public void contextualize( Context context ) throws ContextException
{
m_context = context;
}
//=======================================================================
+ // Configurable
+ //=======================================================================
+
+ public void configure( Configuration config )
+ {
+ m_configuration = config;
+ }
+
+ //=======================================================================
// Initializable
//=======================================================================
@@ -78,7 +96,7 @@
DefaultContext context = new DefaultContext( m_context );
context.put( DefaultKernel.PATH_KEY, "work" );
m_kernel.contextualize( context );
- m_kernel.configure( new DefaultConfiguration( "", null ) );
+ m_kernel.configure( m_configuration.getChild("kernel") );
m_kernel.initialize();
//
@@ -95,7 +113,7 @@
//
getLogger().debug("adding subcontainer: admin");
- Container container = root.createSubContainer( "admin" );
+ Container container = root.addContainer( "admin" );
//
// Add a component to the container programatically.
@@ -105,8 +123,8 @@
// container.
//
- Profile profile = manager.getProfile(
- new ReferenceDescriptor(
"org.apache.excalibur.playground.SimpleService" ) );
+ Profile profile = new Profile("simple2", manager.getProfile(
+ new ReferenceDescriptor(
"org.apache.excalibur.playground.SimpleService" ) ) );
//
// install the profile into the container triggering profile assembly
@@ -143,7 +161,7 @@
public void dispose()
{
getLogger().debug( "dispose" );
- m_kernel.dispose();
+ //m_kernel.dispose();
}
}
1.5 +2 -2
jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/ExploitationManager.xinfo
Index: ExploitationManager.xinfo
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/ExploitationManager.xinfo,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExploitationManager.xinfo 4 Aug 2002 11:49:35 -0000 1.4
+++ ExploitationManager.xinfo 12 Aug 2002 02:00:08 -0000 1.5
@@ -4,7 +4,7 @@
Definition of the extension type phase support.
-->
-<component-info>
+<facility>
<component>
<name>exploit</name>
@@ -29,5 +29,5 @@
</extensions>
-</component-info>
+</facility>
1.1
jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/CustomContainer.xprofile
Index: CustomContainer.xprofile
===================================================================
<?xml version="1.0"?>
<!--
Copyright (C) The Apache Software Foundation. All rights reserved.
This software is published under the terms of the Apache Software License
version 1.1, a copy of which has been included with this distribution in
the LICENSE.txt file.
@author Stephen McConnell
@version 1.0 12/03/2001
-->
<profiles>
<component name="default">
<categories priority="INFO">
<category name="loader" priority="WARN"/>
</categories>
<context>
<import key="merlin:container.manager"/>
<import key="merlin:container.descriptor"/>
<import key="merlin:container.logging"/>
</context>
</component>
</profiles>
1.1
jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/EmbeddedDemo.xconfig
Index: EmbeddedDemo.xconfig
===================================================================
<?xml version="1.0"?>
<!DOCTYPE component-info
PUBLIC "-//AVALON/Component Info DTD Version 1.0//EN"
"http://jakarta.apache.org/avalon/componentinfo_1_0.dtd" >
<configuration>
<kernel>
<container name="working">
<categories priority="INFO">
<category priority="WARN" name="loader" />
<category priority="WARN" name="kernel" />
</categories>
</container>
</kernel>
</configuration>
1.29 +10 -5 jakarta-avalon-excalibur/assembly/src/etc/kernel.xml
Index: kernel.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/etc/kernel.xml,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- kernel.xml 9 Aug 2002 15:28:04 -0000 1.28
+++ kernel.xml 12 Aug 2002 02:00:08 -0000 1.29
@@ -39,6 +39,12 @@
</dirset>
</extensions>
+ <classpath>
+ <fileset dir="dist">
+ <include name="merlin.jar"/>
+ </fileset>
+ </classpath>
+
<!--
Declaration of the root container.
-->
@@ -54,7 +60,6 @@
<categories priority="INFO">
<category priority="WARN" name="loader" />
- <category priority="WARN" name="loader.assembly" />
<category priority="WARN" name="kernel" />
</categories>
@@ -118,7 +123,7 @@
child container instances.
-->
- <container name="sub"
class="org.apache.excalibur.playground.CustomContainer">
+ <container name="sub" >
<categories priority="INFO">
<category priority="WARN" name="loader" />
@@ -136,8 +141,8 @@
from either TerminalComponent or BasicComponent implicitly created
in the parent
container path (due to a depenency declared by ComplexComponent).
In addition, this
profile demonstrates the use of a cascading configuration. The
configuration passed
- to the instantiated component is based primarily on this
configuration declared here,
- and defaults derived from SimpleComponent.xconfig.
+ to the instantiated component is based primarily on this
configuration declared here
+ with defaults derived from SimpleComponent.xconfig.
-->
<component name="simple"
class="org.apache.excalibur.playground.SimpleComponent"
@@ -158,7 +163,7 @@
enabled attribute on the component element to true.
-->
<component name="embedder"
- class="org.apache.excalibur.playground.EmbeddedDemo"
enabled="false" activation="true">
+ class="org.apache.excalibur.playground.EmbeddedDemo"
enabled="true" activation="true">
<categories priority="INFO"/>
<context>
<import key="avalon:home" name="avalon:home"/>
1.15 +3 -3
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/DefaultController.java
Index: DefaultController.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/DefaultController.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DefaultController.java 8 Aug 2002 21:29:24 -0000 1.14
+++ DefaultController.java 12 Aug 2002 02:00:08 -0000 1.15
@@ -220,7 +220,7 @@
/**
* Invoked by a contrainer to request startup of the controller. Thie
implementation
- * simply invokes the [EMAIL PROTECTED] #startup} operation.
+ * simply invokes the [EMAIL PROTECTED] #start} operation.
*/
public void start() throws Exception
{
@@ -241,7 +241,7 @@
/**
* Invoked by a contrainer to request shutdown of the controller. Thie
implementation
- * simply invokes the [EMAIL PROTECTED] #startup} operation.
+ * simply invokes the [EMAIL PROTECTED] #stop} operation.
*/
public void stop() throws Exception
{
1.2 +2 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/AssemblyException.java
Index: AssemblyException.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/AssemblyException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AssemblyException.java 29 Jul 2002 06:14:29 -0000 1.1
+++ AssemblyException.java 12 Aug 2002 02:00:08 -0000 1.2
@@ -19,7 +19,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision$ $Date$
*/
-public final class AssemblyException
+public class AssemblyException
extends CascadingException
{
1.10 +170 -65
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ContainerManager.java
Index: ContainerManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ContainerManager.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ContainerManager.java 9 Aug 2002 15:28:04 -0000 1.9
+++ ContainerManager.java 12 Aug 2002 02:00:08 -0000 1.10
@@ -36,6 +36,7 @@
import org.apache.excalibur.configuration.ConfigurationUtil;
import org.apache.excalibur.merlin.assembly.resource.LifecycleHelper;
import org.apache.excalibur.merlin.assembly.resource.ResourceProvider;
+import org.apache.excalibur.merlin.assembly.resource.ResourceException;
import org.apache.excalibur.merlin.assembly.resource.ProfileDesignator;
import org.apache.excalibur.merlin.model.ContainerDescriptor;
import org.apache.excalibur.merlin.model.ClasspathDescriptor;
@@ -68,7 +69,7 @@
* @version $Revision$ $Date$
*/
-public class ContainerManager extends TypeManager implements Startable
+public class ContainerManager extends TypeManager
{
//===================================================================
@@ -149,6 +150,10 @@
private ContainerManager m_parent;
/**
+ * Mapping of subsidiary managers keyed by container descriptor.
+ */
+
+ /**
* Mapping of established resource designators keyed by profile.
*/
private Hashtable m_resources = new Hashtable();
@@ -249,20 +254,15 @@
public void initialize() throws Exception
{
- XMLContainerUtil creator = new XMLContainerUtil();
+ super.initialize();
- //
- // start internal initialization
- //
+ XMLContainerUtil creator = new XMLContainerUtil();
getLogger().debug(
"creating manager '" + m_name
+ "' " + System.identityHashCode( this )
+ " with parent: " + System.identityHashCode( getParent() ) );
- super.initialize();
-
- getLocalLogger().debug("manager initialization");
m_selector.enableLogging(
getLocalLogger().getChildLogger("selector") );
m_helper.enableLogging( getLocalLogger().getChildLogger("lifecycle")
);
@@ -277,7 +277,7 @@
// setup the assembly sub-system
//
- m_registry = new ProfileRegistry( this, m_map );
+ m_registry = new ProfileRegistry( this, m_map, m_helper, m_provider
);
m_registry.enableLogging( getLocalLogger().getChildLogger(
"assembly") );
//
@@ -321,9 +321,8 @@
*
* @exception Exception if a start related error occurs
*/
- public void start() throws Exception
+ public void start( Profile[] profiles ) throws Exception
{
- Profile[] profiles = m_map.getStartupGraph();
if( profiles.length == 0 )
{
getLocalLogger().debug("nothing to start");
@@ -349,9 +348,8 @@
}
}
- public void stop()
+ public void stop( Profile[] shutdown )
{
- Profile[] shutdown = m_map.getShutdownGraph();
if( shutdown.length == 0 )
{
getLogger().info( "shutdown" );
@@ -426,7 +424,7 @@
public void dispose()
{
// need to complete this ...
- // if stop has ben invoked then dispose has already been invoked on
+ // if stop has been invoked then dispose has already been invoked on
// all of the component we are managing (see LifecycleHelper) - but
// aside from that, we should be going though and cleaning up state
// locally
@@ -437,9 +435,24 @@
//===================================================================
public ContainerManager createContainerManager(
- String name,
+ ContainerDescriptor descriptor,
ClasspathDescriptor classpath )
{
+
+ String path;
+ final String name = descriptor.getName();
+ if( this instanceof KernelManager )
+ {
+ path = getPath().replace('/','.').substring(1);
+ }
+ else
+ {
+ path = getPath().replace('/','.').substring(1) + "." + name;
+ }
+
+ CategoriesDescriptor categories = descriptor.getCategories();
+ getLoggingManager().addCategories( path, categories );
+
try
{
ContainerManager loader = new ContainerManager( this, name );
@@ -457,6 +470,8 @@
}
loader.contextualize( context );
loader.initialize();
+
+ addProfile( descriptor );
return loader;
}
catch( Throwable e )
@@ -511,7 +526,7 @@
+ existing.getType() );
}
- m_profiles.put( profile.getName(), profile );
+ m_profiles.put( name, profile );
ServiceDescriptor[] services = profile.getType().getServices();
for( int i=0; i<services.length; i++ )
{
@@ -646,43 +661,113 @@
return selector.select( profiles );
}
- public Resource getResource( Profile profile ) throws TypeException
+ /**
+ * Return an resource matching the supplied profile.
+ *
+ * @param profile the profile
+ * @param context if the profile is local and a resoruces has not been
assigned
+ * then a new resource will be created using the supplied context
+ * @return a resource matching the supplied profile
+ */
+ Resource getResource( Profile profile, Context context ) throws
ResourceException
{
- return getResource( profile, false );
+ if( isLocal( profile ) )
+ {
+ return createResource( profile, context );
+ }
+ else
+ {
+ ContainerManager parent = getParentManager();
+ if( parent != null )
+ {
+ return parent.getResource( profile, context );
+ }
+ else
+ {
+ final String error = "Unknown profile: " + profile;
+ throw new ResourceException( error );
+ }
+ }
}
- public Resource getResource( Profile profile, boolean create ) throws
TypeException
+ /**
+ * Return an existing resource matching the supplied profile.
+ *
+ * @param profile the profile
+ * @return a resource matching the supplied profile
+ */
+ Resource getResource( Profile profile ) throws ResourceException
{
if( isLocal( profile ) )
{
- Resource resource = getLocalResource( profile );
- if(( resource == null ) && create )
- {
- final String name = getPath() + DELIMITER +
profile.getName();
- ProfileDesignator designator =
- new ProfileDesignator( name, profile, m_helper, m_provider
);
- designator.enableLogging( getLocalLogger().getChildLogger(
"resource" ) );
- m_resources.put( profile, designator );
- resource = designator;
- }
- return resource;
+ return getLocalResource( profile );
}
else
{
ContainerManager parent = getParentManager();
if( parent != null )
{
- return parent.getResource( profile, create );
+ return parent.getResource( profile );
}
else
{
final String error = "Unknown profile: " + profile;
- throw new TypeException( error );
+ throw new ResourceException( error );
}
}
}
/**
+ * Returns an existing or new resource using the supplied local profile
and context.
+ *
+ * @param profile the profile
+ * @param the deployment context
+ * @return a new resource
+ */
+ private Resource createResource( Profile profile, Context context )
+ {
+ Resource resource = getLocalResource( profile );
+ if( resource != null )
+ return resource;
+
+ ProfileDesignator designator =
+ new ProfileDesignator( getPath(), profile, context, m_helper,
m_provider );
+ designator.enableLogging( getLocalLogger().getChildLogger(
"resource" ) );
+ m_resources.put( profile, designator );
+ return designator;
+ }
+
+ /**
+ * Assemble a profile into a consistent application. This method
+ * attempts to establish associations between all dependencies in order
to
+ * resolve an operational application context.
+ *
+ * @param profile the target profile to assemble
+ * @param context the assembly context
+ */
+ public Resource assembleProfile( Profile profile, Context context )
throws AssemblyException
+ {
+ DependencyGraph map = new DependencyGraph( m_map );
+ Resource resource = m_registry.assembleProfile( map, profile,
context );
+ logStartup( getLocalLogger(), "assembly (" + profile.getName() + "):
", map );
+ return resource;
+ }
+
+
+ /**
+ * Assemble a profile into a consistent application. This method
+ * attempts to establish associations between all dependencies in order
to
+ * resolve an operational application context.
+ *
+ * @param profile the target profile to assemble
+ * @param context the assembly context
+ */
+ public DependencyGraph assemble( Profile profile, Context context )
throws Exception
+ {
+ return assemble( new Profile[]{ profile }, context );
+ }
+
+ /**
* Assemble a set of profiles into a consistent application. This method
* attempts to establish associations between all dependencies in order
to
* resolve an operational application context.
@@ -690,43 +775,32 @@
* @param profiles the set of profiles constituting the core components
* from which the associations between components will be based
*/
- public Profile[] assemble( Profile[] profiles ) throws Exception
+ public DependencyGraph assemble( Profile[] profiles ) throws Exception
{
- if( profiles.length == 0 )
- return profiles;
+ return assemble( profiles, m_context );
+ }
+ /**
+ * Assemble a set of profiles into a consistent application. This method
+ * attempts to establish associations between all dependencies in order
to
+ * resolve an operational application context.
+ *
+ * @param profiles the set of profiles constituting the core components
+ * from which the associations between components will be based
+ */
+ public DependencyGraph assemble( Profile[] profiles, Context context )
throws Exception
+ {
DependencyGraph map = new DependencyGraph( m_map );
- m_registry.assemble( map, profiles );
- Profile[] result = map.getStartupGraph();
- if( getLogger().isInfoEnabled() )
- {
- if( result.length > 0 )
- {
- StringBuffer buffer = new StringBuffer();
- for( int i=0; i<result.length; i++ )
- {
- Profile profile = result[i];
- if( isLocal( profile ) )
- {
- buffer.append( result[i].getName() );
- }
- else
- {
- buffer.append( "[" + result[i].getName() + "]" );
- }
- if( i<(result.length-1) )
- buffer.append(", ");
- }
- getLogger().info("assembly: " + buffer.toString() );
- }
- else
- {
- getLogger().info( "assembly (empty)" );
- }
- }
- return result;
+
+ if( profiles.length == 0 )
+ return map;
+
+ m_registry.assemble( map, profiles, context );
+ logStartup( getLogger(), "assembly: ", map );
+ return map;
}
+
/**
* Returns an order sequence of profiles under the management of this
instance.
* @param activate if TRUE, only return profiles with activation on
startup
@@ -932,5 +1006,36 @@
// use the DefaultSelector
return getSelector( dependency.getService(),
dependency.getAttribute("avalon:selector") );
+ }
+
+ private void logStartup( Logger logger, String lead, DependencyGraph map
)
+ {
+ Profile[] result = map.getStartupGraph();
+ if( logger.isInfoEnabled() )
+ {
+ if( result.length > 0 )
+ {
+ StringBuffer buffer = new StringBuffer();
+ for( int i=0; i<result.length; i++ )
+ {
+ Profile profile = result[i];
+ if( isLocal( profile ) )
+ {
+ buffer.append( result[i].getName() );
+ }
+ else
+ {
+ buffer.append( "[" + result[i].getName() + "]" );
+ }
+ if( i<(result.length-1) )
+ buffer.append(", ");
+ }
+ logger.info( lead + buffer.toString() );
+ }
+ else
+ {
+ logger.info( lead + "(empty)" );
+ }
+ }
}
}
1.6 +1 -1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/DefaultLoggerManager.java
Index: DefaultLoggerManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/DefaultLoggerManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultLoggerManager.java 9 Aug 2002 15:28:04 -0000 1.5
+++ DefaultLoggerManager.java 12 Aug 2002 02:00:09 -0000 1.6
@@ -234,7 +234,7 @@
logger.setLogTargets( new LogTarget[]{ (LogTarget)
m_targets.get( DEFAULT_TARGET ) } );
}
- if( notify && getLogger().isDebugEnabled() )
+ if( notify && getLogger().isInfoEnabled() )
{
final String message =
REZ.getString( "category-create", path, target,
logger.getPriority() );
1.2 +5 -54
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/KernelManager.java
Index: KernelManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/KernelManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- KernelManager.java 8 Aug 2002 09:58:40 -0000 1.1
+++ KernelManager.java 12 Aug 2002 02:00:09 -0000 1.2
@@ -7,54 +7,12 @@
*/
package org.apache.excalibur.merlin.assembly;
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.Hashtable;
-import java.util.ArrayList;
-import java.util.Vector;
-import java.util.Iterator;
-import org.apache.avalon.framework.CascadingException;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.logger.LogEnabled;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.activity.Startable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.activity.Startable;
-import org.apache.avalon.framework.activity.Disposable;
+
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
-import org.apache.excalibur.configuration.ConfigurationUtil;
-import org.apache.excalibur.merlin.assembly.resource.LifecycleHelper;
-import org.apache.excalibur.merlin.assembly.resource.ResourceProvider;
-import org.apache.excalibur.merlin.assembly.resource.ProfileDesignator;
-import org.apache.excalibur.merlin.model.ContainerDescriptor;
-import org.apache.excalibur.merlin.model.ClasspathDescriptor;
-import org.apache.excalibur.merlin.container.Container;
-import org.apache.excalibur.merlin.container.DefaultContainer;
-import org.apache.excalibur.merlin.model.LoggingDescriptor;
-import org.apache.excalibur.merlin.model.builder.XMLContainerUtil;
-import org.apache.excalibur.merlin.model.Category;
-import org.apache.excalibur.merlin.model.CategoriesDescriptor;
-import org.apache.excalibur.merlin.model.Profile;
-import org.apache.excalibur.merlin.model.Resource;
-import org.apache.excalibur.meta.info.PhaseDescriptor;
-import org.apache.excalibur.meta.info.ServiceDescriptor;
-import org.apache.excalibur.meta.info.ReferenceDescriptor;
-import org.apache.excalibur.meta.info.DependencyDescriptor;
-import org.apache.excalibur.meta.info.ExtensionDescriptor;
-import org.apache.excalibur.meta.info.Type;
-import org.apache.excalibur.meta.info.Facility;
-import org.apache.excalibur.meta.verifier.ComponentVerifier;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+
/**
* Classloader for an assembly of components that provides the complete
@@ -83,13 +41,6 @@
//===================================================================
// state
//===================================================================
-
- /**
- * The description of the logging system that contains the declaration of
- * the logging targets to use. This value is used as the constructor
- * argument to the DefaultLoggerManager.
- */
- //private LoggingDescriptor m_loggingDescriptor;
/**
* The logging manager that we use to construct logging catagories
1.9 +114 -21
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ProfileRegistry.java
Index: ProfileRegistry.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ProfileRegistry.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ProfileRegistry.java 9 Aug 2002 15:28:04 -0000 1.8
+++ ProfileRegistry.java 12 Aug 2002 02:00:09 -0000 1.9
@@ -20,6 +20,7 @@
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -31,6 +32,10 @@
import org.apache.excalibur.meta.info.Facility;
import org.apache.excalibur.merlin.model.Profile;
import org.apache.excalibur.merlin.model.Resource;
+import org.apache.excalibur.merlin.assembly.resource.LifecycleHelper;
+import org.apache.excalibur.merlin.assembly.resource.ResourceProvider;
+import org.apache.excalibur.merlin.assembly.resource.ResourceException;
+import org.apache.excalibur.merlin.assembly.resource.ProfileDesignator;
/**
* Internal table that holds available component type keyed relative
@@ -57,6 +62,18 @@
*/
private DependencyGraph m_map;
+ /**
+ * The lifecycle helper.
+ */
+ private LifecycleHelper m_helper;
+
+ /**
+ * Utility class that manages supply of context, config, services, etc.
during
+ * startup of a profile.
+ */
+ private ResourceProvider m_provider;
+
+
//=======================================================================
// constructor
//=======================================================================
@@ -66,10 +83,16 @@
* @param manager the container manager
* @param map the dependency map
*/
- public ProfileRegistry( ContainerManager manager, DependencyGraph map )
+ public ProfileRegistry(
+ ContainerManager manager,
+ DependencyGraph map,
+ LifecycleHelper helper,
+ ResourceProvider provider )
{
m_manager = manager;
m_map = map;
+ m_helper = helper;
+ m_provider = provider;
}
//=======================================================================
@@ -77,6 +100,47 @@
//=======================================================================
/**
+ * Initiate dependency correlation for the supplied profile.
+ *
+ * @param map the dependency graph containing candidates and into which
asembled
+ * profiles will be added
+ * @param profile the profile to assemble
+ * @param context supplimentary context
+ * @exception AssemblyException if an error occurs during assembly
+ */
+ public Resource assembleProfile( DependencyGraph map, Profile profile,
Context context ) throws AssemblyException
+ {
+ return assembleProfile( map, profile, context, new ArrayList() );
+ }
+
+ /**
+ * Initiate dependency correlation for the supplied profile.
+ *
+ * @param map the dependency graph containing candidates and into which
asembled
+ * profiles will be added
+ * @param profile the profile to assemble
+ * @param context supplimentary context
+ * @exception AssemblyException if an error occurs during assembly
+ */
+ private Resource assembleProfile( DependencyGraph map, Profile profile,
Context context, List visited ) throws AssemblyException
+ {
+ getLogger().debug("assembly target: " + profile );
+ assembleProfile( map, profile, context, visited, "" );
+ m_map.add( profile );
+ map.add( profile );
+ try
+ {
+ return m_manager.getResource( profile, context );
+ }
+ catch( ResourceException e )
+ {
+ final String error = "Unable to assemble profile '" +
profile.getName() + "'.";
+ throw new AssemblyException( error, e );
+ }
+ }
+
+
+ /**
* For all of the explicity declared profiles, initiate dependency
correlation.
* The implementation will attempt to assembly each profile in the order
* supplied.
@@ -86,25 +150,30 @@
* @param profiles the set of profiles to assemble
* @exception Exception if an error occurs during assembly
*/
- public void assemble( DependencyGraph map, Profile[] profiles ) throws
Exception
+ public void assemble( DependencyGraph map, Profile[] profiles, Context
context ) throws AssemblyException
{
for( int i=0; i<profiles.length; i++ )
{
Profile profile = profiles[i];
getLogger().debug("assembly target: " + profile );
ArrayList visited = new ArrayList();
- assembleProfile( map, profile, visited, "" );
+ assembleProfile( map, profile, context, visited, "" );
- final String name =
- m_manager.getPath() + ContainerManager.DELIMITER +
profile.getName();
- final Resource resource = m_manager.getResource( profile, true );
- getLogger().debug( "created explicit resource for: " + name );
m_map.add( profile );
map.add( profile );
+
+ try
+ {
+ m_manager.getResource( profile, context );
+ }
+ catch( ResourceException e )
+ {
+ final String error = "Unable to assemble profile '" +
profile.getName() + "'.";
+ throw new AssemblyException( error, e );
+ }
}
}
-
/**
* Returns the set of component types know to the registry that are
capable of
* supporting the supplied service.
@@ -134,7 +203,7 @@
* @param pad used in formatting log messages
*/
private void assembleProfile(
- DependencyGraph map, Profile profile, List visited, String pad )
throws Exception
+ DependencyGraph map, Profile profile, Context context, List visited,
String pad ) throws AssemblyException
{
getLogger().debug( pad + "assemble: " + profile );
String pad2 = pad + " ";
@@ -161,7 +230,7 @@
// have at least one solution
//
- boolean ok = assembleProviders( map, profile, dependency,
visited, pad2 );
+ boolean ok = assembleProviders( map, profile, context,
dependency, visited, pad2 );
if( !ok )
{
final String message =
@@ -199,7 +268,20 @@
//
getLogger().debug( pad + " selection: " + supplier );
- Resource resource = m_manager.getResource( supplier, true );
+ Resource resource;
+ try
+ {
+ resource = m_manager.getResource( supplier, context );
+ }
+ catch( ResourceException e )
+ {
+ final String error =
+ "Unable to assemble supplier profile '"
+ + supplier.getName()
+ + "' for the porofile '" + profile.getName() + "'.";
+ throw new AssemblyException( error, e );
+ }
+
profile.addProvider( role, resource );
m_map.add( supplier );
map.add( supplier );
@@ -217,7 +299,7 @@
PhaseDescriptor phase = phases[i];
if( profile.getExtension( phase ) == null )
{
- boolean ok = assembleManagers( map, profile, phase, visited,
pad2 );
+ boolean ok = assembleManagers( map, profile, context, phase,
visited, pad2 );
if( !ok )
{
final String message = "Could not locate an extension
for the phase: "
@@ -252,8 +334,19 @@
//
getLogger().debug( pad + " selection: " + supplier );
- Resource resource =
- m_manager.getResource( supplier, true );
+ Resource resource;
+ try
+ {
+ resource = m_manager.getResource( supplier, context );
+ }
+ catch( ResourceException e )
+ {
+ final String error =
+ "Unable to assemble extension profile '"
+ + supplier.getName()
+ + "' for the profile '" + profile.getName() + "'.";
+ throw new AssemblyException( error, e );
+ }
profile.addExtension( phase, supplier, resource );
m_map.add( supplier );
map.add( supplier );
@@ -262,8 +355,8 @@
}
private boolean assembleManagers(
- DependencyGraph map, Profile source, PhaseDescriptor phase, List
visited, String pad )
- throws Exception
+ DependencyGraph map, Profile source, Context context, PhaseDescriptor
phase, List visited, String pad )
+ throws AssemblyException
{
boolean ok = false;
Profile[] profiles = getProfiles( phase );
@@ -280,7 +373,7 @@
{
try
{
- assembleProfile( map, profile, visited, pad + " " );
+ assembleProfile( map, profile, context, visited, pad + "
" );
ok = true;
getLogger().debug( pad + " extension: " + profile );
}
@@ -298,8 +391,8 @@
}
private boolean assembleProviders(
- DependencyGraph map, Profile source, DependencyDescriptor dependency,
List visited, String pad )
- throws Exception
+ DependencyGraph map, Profile source, Context context,
DependencyDescriptor dependency, List visited, String pad )
+ throws AssemblyException
{
boolean ok = false;
getLogger().debug( pad + "dependency: " + dependency.getRole() );
@@ -311,7 +404,7 @@
{
try
{
- assembleProfile( map, profile, visited, pad + " " );
+ assembleProfile( map, profile, context, visited, pad + "
" );
ok = true;
getLogger().debug( pad + " provider: " + profile );
}
1.8 +6 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeManager.java
Index: TypeManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeManager.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TypeManager.java 8 Aug 2002 10:02:35 -0000 1.7
+++ TypeManager.java 12 Aug 2002 02:00:09 -0000 1.8
@@ -86,6 +86,9 @@
public static final String DEFAULT_CONTAINER_CLASS =
"org.apache.excalibur.merlin.container.DefaultContainer";
+ public static final String DEFAULT_STRUCTURE_CLASS =
+ "org.apache.excalibur.merlin.container.StructuralExtension";
+
//===================================================================
// state
@@ -249,7 +252,8 @@
if( !( getParent() instanceof TypeManager ))
{
- Type type = m_types.addType( DEFAULT_CONTAINER_CLASS );
+ m_types.addType( DEFAULT_CONTAINER_CLASS );
+ m_types.addFacility( DEFAULT_STRUCTURE_CLASS );
}
}
1.2 +2 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/UnresolvedManagerException.java
Index: UnresolvedManagerException.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/UnresolvedManagerException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnresolvedManagerException.java 30 Jul 2002 07:05:55 -0000 1.1
+++ UnresolvedManagerException.java 12 Aug 2002 02:00:09 -0000 1.2
@@ -19,7 +19,7 @@
* @version $Revision$ $Date$
*/
public final class UnresolvedManagerException
- extends CascadingException
+ extends AssemblyException
{
private PhaseDescriptor m_phase;
1.2 +3 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/UnresolvedProviderException.java
Index: UnresolvedProviderException.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/UnresolvedProviderException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnresolvedProviderException.java 29 Jul 2002 06:14:29 -0000 1.1
+++ UnresolvedProviderException.java 12 Aug 2002 02:00:09 -0000 1.2
@@ -19,7 +19,8 @@
* @version $Revision$ $Date$
*/
public final class UnresolvedProviderException
- extends CascadingException
+ //extends CascadingException
+ extends AssemblyException
{
private DependencyDescriptor m_dependency;
1.5 +54 -31
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/resource/LifecycleHelper.java
Index: LifecycleHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/resource/LifecycleHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LifecycleHelper.java 2 Aug 2002 06:36:09 -0000 1.4
+++ LifecycleHelper.java 12 Aug 2002 02:00:09 -0000 1.5
@@ -28,8 +28,11 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
+import org.apache.excalibur.merlin.container.Container;
import org.apache.excalibur.merlin.model.Profile;
import org.apache.excalibur.merlin.model.Resource;
+import org.apache.excalibur.merlin.model.ContextDirective;
+import org.apache.excalibur.meta.info.ContextDescriptor;
import org.apache.excalibur.meta.info.PhaseDescriptor;
import org.apache.excalibur.meta.info.ExtensionDescriptor;
import org.apache.excalibur.meta.info.Facility;
@@ -63,47 +66,63 @@
private static final int STAGE_EXTENSION_POST = 11;
private static final int STAGE_DESTROY = 12;
- /**
- * Method to run a component through it's startup phase.
- * Errors that occur during startup will be logged appropriately and
- * cause exceptions with useful messages to be raised.
- *
- * @param name the name of the component
- * @param profile representing the instance criteria
- * @param provider the resource provider
- * @throws LifecycleException if an error occurs when the component
passes
- * through a specific lifecycle stage
- */
- public Object startup( final String name,
+ /**
+ * Method to run a component through it's startup phase.
+ * Errors that occur during startup will be logged appropriately and
+ * cause exceptions with useful messages to be raised.
+ *
+ * @param name the name of the component
+ * @param profile representing the instance criteria
+ * @param provider the resource provider
+ * @param phaseContext the phase context
+ *
+ * @throws LifecycleException if an error occurs when the component passes
+ * through a specific lifecycle stage
+ */
+ public Object startup( final String path,
final Profile profile,
- final ResourceProvider provider )
+ final ResourceProvider provider,
+ final Context phaseContext )
throws LifecycleException
{
- getLogger().info("startup initiated for '" + name + "'." );
+ if( path == null )
+ throw new NullPointerException("path");
+
+ if( profile == null )
+ throw new NullPointerException("profile");
+
+ if( provider == null )
+ throw new NullPointerException("provider");
+
+ if( phaseContext == null )
+ throw new NullPointerException("phaseContext");
+
+ getLogger().info("startup initiated for '" + path + "'." );
+
int stage = 0;
try
{
//Creation stage
stage = STAGE_CREATE;
- notice( name, stage );
+ notice( path, stage );
final Object object = provider.createObject( profile );
//LogEnabled stage
stage = STAGE_LOGGER;
if( object instanceof LogEnabled )
{
- notice( name, stage );
+ notice( path, stage );
final Logger logger = provider.createLogger( profile );
ContainerUtil.enableLogging( object, logger );
}
//Contextualize stage
stage = STAGE_CONTEXT;
- final Context context = provider.createContext( profile );
if( object instanceof Contextualizable )
{
- notice( name, stage );
+ notice( path, stage );
+ final Context context = provider.createContext( profile,
phaseContext );
ContainerUtil.contextualize( object, context );
}
@@ -111,14 +130,14 @@
stage = STAGE_COMPOSE;
if( object instanceof Serviceable )
{
- notice( name, stage );
+ notice( path, stage );
final ServiceManager manager =
provider.createServiceManager( profile );
ContainerUtil.service( object, manager );
}
else if( object instanceof Composable )
{
- notice( name, stage );
+ notice( path, stage );
final ComponentManager componentManager =
provider.createComponentManager( profile );
ContainerUtil.compose( object, componentManager );
@@ -128,7 +147,7 @@
stage = STAGE_CONFIG;
if( object instanceof Configurable )
{
- notice( name, stage );
+ notice( path, stage );
final Configuration configuration =
provider.createConfiguration( profile );
ContainerUtil.configure( object, configuration );
@@ -138,7 +157,7 @@
stage = STAGE_PARAMETER;
if( object instanceof Parameterizable )
{
- notice( name, stage );
+ notice( path, stage );
final Parameters parameters =
provider.createParameters( profile );
ContainerUtil.parameterize( object, parameters );
@@ -151,7 +170,7 @@
stage = STAGE_EXTENSION_PRE;
PhaseDescriptor[] phases = profile.getType().getPhases();
if( phases.length > 0 )
- notice( name, stage );
+ notice( path, stage );
for( int i=0; i<phases.length; i++ )
{
PhaseDescriptor phase = phases[i];
@@ -163,8 +182,9 @@
Extension extension = (Extension) resource.access();
try
{
- getLogger().info("applying phase " +
phase.getReference() + " to " + name );
- extension.extend( Extension.CREATE, object, context
);
+ getLogger().info("applying phase " +
phase.getReference() + " to " + path );
+ Context extContext = provider.createContext( ext,
phaseContext );
+ extension.extend( Extension.CREATE, object,
extContext );
}
catch( Throwable e )
{
@@ -172,7 +192,7 @@
"Extension " + extension.getClass().getName()
+ " raised an exception " + e.getClass().getName()
+ " while processing the creation phase for the
component "
- + name;
+ + path;
throw new LifecycleException( error, e );
}
}
@@ -182,23 +202,26 @@
stage = STAGE_INIT;
if( object instanceof Initializable )
{
- notice( name, stage );
+ notice( path, stage );
ContainerUtil.initialize( object );
}
//Start stage
stage = STAGE_START;
- if( object instanceof Startable )
+ if( !(object instanceof Container) )
{
- notice( name, stage );
- ContainerUtil.start( object );
+ if( object instanceof Startable )
+ {
+ notice( path, stage );
+ ContainerUtil.start( object );
+ }
}
return object;
}
catch( final Throwable t )
{
- fail( name, stage, t );
+ fail( path, stage, t );
//fail() throws an exception so next
//line will never be executed
1.8 +35 -6
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/resource/ProfileDesignator.java
Index: ProfileDesignator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/resource/ProfileDesignator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ProfileDesignator.java 5 Aug 2002 12:39:37 -0000 1.7
+++ ProfileDesignator.java 12 Aug 2002 02:00:09 -0000 1.8
@@ -43,6 +43,11 @@
private final Profile m_profile;
/**
+ * The deployment context.
+ */
+ private final Context m_context;
+
+ /**
* A singleton reference to the instantiated service.
*/
private Object m_object;
@@ -70,13 +75,15 @@
/**
* Create a profile designator instance.
*
- * @param path the resource path
+ * @param path the container path
* @param profile the resource's profile
+ * @param context the deployment context
* @param helper the lifecycle helper
* @param provider the resource provider
*/
public ProfileDesignator( final String path,
final Profile profile,
+ final Context context,
final LifecycleHelper helper,
final ResourceProvider provider )
{
@@ -88,6 +95,10 @@
{
throw new NullPointerException( "profile" );
}
+ if( null == context )
+ {
+ throw new NullPointerException( "context" );
+ }
if( null == helper )
{
throw new NullPointerException( "helper" );
@@ -99,6 +110,7 @@
m_path = path;
m_profile = profile;
+ m_context = context;
m_helper = helper;
m_provider = provider;
}
@@ -124,16 +136,33 @@
}
/**
- * Creation of a new instance of the coponent instance.
+ * Creation of a new instance of the component instance using the
profile name
+ * as the name to assign to the new component.
*
- * @return the service instance.
+ * @return the component instance.
* @exception LifecycleException if an error occurs while establishing
the object
*/
public Object create() throws Exception
{
+ return create( m_profile.getName() );
+ }
+
+ /**
+ * Creation of a new instance of the component instance using a supplied
+ * context and name.
+ *
+ * @param context the creation context
+ * @param name the name to assign to the component
+ * @return the service instance.
+ * @exception LifecycleException if an error occurs while establishing
the object
+ */
+ public Object create( String name ) throws Exception
+ {
if( getState() == STARTED )
return m_object;
- m_object = m_helper.startup( m_path, m_profile, m_provider );
+
+ final String path = m_path + "/" + name;
+ m_object = m_helper.startup( path, m_profile, m_provider, m_context
);
setState( STARTED );
return m_object;
}
@@ -252,6 +281,6 @@
public String toString()
{
- return "ProfileResource: " + getPath();
+ return "ProfileDesignator - profile:" + m_profile;
}
}
1.5 +237 -47
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/resource/ResourceProvider.java
Index: ResourceProvider.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/resource/ResourceProvider.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ResourceProvider.java 2 Aug 2002 06:36:09 -0000 1.4
+++ ResourceProvider.java 12 Aug 2002 02:00:09 -0000 1.5
@@ -26,6 +26,7 @@
import java.security.Policy;
import java.io.FileInputStream;
import java.util.HashMap;
+import java.lang.reflect.Constructor;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
@@ -61,13 +62,19 @@
import org.apache.excalibur.meta.info.ServiceDescriptor;
import org.apache.excalibur.meta.info.DependencyDescriptor;
import org.apache.excalibur.meta.info.ReferenceDescriptor;
+import org.apache.excalibur.meta.info.ContextDescriptor;
+import org.apache.excalibur.meta.info.EntryDescriptor;
+import org.apache.excalibur.meta.info.ExtensionDescriptor;
+import org.apache.excalibur.merlin.assembly.KernelManager;
import org.apache.excalibur.merlin.assembly.ContainerManager;
import org.apache.excalibur.merlin.assembly.DefaultLoggerManager;
import org.apache.excalibur.merlin.model.ContainerDescriptor;
+import org.apache.excalibur.merlin.model.ContextDirective;
import org.apache.excalibur.merlin.model.Profile;
import org.apache.excalibur.merlin.model.Association;
import org.apache.excalibur.merlin.model.Resource;
import org.apache.excalibur.merlin.model.Import;
+import org.apache.excalibur.merlin.model.Entry;
/**
@@ -79,6 +86,15 @@
*/
public class ResourceProvider extends AbstractLogEnabled
{
+
+ //#######################################################################
+ //## ##
+ //## This class will be changed to a interface and singleton policy ##
+ //## implementation class and probably an underlying abstract ##
+ //## provider class. ##
+ //## ##
+ //#######################################################################
+
//=======================================================================
// state
//=======================================================================
@@ -198,8 +214,16 @@
public Logger createLogger( Profile profile )
throws Exception
{
- final String path = m_classloader.getPath();
- final String root = path.replace('/','.').substring(1) + "." +
profile.getName();
+ String root;
+ if( m_classloader instanceof KernelManager )
+ {
+ root = m_classloader.getPath().replace('/','.').substring(1);
+ }
+ else
+ {
+ root = m_classloader.getPath().replace('/','.').substring(1) +
"." + profile.getName();
+ }
+
m_logging.addCategories( root, profile.getCategories() );
return m_logging.getLoggerForCategory( root );
}
@@ -208,43 +232,218 @@
* Create a new Context for component.
*
* @param profile the profile
+ * @param a supplimentary context usable during import resolution
* @return a new Context for service
* @throws Exception if unable to create context
*/
- public Context createContext( Profile profile )
+ public Context createContext( Profile profile, Context context )
throws Exception
{
- DefaultContext parent = new DefaultContext();
- Import[] imports = profile.getContext().getImports();
- for( int i=0; i<imports.length; i++ )
- {
- Import directive = imports[i];
- final String name = directive.getImportName();
- final String key = directive.getKey();
- Object object = null;
+ ContextDescriptor descriptor = profile.getType().getContext();
+ ContextDirective directive = profile.getContext();
+ return buildContext( descriptor, directive, context );
+ }
+
+ /**
+ * Create a new Context for an extension.
+ *
+ * @param profile the profile
+ * @param a supplimentary context usable during import resolution
+ * @return a new Context for service
+ * @throws Exception if unable to create context
+ */
+ public Context createContext( ExtensionDescriptor extension, Context
context )
+ throws Exception
+ {
+ ContextDescriptor descriptor = extension.getContext();
+ return buildContext( descriptor, null, context );
+ }
+
+ /**
+ * Internal utility to construct a context instance using a descriptor,
directive and source
+ * context instances.
+ *
+ * @param descriptor the descriptor containing the context dependency
declarations
+ * @param directive an optional context directive containing import and
context value
+ * creation parameters
+ * @param context a supplimentary context object to used during value
resolution
+ * @return a context object containing only those context entries
desribed under the
+ * supplied descriptor
+ * @exception Exception if a required context value cannot be resolved or
an error
+ * occurs during context value creation
+ */
+ private Context buildContext(
+ ContextDescriptor descriptors,
+ ContextDirective directive,
+ Context context )
+ throws Exception
+ {
+ Map map = new HashMap();
+ Context result;
+
+ if( directive != null )
+ {
+ final String classname = directive.getClassname();
+ Class clazz;
+ try
+ {
+ clazz = m_classloader.loadClass( classname );
+ }
+ catch( ClassNotFoundException cnfe )
+ {
+ throw new ResourceException(
+ "Could not find context class " + classname, cnfe );
+ }
try
{
- object = m_dictionary.get( name );
- parent.put( key, object );
- getLogger().debug(
- "adding context entry: " + key
- + ", from: " + name
- + ", and object: " + object );
+ Constructor constructor = clazz.getConstructor(
+ new Class[]{ Map.class, Context.class } );
+ result = (Context)constructor.newInstance( new Object[]{
map, null } );
}
catch( Throwable e )
{
- final String error =
- "Could not resolve a value for the import directive in
profile '"
- + profile.getName()
- + "' with the name '" + name
- + "' for the key '" + key
- + "'.";
- throw new ResourceException( error );
+ throw new ResourceException(
+ "Unexpected exception while creating context form "
+ + classname, e );
+ }
+ }
+ else
+ {
+ result = new DefaultContext( map );
+ }
+
+ Context dictionary = m_dictionary;
+ EntryDescriptor[] entries = descriptors.getEntrys();
+ for( int i=0; i<entries.length; i++ )
+ {
+ EntryDescriptor entry = entries[i];
+ String key = entry.getKey();
+
+ //
+ // if the entry is already in the supplied context then use it
+ //
+
+ Object object = getContextValue( context, key );
+ if( object == null )
+ {
+ object = getContextValue( dictionary, key );
+ }
+
+ //
+ // If the context value is unresolved, try to handle resolution
+ // using an import directive supplied under the directive
+ //
+
+ if( object == null )
+ {
+
+ //
+ // check if the profile declares an import directive
+ // for the context
+ //
+
+ if( directive != null )
+ {
+ Import imp = directive.getImport( key );
+ if( imp != null )
+ {
+ String name = imp.getImportName();
+ object = getContextValue( context, name );
+ if( object == null )
+ {
+ object = getContextValue( dictionary, name );
+ }
+ if( object == null )
+ {
+ final String error =
+ "Import directive for key: " + key + " via
name: " + name
+ + " cannot be resolved.";
+ getLogger().warn( error );
+ }
+ }
+
+ //
+ // if the context value is unresolved, try to construct
a context
+ // value using an entry constructor directive
+ //
+
+ if( object == null )
+ {
+ //
+ // check if the directive declares a context value
constructor
+ //
+
+ Entry ent = directive.getEntry( key );
+ if( ent != null )
+ {
+ object = ent.getValue( m_classloader, map );
+ }
+ }
+ }
}
+
+ //
+ // finally, if the object is still null, and its not optional,
then
+ // throw an exception, otherwise, add the object to the context
+ //
+
+ if( object != null )
+ {
+ try
+ {
+ boolean ok = objectImplementsType( object,
entry.getType() );
+ if( ok )
+ {
+ map.put( key, object );
+ }
+ else
+ {
+ final String error =
+ "Object resolved for the key '" + key + "' of
class '"
+ + object.getClass().getName() + "' does not
implement the type '"
+ + entry.getType();
+ throw new ResourceException( error );
+ }
+ }
+ catch( ClassNotFoundException cnfe )
+ {
+ final String error =
+ "Context criteria for the key '" + key + "' specifies
an unknown type '"
+ + entry.getType() + "'.";
+ throw new ResourceException( error );
+ }
+ }
+ else
+ {
+ if( entry.isRequired() )
+ {
+ final String error =
+ "Unable to resolve a context value for the entry: " +
key;
+ throw new ResourceException( error );
+ }
+ }
+ }
+
+ if( result instanceof DefaultContext )
+ {
+ ((DefaultContext)result).makeReadOnly();
}
- return profile.getContext().getContext( m_classloader, parent );
+ return result;
+ }
+
+ private Object getContextValue( Context context, String key )
+ {
+ if( context == null ) return null;
+ try
+ {
+ return context.get( key );
+ }
+ catch( ContextException e )
+ {
+ return null;
+ }
}
/**
@@ -350,7 +549,7 @@
catch( Throwable e )
{
final String error =
- "Unexpected exception while attempting to locate a service
to fulfill a dependency for "
+ "Unexpected exception while attempting to locate a service to fulfill a
dependency for "
+ "the role: " + role + " in profile: " +
profile.getName() + ".";
throw new ResourceException( error, e );
}
@@ -365,26 +564,17 @@
* @param type the desired type
* @return true if value is compatible with type, false otherwise
*/
- /*
- private boolean objectImplementsType( final Object value, final String
type ) throws Exception
+ private boolean objectImplementsType( final Object value, final String
type )
+ throws ClassNotFoundException
{
- // ######### need to handle this sort of checking inside a service
manager
- if( value == null )
- return false;
- try
- {
- final Class clazz = value.getClass();
- final ClassLoader classLoader = clazz.getClassLoader();
- final Class typeClass = classLoader.loadClass( type );
- if( typeClass.isAssignableFrom( clazz ) )
- {
- return true;
- }
- }
- catch( final ClassNotFoundException cnfe )
- {
- }
- return false;
+ if( type == null )
+ throw new NullPointerException("type");
+
+ if( value == null )
+ throw new NullPointerException("value");
+
+ final Class clazz = value.getClass();
+ final Class typeClass = m_classloader.loadClass( type );
+ return typeClass.isAssignableFrom( clazz );
}
- */
}
1.12 +35 -6
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/Container.java
Index: Container.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/Container.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Container.java 8 Aug 2002 21:30:17 -0000 1.11
+++ Container.java 12 Aug 2002 02:00:09 -0000 1.12
@@ -69,6 +69,36 @@
static final int DISPOSED = 5;
/**
+ * Context key used to locate the container manager.
+ */
+ public static final String MANAGER_KEY = "merlin:container.manager";
+
+ /**
+ * Context key used to locate the container descriptor.
+ */
+ public static final String DESCRIPTOR_KEY =
"merlin:container.descriptor";
+
+ /**
+ * Context key used to locate a state listener.
+ */
+ public static final String STATE_LISTENER_KEY =
"merlin:container.state-listener";
+
+ /**
+ * Context key used to locate a content listener.
+ */
+ public static final String CONTAINER_LISTENER_KEY =
"merlin:container.container-listener";
+
+ /**
+ * Context key used to locate the logging manager.
+ */
+ public static final String LOGGING_KEY = "merlin:container.logging";
+
+ /**
+ * Context key used to locate the container factory.
+ */
+ public static final String SERVICES_KEY = "merlin:container.services";
+
+ /**
* Return the container name.
*
* @return the name of the container
@@ -111,7 +141,7 @@
* @param name the name to assign to the new container
* @exception Exception is an error occurs
*/
- Container createSubContainer( String name )
+ Container addContainer( String name )
throws Exception;
/**
@@ -122,7 +152,7 @@
* @param classpath the container classpath
* @exception Exception is an error occurs
*/
- Container createSubContainer( String name, ClasspathDescriptor classpath
)
+ Container addContainer( String name, ClasspathDescriptor classpath )
throws Exception;
/**
@@ -133,7 +163,6 @@
* @param classpath the container classpath
* @exception Exception is an error occurs
*/
- public Container createSubContainer(
- String name, ContainerDescriptor descriptor, ClasspathDescriptor
classpath )
- throws Exception;
+ //public Container addContainer( ContainerDescriptor descriptor,
ClasspathDescriptor classpath )
+ // throws Exception;
}
1.29 +118 -258
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/DefaultContainer.java
Index: DefaultContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/DefaultContainer.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- DefaultContainer.java 9 Aug 2002 15:28:04 -0000 1.28
+++ DefaultContainer.java 12 Aug 2002 02:00:09 -0000 1.29
@@ -65,9 +65,11 @@
import org.apache.excalibur.meta.info.DependencyDescriptor;
import org.apache.excalibur.meta.info.ReferenceDescriptor;
import org.apache.excalibur.merlin.assembly.TypeManager;
+import org.apache.excalibur.merlin.assembly.AssemblyException;
import org.apache.excalibur.merlin.assembly.TypeException;
import org.apache.excalibur.merlin.assembly.ContainerManager;
import org.apache.excalibur.merlin.assembly.DefaultLoggerManager;
+import org.apache.excalibur.merlin.assembly.DependencyGraph;
import org.apache.excalibur.merlin.container.Container;
import org.apache.excalibur.merlin.model.ContainerDescriptor;
import org.apache.excalibur.merlin.model.ClasspathDescriptor;
@@ -76,6 +78,8 @@
import org.apache.excalibur.merlin.model.ContextDirective;
import org.apache.excalibur.merlin.model.CategoriesDescriptor;
import org.apache.excalibur.merlin.model.builder.XMLContainerUtil;
+import org.apache.excalibur.merlin.model.builder.XMLContainerCreator;
+import org.apache.excalibur.merlin.model.builder.ContainerBuilder;
import org.apache.excalibur.merlin.Controller;
import org.apache.excalibur.configuration.ConfigurationUtil;
@@ -88,42 +92,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision$ $Date$
*/
-public class DefaultContainer extends AbstractLogEnabled implements
Container, Contextualizable, Configurable, Initializable, Startable,
Suspendable, Disposable, Runnable, StateListener
+public class DefaultContainer extends AbstractLogEnabled implements
Container, Contextualizable, Configurable, Structural, Initializable,
Startable, Suspendable, Disposable, Runnable, StateListener
{
//=======================================================================
// static
//=======================================================================
- /**
- * Context key used to locate the container manager.
- */
- public static final String MANAGER_KEY = "manager";
-
- /**
- * Context key used to locate the container descriptor.
- */
- public static final String DESCRIPTOR_KEY = "descriptor";
-
- /**
- * Context key used to locate a state listener.
- */
- public static final String STATE_LISTENER_KEY = "state-listener";
-
- /**
- * Context key used to locate a content listener.
- */
- public static final String CONTAINER_LISTENER_KEY = "container-listener";
-
- /**
- * Context key used to locate subsidiary container configurations.
- */
- public static final String CONFIGURATIONS_KEY = "configurations";
-
- /**
- * Context key used to locate the logging manager.
- */
- public static final String LOGGING_KEY = "logging";
-
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultContainer.class );
@@ -135,7 +109,7 @@
* Utility class that provides support for marshalling an XML
configuration
* into meta-data and meta-info instances.
*/
- private XMLContainerUtil m_creator = new XMLContainerUtil();
+ private XMLContainerCreator m_creator = new XMLContainerCreator();
/**
* The list of initialized embedded containers wrapped in Container
instances.
@@ -189,12 +163,16 @@
*/
private Thread m_thread;
- private Configuration[] m_configs;
+ private ContainerFactory m_factory;
private DefaultLoggerManager m_logging;
private Throwable m_error;
+ private DependencyGraph m_map;
+
+ private Map m_services;
+
//=======================================================================
// Contextualizable
//=======================================================================
@@ -208,10 +186,10 @@
* a [EMAIL PROTECTED] ContainerManager} (REQUIRED}</li>
* <li>[EMAIL PROTECTED] #DESCRIPTOR_KEY} the container meta data
* [EMAIL PROTECTED] ContainerDescriptor} (REQUIRED}</li>
+ * <li>[EMAIL PROTECTED] #SERVICES_KEY} the container services
+ * [EMAIL PROTECTED] Map} (REQUIRED}</li>
* <li>[EMAIL PROTECTED] #LOGGING_KEY} the logging manager
[EMAIL PROTECTED] DefaultLoggerManager} (REQUIRED}</li>
- * <li>[EMAIL PROTECTED] #CONFIGURATIONS_KEY} the set of subsidiary
container
- * configurations [EMAIL PROTECTED] Configuration}[]
(OPTIONAL}</li>
* <li>[EMAIL PROTECTED] #STATE_LISTENER_KEY} a container state listener
[EMAIL PROTECTED] StateListener} (OPTIONAL}</li>
* <li>[EMAIL PROTECTED] #CONTAINER_LISTENER_KEY} a container container
listener
@@ -224,15 +202,7 @@
m_manager = (ContainerManager) context.get( MANAGER_KEY );
m_descriptor = (ContainerDescriptor) context.get( DESCRIPTOR_KEY );
m_logging = (DefaultLoggerManager) context.get( LOGGING_KEY );
-
- try
- {
- m_configs = (Configuration[]) context.get( CONFIGURATIONS_KEY );
- }
- catch( ContextException e )
- {
- m_configs = new Configuration[0];
- }
+ m_services = (Map) context.get( SERVICES_KEY );
try
{
@@ -253,6 +223,8 @@
{
// optional
}
+
+ m_factory = new ContainerFactory( m_manager, m_logging );
}
//=======================================================================
@@ -275,6 +247,45 @@
}
//=======================================================================
+ // Structural
+ //=======================================================================
+
+ /**
+ * Lifecycle extension stage during which an array of configuration
instances
+ * is supplied. Each contiguration instance represents the configuration
of
+ * a subsidiary container to be hosted within this container.
+ *
+ * @param assembly the subsidiary container configurations
+ */
+ public void assemble( ) throws AssemblyException
+ {
+ //
+ // initiate assembly of the immediate child components contained
within
+ // this container
+ //
+
+ getLogger().debug("assembly");
+ Profile[] profiles = m_descriptor.getComponents( Profile.EXPLICIT,
true );
+ if( profiles.length > 0 )
+ {
+ try
+ {
+ getLogger().debug("profile assembly (" + profiles.length +
")");
+ m_map = m_manager.assemble( profiles );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Assembly failure.";
+ throw new AssemblyException( error, e );
+ }
+ }
+ else
+ {
+ m_map = new DependencyGraph();
+ }
+ }
+
+ //=======================================================================
// Initializable
//=======================================================================
@@ -376,39 +387,26 @@
if( m_state >= INITIALIZED )
return;
- //
- // initiate component assembly
- //
-
- getLogger().debug("assembly");
- Profile[] profiles = m_descriptor.getComponents( Profile.EXPLICIT,
true );
- if( profiles.length > 0 )
- {
- try
- {
- getLogger().debug("profile assembly (" + profiles.length +
")");
- m_manager.assemble( profiles );
- }
- catch( Throwable e )
- {
- final String error = "Assembly failure.";
- throw new ContainerException( error, e );
- }
- }
-
//
// creation of the subsidiary containers
//
getLogger().debug("subsidiary container creation" );
- if( m_configs == null )
- m_configs = new Configuration[0];
-
- for( int i=0; i<m_configs.length; i++ )
+ ContainerDescriptor[] containers = m_descriptor.getContainers();
+ for( int i=0; i<containers.length; i++ )
{
- final Configuration conf = m_configs[i];
- final Container container = createContainer( conf );
+ ContainerDescriptor descriptor = containers[i];
+ ContainerService service = (ContainerService) m_services.get(
descriptor );
+ if( service == null )
+ {
+ final String error =
+ "Missing container service for descriptor: "
+ + descriptor.getName();
+ throw new IllegalStateException( error );
+ }
+ Resource resource = service.getResource( this );
+ resource.create();
}
m_state = INITIALIZED;
@@ -526,13 +524,13 @@
"Container has already passed through start phase.");
if( getLogger().isInfoEnabled() )
- getLogger().info( "startup" );
+ getLogger().info( "startup " + m_map.getStartupGraph().length );
//
// request startup of any unstarted components
//
- m_manager.start();
+ m_manager.start( m_map.getStartupGraph() );
//
// statup all of the subsidiary containers
@@ -605,7 +603,7 @@
// stop the local components
//
- m_manager.stop();
+ m_manager.stop( m_map.getShutdownGraph() );
m_state = STOPPED;
getLogger().debug("container shutdown complete");
@@ -660,12 +658,12 @@
getLogger().debug("container resuming");
//
- // reapply start to the manager
+ // re-apply start to the manager
//
try
{
- m_manager.start();
+ m_manager.start( m_map.getStartupGraph() );
}
catch( Throwable e )
{
@@ -715,8 +713,6 @@
switch( state )
{
case INITIALIZED:
- getLogger().debug(
- "subsidiary container initialized: " +
container.getName() );
synchronized( m_containers )
{
m_containers.add( container );
@@ -862,11 +858,27 @@
if( m_state != INITIALIZED )
throw new IllegalStateException( "Container not in suspended or
initialized state." );
+ //
+ // Add the supplied profiles to this container and declare them to
the
+ // container manager
+ //
+
for( int i=0; i<profiles.length; i++ )
{
- m_manager.addProfile( profiles[i] );
+ Profile profile = profiles[i];
+ m_descriptor.addComponent( profile );
+ m_manager.addProfile( profile );
}
- m_manager.assemble( profiles );
+
+ //
+ // update the container's dependecy graph so that the startup
+ // procedure will include the installed components
+ //
+
+ Profile[] startup = m_descriptor.getComponents( Profile.EXPLICIT,
true );
+ getLogger().info("startup sequence length = " + startup.length );
+ m_map = m_manager.assemble( startup );
+ getLogger().info("map startup sequence length = " +
m_map.getStartupGraph().length );
}
//=======================================================================
@@ -1014,17 +1026,15 @@
/**
* Creation of a new empty container associated as a subsidiary of this
container
- * using the same container profile as this container and an empty
classpath.
+ * using the default container type and an empty classpath.
*
* @param name the name to assign to the new container
* @exception Exception is an error occurs
*/
- public Container createSubContainer(
- String name )
+ public Container addContainer( String name )
throws Exception
{
- return createContainer(
- name, m_descriptor, new ClasspathDescriptor(), new
Configuration[0], new Configuration[0] );
+ return addContainer( name, new ClasspathDescriptor() );
}
@@ -1036,122 +1046,28 @@
* @param classpath the container classpath
* @exception Exception is an error occurs
*/
- public Container createSubContainer(
- String name,
- ClasspathDescriptor classpath )
+ public Container addContainer( String name, ClasspathDescriptor
classpath )
throws Exception
{
- return createContainer(
- name, m_descriptor, classpath, new Configuration[0], new
Configuration[0] );
+ return addContainer(
+ new ContainerDescriptor( name, m_descriptor ), classpath );
}
/**
- * Creation of a new empty container associated as a subsidiary of this
container.
- *
- * @param name the name to assign to the new container
- * @param descriptor the container meta descriptor
- * @param classpath the container classpath
- * @exception Exception is an error occurs
- */
- public Container createSubContainer(
- String name,
- ContainerDescriptor descriptor,
- ClasspathDescriptor classpath )
- throws Exception
- {
- if( m_state != SUSPENDED )
- if( m_state != INITIALIZED )
- throw new IllegalStateException( "Container not in initialized
or suspended state." );
-
- return createContainer(
- name, descriptor, classpath, new Configuration[0], new
Configuration[0] );
- }
-
- /**
- * Internal utility to create and add a new subsidiary container.
+ * Utility to create a subsidiary container from a configuration.
*
* @param config the subsidiary container configuration
* @exception Exception is an error occurs
*/
- private DefaultContainer createContainer(
- String name,
- ContainerDescriptor descriptor,
- ClasspathDescriptor classpath,
- Configuration[] components,
- Configuration[] containers )
- throws Exception
+ public Container addContainer( Configuration config ) throws Exception
{
-
- try
- {
- //
- // create the logging categories for the container
- //
-
- CategoriesDescriptor categories = descriptor.getCategories();
- String base = m_manager.getPath().replace('/','.').substring(1)
+ "." + name;
- m_logging.addCategories( base, categories );
-
- //
- // create the manager
- //
-
- final ContainerManager manager =
- m_manager.createContainerManager( name, classpath );
-
- //
- // populate the descriptor with the components it contains
- //
-
- for( int i=0; i<components.length; i++ )
- {
- final Configuration component = components[i];
- final String cn = component.getAttribute("class");
- try
- {
- final Type t = manager.getType( cn );
- final Profile profile = m_creator.createProfile( t,
component );
- manager.addProfile( profile );
- descriptor.addComponent( profile );
- }
- catch( TypeException e )
- {
- final String warning =
- "Ignoring component declaration at " +
component.getLocation()
- + " due to unknown type: " + cn;
- getLogger().warn( warning );
- }
- }
-
- //
- // create the container
- //
-
- getLogger().debug("creating subsidiary container: " + name );
- DefaultContext context = new DefaultContext();
- context.put( MANAGER_KEY, manager );
- context.put( DESCRIPTOR_KEY, descriptor );
- context.put( LOGGING_KEY, m_logging );
- context.put( CONFIGURATIONS_KEY, containers );
- context.put( STATE_LISTENER_KEY, this );
- context.makeReadOnly();
-
- DefaultContainer container =
- createContainerInstance(
- manager,
descriptor.getType().getInfo().getImplementationKey() );
-
- final Logger logger = getLogger().getChildLogger( name );
- container.enableLogging( logger );
- container.contextualize( context );
- container.configure( descriptor.getConfiguration( manager ) );
- container.initialize( );
- return container;
- }
- catch( Throwable e )
- {
- final String error = "Error creating a subsidiary container.";
- throw new ContainerException( error, e );
- }
+ if( !(( m_state == INITIALIZED ) || ( m_state == SUSPENDED )) )
+ throw new IllegalStateException(
+ "Container not in initialized or suspended state." );
+
+ ContainerService service = m_factory.build( config );
+ Resource resource = service.getResource( this );
+ return (Container) resource.create();
}
/**
@@ -1160,74 +1076,18 @@
* @param config the subsidiary container configuration
* @exception Exception is an error occurs
*/
- private DefaultContainer createContainer( Configuration config ) throws
Exception
- {
- try
- {
- final String name = config.getAttribute("name");
- final String classname =
- config.getAttribute( "class", DefaultContainer.class.getName()
);
- final Type type = m_manager.getType( classname );
-
- final CategoriesDescriptor categories =
- m_creator.createCategoriesDescriptor( name,
config.getChild("categories") );
- final boolean enabled =
- config.getAttributeAsBoolean( "enabled",
m_descriptor.isEnabled() );
- final boolean activation =
- config.getAttributeAsBoolean( "activation",
m_descriptor.getActivationPolicy() );
- final Parameters params =
- Parameters.fromConfiguration( config.getChild("parameters") );
- final ContextDirective contextDirective =
- m_creator.createContextDirective( config.getChild("context") );
- final Configuration conf = config.getChild("configuration");
-
- //
- // create the descriptor
- //
-
- final ContainerDescriptor descriptor =
- new ContainerDescriptor(
- name, params, conf, contextDirective, categories, type,
enabled,
- activation, ContainerDescriptor.EXPLICIT
- );
-
- final ClasspathDescriptor classpath =
- m_creator.createClasspathDescriptor(
config.getChild("classpath") );
-
- return createContainer(
- name,
- descriptor,
- classpath,
- config.getChildren("component"),
- config.getChildren("container")
- );
- }
- catch( Throwable e )
- {
- final String error = "Error establishing subsidiary container.";
- throw new ContainerException( error, e );
- }
- }
-
- /**
- * Internel utility to create a new instance of a container based on a
supplied classname.
- * The clasname must be a type extending the DefaultContainer class.
- * @param loader the classloader containing the class to be used as the
container
- * @param classname the name of the container class
- * @return the new container
- */
- private DefaultContainer createContainerInstance( ClassLoader loader,
String classname )
- throws ContainerException
+ private Container addContainer(
+ ContainerDescriptor descriptor,
+ ClasspathDescriptor classpath )
+ throws Exception
{
- try
- {
- return (DefaultContainer) loader.loadClass( classname
).newInstance();
- }
- catch( Throwable e )
- {
- final String error = "Cannot create a container from the
classname: " + classname;
- throw new ContainerException( error, e );
- }
+ if( !(( m_state == INITIALIZED ) || ( m_state == SUSPENDED )) )
+ throw new IllegalStateException(
+ "Container not in initialized or suspended state." );
+
+ ContainerService service = m_factory.build( descriptor, classpath );
+ Resource resource = service.getResource( this );
+ return (Container) resource.create();
}
/**
1.8 +22 -4
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/DefaultContainer.xinfo
Index: DefaultContainer.xinfo
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/DefaultContainer.xinfo,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultContainer.xinfo 4 Aug 2002 06:43:20 -0000 1.7
+++ DefaultContainer.xinfo 12 Aug 2002 02:00:10 -0000 1.8
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<!--
+<!--
Copyright (C) The Apache Software Foundation. All rights reserved.
This software is published under the terms of the Apache Software License
version 1.1, a copy of which has been included with this distribution in
@@ -10,7 +10,7 @@
@version 1.0 12/03/2001
-->
-<component-info>
+<type>
<component>
<name>container</name>
@@ -18,7 +18,19 @@
</component>
<context>
- <entry key="manager"
type="org.apache.excalibur.merlin.assembly.ContainerManager" optional="false"/>
+ <entry key="merlin:container.descriptor"
+ type="org.apache.excalibur.merlin.model.ContainerDescriptor" />
+ <entry key="merlin:container.manager"
+ type="org.apache.excalibur.merlin.assembly.ContainerManager"/>
+ <entry key="merlin:container.services" type="java.util.Map"/>
+ <entry key="merlin:container.state-listener"
+ type="org.apache.excalibur.merlin.container.StateListener"
+ optional="true"/>
+ <entry key="merlin:container.container-listener"
+ type="org.apache.excalibur.merlin.container.ContainerListener"
+ optional="true"/>
+ <entry key="merlin:container.logging"
+ type="org.apache.excalibur.merlin.assembly.DefaultLoggerManager"/>
</context>
<services>
@@ -27,4 +39,10 @@
</service>
</services>
-</component-info>
+ <phases>
+ <phase>
+ <reference type="org.apache.excalibur.merlin.container.Structural"/>
+ </phase>
+ </phases>
+
+</type>
1.34 +81 -181
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultKernel.java
Index: DefaultKernel.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultKernel.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- DefaultKernel.java 9 Aug 2002 15:28:04 -0000 1.33
+++ DefaultKernel.java 12 Aug 2002 02:00:10 -0000 1.34
@@ -46,9 +46,9 @@
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.DefaultServiceManager;
@@ -85,8 +85,10 @@
import org.apache.excalibur.merlin.model.LoggingDescriptor;
import org.apache.excalibur.merlin.container.Container;
import org.apache.excalibur.merlin.container.DefaultContainer;
+import org.apache.excalibur.merlin.container.ContainerService;
import org.apache.excalibur.merlin.container.StateListener;
import org.apache.excalibur.merlin.container.StateEvent;
+import org.apache.excalibur.merlin.container.ContainerFactory;
import org.apache.excalibur.configuration.ConfigurationUtil;
/**
@@ -159,7 +161,7 @@
// state
//=======================================================================
- private DefaultContainer m_container;
+ private Container m_container;
private boolean m_verified = false;
@@ -247,24 +249,6 @@
{
m_context = context;
context.get( DIR_KEY );
-
- try
- {
- m_path = (String) context.get( PATH_KEY );
- }
- catch( Throwable e )
- {
- m_path = "root";
- }
-
- if( m_path.indexOf("/") > -1 )
- {
- m_name = m_path.substring( m_path.lastIndexOf("/") + 1 );
- }
- else
- {
- m_name = m_path;
- }
}
//=======================================================================
@@ -282,26 +266,46 @@
public void initialize() throws Exception
{
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
final Configuration config = m_config.getChild("container");
-
+ String name = config.getAttribute("name");
+
+ //
+ // If this kernel has been created inside container scope then
+ // all we need to do is to setup a root container that the client
+ // can access.
+ //
+
+ if( classloader instanceof ContainerManager )
+ {
+ ContainerManager manager = (ContainerManager) classloader;
+
+ m_base = manager.getPath().replace('/','.').substring(1) + "." +
name;
+ m_logger = getLoggingManager().getLoggerForCategory( m_base );
+ m_localLogger = m_logger.getChildLogger("kernel");
+
+ ContainerFactory factory = new ContainerFactory( manager,
getLoggingManager() );
+ factory.enableLogging( m_logger );
+
+ ContainerService service = factory.build( config );
+ Resource resource = service.getResource();
+
+ m_container = (Container) resource.create();
+ m_initialized = true;
+ return;
+ }
+
+ //
+ // Otherwise this is a full root kernel under which we need to
establish
+ // the singleton logging system, extension, etc.
+ //
+
try
{
- String name = m_name;
- if( Thread.currentThread().getContextClassLoader() instanceof
ContainerManager )
- {
- m_root = false;
- m_parent =
-
(ContainerManager)Thread.currentThread().getContextClassLoader();
- m_base = m_parent.getPath().replace('/','.').substring(1) +
"." + name;
- }
- else
- {
- m_root = true;
- LoggingDescriptor logging =
- m_creator.createLoggingDescriptor(
m_config.getChild("logging"), name );
- m_logging = new DefaultLoggerManager( logging );
- m_base = name;
- }
+ LoggingDescriptor logging =
+ m_creator.createLoggingDescriptor(
m_config.getChild("logging"), name );
+ m_logging = new DefaultLoggerManager( logging );
+ m_base = name;
//
// Setup the logging categories
@@ -309,8 +313,10 @@
Configuration categoriesConfig = config.getChild("categories" );
CategoriesDescriptor categories =
- m_creator.createCategoriesDescriptor( name,
categoriesConfig );
+ m_creator.createCategoriesDescriptor( m_base,
categoriesConfig );
getLoggingManager().addCategories( m_base, categories );
+ m_logger = getLoggingManager().getLoggerForCategory( m_base );
+ m_localLogger = m_logger.getChildLogger("kernel");
//
// Create the kernel type manager.
@@ -324,10 +330,7 @@
ClasspathDescriptor classpath =
m_creator.createClasspathDescriptor(
m_config.getChild("classpath") );
- m_logger = getLoggingManager().getLoggerForCategory( m_base );
- m_localLogger = m_logger.getChildLogger("kernel");
-
- m_manager = new KernelManager( m_path );
+ m_manager = new KernelManager( m_base );
m_manager.enableLogging( m_logger );
DefaultContext ctx = new DefaultContext( m_context );
ctx.put( KernelManager.LOGGING_KEY, m_logging );
@@ -339,12 +342,19 @@
Thread.currentThread().setContextClassLoader( m_manager );
getLogger().info("kernel established: " + name );
+ //
+ // setup the root container
+ //
- m_container = createContainer( config );
- m_initialized = true;
+ ContainerFactory factory = new ContainerFactory( m_manager,
getLoggingManager() );
+ factory.enableLogging( m_logger );
- getLogger().info("kernel initialization complete");
+ ContainerService service = factory.build( config );
+ Resource resource = service.getResource();
+ m_container = (Container) resource.create();
+ getLogger().info("kernel initialization complete");
+ m_initialized = true;
}
catch( Throwable e )
{
@@ -378,122 +388,6 @@
return m_localLogger;
}
- /**
- * Internal utility to create the root container.
- *
- * @param descriptor the subsidiary container descriptor
- * @exception Exception is an error occurs
- */
- private DefaultContainer createContainer( Configuration config ) throws
Exception
- {
- try
- {
- //
- // collect the information defining the root container
- // descriptor
- //
-
- final String name = config.getAttribute( "name", "root" );
- final String classname = config.getAttribute( "class",
DefaultContainer.class.getName() );
- final Type type = m_manager.getType( classname );
- final CategoriesDescriptor categories =
- m_creator.createCategoriesDescriptor( name,
config.getChild("categories") );
- final boolean enabled =
- config.getAttributeAsBoolean( "enabled", true );
- final boolean activation =
- config.getAttributeAsBoolean( "activation", false );
- final Parameters params =
- Parameters.fromConfiguration( config.getChild("parameters") );
- final ContextDirective contextDirective =
- m_creator.createContextDirective( config.getChild("context") );
- final Configuration conf = config.getChild("configuration");
-
- //
- // create the descriptor
- //
-
- final ContainerDescriptor descriptor =
- new ContainerDescriptor(
- name, params, conf, contextDirective, categories, type,
enabled,
- activation, ContainerDescriptor.EXPLICIT
- );
-
- //
- // create the container manager
- //
-
- final ClasspathDescriptor classpath =
- m_creator.createClasspathDescriptor(
config.getChild("classpath") );
- final ContainerManager manager =
- m_manager.createContainerManager( name, classpath );
-
- //
- // populate the container descriptor with the components it
contains
- //
-
- final Configuration[] components =
config.getChildren("component");
- for( int i=0; i<components.length; i++ )
- {
- final Configuration component = components[i];
- final String c = component.getAttribute("class");
- try
- {
- final Type t = manager.getType( c );
- final Profile profile = m_creator.createProfile( t,
component );
- manager.addProfile( profile );
- descriptor.addComponent( profile );
- }
- catch( TypeException e )
- {
- final String warning =
- "Ignoring component declaration at " +
config.getLocation()
- + " due to unknown type: " + classname;
- getLogger().warn( warning );
- }
- }
-
- //
- // create the container instance
- //
-
- getLogger().debug("creating root container: " + name );
- final DefaultContext context = new DefaultContext();
- context.put( DefaultContainer.MANAGER_KEY, manager );
- context.put( DefaultContainer.DESCRIPTOR_KEY, descriptor );
- context.put( DefaultContainer.LOGGING_KEY, m_logging );
- context.put( DefaultContainer.CONFIGURATIONS_KEY,
config.getChildren("container") );
- context.makeReadOnly();
-
- final DefaultContainer container = createContainerInstance(
m_manager, classname );
- //final Logger logger =
manager.getLoggingManager().getLoggerForCategory( name );
- container.enableLogging( m_logger );
- container.contextualize( context );
- container.configure( descriptor.getConfiguration( manager ) );
- container.initialize( );
- return container;
- }
- catch( Throwable e )
- {
- final String error = "Error establishing root container.";
- throw new KernelException( error, e );
- }
- }
-
- private DefaultContainer createContainerInstance(
- ClassLoader loader, String classname ) throws KernelException
- {
- try
- {
- return (DefaultContainer) loader.loadClass( classname
).newInstance();
- }
- catch( Throwable e )
- {
- final String error =
- "Cannot create a container from the classname: " + classname;
- throw new KernelException( error, e );
- }
- }
-
//=======================================================================
// Startable
//=======================================================================
@@ -514,16 +408,19 @@
if( getLogger().isInfoEnabled() )
getLogger().info("startup");
- try
- {
- m_container.start();
- m_started = true;
- }
- catch( Throwable e )
+ if( m_container instanceof Startable )
{
- final String error = "Kernel startup failure.";
- getLogger().error( error, e );
- throw new KernelException( error, e );
+ try
+ {
+ ((Startable)m_container).start();
+ m_started = true;
+ }
+ catch( Throwable e )
+ {
+ final String error = "Kernel startup failure.";
+ getLogger().error( error, e );
+ throw new KernelException( error, e );
+ }
}
if( getLogger().isInfoEnabled() )
@@ -539,15 +436,18 @@
if( !m_started )
throw new IllegalStateException("not started");
- try
+ if( m_container instanceof Startable )
{
- m_container.stop();
- m_stopped = true;
- }
- catch( Throwable e )
- {
- final String error = "Unepected error while stopping root
container.";
- getLogger().warn( error, e );
+ try
+ {
+ ((Startable)m_container).stop();
+ m_stopped = true;
+ }
+ catch( Throwable e )
+ {
+ final String error = "Unepected error while stopping root
container.";
+ getLogger().warn( error, e );
+ }
}
}
@@ -561,9 +461,9 @@
*/
public void dispose()
{
- if( m_container != null )
+ if(( m_container != null ) && ( m_container instanceof Disposable ))
{
- m_container.dispose();
+ ((Disposable)m_container).dispose();
}
}
1.13 +59 -5
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ContainerDescriptor.java
Index: ContainerDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ContainerDescriptor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ContainerDescriptor.java 8 Aug 2002 10:02:35 -0000 1.12
+++ ContainerDescriptor.java 12 Aug 2002 02:00:10 -0000 1.13
@@ -91,16 +91,44 @@
*/
public class ContainerDescriptor extends Profile
{
- /**
- * The component described within the scope of the container.
- */
- private final ArrayList m_components = new ArrayList();
+
//========================================================================
+ // static
+
//========================================================================
/**
* Container path delimiter.
*/
public static final String DELIMITER = "/";
+
//========================================================================
+ // state
+
//========================================================================
+
+ /**
+ * The component described within the scope of the container.
+ */
+ private final ArrayList m_components = new ArrayList();
+
+ /**
+ * The containers described within the scope of the container.
+ */
+ private final ArrayList m_containers = new ArrayList();
+
+
//========================================================================
+ // constructors
+
//========================================================================
+
+ /**
+ * Create a ContainerDescriptor instance using an existing descriptor as
a template.
+ *
+ * @param name the abstract name of container descriptor
+ * @param template the template descritptor
+ */
+ public ContainerDescriptor( final String name, final ContainerDescriptor
template )
+ {
+ super( name, template );
+ }
+
/**
* Create a ContainerDescriptor instance.
*
@@ -130,6 +158,10 @@
);
}
+
//========================================================================
+ // implementation
+
//========================================================================
+
/**
* Add a component profile to this container.
*
@@ -220,4 +252,26 @@
return (Profile[] ) list.toArray( new Profile[0] );
}
+ /**
+ * Add a container profile to this container.
+ *
+ * @param container the container profile to add to the container
+ */
+ public void addContainer( ContainerDescriptor container )
+ {
+ if( !m_containers.contains( container ) )
+ {
+ m_containers.add( container );
+ }
+ }
+
+ /**
+ * Return the set of container descriptors contained within this
container.
+ *
+ * @return the container descriptors
+ */
+ public ContainerDescriptor[] getContainers()
+ {
+ return (ContainerDescriptor[]) m_containers.toArray( new
ContainerDescriptor[0] );
+ }
}
1.7 +20 -60
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ContextDirective.java
Index: ContextDirective.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ContextDirective.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ContextDirective.java 2 Aug 2002 06:34:51 -0000 1.6
+++ ContextDirective.java 12 Aug 2002 02:00:10 -0000 1.7
@@ -105,6 +105,18 @@
return m_entries;
}
+ public Entry getEntry( String key )
+ {
+ for( int i=0; i<m_entries.length; i++ )
+ {
+ Entry entry = m_entries[i];
+ if( entry.getKey().equals( key ) )
+ return entry;
+ }
+ return null;
+ }
+
+
/**
* Return the set of import directives.
* @return the imports
@@ -114,66 +126,14 @@
return m_imports;
}
- /**
- * Returns the context object based on the context directives.
- * @param parent a possibly null parent context
- * @return the context object
- * @exception ModelException if a context instantiation error occurs
- */
- public Context getContext( ClassLoader loader, Context parent ) throws
ModelException
+ public Import getImport( String key )
{
- if( m_context != null )
- return m_context;
-
- final String classname = getClassname();
- Class clazz;
- try
+ for( int i=0; i<m_imports.length; i++ )
{
- clazz = loader.loadClass( classname );
+ Import imp = m_imports[i];
+ if( imp.getKey().equals( key ) )
+ return imp;
}
- catch( ClassNotFoundException cnfe )
- {
- throw new ModelException(
- "Could not find context class " + classname, cnfe );
- }
-
- Map map = new Hashtable();
- try
- {
- Constructor constructor = clazz.getConstructor(
- new Class[]{Map.class, Context.class} );
- m_context = (Context)constructor.newInstance( new Object[]{map,
parent} );
- }
- catch( Throwable e )
- {
- throw new ModelException(
- "Unexpected exception while creating context form "
- + classname, e );
- }
-
- Entry[] entries = getEntries();
- for( int i=0; i<entries.length; i++ )
- {
- Entry entry = entries[i];
- final String key = entry.getKey();
- try
- {
- final Object value = entry.getValue( loader, parent );
- map.put( key, value );
- }
- catch( Throwable e )
- {
- final String error =
- "Unable to create the context entry for the key: " + key;
- throw new ModelException( error, e );
- }
- }
-
- if( m_context instanceof DefaultContext )
- {
- ((DefaultContext)m_context).makeReadOnly();
- }
-
- return m_context;
+ return null;
}
}
1.6 +9 -5
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Import.java
Index: Import.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Import.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Import.java 2 Aug 2002 06:34:51 -0000 1.5
+++ Import.java 12 Aug 2002 02:00:10 -0000 1.6
@@ -59,11 +59,15 @@
if( null == key )
throw new NullPointerException("key");
- if( null == name )
- throw new NullPointerException("name");
-
m_key = key;
- m_name = name;
+ if( null == name )
+ {
+ m_name = key;
+ }
+ else
+ {
+ m_name = name;
+ }
}
/**
1.7 +8 -8
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Parameter.java
Index: Parameter.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Parameter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Parameter.java 25 Jul 2002 18:07:16 -0000 1.6
+++ Parameter.java 12 Aug 2002 02:00:10 -0000 1.7
@@ -7,8 +7,8 @@
*/
package org.apache.excalibur.merlin.model;
+import java.util.Map;
import java.lang.reflect.Constructor;
-import org.apache.avalon.framework.context.Context;
/**
* A <code>Parameter</code> represents a single constructor typed argument
value. A parameter
@@ -187,7 +187,7 @@
* Return the derived parameter value.
* @return the value
*/
- public Object getValue( ClassLoader loader, Context context ) throws
ModelException
+ public Object getValue( ClassLoader loader, Map map ) throws
ModelException
{
//
// if the parameter value has already been established - return it
now
@@ -200,7 +200,7 @@
//
// if the parameter contains a text argument then check if its a
reference
- // to a context entry (in the form"${<key>}" ), otherwise its a
simple constructor
+ // to a map entry (in the form"${<key>}" ), otherwise its a simple
constructor
// case with a single string paremeter
//
@@ -211,12 +211,12 @@
if( m_argument.endsWith("}") )
{
final String key = m_argument.substring( 2,
m_argument.length() -1 );
- try
+ m_value = map.get( key );
+ if( m_value != null )
{
- m_value = context.get( key );
return m_value;
}
- catch( Throwable e )
+ else
{
final String error = "Missing context value: '" +
key + "'.";
throw new IllegalArgumentException( error );
@@ -315,7 +315,7 @@
try
{
- values[i] = m_parameters[i].getValue( loader, context );
+ values[i] = m_parameters[i].getValue( loader, map );
}
catch( Throwable e )
{
1.20 +23 -1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Profile.java
Index: Profile.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Profile.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Profile.java 8 Aug 2002 10:02:35 -0000 1.19
+++ Profile.java 12 Aug 2002 02:00:10 -0000 1.20
@@ -225,6 +225,28 @@
}
/**
+ * Create a Profile instance without parameters.
+ *
+ * @param name the abstract name of profile
+ * @param profile the profile to use as a template
+ */
+ public Profile( final String name,
+ final Profile template )
+ {
+ this(
+ name,
+ template.getParameters(),
+ template.getConfiguration(),
+ template.getContext(),
+ template.getCategories(),
+ template.getType(),
+ template.isEnabled(),
+ template.getActivationPolicy(),
+ template.getMode() );
+ }
+
+
+ /**
* Create a Profile instance.
*
* @param name the abstract name of component meta data instance
1.4 +11 -1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Resource.java
Index: Resource.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Resource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resource.java 2 Aug 2002 06:34:51 -0000 1.3
+++ Resource.java 12 Aug 2002 02:00:10 -0000 1.4
@@ -8,6 +8,7 @@
package org.apache.excalibur.merlin.model;
import org.apache.excalibur.meta.info.ServiceDescriptor;
+import org.apache.avalon.framework.context.Context;
/**
* Interface implemented by object capable of supply a resources.
@@ -56,6 +57,15 @@
* @return an instance of the type constrained to the profile
*/
Object create() throws Exception;
+
+ /**
+ * Return the resource instance using a supplied context.
+ *
+ * @param context a supplimentary context for inport resolution
+ * @return an instance of the type constrained to the profile
+ */
+ Object create( String name ) throws Exception;
+
/**
* Return the resource instance.
1.4 +2 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/ContainerBuilder.java
Index: ContainerBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/ContainerBuilder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContainerBuilder.java 9 Aug 2002 15:28:04 -0000 1.3
+++ ContainerBuilder.java 12 Aug 2002 02:00:10 -0000 1.4
@@ -50,8 +50,8 @@
final ContainerCreator creator = getXMLContainerCreator( xprofile );
return creator.createPackagedContainerDescriptors( loader, type,
inputStream );
-
}
+
/**
* Utility to get xml info builder, else throw
1.9 +114 -1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLContainerCreator.java
Index: XMLContainerCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLContainerCreator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XMLContainerCreator.java 8 Aug 2002 10:00:50 -0000 1.8
+++ XMLContainerCreator.java 12 Aug 2002 02:00:10 -0000 1.9
@@ -159,4 +159,117 @@
return new ContainerDescriptor(
name, params, config, context, categories, type, enabled,
activation, mode );
}
+
+ public ClasspathDescriptor createClasspathDescriptor( Configuration
config )
+ throws ConfigurationException
+ {
+ ArrayList list = new ArrayList();
+ Configuration[] configs = config.getChildren("fileset");
+ for( int i=0; i<configs.length; i++ )
+ {
+ Configuration c = configs[i];
+ list.add( createFilesetDescriptor( c ) );
+ }
+ FilesetDescriptor[] filesets = (FilesetDescriptor[]) list.toArray(
new FilesetDescriptor[0] );
+ return new ClasspathDescriptor( filesets );
+ }
+
+ public FilesetDescriptor createFilesetDescriptor( Configuration config )
+ throws ConfigurationException
+ {
+ String base = config.getAttribute("dir");
+ ArrayList list = new ArrayList();
+ Configuration[] includeConfigs = config.getChildren("include");
+ for( int i=0; i<includeConfigs.length; i++ )
+ {
+ Configuration includeConfig = includeConfigs[i];
+ list.add( createIncludeDescriptor( includeConfig ) );
+ }
+ IncludeDescriptor[] includes = (IncludeDescriptor[]) list.toArray(
new IncludeDescriptor[0] );
+ return new FilesetDescriptor( base, includes );
+ }
+
+ public IncludeDescriptor createIncludeDescriptor( Configuration config )
+ throws ConfigurationException
+ {
+ String filename = config.getAttribute("name");
+ return new IncludeDescriptor( filename );
+ }
+
+ public LoggingDescriptor createLoggingDescriptor( Configuration config,
String name )
+ throws ConfigurationException
+ {
+ final String target = config.getAttribute(
+ "target", Category.DEFAULT_LOGGING_TARGET );
+ final String priority = config.getAttribute( "priority", null );
+ Category category = createCategory( config.getChild("category") );
+
+ ArrayList list = new ArrayList();
+ Configuration[] configs = config.getChildren("target");
+ for( int i=0; i<configs.length; i++ )
+ {
+ Configuration c = configs[i];
+ list.add( createTargetDescriptor( c ) );
+ }
+ TargetDescriptor[] targets = (TargetDescriptor[]) list.toArray( new
TargetDescriptor[0] );
+ return new LoggingDescriptor( name, priority, target, targets,
category );
+ }
+
+ public TargetDescriptor createTargetDescriptor( Configuration config )
+ throws ConfigurationException
+ {
+ final String name = config.getAttribute("name");
+ if( config.getChildren().length == 0 )
+ throw new ConfigurationException(
+ "missing target provider elememt in '" + config.getName() +
"'.");
+ final Configuration c = config.getChildren()[0];
+ TargetProvider provider = null;
+ if( c.getName().equals("file") )
+ {
+ provider = createFileTargetProvider( c );
+ }
+ else
+ {
+ throw new ConfigurationException(
+ "Unrecognized provider: " + c.getName() + " in " +
config.getName() );
+ }
+ return new TargetDescriptor( name, provider );
+ }
+
+ public FileTargetProvider createFileTargetProvider( Configuration config
)
+ throws ConfigurationException
+ {
+ String file = config.getAttribute("location");
+ return new FileTargetProvider( file );
+ }
+
+ public ExtensionsDescriptor createExtensionsDescriptor( Configuration
config )
+ throws ConfigurationException
+ {
+ ArrayList list = new ArrayList();
+ Configuration[] configs = config.getChildren("dirset");
+ for( int i=0; i<configs.length; i++ )
+ {
+ Configuration c = configs[i];
+ list.add( createDirsetDescriptor( c ) );
+ }
+ DirsetDescriptor[] dirs = (DirsetDescriptor[]) list.toArray( new
DirsetDescriptor[0] );
+ return new ExtensionsDescriptor( dirs );
+ }
+
+ public DirsetDescriptor createDirsetDescriptor( Configuration config )
+ throws ConfigurationException
+ {
+ String base = config.getAttribute("dir");
+ ArrayList list = new ArrayList();
+ Configuration[] includeConfigs = config.getChildren("include");
+ for( int i=0; i<includeConfigs.length; i++ )
+ {
+ Configuration includeConfig = includeConfigs[i];
+ list.add( createIncludeDescriptor( includeConfig ) );
+ }
+ IncludeDescriptor[] includes = (IncludeDescriptor[]) list.toArray(
new IncludeDescriptor[0] );
+ return new DirsetDescriptor( base, includes );
+ }
+
}
1.3 +2 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLContainerUtil.java
Index: XMLContainerUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLContainerUtil.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLContainerUtil.java 9 Aug 2002 15:28:04 -0000 1.2
+++ XMLContainerUtil.java 12 Aug 2002 02:00:11 -0000 1.3
@@ -85,7 +85,7 @@
final String target = config.getAttribute(
"target", Category.DEFAULT_LOGGING_TARGET );
final String priority = config.getAttribute( "priority", null );
- Category category = createCategory( config.getChild("category") );
+ Category category = createCategory( config.getChild("category"),
"logging" );
ArrayList list = new ArrayList();
Configuration[] configs = config.getChildren("target");
1.16 +12 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLProfileCreator.java
Index: XMLProfileCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLProfileCreator.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XMLProfileCreator.java 9 Aug 2002 15:28:04 -0000 1.15
+++ XMLProfileCreator.java 12 Aug 2002 02:00:11 -0000 1.16
@@ -168,7 +168,7 @@
public Import createImport( Configuration config ) throws
ConfigurationException
{
final String key = config.getAttribute( "key" );
- final String path = config.getAttribute( "name" );
+ final String path = config.getAttribute( "name", null );
return new Import( key, path );
}
@@ -251,6 +251,16 @@
final String target = config.getAttribute( "target", null );
return new Category( name, priority, target );
}
+
+ public Category createCategory( Configuration config, String def )
+ throws ConfigurationException
+ {
+ final String name = config.getAttribute( "name", def );
+ final String priority = config.getAttribute( "priority", null );
+ final String target = config.getAttribute( "target", null );
+ return new Category( name, priority, target );
+ }
+
private Profile createImplicitProfile( Type type ) throws Exception
{
1.6 +24 -3
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/ExtensionDescriptor.java
Index: ExtensionDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/ExtensionDescriptor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ExtensionDescriptor.java 6 Aug 2002 04:10:38 -0000 1.5
+++ ExtensionDescriptor.java 12 Aug 2002 02:00:11 -0000 1.6
@@ -76,15 +76,21 @@
private final ReferenceDescriptor m_reference;
/**
+ * Context dependecies declared by the extension.
+ */
+ private final ContextDescriptor m_context;
+
+ /**
* Constructor a phase descriptor without attributes.
* @param name the phase name
* @param interface the phase type
*/
public ExtensionDescriptor( final String name,
final int stage,
+ final ContextDescriptor context,
final ReferenceDescriptor reference )
{
- this( name, stage, reference, null );
+ this( name, stage, reference, context, null );
}
/**
@@ -95,6 +101,7 @@
public ExtensionDescriptor( final String name,
final int stage,
final ReferenceDescriptor reference,
+ final ContextDescriptor context,
final Properties attributes )
{
super( attributes );
@@ -103,11 +110,14 @@
throw new NullPointerException( "name" );
if( null == reference )
throw new NullPointerException( "reference" );
+ if( null == context )
+ throw new NullPointerException( "context" );
if( (ALL < stage) || (stage < CREATE ))
throw new IllegalArgumentException( "stage: " + stage );
m_name = name;
m_reference = reference;
+ m_context = context;
m_stage = stage;
}
@@ -132,10 +142,21 @@
}
/**
+ * Return the context constraints.
+ *
+ * @return the context descriptor
+ */
+ public ContextDescriptor getContext()
+ {
+ return m_context;
+ }
+
+ /**
* Return the component management lifecycle stage that this
* extension is to be applied under.
*
- * @return one of the phase values [EMAIL PROTECTED] #CREATE}, [EMAIL
PROTECTED] #ACCESS}, [EMAIL PROTECTED] #RELEASE}, [EMAIL PROTECTED] #DESTROY},
+ * @return one of the phase values [EMAIL PROTECTED] #CREATE}, [EMAIL
PROTECTED] #ACCESS},
+ * [EMAIL PROTECTED] #RELEASE}, [EMAIL PROTECTED] #DESTROY},
* [EMAIL PROTECTED] #INNER}, [EMAIL PROTECTED] #OUTER}, or [EMAIL
PROTECTED] #ALL}.
*/
public int getStage()
1.3 +6 -4
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLFacilityCreator.java
Index: XMLFacilityCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLFacilityCreator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLFacilityCreator.java 30 Jul 2002 07:05:56 -0000 1.2
+++ XMLFacilityCreator.java 12 Aug 2002 02:00:11 -0000 1.3
@@ -90,10 +90,11 @@
}
final String topLevelName = info.getName();
- if( !topLevelName.equals( "component-info" ) )
+
+ if( !topLevelName.equals( "facility" ) )
{
final String message =
- REZ.getString( "builder.bad-toplevel-element.error",
+ REZ.getString( "builder.bad-toplevel-element.error",
classname,
topLevelName );
throw new ConfigurationException( message );
@@ -157,9 +158,10 @@
final int stage = getStageValue( extension );
ReferenceDescriptor reference =
buildReferenceDescriptor( extension.getChild("reference") );
+ ContextDescriptor context = super.buildContext(
extension.getChild("context") );
final Properties attributes =
super.buildAttributes( extension.getChild( "attributes" ) );
- list.add( new ExtensionDescriptor( name, stage, reference,
attributes ) );
+ list.add( new ExtensionDescriptor( name, stage, reference,
context, attributes ) );
}
return (ExtensionDescriptor[]) list.toArray( new
ExtensionDescriptor[0] );
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>