mcconnell 2003/03/06 01:10:20
Modified: assembly/src/java/org/apache/avalon/assembly/appliance
DefaultAppliance.java Appliance.java
Log:
Addition of assemble() operation enabling self assembly semantics.
Revision Changes Path
1.37 +38 -12
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java
Index: DefaultAppliance.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- DefaultAppliance.java 28 Feb 2003 06:09:15 -0000 1.36
+++ DefaultAppliance.java 6 Mar 2003 09:10:20 -0000 1.37
@@ -164,15 +164,11 @@
private ApplianceContext m_applianceContext;
/**
- * The lifestyle service from which the appliance lifestyle handler is
established.
+ * The engine classloader.
*/
private EngineClassLoader m_engine;
/**
- * The lifestyle service from which the appliance lifestyle handler is
established.
- */
-
- /**
* The system context.
*/
private Locator m_system;
@@ -345,18 +341,32 @@
//=====================================================================
/**
- * Resolve a object to a value.
+ * Resolve a object to a value. If the appliance has not been assembled
+ * the implementation will attempt a self assembly prior to
+ * resolving the service.
*
* @param partition the context within the the resolution is applied
* @return the resolved object
- * @throws ContextException if an error occurs
+ * @throws LocatorException if an error occurs
*/
public Object resolve( Object partition )
throws LocatorException
{
if( !m_assembled )
{
- throw new IllegalStateException( "Appliance has not been assembled: " +
this );
+ final String message =
+ "invoking self assembly in appliance: " + this;
+ getLogger().debug( message );
+ try
+ {
+ assemble();
+ }
+ catch( AssemblyException ae )
+ {
+ final String error =
+ "Unable to resolve service due to a self assembly failure in
applaince: " + this;
+ throw new LocatorException( error, ae );
+ }
}
return m_handler.resolve( partition );
}
@@ -552,6 +562,17 @@
* Assemble the appliance.
* @exception AssemblyException if an error occurs during appliance assembly
*/
+ public void assemble() throws AssemblyException
+ {
+ assemble( new DependencyGraph() );
+ }
+
+ /**
+ * Assemble the appliance.
+ * @param graph the dependency graph
+ * @exception AssemblyException if an error occurs during appliance assembly
+ * @exception NullPointerException if the supplied graph is null
+ */
public void assemble( DependencyGraph graph ) throws AssemblyException
{
if( m_assembled )
@@ -559,10 +580,15 @@
return;
}
+ if( graph == null )
+ {
+ throw new NullPointerException( "graph" );
+ }
+
m_graph = graph;
- synchronized( graph )
+ synchronized( m_graph )
{
- executeAssembly( graph );
+ executeAssembly( m_graph );
}
if( isContextEnabled() )
@@ -575,7 +601,7 @@
if( getLogger().isDebugEnabled() )
{
- Appliance[] providers = graph.getProviderGraph( this );
+ Appliance[] providers = m_graph.getProviderGraph( this );
StringBuffer buffer =
new StringBuffer(
"assembled: " + this.toString()
1.27 +7 -1
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/Appliance.java
Index: Appliance.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/Appliance.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- Appliance.java 27 Feb 2003 22:55:21 -0000 1.26
+++ Appliance.java 6 Mar 2003 09:10:20 -0000 1.27
@@ -240,6 +240,12 @@
* Assemble the appliance.
* @exception AssemblyException if an error occurs during appliance assembly
*/
+ void assemble() throws AssemblyException;
+
+ /**
+ * Assemble the appliance.
+ * @exception AssemblyException if an error occurs during appliance assembly
+ */
void assemble( DependencyGraph graph ) throws AssemblyException;
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]