Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2433 - in development/main/metro: composition/builder/src/main/net/dpml/composition/builder composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/model composition/part/src/main/net/dpml/composition/info composition/testing/test composition/testing/test/src/main/net/dpml/test/config composition/testing/test/src/main/net/dpml/test/state composition/testing/test/src/test/net/dpml/composition/testing composition/testing/test/src/test/net/dpml/test/config composition/testing/test/src/test/net/dpml/test/state parts/src/main/net/dpml/parts/control parts/src/main/net/dpml/parts/model parts/src/main/net/dpml/parts/state

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2433 - in development/main/metro: composition/builder/src/main/net/dpml/composition/builder composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/model composition/part/src/main/net/dpml/composition/info composition/testing/test composition/testing/test/src/main/net/dpml/test/config composition/testing/test/src/main/net/dpml/test/state composition/testing/test/src/test/net/dpml/composition/testing composition/testing/test/src/test/net/dpml/test/config composition/testing/test/src/test/net/dpml/test/state parts/src/main/net/dpml/parts/control parts/src/main/net/dpml/parts/model parts/src/main/net/dpml/parts/state
  • Date: Thu, 28 Apr 2005 04:11:21 -0400

Author: mcconnell AT dpml.net
Date: Thu Apr 28 04:11:16 2005
New Revision: 2433

Added:

development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentEntry.java
- copied, changed from r2430,
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentModel.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceEntry.java
- copied, changed from r2429,
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceModel.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueEntry.java
development/main/metro/parts/src/main/net/dpml/parts/control/Manager.java
- copied, changed from r2429,
development/main/metro/parts/src/main/net/dpml/parts/state/Manager.java
development/main/metro/parts/src/main/net/dpml/parts/model/Component.java
Removed:

development/main/metro/composition/control/src/main/net/dpml/composition/model/AbstractModel.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentModel.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceModel.java
development/main/metro/parts/src/main/net/dpml/parts/state/Manager.java
Modified:

development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ComponentController.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionPartHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextManagerInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java

development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java

development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java

development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java
development/main/metro/composition/testing/test/build.xml

development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java

development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java

development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/CompositeTestCase.java

development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java

development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java

development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java

development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java

development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java

development/main/metro/parts/src/main/net/dpml/parts/control/Manageable.java

development/main/metro/parts/src/main/net/dpml/parts/control/SystemManager.java
development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
Log:
Breakout of component management from a distinct Component model (where a
Component is a model of a managed instance).

Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java
==============================================================================
---
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java
(original)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypeBuilderTask.java
Thu Apr 28 04:11:16 2005
@@ -542,7 +542,7 @@
validateNonArrayReturnType( method, returnType );
String type = returnType.getName();
String postfix = PartDescriptor.getPartPostfix( method );
- if( PartDescriptor.MANAGER_KEY.equals( postfix ) )
+ if( PartDescriptor.COMPONENT_KEY.equals( postfix ) )
{
validateNonNullReturnType( method );
validateAtMostOneParameter( method );

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ApplianceInvocationHandler.java
Thu Apr 28 04:11:16 2005
@@ -24,6 +24,8 @@
import java.lang.reflect.UndeclaredThrowableException;
import java.net.URI;

+import net.dpml.composition.model.ComponentEntry;
+
import net.dpml.parts.control.Disposable;

/**
@@ -41,7 +43,7 @@
// state
//-------------------------------------------------------------------

- private final ComponentController m_manager;
+ private final ComponentEntry m_component;
private boolean m_disposed = false;

//-------------------------------------------------------------------
@@ -53,11 +55,11 @@
*
* @param holder the instance holder
*/
- ApplianceInvocationHandler( ComponentController manager )
+ ApplianceInvocationHandler( ComponentEntry component )
throws Exception
{
- assertNotNull( manager, "manager" );
- m_manager = manager ;
+ assertNotNull( component, "component" );
+ m_component = component;
}

//-------------------------------------------------------------------
@@ -84,7 +86,7 @@

try
{
- Object instance = m_manager.getInstance();
+ Object instance = m_component.resolve( false );
return method.invoke( instance, args );
}
catch( Throwable e )
@@ -99,7 +101,7 @@

public URI getURI()
{
- return m_manager.getURI();
+ return m_component.getURI();
}

public void dispose()
@@ -107,7 +109,7 @@
if( !m_disposed )
{
m_disposed = true;
- m_manager.release( this );
+ m_component.release( this );
}
}


Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ComponentController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ComponentController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ComponentController.java
Thu Apr 28 04:11:16 2005
@@ -28,9 +28,11 @@
import java.util.Vector;
import java.util.logging.Logger;
import java.util.logging.Level;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Observable;
@@ -45,13 +47,15 @@
import net.dpml.composition.state.RecursiveTerminationException;

import net.dpml.composition.model.CompositionModel;
-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;

import net.dpml.parts.control.Monitor;
+import net.dpml.parts.control.Manager;
+import net.dpml.parts.control.ControlRuntimeException;
+import net.dpml.parts.model.Component;
import net.dpml.parts.model.DuplicateKeyException;
import net.dpml.parts.state.State;
import net.dpml.parts.state.Transition;
-import net.dpml.parts.state.Manager;
import net.dpml.parts.state.ResourceUnavailableException;
import net.dpml.parts.state.NoSuchTransitionException;
import net.dpml.parts.state.NoSuchOperationException;
@@ -59,24 +63,39 @@
import net.dpml.parts.state.Operation;
import net.dpml.parts.state.StateEvent;
import net.dpml.parts.state.StateListener;
+import net.dpml.parts.control.Disposable;

+import net.dpml.system.SystemContext;

/**
* The ComponentController class is a controller of a component instance.
*
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
*/
-public class ComponentController extends ComponentModel implements Manager
+public class ComponentController implements Manager
{
private final Map m_handlers = new Hashtable();
+ private final LifecycleHandler m_lifecycleHandler;

- public ComponentController(
- Monitor monitor, CompositionModel model, Object key, Object owner )
- throws Exception
+ private final URI m_uri;
+ private final CompositionController m_controller;
+ private final Monitor m_monitor;
+ private final SystemContext m_system;
+
+ public ComponentController( Monitor monitor, SystemContext system,
CompositionController controller )
{
- super( monitor, model, key, owner );
+ m_controller = controller;
+ m_monitor = monitor;
+ m_system = system;
+ m_lifecycleHandler = new LifecycleHandler( monitor, system );
+ URI uri = controller.getURI();
+ String path = uri.getSchemeSpecificPart();
+ m_uri = CompositionController.createURI( "manager", path );
+ }

- initialize();
+ public URI getURI()
+ {
+ return m_uri;
}

public String getName()
@@ -84,61 +103,101 @@
return getClass().getName();
}

- /**
- * Return an registered transition or operation handler.
- *
- * @param uri a handler uri
- * @return the handler instance
- * @exception NoSuchHandlerException if the supplied key is unknown
- * @exception NullPointerException if the key is null
- */
- protected Object getHandler( String key ) throws NoSuchHandlerException
+ public Monitor getMonitor()
+ {
+ return m_monitor;
+ }
+
+ public Object resolve( Component component ) throws Exception
+ {
+ return resolve( component, true );
+ }
+
+ public Object resolve( Component component, boolean policy ) throws
Exception
{
- if( null == key )
+ if( component instanceof ComponentEntry )
{
- throw new NullPointerException( "key" );
+ ComponentEntry entry = (ComponentEntry) component;
+ if( policy )
+ {
+ InvocationHandler handler = new ApplianceInvocationHandler(
entry );
+ return entry.getProxy( handler );
+ }
+ else
+ {
+ Object instance = getInstance( entry );
+ if( false == entry.isInitialized() )
+ {
+ initialize( entry );
+ }
+ return instance;
+ }
}
- Object handler = m_handlers.get( key );
- if( null == handler )
+ else
{
- throw new NoSuchHandlerException( key );
+ final String error =
+ "Unsupported component implementation class."
+ + "\nComponent: " + component.getURI()
+ + "\nClass: " + component.getClass().getName()
+ + "\nMethod: resolve/2";
+ throw new IllegalArgumentException( error );
}
- return handler;
}

/**
- * Register a handler with the manager. The handler object must
- * implement a publically accessible method named 'handle'. Method
parameters
- * may include java.net.logging.Logger, up to two occurance of
net.dpml.parts.state.State
- * (the first occurance will be assingned the current state and second
the
- * transition target state), and lastly, a type assignable to the current
- * component instance. All parameters are optional.
- *
- * @param key the key under which the handler is registered
- * @param handler the handler instance
- * @exception NullPointerException if the key or handler argument is null
- * @exception DuplicateKeyException if a handler is already registered
under
- * the supplied key
+ * Release a reference to an object managed by the instance.
+ *
+ * @param instance the instance to release
*/
- protected void addHandler( String key, Object handler ) throws
ValidationException
+ public void release( Object instance )
{
- if( null == key )
+ if( null == instance )
{
- throw new NullPointerException( "key" );
+ return;
+ }
+ if( Proxy.isProxyClass( instance.getClass() ) )
+ {
+ Object handler = Proxy.getInvocationHandler( instance );
+ if( handler instanceof Disposable )
+ {
+ Disposable disposable = (Disposable) handler;
+ disposable.dispose();
+ }
}
- if( null == handler )
+ else
{
- throw new NullPointerException( "handler" );
+ m_lifecycleHandler.etherialize( instance );
}
- if( m_handlers.containsKey( key ) )
+ }
+
+ /**
+ * Initialization of the manager by a controller.
+ * If the root state is not terminal the implementation will invoke a
+ * transiton named "initalize". If the transition results in a modified
+ * state, the implementation will continue to recursivly invoke
+ * initialize operations until a non-initializing state is established
+ * as the current state.
+ *
+ * @return the initialized object
+ * @exception IllegalStateException if an error occurs during validation
+ * @exception Exception if an error is raised by a handler assigned to
+ * and invoked initialization transition
+ */
+ public void initialize( Component component ) throws Exception
+ {
+ if( component instanceof ComponentEntry )
{
- throw new DuplicateKeyException( key );
+ ComponentEntry entry = (ComponentEntry) component;
+ initializeComponent( entry );
}
else
{
- Class clazz = handler.getClass();
- locateMethod( clazz, "handle" );
- m_handlers.put( key, handler );
+ final String error =
+ "Unsupported component implementation class."
+ + "\nComponent: " + component.getURI()
+ + "\nClass: " + component.getClass().getName()
+ + "\nMethod: initialize/1";
+ throw new IllegalArgumentException( error );
}
}

@@ -155,26 +214,22 @@
* @exception Exception if an error is raised by a handler assigned to
* and invoked initialization transition
*/
- public synchronized void initialize() throws ValidationException,
Exception
+ private synchronized void initializeComponent( ComponentEntry component
) throws Exception
{
- if( isInitialized() )
+ if( component.isInitialized() )
{
return;
}

- if( null == getLocalInstance() )
- {
- Object instance =
getModel().getCompositionController().incarnate( this );
- setLocalInstance( instance );
- }
-
+ Object instance = getInstance( component );
List visited = new LinkedList();
- DefaultState graph = getStateGraph();
- validate( graph );
+ DefaultState graph = component.getStateGraph();
+ Class subject = component.getModel().getDeploymentClass();
+ validate( subject, graph );
boolean flag = true;
while( flag )
{
- DefaultState state = getCurrentState();
+ DefaultState state = component.getCurrentState();
DefaultTransition initialization = state.getInitialization();
if( null == initialization )
{
@@ -183,7 +238,7 @@
else if( false == visited.contains( state.getName() ) )
{
visited.add( state.getName() );
- flag = applyTransition( initialization );
+ flag = applyTransition( component, initialization );
}
else
{
@@ -211,10 +266,34 @@
throw new RecursiveInitializationException( error );
}
}
- setInitialized( true );
+ component.setInitialized( true );
+ }
+
+ private Object getInstance( ComponentEntry component )
+ {
+ Object instance = component.getLocalInstance();
+ if( null == instance)
+ {
+ try
+ {
+ instance = m_lifecycleHandler.incarnate( component );
+ component.setLocalInstance( instance );
+ }
+ catch( Exception e )
+ {
+ URI uri = getURI();
+ final String error =
+ "Unable to establish a component instance."
+ + "\nComponent URI: " + component.getURI()
+ + "\nComponent Model: " + component.getModel().getURI()
+ + "\nClass: " + component.getModel().getDeploymentClass();
+ throw new ControlRuntimeException( uri, error, e );
+ }
+ }
+ return instance;
}

- private void validate( DefaultState state ) throws ValidationException
+ private void validate( Class subject, DefaultState state ) throws
ValidationException
{
if( null == state )
{
@@ -226,7 +305,7 @@
URI uri = init.getHandlerURI();
try
{
- validateHandlerURI( uri );
+ validateHandlerURI( subject, uri );
}
catch( ValidationException e )
{
@@ -246,7 +325,7 @@
URI uri = operation.getHandlerURI();
try
{
- validateHandlerURI( uri );
+ validateHandlerURI( subject, uri );
}
catch( ValidationException e )
{
@@ -267,7 +346,7 @@
URI uri = transition.getHandlerURI();
try
{
- validateHandlerURI( uri );
+ validateHandlerURI( subject, uri );
}
catch( ValidationException e )
{
@@ -286,7 +365,7 @@
URI uri = terminator.getHandlerURI();
try
{
- validateHandlerURI( uri );
+ validateHandlerURI( subject, uri );
}
catch( ValidationException e )
{
@@ -300,7 +379,7 @@
}
}

- private void validateHandlerURI( URI uri ) throws ValidationException
+ private void validateHandlerURI( Class c, URI uri ) throws
ValidationException
{
if( null == uri )
{
@@ -317,23 +396,9 @@
}
else
{
- Class c = getModel().getDeploymentClass();
Method method = locateMethod( c, spec );
}
}
- else if( "handler".equals( scheme ) )
- {
- try
- {
- getHandler( spec );
- }
- catch( NoSuchHandlerException e )
- {
- final String error =
- "no handler registered under the key [" + spec + "]";
- throw new ValidationException( error );
- }
- }
else
{
final String error =
@@ -359,12 +424,25 @@
* @return the state established by the transition
* @exception if a error occurs in transition execution
*/
- public State apply( String key ) throws Exception
+ public State apply( Component component, String key ) throws Exception
{
- DefaultState state = getCurrentState();
- DefaultTransition transition = state.getNamedTransition( key );
- applyTransition( transition );
- return getState();
+ if( component instanceof ComponentEntry )
+ {
+ ComponentEntry entry = (ComponentEntry) component;
+ DefaultState state = entry.getCurrentState();
+ DefaultTransition transition = state.getNamedTransition( key );
+ applyTransition( entry, transition );
+ return entry.getState();
+ }
+ else
+ {
+ final String error =
+ "Unsupported component implementation class."
+ + "\nComponent: " + component.getURI()
+ + "\nClass: " + component.getClass().getName()
+ + "\nMethod: apply/2";
+ throw new IllegalArgumentException( error );
+ }
}

/**
@@ -382,9 +460,9 @@
* @return TRUE if the transition was executed
* @exception if a error occurs in transition execution
*/
- private boolean applyTransition( DefaultTransition transition ) throws
Exception
+ private boolean applyTransition( ComponentEntry entry, DefaultTransition
transition ) throws Exception
{
- DefaultState state = getCurrentState();
+ DefaultState state = entry.getCurrentState();
URI handler = transition.getHandlerURI();
DefaultState target = transition.getTransitionTarget();

@@ -399,11 +477,11 @@
getMonitor().debug( message );
}

- execution( handler, state, target );
+ execution( entry, handler, state, target );

if( state != target )
{
- setState( target );
+ entry.setState( target );
return true;
}
else
@@ -421,26 +499,39 @@
* @param key the operation key
* @exception if a error occurs in transition execution
*/
- public void execute( String key ) throws Exception
+ public void execute( Component component, String key ) throws Exception
{
- DefaultState state = getCurrentState();
- DefaultOperation operation = state.getNamedOperation( key );
- URI handler = operation.getHandlerURI();
- if( null == handler )
+ if( component instanceof ComponentEntry )
{
- return;
+ ComponentEntry entry = (ComponentEntry) component;
+ DefaultState state = entry.getCurrentState();
+ DefaultOperation operation = state.getNamedOperation( key );
+ URI handler = operation.getHandlerURI();
+ if( null == handler )
+ {
+ return;
+ }
+ else
+ {
+ if( getMonitor().isDebugEnabled() )
+ {
+ final String message =
+ "executing operation ["
+ + handler.toString()
+ + "]";
+ getMonitor().debug( message );
+ }
+ execution( entry, handler, state, null );
+ }
}
else
{
- if( getMonitor().isDebugEnabled() )
- {
- final String message =
- "executing operation ["
- + handler.toString()
- + "]";
- getMonitor().debug( message );
- }
- execution( handler, state, null );
+ final String error =
+ "Unsupported component implementation class."
+ + "\nComponent: " + component.getURI()
+ + "\nClass: " + component.getClass().getName()
+ + "\nMethod: execute/2";
+ throw new IllegalArgumentException( error );
}
}

@@ -463,7 +554,7 @@
* @param target the target of the transition
* @excetion Exception of an invocation or handler error occurs
*/
- private void execution( URI uri, State state, State target ) throws
Exception
+ private void execution( ComponentEntry entry, URI uri, State state,
State target ) throws Exception
{
if( null == uri )
{
@@ -483,35 +574,14 @@
}
else
{
- Object instance = getLocalInstance(); //##
+ Object instance = getInstance( entry );
Class c = instance.getClass();
Method method = locateMethod( c, spec );
Class[] parameters = method.getParameterTypes();
- Object[] args = resolveArguments( parameters, state, target
);
+ Object[] args = resolveArguments( entry, parameters, state,
target );
method.invoke( instance, args );
}
}
- else if( "handler".equals( scheme ) )
- {
- //
- // delegate execution to a registered handler
- //
-
- String spec = uri.getSchemeSpecificPart();
- if( "null".equals( spec ) )
- {
- return;
- }
- else
- {
- Object h = getHandler( spec );
- Class c = h.getClass();
- Method method = locateMethod( c, "handle" );
- Class[] parameters = method.getParameterTypes();
- Object[] args = resolveArguments( parameters, state, target
);
- method.invoke( h, args );
- }
- }
else
{
final String error =
@@ -532,10 +602,9 @@
* @param target the transition target state (possible null when handling
operations)
* @return the populated object array
*/
- private Object[] resolveArguments( Class[] parameters, State state,
State target )
+ private Object[] resolveArguments( ComponentEntry entry, Class[]
parameters, State state, State target )
{
- Object instance = getLocalInstance(); // ##
-
+ Object instance = getInstance( entry );
boolean firstStateAssigned = false;
Object[] args = new Object[ parameters.length ];
for( int i=0; i<parameters.length; i++ )
@@ -543,7 +612,7 @@
Class c = parameters[i];
if( Logger.class.isAssignableFrom( c ) )
{
- CompositionModel model = getModel();
+ CompositionModel model = entry.getModel();
args[i] = model.getCompositionController().getLogChannel(
model );
}
else if( State.class.isAssignableFrom( c ) )
@@ -588,41 +657,49 @@
* non-terminal state the procedure will be repeated. If the current
state
* is a terminal state the operation simply returns.
*/
- public synchronized void terminate()
+ public synchronized void terminate( Component component )
{
- if( false == isInitialized() )
+ if( component instanceof ComponentEntry )
{
- return;
- }
- try
- {
- executeTermination();
- }
- catch( RecursiveTerminationException e )
- {
- // recusive termination path
- String error = e.getMessage();
- getMonitor().warn( error );
+ ComponentEntry entry = (ComponentEntry) component;
+ try
+ {
+ executeTermination( entry );
+ }
+ catch( RecursiveTerminationException e )
+ {
+ // recusive termination path
+ String error = e.getMessage();
+ getMonitor().warn( error );
+ }
+ finally
+ {
+ entry.setInitialized( false );
+ entry.setState( entry.getStateGraph() );
+ }
}
- finally
+ else
{
- setInitialized( false );
- setState( getStateGraph() );
+ final String error =
+ "Unsupported component implementation class."
+ + "\nComponent: " + component.getURI()
+ + "\nClass: " + component.getClass().getName()
+ + "\nMethod: terminate/1";
+ throw new IllegalArgumentException( error );
}
}

- synchronized void executeTermination() throws
RecursiveTerminationException
+ synchronized void executeTermination( ComponentEntry component ) throws
RecursiveTerminationException
{
- if( false == isInitialized() )
+ if( false == component.isInitialized() )
{
return;
}
-
List visited = new LinkedList();
boolean flag = true;
while( flag )
{
- DefaultState state = getCurrentState();
+ DefaultState state = component.getCurrentState();
DefaultTransition terminator = state.getTerminator();
if( null == terminator )
{
@@ -633,7 +710,7 @@
try
{
visited.add( state.getName() );
- flag = applyTransition( terminator );
+ flag = applyTransition( component, terminator );
}
catch( Exception e )
{

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionController.java
Thu Apr 28 04:11:16 2005
@@ -33,9 +33,12 @@
import net.dpml.composition.data.ClasspathDirective;
import net.dpml.composition.data.ComponentProfile;
import net.dpml.composition.data.ValueDirective;
-import net.dpml.composition.model.ComponentModel;
+
+import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.model.CompositionModel;
import net.dpml.composition.model.ValueModel;
+
+import net.dpml.parts.control.HandlerNotFoundException;
import net.dpml.parts.control.ControlRuntimeException;
import net.dpml.parts.control.Controller;
import net.dpml.parts.control.DelegationException;
@@ -43,10 +46,15 @@
import net.dpml.parts.control.LifecycleException;
import net.dpml.parts.control.Monitor;
import net.dpml.parts.control.PartNotFoundException;
+
+import net.dpml.parts.control.Manager;
+
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
+import net.dpml.parts.model.Component;
+
import net.dpml.parts.part.Part;
-import net.dpml.parts.state.Manager;
+
import net.dpml.system.SystemContext;

/**
@@ -69,10 +77,9 @@

private final Monitor m_monitor;
private final SystemContext m_system;
- private final LifecycleHandler m_lifecycleHandler;
private final LifestyleHandler m_lifestyleHandler;
private final URI m_partition;
-
+ private final ValueController m_valueController;
private final InstanceTable m_instances;

//--------------------------------------------------------------------
@@ -85,12 +92,10 @@
m_monitor = monitor;
m_system = system;
m_partition = partition;
-
- m_lifestyleHandler = new LifestyleHandler( monitor );
- m_lifecycleHandler = new LifecycleHandler( monitor, system );
-
+ m_valueController = new ValueController( this );
+ ComponentController manager = new ComponentController( monitor,
system, this );
+ m_lifestyleHandler = new LifestyleHandler( monitor, manager );
m_instances = new InstanceTable( this );
-
}

public InstanceTable getInstanceTable()
@@ -106,7 +111,7 @@
* Load the model controller.
* @return the controller
*/
- public Controller getController()
+ public Controller getController()
{
return getCompositionController();
}
@@ -131,7 +136,7 @@
* <li>system:work.dir</li>
* <li>system:temp.dir</li>
* <li>model:name</li>
- * <li>model:urn</li>
+ * <li>model:uri</li>
* <li>model:partition</li>
* </ol>
* @param model the model
@@ -168,13 +173,13 @@
}
else if( "model".equals( scheme ) )
{
- if( "name".equals( key ) )
+ if( "partition".equals( key ) )
{
- return model.getKey();
+ return model.getPartition();
}
- else if( "partition".equals( key ) )
+ if( "name".equals( key ) )
{
- return model.getPartition();
+ return model.getKey();
}
else if( "uri".equals( key ) )
{
@@ -221,7 +226,8 @@
* @return the model of the part
*/
public Model getModel( URI uri )
- throws IOException, DelegationException, ModelException,
PartNotFoundException
+ throws IOException, DelegationException, ModelException,
PartNotFoundException,
+ HandlerNotFoundException, DelegationException
{
Part part = loadPart( uri );
ClassLoader anchor = net.dpml.logging.Logger.class.getClassLoader();
@@ -233,14 +239,23 @@
/**
* Return the model for a supplied part.
*
- * @param parent the parent classloader
+ * @param classloader the parent classloader
* @param part the part datastructure
* @param key the key to assign to the model
* @return the model
*/
- public Model getModel( ClassLoader parent, Part part, String key )
throws ModelException
+ public Model getModel( ClassLoader classloader, Part part, String key )
+ throws ModelException, HandlerNotFoundException, DelegationException
{
- return getModel( null, parent, part, key );
+ if( isRecognizedPart( part ) )
+ {
+ return getModel( null, classloader, part, key );
+ }
+ else
+ {
+ Controller controller = getPartHandler( part );
+ return controller.getModel( classloader, part, key );
+ }
}

/**
@@ -279,12 +294,10 @@
}
else if( part instanceof ValueDirective )
{
- if( null == key )
- {
- throw new NullPointerException( "key" );
- }
final ValueDirective directive = (ValueDirective) part;
- return new ValueModel( key, this, classloader, directive, model
);
+ getMonitor().debug( "creating nested value model using " +
directive );
+ URI partition = getPartition( model );
+ return new ValueModel( key, this, partition, m_valueController,
classloader, directive, model );
}
else
{
@@ -296,80 +309,89 @@
}
}

- public Manager getManager( Object controller, Model model ) throws
Exception
+ /**
+ * Return a nested component for a supplied part.
+ *
+ * @param model the enclosing model
+ * @param classloader the parent classloader
+ * @param part the part datastructure
+ * @param key the key to assign to the model
+ * @return the model
+ */
+ public Component getComponent( ClassLoader classloader, Part part,
String key )
+ throws ModelException, HandlerNotFoundException, DelegationException
{
- return getManager( controller, model, null );
+ return getComponent( null, classloader, part, key );
}

- public Manager getManager( Object controller, Model model, Object key )
throws Exception
+ /**
+ * Return a nested component for a supplied part using enclosing model.
+ *
+ * @param model the enclosing model
+ * @param classloader the parent classloader
+ * @param part the part datastructure
+ * @param key the key to assign to the model
+ * @return the model
+ */
+ public Component getComponent(
+ CompositionModel model, ClassLoader classloader, Part part, String key
)
+ throws ModelException, HandlerNotFoundException, DelegationException
{
- if( model instanceof CompositionModel )
+ if( isRecognizedPart( part ) )
{
- CompositionModel componentModel = (CompositionModel) model;
- return (Manager) getComponentController( componentModel , key,
controller );
- }
- else if(( model instanceof ValueModel ) )
- {
- if( null == key )
- {
- return new ValueController( (ValueModel) model );
- }
- else
- {
- final String error =
- "Model does not support identity management."
- + "\nModel URI: " + model.getURI()
- + "\nModel Class: " + model.getClass().getName()
- + "\nRequested ID: " + key;
- throw new UnsupportedOperationException( error );
- }
+ Model componentModel = getModel( model, classloader, part, key );
+ return getComponent( componentModel );
}
else
{
- final String error =
- "Unsupported model type."
- + "\nModel URI: " + model.getURI()
- + "\nModel Class: " + model.getClass().getName()
- + "\nRequested ID: " + key;
- throw new UnsupportedOperationException( error );
+ Controller controller = getPartHandler( part );
+ return controller.getComponent( classloader, part, key );
}
}

/**
- * Create and return a new instance of the component represented
- * by the supplied model using the assigned lifestyle policy.
- *
- * @param model the component model
- * @return the resolved instance
+ * Return a default instance model.
+ *
+ * @param model the reference model
+ * @param identity the instance identity
+ * @return the model
*/
- public Object resolve( Model model ) throws Exception
+ public Component getComponent( Model model )
+ throws ModelException
{
- return resolve( model, null, true );
+ if( model instanceof ValueModel )
+ {
+ ValueModel m = (ValueModel) model;
+ return m.getComponent();
+ }
+ else
+ {
+ return getComponentEntry( model, null );
+ }
}

/**
- * Create and return a new identifiable instance of the component
represented
- * by the supplied model using the assigned lifestyle policy.
- *
- * @param model the component model
- * @param key the object key
- * @return the resolved instance
+ * Return a default instance model.
+ *
+ * @param model the reference model
+ * @param identity the instance identity
+ * @return the model
*/
- public Object resolve( Model model, Object key ) throws Exception
+ public Component getComponent( Model model, Object key )
+ throws ModelException
{
- return resolve( model, key, true );
+ return getComponentEntry( model, key );
}

/**
- * Create and return a new identifiable instance of the component
represented
- * by the supplied proxy policy.
- *
- * @param model the component model
- * @param key the object key
- * @param policy the proxy creation policy
- * @return the resolved instance
+ * Return a default instance model.
+ *
+ * @param model the reference model
+ * @param identity the instance identity
+ * @return the model
*/
- public Object resolve( Model model, Object key, boolean policy ) throws
Exception
+ public ComponentEntry getComponentEntry( Model model, Object key )
+ throws ModelException
{
if( null == model )
{
@@ -377,16 +399,14 @@
}
if( model instanceof CompositionModel )
{
- CompositionModel componentModel = (CompositionModel) model;
- ComponentController manager = getComponentController(
componentModel , key, null );
- if( policy )
+ CompositionModel m = (CompositionModel) model;
+ if( null == key )
{
- InvocationHandler handler = new ApplianceInvocationHandler(
manager );
- return manager.getProxy( handler );
+ return m_lifestyleHandler.aquire( m, null );
}
else
{
- return manager.getInstance();
+ return m_lifestyleHandler.aquire( m, key, null );
}
}
else
@@ -399,42 +419,6 @@
}
}

- private ComponentController getComponentController( CompositionModel
model, Object key, Object owner )
- throws Exception
- {
- if( null == key )
- {
- return (ComponentController) m_lifestyleHandler.aquire( model,
owner );
- }
- else
- {
- return (ComponentController) m_lifestyleHandler.aquire( model,
key, owner );
- }
- }
-
- /**
- * Release an instance.
- *
- * @param instance the object to release
- */
- public void release( Object instance )
- {
- if( Proxy.isProxyClass( instance.getClass() ) )
- {
- Object handler = Proxy.getInvocationHandler( instance );
- if( handler instanceof ApplianceInvocationHandler )
- {
- ApplianceInvocationHandler aic =
- (ApplianceInvocationHandler) handler;
- aic.dispose();
- }
- }
- else
- {
- m_lifecycleHandler.etherialize( instance );
- }
- }
-
//--------------------------------------------------------------------
// CompositionController
//--------------------------------------------------------------------
@@ -472,31 +456,6 @@
return m_system.getLoggingManager().getLoggerForCategory( path );
}

- public Object incarnate( ComponentModel holder ) throws
LifecycleException, InvocationTargetException
- {
- return m_lifecycleHandler.incarnate( holder );
- }
-
- public void etherialize( Object instance )
- {
- if( null == instance )
- {
- return;
- }
- else if( Proxy.isProxyClass( instance.getClass() ) )
- {
- Object handler = Proxy.getInvocationHandler( instance );
- if( handler instanceof Disposable )
- {
- Disposable disposable = (Disposable) handler;
- disposable.dispose();
- }
- }
- else
- {
- m_lifecycleHandler.etherialize( instance );
- }
- }

/**
* Return the monitor assigned to this controller.
@@ -580,6 +539,11 @@
}
}

+ private boolean isRecognizedPart( Part part )
+ {
+ return getURI().equals( part.getPartHandlerURI() );
+ }
+
//--------------------------------------------------------------------
// static utilities
//--------------------------------------------------------------------

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionManager.java
Thu Apr 28 04:11:16 2005
@@ -36,6 +36,7 @@
import net.dpml.parts.control.ControlRuntimeException;
import net.dpml.parts.control.Controller;
import net.dpml.parts.control.DelegationException;
+import net.dpml.parts.control.HandlerNotFoundException;
import net.dpml.parts.control.PartNotFoundException;
import net.dpml.parts.control.SystemManager;
import net.dpml.parts.model.Model;
@@ -150,7 +151,7 @@
* @return the model of the part
*/
public Model addPart( URI uri )
- throws IOException, DelegationException, ModelException,
PartNotFoundException
+ throws IOException, DelegationException, ModelException,
PartNotFoundException, HandlerNotFoundException
{
Model model = getModel( uri);
addModel( model );
@@ -164,7 +165,7 @@
* @return the model of the part
*/
public Model addPart( URI uri, String key )
- throws IOException, DelegationException, ModelException,
PartNotFoundException
+ throws IOException, DelegationException, ModelException,
PartNotFoundException, HandlerNotFoundException
{
Part part = loadPart( uri );
ClassLoader classloader = getClassLoader();
@@ -182,33 +183,35 @@
m_models.add( model );
}

+ // TODO: statup means start of all registered Component instances
public synchronized void start() throws Exception
{
- getMonitor().debug( "initiating startup in " + getURI() );
- Model[] models = getManagedModels();
- for( int i=0; i<models.length; i++ )
- {
- Model model = models[i];
- getMonitor().debug( "starting " + model.getURI() );
- Controller controller = model.getController();
- Object instance = controller.resolve( model );
- m_instances.put( model, instance );
- }
+ // getMonitor().debug( "initiating startup in " + getURI() );
+ // Model[] models = getManagedModels();
+ // for( int i=0; i<models.length; i++ )
+ // {
+ // Model model = models[i];
+ // getMonitor().debug( "starting " + model.getURI() );
+ // Controller controller = model.getController();
+ // Object instance = controller.resolve( model );
+ // m_instances.put( model, instance );
+ // }
}

+ // TODO: statup means stop of all registered Component instances
public synchronized void stop()
{
- getMonitor().debug( "initiating shutdown in " + getURI() );
- Model[] models = (Model[]) m_instances.keySet().toArray( new
Model[0] );
- for( int i=0; i<models.length; i++ )
- {
- Model model = models[i];
- getMonitor().debug( "stopping " + model.getURI() );
- Controller controller = model.getController();
- Object instance = m_instances.get( model );
- controller.release( instance );
- m_instances.remove( model );
- }
+ // getMonitor().debug( "initiating shutdown in " + getURI() );
+ // Model[] models = (Model[]) m_instances.keySet().toArray( new
Model[0] );
+ // for( int i=0; i<models.length; i++ )
+ // {
+ // Model model = models[i];
+ // getMonitor().debug( "stopping " + model.getURI() );
+ // Controller controller = model.getController();
+ // Object instance = m_instances.get( model );
+ // controller.release( instance );
+ // m_instances.remove( model );
+ // }
}

//--------------------------------------------------------------------

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionPartHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionPartHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/CompositionPartHandler.java
Thu Apr 28 04:11:16 2005
@@ -130,12 +130,19 @@
}
}

+ public Controller getPartHandler( Part part ) throws
HandlerNotFoundException, DelegationException
+ {
+ URI uri = part.getPartHandlerURI();
+ PartHandler handler = loadPartHandler( uri );
+ return (Controller) handler;
+ }
+
/**
* Load a part handler giiven a handler uri.
* @return the part handler
*/
public PartHandler loadPartHandler( URI uri )
- throws HandlerNotFoundException, DelegationException, IOException
+ throws HandlerNotFoundException, DelegationException
{
if( false == getURI().equals( uri ) )
{
@@ -242,7 +249,7 @@
}
}

- protected PartHandler resolvePartHandler( URI uri ) throws
HandlerNotFoundException, IOException
+ protected PartHandler resolvePartHandler( URI uri ) throws
HandlerNotFoundException
{
if( getURI().equals( uri ) )
{
@@ -261,6 +268,7 @@
}
}

+
private PartHandler loadHandler( URI uri ) throws
HandlerNotFoundException
{
ClassLoader classloader = PartHandler.class.getClassLoader();

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextInvocationHandler.java
Thu Apr 28 04:11:16 2005
@@ -26,7 +26,7 @@
import net.dpml.parts.model.ModelException;
import net.dpml.parts.state.StateListener;

-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.model.CompositionModel;

import net.dpml.system.SystemContext;
@@ -53,7 +53,7 @@
/**
* The component model.
*/
- private final ComponentModel m_holder;
+ private final ComponentEntry m_component;

//-------------------------------------------------------------------
// constructor
@@ -65,20 +65,25 @@
* @param system the system context
* @param model the component model
*/
- ContextInvocationHandler( SystemContext system, ComponentModel holder )
+ ContextInvocationHandler( SystemContext system, ComponentEntry component
)
throws LifecycleException, ModelException
{
m_system = system;
- m_holder = holder;
+ m_component = component;
}

//-------------------------------------------------------------------
// implementation
//-------------------------------------------------------------------

+ ComponentEntry getComponentEntry()
+ {
+ return m_component;
+ }
+
CompositionModel getModel()
{
- return m_holder.getModel();
+ return getComponentEntry().getModel();
}

/**
@@ -107,7 +112,7 @@
if( name.startsWith( "get" ) )
{
String key = getKeyFromMethod( method );
- ComponentModel.ContextMap map = getHolder().getContextMap();
+ ComponentEntry.ContextMap map =
getComponentEntry().getContextMap();
return map.getValue( key, args );
}
else if( null != args )
@@ -117,13 +122,13 @@
if( "addObserver".equals( name ) )
{
Observer observer = (Observer) args[0];
- getHolder().addObserver( observer );
+ getComponentEntry().addObserver( observer );
return null;
}
else if( "addStateListener".equals( name ) )
{
StateListener listener = (StateListener) args[0];
- getHolder().addStateListener( listener );
+ getComponentEntry().addStateListener( listener );
return null;
}
else
@@ -171,11 +176,6 @@
return first + remainder;
}

- ComponentModel getHolder()
- {
- return m_holder;
- }
-
//-------------------------------------------------------------------
// implementation
//-------------------------------------------------------------------

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextManagerInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextManagerInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ContextManagerInvocationHandler.java
Thu Apr 28 04:11:16 2005
@@ -21,7 +21,7 @@
import java.lang.reflect.Method;
import java.util.Map;

-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;

import net.dpml.parts.control.LifecycleException;

@@ -49,7 +49,7 @@
* @param model the component model
*/
ContextManagerInvocationHandler(
- SystemContext system, ComponentModel holder )
+ SystemContext system, ComponentEntry holder )
throws LifecycleException, ModelException
{
super( system, holder );
@@ -82,7 +82,7 @@
}
else if( Map.class == source )
{
- Map map = getHolder().getContextMap();
+ Map map = getComponentEntry().getContextMap();
return method.invoke( map, args );
}
else if( name.startsWith( "set" ) )
@@ -98,7 +98,7 @@
throw new IllegalStateException( error );
}
Object value = args[0];
- getHolder().getContextMap().put( key, value );
+ getComponentEntry().getContextMap().put( key, value );
return null;
}
else

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/InstanceTable.java
Thu Apr 28 04:11:16 2005
@@ -22,7 +22,7 @@
import java.util.Map;
import java.util.WeakHashMap;

-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.model.CompositionModel;

/**
@@ -47,7 +47,7 @@
m_controller = controller;
}

- public void add( ComponentModel holder )
+ public void add( ComponentEntry holder )
{
if( null == holder )
{
@@ -56,7 +56,7 @@
m_holders.put( holder, holder.getModel() );
}

- public ComponentModel get( CompositionModel model, Object key )
+ public ComponentEntry get( CompositionModel model, Object key )
{
if( null == key )
{
@@ -64,10 +64,10 @@
}
synchronized( m_holders )
{
- ComponentModel[] holders = (ComponentModel[])
m_holders.keySet().toArray( new ComponentModel[0] );
+ ComponentEntry[] holders = (ComponentEntry[])
m_holders.keySet().toArray( new ComponentEntry[0] );
for( int i=0; i<holders.length; i++ )
{
- ComponentModel holder = holders[i];
+ ComponentEntry holder = holders[i];
CompositionModel m = holder.getModel();
if( key.equals( holder.getKey() ) && m.equals( model ) )
{
@@ -78,12 +78,12 @@
}
}

- private ComponentModel[] list()
+ private ComponentEntry[] list()
{
- return (ComponentModel[]) m_holders.keySet().toArray( new
ComponentModel[0] );
+ return (ComponentEntry[]) m_holders.keySet().toArray( new
ComponentEntry[0] );
}

- public void remove( ComponentModel holder )
+ public void remove( ComponentEntry holder )
{
m_holders.remove( holder );
}
@@ -92,7 +92,7 @@
{
synchronized( m_holders )
{
- ComponentModel holder = get( model, key );
+ ComponentEntry holder = get( model, key );
if( null != holder )
{
remove( holder );
@@ -117,15 +117,15 @@
{
return false;
}
- ComponentModel[] mine = list();
- ComponentModel[] yours = table.list();
+ ComponentEntry[] mine = list();
+ ComponentEntry[] yours = table.list();
if( mine.length != yours.length )
{
return false;
}
for( int i=0; i<mine.length; i++ )
{
- ComponentModel holder = mine[i];
+ ComponentEntry holder = mine[i];
if( false == holder.equals( yours[i] ) )
{
return false;
@@ -138,10 +138,10 @@
public int hashCode()
{
int hash = m_controller.hashCode();
- ComponentModel[] holders = list();
+ ComponentEntry[] holders = list();
for( int i=0; i<holders.length; i++ )
{
- ComponentModel holder = holders[i];
+ ComponentEntry holder = holders[i];
hash ^= holder.hashCode();
}
return hash;

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifecycleHandler.java
Thu Apr 28 04:11:16 2005
@@ -25,7 +25,7 @@
import java.lang.reflect.Proxy;
import java.net.URI;

-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.model.CompositionModel;
import net.dpml.configuration.Configuration;
import net.dpml.lang.DefaultInvocationHandler;
@@ -83,7 +83,7 @@
*
* @return a new component instance
*/
- public Object incarnate( ComponentModel holder ) throws
LifecycleException, InvocationTargetException
+ public Object incarnate( ComponentEntry holder ) throws
LifecycleException, InvocationTargetException
{
if( getMonitor().isDebugEnabled() )
{
@@ -162,7 +162,7 @@
* @return the state manager (possibly null)
*/
/*
- public Manager getManager( ComponentModel holder ) throws
LifecycleException, InvocationTargetException
+ public Manager getManager( ComponentEntry holder ) throws
LifecycleException, InvocationTargetException
{
if( getMonitor().isDebugEnabled() )
{
@@ -338,7 +338,7 @@
}
}

- private Object newContextInvocationHandler( ComponentModel holder, Class
clazz ) throws LifecycleRuntimeException
+ private Object newContextInvocationHandler( ComponentEntry holder, Class
clazz ) throws LifecycleRuntimeException
{
try
{
@@ -354,7 +354,7 @@
}
}

- private Object newPartsInvocationHandler( ComponentModel holder, Class
clazz ) throws LifecycleException
+ private Object newPartsInvocationHandler( ComponentEntry holder, Class
clazz ) throws LifecycleException
{
try
{

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/LifestyleHandler.java
Thu Apr 28 04:11:16 2005
@@ -18,7 +18,7 @@

package net.dpml.composition.control;

-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.model.CompositionModel;
import net.dpml.parts.control.Monitor;

@@ -34,10 +34,12 @@
class LifestyleHandler
{
private Monitor m_monitor;
+ private ComponentController m_controller;

- LifestyleHandler( Monitor monitor )
+ LifestyleHandler( Monitor monitor, ComponentController controller )
{
m_monitor = monitor;
+ m_controller = controller;
}

/**
@@ -46,7 +48,7 @@
* @param model the model from which new or existing instances will be
resolved
* @return the key to the resolved instance
*/
- public ComponentModel aquire( CompositionModel model, Object owner )
throws Exception
+ public ComponentEntry aquire( CompositionModel model, Object owner )
{
final String lifestyle = model.getLifestylePolicy();
if( getMonitor().isDebugEnabled() )
@@ -63,7 +65,7 @@
{
synchronized( model )
{
- ComponentModel holder = new ComponentController( m_monitor,
model, null, owner );
+ ComponentEntry holder = new ComponentEntry( m_monitor,
m_controller, model, null, owner );
Object key = holder.getKey();
if( getMonitor().isDebugEnabled() )
{
@@ -108,8 +110,7 @@
* @param model the model from which new or existing instances will be
resolved
* @return the key to the resolved instance
*/
- public ComponentModel aquire( CompositionModel model, Object key, Object
owner )
- throws Exception
+ public ComponentEntry aquire( CompositionModel model, Object key, Object
owner )
{
if( null == model )
{
@@ -119,7 +120,7 @@
{
throw new NullPointerException( "key" );
}
- ComponentModel holder =
model.getCompositionController().getInstanceTable().get( model, key );
+ ComponentEntry holder =
model.getCompositionController().getInstanceTable().get( model, key );

if( null == holder )
{
@@ -131,7 +132,7 @@
+ "].";
getMonitor().debug( message );
}
- holder = new ComponentController( m_monitor, model, key, owner );
+ holder = new ComponentEntry( m_monitor, m_controller, model,
key, owner );
if( getMonitor().isDebugEnabled() )
{
final String message =

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ManagerInvocationHandler.java
Thu Apr 28 04:11:16 2005
@@ -23,13 +23,13 @@
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;

-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.state.DefaultState;
import net.dpml.lang.DelegationRuntimeException;
import net.dpml.parts.state.State;

/**
- * This makes a dynamic proxy for an state manager.
+ * This makes a dynamic proxy for an component manager.
*
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: ApplianceInvocationHandler.java 2106 2005-03-21 18:46:10Z
mcconnell AT dpml.net $
@@ -40,7 +40,7 @@
// state
//-------------------------------------------------------------------

- private final ComponentModel m_holder;
+ private final ComponentEntry m_component;
private final Object m_manager;
private final Class m_class;

@@ -54,9 +54,9 @@
* @param system the system context
* @param model the component model
*/
- ManagerInvocationHandler( ComponentModel holder, Object manager )
+ ManagerInvocationHandler( ComponentEntry holder, Object manager )
{
- m_holder = holder;
+ m_component = holder;
m_manager = manager;
m_class = m_manager.getClass();
}
@@ -87,7 +87,8 @@
return method.invoke( m_manager, args );
}

- if( name.equals( "initialize" ) || name.equals( "terminate" ) )
+ // TODO: remove initialize and terminate
+ if( name.equals( "resolve" ) || name.equals( "initialize" ) ||
name.equals( "terminate" ) )
{
try
{
@@ -133,7 +134,7 @@
+ name
+ " method is not implemented."
+ "\nOperation: " + name
- + "\nInstance: " + m_holder.getURI();
+ + "\nInstance: " + m_component.getURI();
throw new UnsupportedOperationException( error );
}
catch( Throwable e )
@@ -146,7 +147,7 @@
final String error =
"The requested operation is not recognized."
+ "\nOperation: " + name
- + "\nInstance: " + m_holder.getURI();
+ + "\nInstance: " + m_component.getURI();
throw new UnsupportedOperationException( error );
}
}
@@ -157,7 +158,7 @@
final String error =
"Unexpected error while attempting to invoke a state manager
operation."
+ "\nMethod: " + name
- + "\nInstance: " + m_holder.getURI();
+ + "\nInstance: " + m_component.getURI();

while( true )
{

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/PartsInvocationHandler.java
Thu Apr 28 04:11:16 2005
@@ -25,12 +25,15 @@
import java.net.URI;

import net.dpml.composition.info.PartDescriptor;
-import net.dpml.composition.model.ComponentModel;
+import net.dpml.composition.model.ComponentEntry;
import net.dpml.composition.model.CompositionModel;
+
import net.dpml.parts.control.Controller;
import net.dpml.parts.control.DelegationException;
+import net.dpml.parts.model.Component;
import net.dpml.parts.model.Model;
-import net.dpml.parts.state.Manager;
+import net.dpml.parts.control.Manager;
+
import net.dpml.system.SystemContext;

/**
@@ -58,7 +61,7 @@
/**
* The component model.
*/
- private final ComponentModel m_holder;
+ private final ComponentEntry m_holder;

/**
* The system context.
@@ -74,7 +77,7 @@
*
* @param model the component model
*/
- PartsInvocationHandler( SystemContext system, ComponentModel holder )
+ PartsInvocationHandler( SystemContext system, ComponentEntry holder )
throws NullPointerException
{
m_holder = holder;
@@ -110,7 +113,7 @@
}
}

- CompositionModel getComponentModel()
+ CompositionModel getModel()
{
return m_holder.getModel();
}
@@ -144,16 +147,16 @@
int semantic = PartDescriptor.getPartSemantic( method );
String postfix = PartDescriptor.getPartPostfix( method );
String key = PartDescriptor.getPartKey( method, semantic );
- Model provider = getComponentModel().getPartsTable().getModel( key );
+ Model provider = getModel().getPartsTable().getModel( key );

if( PartDescriptor.SELECT == semantic )
{
if( null == postfix )
{
- Controller controller = provider.getController();
+ Controller controller = provider.getController();
if( null == args )
{
- return controller.resolve( provider );
+ return controller.getComponent( provider ).resolve();
}
else if( args.length == 1 )
{
@@ -161,18 +164,18 @@
if( arg.getClass() == Boolean.TYPE )
{
boolean policy = getBooleanValue( args[1] );
- return controller.resolve( provider, null, policy );
+ return controller.getComponent( provider ).resolve(
policy );
}
else
{
- return controller.resolve( provider, arg );
+ return controller.getComponent( provider, arg
).resolve();
}
}
else if( args.length == 2 )
{
Object arg = args[0];
boolean policy = getBooleanValue( args[1] );
- return controller.resolve( provider, arg, policy );
+ return controller.getComponent( provider, arg ).resolve(
policy );
}
else
{
@@ -198,7 +201,7 @@
"The request for the context manager for the key ["
+ key
+ "] in the component ["
- + getComponentModel().getURI()
+ + getModel().getURI()
+ "] could not be completed as the requested return
type ["
+ clazz.getName()
+ "] is not an interface.";
@@ -209,71 +212,30 @@
{
//
// TODO: we could construct a context manager with no
- // visible contest entries - but let's leave that till
+ // visible context entries - but let's leave that till
// later
//

final String error =
"Dynamic creation of context managers for foreign
object types is not supported."
+ "\nClass: " + provider.getClass().getName()
- + "\nKey: " + provider.getKey()
+ + "\nProvider: " + provider.getURI()
+ "Instance: " + m_holder.getURI();
throw new UnsupportedOperationException( error );
}

CompositionModel model = (CompositionModel) provider;
Controller controller = model.getController();
- ComponentModel holder = getHolder( model, args, proxy );
+ ComponentEntry component = getComponentEntry( model, args );
ClassLoader classloader = model.getClassLoader();
SystemContext system = getSystemContext();
ContextManagerInvocationHandler handler =
- new ContextManagerInvocationHandler( system, holder );
+ new ContextManagerInvocationHandler( system, component );
return Proxy.newProxyInstance( classloader, new Class[]{
clazz }, handler );
}
- else if( PartDescriptor.MANAGER_KEY.equals( postfix ) )
+ else if( PartDescriptor.COMPONENT_KEY.equals( postfix ) )
{
- if( false == ( provider instanceof CompositionModel ) )
- {
- //
- // TODO: we could construct a state manager with no
- // visible state entries - but let's leave that till
- // later
- //
-
- final String error =
- "Dynamic creation of state managers for foreign object
types is not supported."
- + "\nClass: " + provider.getClass().getName()
- + "\nKey: " + provider.getKey()
- + "Instance: " + m_holder.getURI();
- throw new UnsupportedOperationException( error );
- }
- else
- {
- CompositionModel model = (CompositionModel) provider;
- return getManager( model, args, proxy );
- }
-
- /*
- CompositionModel model = (CompositionModel) provider;
- Controller controller = model.getController();
- ComponentModel holder = getHolder( model, args );
- Manager manager = holder.getManager();
- if( null == manager )
- {
- return new ClassicManager( holder.getValue() );
- }
- else if( Manager.class.isAssignableFrom( manager.getClass()
) )
- {
- return manager;
- }
- else
- {
- ClassLoader classloader = model.getClassLoader();
- ManagerInvocationHandler handler =
- new ManagerInvocationHandler( holder );
- return Proxy.newProxyInstance( classloader, new Class[]{
Manager.class }, handler );
- }
- */
+ return getComponent( provider, args );
}
else
{
@@ -290,26 +252,8 @@
{
if( args.length == 1 )
{
- Object arg = args[0];
- if( provider instanceof Model )
- {
- Model model = (Model) provider;
- Controller controller = model.getController();
- controller.release( arg );
- return null;
- }
- else
- {
- final String error =
- "The request for the application of 'release/1' for
the instance ["
- + arg
- + "] in the component ["
- + getComponentModel().getURI()
- + "] could not be applied as the entry referenced by
the key is not an instance of "
- + Model.class.getName()
- + ".";
- throw new IllegalStateException( error );
- }
+ m_holder.getManager().release( args[0] );
+ return null;
}
else
{
@@ -339,7 +283,7 @@
+ " for the key ["
+ key
+ "] in the component ["
- + getComponentModel().getURI()
+ + getModel().getURI()
+ "] could not be completed as the provider ["
+ uri
+ "] raised an exception.";
@@ -373,7 +317,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append( "[parts {" );
- PartDescriptor[] entries =
getComponentModel().getType().getPartDescriptors();
+ PartDescriptor[] entries = getModel().getType().getPartDescriptors();
for( int i=0; i<entries.length; i++ )
{
PartDescriptor p = entries[i];
@@ -404,26 +348,43 @@
}
}

- private ComponentModel getHolder( CompositionModel model, Object[] args,
Object owner ) throws Exception
+ private Component getComponent( Model model, Object[] args ) throws
Exception
{
- return (ComponentModel) getManager( model, args, owner );
+ if( null == args )
+ {
+ return model.getComponent();
+ }
+ else if( args.length == 0 )
+ {
+ return model.getComponent();
+ }
+ else
+ {
+ return model.getComponent( args[0] );
+ }
}

- private Manager getManager( CompositionModel model, Object[] args,
Object owner ) throws Exception
+ private ComponentEntry getComponentEntry( CompositionModel model,
Object[] args ) throws Exception
{
CompositionController controller = model.getCompositionController();
if( null == args )
{
- return controller.getManager( owner, model );
+ return controller.getComponentEntry( model, null );
}
else if( args.length == 0 )
{
- return controller.getManager( owner, model );
+ return controller.getComponentEntry( model, null );
}
else
{
- return controller.getManager( owner, model, args[0] );
+ return controller.getComponentEntry( model, args[0] );
}
}

+ private Manager getManager( CompositionModel model, Object[] args )
throws Exception
+ {
+ ComponentEntry entry = getComponentEntry( model, args );
+ return entry.getManager();
+ }
+
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/control/ValueController.java
Thu Apr 28 04:11:16 2005
@@ -20,8 +20,10 @@

import java.net.URI;

-import net.dpml.composition.model.ValueModel;
-import net.dpml.parts.state.Manager;
+import net.dpml.composition.model.ValueEntry;
+
+import net.dpml.parts.control.Manager;
+import net.dpml.parts.model.Component;
import net.dpml.parts.state.NoSuchOperationException;
import net.dpml.parts.state.NoSuchTransitionException;
import net.dpml.parts.state.State;
@@ -33,13 +35,13 @@
*/
public class ValueController implements Manager
{
- private final ValueModel m_model;
-
- private boolean m_initialized = false;
+ private URI m_uri;

- public ValueController( ValueModel model )
+ public ValueController( CompositionController controller )
{
- m_model = model;
+ URI uri = controller.getURI();
+ String path = uri.getSchemeSpecificPart();
+ m_uri = CompositionController.createURI( "manager", path );
}

public String getName()
@@ -49,61 +51,36 @@

public URI getURI()
{
- return m_model.getURI();
+ return m_uri;
}

/**
* Initialize the component.
*/
- public void initialize() throws Exception
+ public void initialize( Component entry ) throws Exception
{
- if( false == m_initialized )
- {
- m_initialized = true;
- }
- else
- {
- final String error =
- "Manager has already been initialized.";
- throw new IllegalStateException( error );
- }
}

/**
* Return the instance managed by this manager.
* @return the managed instance
*/
- public Object getInstance()
+ public Object resolve( Component entry, boolean policy )
{
- if( m_initialized )
- {
- return m_model.getValue();
- }
- else
- {
- final String error =
- "Manager has not been initialized.";
- throw new IllegalStateException( error );
- }
+ return entry.getValue();
}

+ public void release( Object instance )
+ {
+ }

/**
* Return the current state of the component.
* @return the current state
*/
- public State getState()
+ public State getState( Component entry )
{
- if( m_initialized )
- {
- return AVAILABLE;
- }
- else
- {
- final String error =
- "Manager has not been initialized.";
- throw new IllegalStateException( error );
- }
+ return AVAILABLE;
}

/**
@@ -113,18 +90,9 @@
* @return the state resulting from the transition
* @exception if a transition error occurs
*/
- public State apply( String key ) throws Exception
+ public State apply( Component entry, String key ) throws Exception
{
- if( false == m_initialized )
- {
- final String error =
- "Manager has not been initialized.";
- throw new IllegalStateException( error );
- }
- else
- {
- throw new NoSuchTransitionException( key );
- }
+ throw new NoSuchTransitionException( key );
}

/**
@@ -133,26 +101,16 @@
* @param key the key identifying the operation to execute
* @exception if a transition error occurs
*/
- public void execute( String key ) throws Exception
+ public void execute( Component entry, String key ) throws Exception
{
- if( m_initialized )
- {
- throw new NoSuchOperationException ( key );
- }
- else
- {
- final String error =
- "Manager has not been initialized.";
- throw new IllegalStateException( error );
- }
+ throw new NoSuchOperationException ( key );
}

/**
* Termination of the component.
*/
- public void terminate()
+ public void terminate( Component entry )
{
- m_initialized = false;
}

public static final State AVAILABLE = new AvailableState();

Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentEntry.java
(from r2430,
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentModel.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ComponentEntry.java
Thu Apr 28 04:11:16 2005
@@ -38,6 +38,7 @@
import net.dpml.activity.Startable;


+import net.dpml.composition.control.ComponentController;
import net.dpml.composition.control.CompositionController;
import net.dpml.composition.state.DefaultState;
import net.dpml.composition.event.AvailabilityEvent;
@@ -50,6 +51,8 @@
import net.dpml.parts.state.StateListener;
import net.dpml.parts.state.State;
import net.dpml.parts.state.ResourceUnavailableException;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.control.Manager;

/**
* A lifestyle handler provides support for the aquisition and release
@@ -60,7 +63,7 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: LifestyleManager.java 259 2004-10-30 07:24:40Z mcconnell $
*/
-public class ComponentModel extends Observable implements Entry, Identifiable
+public class ComponentEntry extends Observable implements Entry, Component
{
private final Map m_proxies = new WeakHashMap();

@@ -72,6 +75,7 @@
private final DefaultState m_graph;
private DefaultState m_state;
private boolean m_initialized = false;
+ private ComponentController m_manager;

private transient Object m_instance;

@@ -80,9 +84,9 @@

private boolean m_disposed = false;

- public ComponentModel( Monitor monitor, CompositionModel model, Object
key, Object owner )
- throws LifecycleException, InvocationTargetException,
IllegalAccessException
+ public ComponentEntry( Monitor monitor, ComponentController manager,
CompositionModel model, Object key, Object owner )
{
+ m_manager = manager;
m_monitor = monitor;
m_model = model;
m_owner = owner;
@@ -118,6 +122,73 @@
m_state = m_graph;
}

+ public Manager getManager()
+ {
+ return m_manager;
+ }
+
+ /**
+ * Return an instance of the component type represented
+ * by the supplied model using the default proxy policy.
+ *
+ * @return the resolved instance
+ */
+ public Object resolve() throws Exception
+ {
+ return getManager().resolve( this, true );
+ }
+
+ /**
+ * Return an instance of the component type represented
+ * by the supplied model.
+ *
+ * @param policy the proxy creation policy
+ * @return the resolved instance
+ */
+ public Object resolve( boolean policy ) throws Exception
+ {
+ return getManager().resolve( this, policy );
+ }
+
+ /**
+ * Initialize the component.
+ */
+ public void initialize() throws Exception
+ {
+ m_manager.initialize( this );
+ }
+
+ /**
+ * Applies a state transition identified by a supplied transition key.
+ *
+ * @param key the key identifying the transition to apply to the
component's controller
+ * @return the state resulting from the transition
+ * @exception if a transition error occurs
+ */
+ public State apply( String key ) throws Exception
+ {
+ return m_manager.apply( this, key );
+ }
+
+ /**
+ * Executes an operation identified by a supplied operation key.
+ *
+ * @param key the key identifying the operation to execute
+ * @exception if a transition error occurs
+ */
+ public void execute( String key ) throws Exception
+ {
+ m_manager.execute( this, key );
+ }
+
+ /**
+ * Termination of the component.
+ */
+ public void terminate()
+ {
+ m_manager.terminate( this );
+ }
+
public boolean isInitialized()
{
return m_initialized;
@@ -130,19 +201,6 @@
notifyObservers( event );
}

- public Object getInstance() throws ResourceUnavailableException
- {
- if(( null == m_instance ) || false == isInitialized() )
- {
- String id = getURI().toString();
- throw new ResourceUnavailableException( id );
- }
- else
- {
- return getLocalInstance();
- }
- }
-
public Object getLocalInstance()
{
return m_instance;
@@ -166,7 +224,7 @@
*
* @param state the state to assign as the current state
*/
- protected synchronized void setState( DefaultState state )
+ public synchronized void setState( DefaultState state )
{
if( false == m_state.equals( state ) )
{
@@ -227,7 +285,7 @@
*
* @return the state representing the current state of execution
*/
- protected DefaultState getCurrentState()
+ public DefaultState getCurrentState()
{
if( null == m_state )
{
@@ -241,7 +299,6 @@
}
}

-
public Monitor getMonitor()
{
return m_monitor;
@@ -306,7 +363,15 @@
*/
public Object getValue()
{
- return getInstance();
+ if( false == isInitialized() )
+ {
+ String spec = getURI().toString();
+ throw new ResourceUnavailableException( spec );
+ }
+ else
+ {
+ return getLocalInstance();
+ }
}

/**
@@ -343,14 +408,14 @@
for( int i=0; i<proxies.length; i++ )
{
Object proxy = proxies[i];
- controller.etherialize( proxy );
+ m_manager.release( proxy );
}
m_proxies.clear();
controller.getInstanceTable().remove( this );
try
{
- Object instance = getInstance();
- controller.etherialize( instance );
+ Object instance = getLocalInstance();
+ m_manager.release( instance );
}
catch( IllegalStateException e )
{
@@ -410,7 +475,7 @@
}
}

- private DefaultState resolveStateGraph( Class subject ) throws
IllegalAccessException
+ private DefaultState resolveStateGraph( Class subject )
{
try
{
@@ -440,6 +505,13 @@
+ "\nObject: " + getURI();
throw new IllegalArgumentException( error );
}
+ catch( IllegalAccessException e )
+ {
+ final String error =
+ "Unexpected access exception while resolving class STATE_GRAPH
field."
+ + "\nClass: " + subject.getName();
+ throw new IllegalStateException( error );
+ }
}

/**

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/CompositionModel.java
Thu Apr 28 04:11:16 2005
@@ -41,6 +41,9 @@
import net.dpml.parameters.Parameterizable;
import net.dpml.parameters.impl.DefaultParameters;

+import net.dpml.parts.control.Controller;
+
+import net.dpml.parts.model.Component;
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
@@ -55,10 +58,12 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
*/
-public class CompositionModel extends AbstractModel implements Model,
Configurable, Parameterizable, Serializable
+public class CompositionModel implements Model, Configurable,
Parameterizable, Serializable
{
private final List m_errors = new LinkedList();

+ private final String m_key;
+ private final CompositionController m_controller;
private final ComponentProfile m_profile;
private final ClassLoader m_classloader;
private final URI m_partition;
@@ -120,8 +125,8 @@
ComponentProfile profile, String name )
throws ModelException
{
- super( controller, name );
-
+ m_key = name;
+ m_controller = controller;
m_partition = partition;
m_classloader = classloader;
m_profile = profile;
@@ -251,6 +256,46 @@
}
}

+ public Component getComponent() throws ModelException
+ {
+ return getCompositionController().getComponent( this );
+ }
+
+ public Component getComponent( Object key ) throws ModelException
+ {
+ return getCompositionController().getComponent( this, key );
+ }
+
+ /**
+ * Return the key identifying this model within the context is used.
+ * For example - a key may identify a a model relative to a collection of
+ * of parts or within the set of context entries.
+ *
+ * @return the model key
+ */
+ public Object getKey()
+ {
+ return m_key;
+ }
+
+ /**
+ * Return the primary controller assigned to the model.
+ * @return the primary controller
+ */
+ public Controller getController()
+ {
+ return getCompositionController();
+ }
+
+ /**
+ * Return the primary controller assigned to the model.
+ * @return the primary controller
+ */
+ public CompositionController getCompositionController()
+ {
+ return m_controller;
+ }
+
public void configure( Configuration configuration )
{
m_configuration = configuration;
@@ -285,6 +330,7 @@
}
}

+ /*
public Object getValue()
{
try
@@ -300,6 +346,7 @@
throw new ModelRuntimeException( error, e );
}
}
+ */

public Throwable[] getIssues()
{

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ContextTable.java
Thu Apr 28 04:11:16 2005
@@ -24,6 +24,9 @@
import java.util.Map.Entry;

import net.dpml.parts.control.Controller;
+import net.dpml.parts.control.DelegationException;
+import net.dpml.parts.control.HandlerNotFoundException;
+import net.dpml.parts.model.Component;
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
@@ -32,6 +35,7 @@

import net.dpml.composition.control.CompositionController;
import net.dpml.composition.data.ReferenceDirective;
+import net.dpml.composition.data.ValueDirective;

/**
* The parts model is a model of the set of parts maintained by a parent
model.
@@ -112,16 +116,46 @@
//

CompositionController controller =
getModel().getCompositionController();
- ReferenceModel entry = new ReferenceModel( controller, key,
target, uri );
+ ReferenceEntry entry = new ReferenceEntry( controller, key,
target, uri );
addEntry( key, entry );
}
else
{
- ClassLoader classloader = getModel().getClassLoader();
CompositionModel model = getModel();
+ ClassLoader classloader = model.getClassLoader();
CompositionController controller =
model.getCompositionController();
- Model entry = controller.getModel( model, classloader, part, key
);
- addEntry( key, entry );
+ try
+ {
+ Component entry = controller.getComponent( model,
classloader, part, key );
+ addEntry( key, entry );
+ }
+ catch( ModelException e )
+ {
+ final String error =
+ "Cannot add part-based entry due to a model related error."
+ + "\nModel: " + getModel().getURI()
+ + "\nContext Key: " + key
+ + "\nPart Class: " + part.getClass().getName();
+ throw new ModelException( error, e );
+ }
+ catch( HandlerNotFoundException e )
+ {
+ final String error =
+ "Cannot add part-based entry as the part handler could not
be found."
+ + "\nModel: " + getModel().getURI()
+ + "\nContext Key: " + key
+ + "\nPart Class: " + part.getClass().getName();
+ throw new ModelException( error, e );
+ }
+ catch( DelegationException e )
+ {
+ final String error =
+ "Cannot add part-based entry as a part handler referenced
by a part raised an error."
+ + "\nModel: " + getModel().getURI()
+ + "\nContext Key: " + key
+ + "\nPart Class: " + part.getClass().getName();
+ throw new ModelException( error, e );
+ }
}
}

@@ -175,16 +209,34 @@
{
return getDefaultValueUsingArgs( args );
}
- else if( entry instanceof ReferenceModel )
+ else if( entry instanceof Component )
+ {
+ Component component = (Component) entry;
+ try
+ {
+ return component.resolve();
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to resolve the value of
context entry."
+ + "\nModel: " + getModel().getURI()
+ + "\nContext Key: " + key
+ + "\nComponent URI: " + component.getURI();
+ throw new ModelRuntimeException( error, e );
+ }
+ }
+ else if( entry instanceof ReferenceEntry )
{
// TODO: move this to the controller
- ReferenceModel reference = (ReferenceModel) entry;
+ ReferenceEntry reference = (ReferenceEntry) entry;
URI ref = reference.getReferenceURI();
Model provider = reference.getProviderModel();
try
{
Controller controller = provider.getController();
- return controller.resolve( provider, ref.getFragment(), true
);
+ Component component = controller.getComponent( provider,
ref.getFragment() );
+ return component.getManager().resolve( component, true );
}
catch( Exception e )
{

Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceEntry.java
(from r2429,
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceModel.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ReferenceEntry.java
Thu Apr 28 04:11:16 2005
@@ -20,6 +20,7 @@

import java.lang.reflect.Constructor;
import java.net.URI;
+import java.util.Map.Entry;

import net.dpml.composition.control.CompositionController;
import net.dpml.composition.data.ValueDirective;
@@ -29,6 +30,7 @@
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
+import net.dpml.parts.model.Component;

/**
* Default implementation of a the context entry constructor model.
@@ -36,7 +38,7 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: DefaultConstructorModel.java 1518 2005-01-17 17:13:05Z
niclas $
*/
-public class ReferenceModel extends AbstractModel
+public class ReferenceEntry implements Entry
{
//--------------------------------------------------------------
// state
@@ -44,6 +46,7 @@

private final URI m_reference;
private final Model m_provider;
+ private final String m_key;

//--------------------------------------------------------------
// constructor
@@ -66,10 +69,9 @@
* @exception NullArgumentException if either the directive argument or
the
* context argument is null.
*/
- public ReferenceModel( CompositionController controller, String key,
Model provider, URI ref )
+ public ReferenceEntry( CompositionController controller, String key,
Model provider, URI ref )
throws ModelException, NullPointerException
{
- super( controller, key );
if( null == provider )
{
throw new NullPointerException( "model" );
@@ -78,6 +80,7 @@
{
throw new NullPointerException( "ref" );
}
+ m_key = key;
m_reference = ref;
m_provider = provider;
}
@@ -103,9 +106,14 @@
}

//--------------------------------------------------------------
- // EntryModel
+ // Entry
//--------------------------------------------------------------

+ public Object getKey()
+ {
+ return m_key;
+ }
+
/**
* Return the context entry value.
*
@@ -116,4 +124,15 @@
throw new UnsupportedOperationException( "getValue/0" );
}

+ /**
+ * Set the value.
+ *
+ * @param the new value
+ */
+ public Object setValue( Object value )
+ {
+ throw new UnsupportedOperationException( "setValue/1" );
+ }
+
+
}

Added:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueEntry.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueEntry.java
Thu Apr 28 04:11:16 2005
@@ -0,0 +1,800 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.composition.model;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import net.dpml.composition.control.CompositionController;
+import net.dpml.composition.data.ValueDirective;
+import net.dpml.composition.data.ValueDirective.Value;
+
+import net.dpml.parts.control.Controller;
+import net.dpml.parts.control.Manager;
+
+import net.dpml.parts.model.Model;
+import net.dpml.parts.model.ModelException;
+import net.dpml.parts.model.ModelRuntimeException;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.state.State;
+
+/**
+ * Default implementation of a the context entry constructor model.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id: DefaultConstructorModel.java 1518 2005-01-17 17:13:05Z
niclas $
+ */
+public class ValueEntry implements Component
+{
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final URI m_uri;
+ private final ValueDirective m_directive;
+ private final ClassLoader m_classloader;
+ private final ValueModel m_model;
+ private final Manager m_manager;
+ private final Model m_parent;
+
+ private String m_key;
+ private Object m_value;
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ /**
+ * Creation of a new context entry import model.
+ *
+ * @param name the name of this value model
+ * @param controller the value model's controller
+ * @param classloader the assigned classloader
+ * @param directive the value directive from which we construct the value
model
+ * @param model the enclosing model
+
+ * @exception NullArgumentException if either the directive argument or
the
+ * context argument is null.
+ */
+ public ValueEntry(
+ ValueModel model, String name, Manager manager, ClassLoader
classloader, ValueDirective directive, Model parent )
+ throws ModelException, NullPointerException
+ {
+ if( directive == null )
+ {
+ throw new NullPointerException( "directive" );
+ }
+ if( null == model )
+ {
+ throw new NullPointerException( "model" );
+ }
+ m_directive = directive;
+ m_classloader = classloader;
+ m_model = model;
+ m_parent = parent;
+ m_key = name;
+
+ URI base = m_model.getURI();
+ m_uri = CompositionController.createURI( base, name );
+ m_manager = manager;
+
+ //validate();
+ }
+
+ public Manager getManager()
+ {
+ return m_manager;
+ }
+
+ /**
+ * Return the key identifying this instance.
+ *
+ * @return the key
+ */
+ public Object getKey()
+ {
+ return m_key;
+ }
+
+ /**
+ * Return the current state.
+ *
+ * @return the state
+ */
+ public State getState()
+ {
+ throw new UnsupportedOperationException( "getState/0" );
+ }
+
+ public URI getURI()
+ {
+ return m_uri;
+ }
+
+ /**
+ * Return an initialized instance of the component.
+ * @return the resolved instance
+ */
+ public Object resolve()
+ {
+ return getValue();
+ }
+
+ /**
+ * Return an initialized instance of the component.
+ * @param proxy the proxy policy
+ * @return the resolved instance
+ */
+ public Object resolve( boolean policy )
+ {
+ return getValue();
+ }
+
+ public void release( Object instance )
+ {
+ }
+
+ public Object getInstance()
+ {
+ return getValue();
+ }
+
+ /**
+ * Initialize the component.
+ */
+ public void initialize() throws Exception
+ {
+ m_manager.initialize( this );
+ }
+
+ /**
+ * Applies a state transition identified by a supplied transition key.
+ *
+ * @param key the key identifying the transition to apply to the
component's controller
+ * @return the state resulting from the transition
+ * @exception if a transition error occurs
+ */
+ public State apply( String key ) throws Exception
+ {
+ return m_manager.apply( this, key );
+ }
+
+ /**
+ * Executes an operation identified by a supplied operation key.
+ *
+ * @param key the key identifying the operation to execute
+ * @exception if a transition error occurs
+ */
+ public void execute( String key ) throws Exception
+ {
+ m_manager.execute( this, key );
+ }
+
+ /**
+ * Termination of the component.
+ */
+ public void terminate()
+ {
+ m_manager.terminate( this );
+ }
+
+ //--------------------------------------------------------------
+ // EntryModel
+ //--------------------------------------------------------------
+
+ public Object setValue( Object value )
+ {
+ throw new UnsupportedOperationException( "setValue/1" );
+ }
+
+ /**
+ * Return the context entry value.
+ *
+ * @return the context entry value
+ */
+ public Object getValue()
+ {
+ if( m_value != null )
+ {
+ return m_value;
+ }
+
+ try
+ {
+ String argument = m_directive.getLocalValue();
+ Object object = checkForURNReference( argument );
+ if( null == object )
+ {
+ String classname = getReturnTypeClassname();
+ Value[] params = m_directive.getValues();
+ Class clazz = getValueClass( classname );
+ object = getValue( clazz, argument, params );
+ }
+ //if( !m_descriptor.isVolatile() )
+ //{
+ // m_value = object;
+ //}
+ return object;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Cannot establish a constructed value in the model ["
+ + getURI()
+ + "] withing the value ["
+ + getKey()
+ + "].";
+ throw new ModelRuntimeException( error, e );
+ }
+ }
+
+ private String getReturnTypeClassname()
+ {
+ return m_directive.getClassname();
+ }
+
+ /**
+ * Return the context entry value.
+ *
+ * @return the context entry value
+ */
+ public Object getValue( Value p )
+ throws ModelException
+ {
+ String argument = p.getArgument();
+ Object object = checkForURNReference( argument );
+ if( null != object )
+ {
+ return object;
+ }
+ String classname = p.getClassname();
+ Value[] params = p.getValueDirectives();
+ Class clazz = getValueClass( classname );
+ return getValue( clazz, argument, params );
+ }
+
+ /**
+ * Return the derived parameter value.
+ * @param clazz the constructor class
+ * @param argument a single string constructor argument
+ * @param parameters an alternative sequence of arguments
+ * @return the value
+ * @exception ModelException if the parameter value cannot be resolved
+ */
+ public Object getValue( Class clazz, String argument, Value[] parameters
)
+ throws ModelException
+ {
+ if( parameters.length == 0 )
+ {
+ if( argument == null )
+ {
+ return getNullArgumentConstructorValue( clazz );
+ }
+ else
+ {
+ return getSingleArgumentConstructorValue( clazz, argument );
+ }
+ }
+ else
+ {
+ return getMultiArgumentConstructorValue( clazz, parameters );
+ }
+ }
+
+ private Object getMultiArgumentConstructorValue( Class clazz, Value[]
parameters )
+ throws ModelException
+ {
+ //
+ // getting here means we are dealing with 0..n types parameter
constructor where the
+ // parameters are defined by the nested parameter definitions
+ //
+
+ if ( parameters.length == 0 )
+ {
+ try
+ {
+ return clazz.newInstance();
+ }
+ catch ( InstantiationException e )
+ {
+ final String error =
+ "Unable to instantiate instance of class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ final String error =
+ "Cannot access null constructor for the class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ }
+ else
+ {
+ Class[] params = new Class[ parameters.length ];
+ for ( int i = 0; i < parameters.length; i++ )
+ {
+ Value value = parameters[i];
+ try
+ {
+ params[i] = getValueClass( value );
+ }
+ catch ( Throwable e )
+ {
+ final String error =
+ "Unable to resolve sub-parameter class ["
+ + value.getClassname()
+ + "] for the parameter ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ }
+
+ Object[] values = new Object[ parameters.length ];
+ for ( int i = 0; i < parameters.length; i++ )
+ {
+ Value p = parameters[i];
+ String classname = p.getClassname();
+ try
+ {
+ values[i] = getValue( p );
+ }
+ catch ( Throwable e )
+ {
+ final String error =
+ "Unable to instantiate sub-parameter for value ["
+ + classname
+ + "] inside the parameter ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ }
+ Constructor constructor = null;
+ try
+ {
+ constructor = clazz.getConstructor( params );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ final String error =
+ "Supplied parameters class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "] does not match the available class constructors.";
+ throw new ModelException( error, e );
+ }
+
+ try
+ {
+ return constructor.newInstance( values );
+ }
+ catch ( InstantiationException e )
+ {
+ final String error =
+ "Unable to instantiate an instance of a multi-parameter
constructor for class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ final String error =
+ "Cannot access multi-parameter constructor for the class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ catch ( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to instantiate a
multi-parameter constructor for the class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ }
+ }
+
+
+
+
+ private Object getNullArgumentConstructorValue( Class clazz )
+ throws ModelException
+ {
+ try
+ {
+ return clazz.newInstance();
+ }
+ catch ( InstantiationException e )
+ {
+ final String error =
+ "Unable to instantiate instance of class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ final String error =
+ "Cannot access null parameter constructor for the class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ catch ( Throwable e )
+ {
+ final String error =
+ "Unexpected exception while creating the class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ }
+
+ private Object getSingleArgumentConstructorValue( Class clazz, String
argument )
+ throws ModelException
+ {
+ Object object = checkForURNReference( argument );
+ if( null != object )
+ {
+ return object;
+ }
+ else
+ {
+ //
+ // the argument is a simple type that takes a single String value
+ // as a constructor argument
+ //
+
+ if( clazz.isPrimitive() )
+ {
+ return getPrimitiveValue( clazz, argument );
+ }
+
+ try
+ {
+ final Class[] params = new Class[]{ String.class };
+ Constructor constructor = clazz.getConstructor( params );
+ final Object[] values = new Object[]{ argument };
+ return constructor.newInstance( values );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ final String error =
+ "Class: ["
+ + clazz.getName()
+ + "] referenced withing the value type ["
+ + getURI()
+ + "] does not implement a single string argument
constructor.";
+ throw new ModelException( error );
+ }
+ catch ( InstantiationException e )
+ {
+ final String error =
+ "Unable to instantiate instance of class ["
+ + clazz.getName()
+ + "] with the single argument ["
+ + argument
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ final String error =
+ "Cannot access single string parameter constructor for the
class: ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ catch ( Throwable e )
+ {
+ final String error =
+ "Unexpected exception while creating a single string
parameter value for the class ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ }
+ }
+
+ private Object getPrimitiveValue( Class clazz, String argument ) throws
ModelException
+ {
+ if( Integer.TYPE == clazz )
+ {
+ return Integer.valueOf( argument );
+ }
+ else if( Boolean.TYPE == clazz )
+ {
+ return Boolean.valueOf( argument );
+ }
+ else if( Byte.TYPE == clazz )
+ {
+ return Byte.valueOf( argument );
+ }
+ else if( Short.TYPE == clazz )
+ {
+ return Short.valueOf( argument );
+ }
+ else if( Long.TYPE == clazz )
+ {
+ return Long.valueOf( argument );
+ }
+ else if( Float.TYPE == clazz )
+ {
+ return Float.valueOf( argument );
+ }
+ else if( Double.TYPE == clazz )
+ {
+ return Double.valueOf( argument );
+ }
+ else
+ {
+ final String error =
+ "The primitive return type ["
+ + clazz.getName()
+ + "] withing the value type ["
+ + getURI()
+ + "] is not supported.";
+ throw new ModelException( error );
+ }
+ }
+
+ /**
+ * Return the classname of the parameter implementation to use.
+ * @return the parameter class
+ * @exception ModelException if the parameter class cannot be resolved
+ */
+ Class getValueClass( Value value ) throws ModelException
+ {
+ String v = value.getArgument();
+ Object object = checkForURNReference( v );
+ if( null != object )
+ {
+ return object.getClass();
+ }
+ else
+ {
+ String classname = value.getClassname();
+ return getValueClass( classname );
+ }
+ }
+
+ /**
+ * Return the classname of the parameter implementation to use.
+ * @return the parameter class
+ * @exception ModelException if the parameter class cannot be resolved
+ */
+ Class getValueClass( String classname ) throws ModelException
+ {
+ try
+ {
+ return m_classloader.loadClass( classname );
+ }
+ catch ( final ClassNotFoundException e )
+ {
+ if ( classname.equals( "int" ) )
+ {
+ return int.class;
+ }
+ else if ( classname.equals( "short" ) )
+ {
+ return short.class;
+ }
+ else if ( classname.equals( "long" ) )
+ {
+ return long.class;
+ }
+ else if ( classname.equals( "byte" ) )
+ {
+ return byte.class;
+ }
+ else if ( classname.equals( "double" ) )
+ {
+ return double.class;
+ }
+ else if ( classname.equals( "byte" ) )
+ {
+ return byte.class;
+ }
+ else if ( classname.equals( "float" ) )
+ {
+ return float.class;
+ }
+ else if ( classname.equals( "char" ) )
+ {
+ return char.class;
+ }
+ else if ( classname.equals( "char" ) )
+ {
+ return char.class;
+ }
+ else if ( classname.equals( "boolean" ) )
+ {
+ return boolean.class;
+ }
+ else
+ {
+ final String error =
+ "Could not locate the implementation for class ["
+ + classname
+ + "] withing the value type ["
+ + getURI()
+ + "].";
+ throw new ModelException( error, e );
+ }
+ }
+ }
+
+ private Object checkForURNReference( String argument )
+ {
+ if( null == argument )
+ {
+ return null;
+ }
+ else if ( argument.startsWith( "urn:system:" ) )
+ {
+ String arg = argument.substring( 11 );
+ URI urn = CompositionController.createURI( "system", arg );
+ return getParentResource( urn );
+ }
+ else if ( argument.startsWith( "urn:model:" ) )
+ {
+ String arg = argument.substring( 10 );
+ URI urn = CompositionController.createURI( "model", arg );
+ return getParentResource( urn );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private Object getParentResource( URI urn )
+ {
+ Controller controller = m_model.getController();
+ if( null != m_parent )
+ {
+ return controller.getResource( m_parent, urn );
+ }
+ else
+ {
+ final String error =
+ "Cannot resolve a parent resource urn from a non-nested
component."
+ + "\nQuery URN: " + urn
+ + "\nComponent URI: " + getURI();
+ throw new ModelRuntimeException( error );
+ }
+ }
+
+ /*
+ private void validate()
+ throws ModelException
+ {
+ final String descriptorClassName = m_descriptor.getClassname();
+ final String directiveClassName = m_directive.getClassname();
+ validatePair( descriptorClassName, directiveClassName );
+ }
+
+ private void validatePair( String descriptorClassName, String
directiveClassName )
+ throws ModelException
+ {
+ if( "int".equals( descriptorClassName ) )
+ {
+ if( ( null == directiveClassName ) || "int".equals(
directiveClassName ) )
+ {
+ return;
+ }
+ else
+ {
+ final String error =
+ "Descriptor class ["
+ + descriptorClassName
+ + "] does not match the supplied directive class ["
+ + directiveClassName
+ + "].";
+ throw new ModelException( error );
+ }
+ }
+
+ if( null == directiveClassName )
+ {
+ return;
+ }
+
+ final String key = m_descriptor.getKey();
+ Class target = null;
+ try
+ {
+ target = getValueClass( classname );
+ }
+ catch( ClassNotFoundException e )
+ {
+ final String error =
+ "Context entry return class ["
+ + descriptorClassName
+ + "] declared under the key ["
+ + key
+ + "] not found.";
+ throw new ModelException( error );
+ }
+
+ Class source = null;
+ try
+ {
+ source = getValueClass( classname );
+ //source = m_classloader.loadClass( directiveClassName );
+ }
+ catch( ClassNotFoundException e )
+ {
+ final String error =
+ "Context entry implementation class ["
+ + directiveClassName
+ + "] declared under the key ["
+ + key
+ + "] not found.";
+ throw new ModelException( error );
+ }
+
+ if( !target.isAssignableFrom( source ) )
+ {
+ final String error =
+ "Context entry implementation class ["
+ + directiveClassName
+ + "] declared under the key ["
+ + key
+ + "] is not assignable to the context entry return type ["
+ + descriptorClassName
+ + "].";
+ throw new ModelException( error );
+ }
+ }
+ */
+}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/model/ValueModel.java
Thu Apr 28 04:11:16 2005
@@ -26,9 +26,11 @@
import net.dpml.composition.data.ValueDirective.Value;

import net.dpml.parts.control.Controller;
+import net.dpml.parts.control.Manager;
import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.model.ModelRuntimeException;
+import net.dpml.parts.model.Component;

/**
* Default implementation of a the context entry constructor model.
@@ -36,18 +38,18 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Id: DefaultConstructorModel.java 1518 2005-01-17 17:13:05Z
niclas $
*/
-public class ValueModel extends AbstractModel
+public class ValueModel implements Model
{
//--------------------------------------------------------------
// state
//--------------------------------------------------------------

private final URI m_uri;
+ private final URI m_partition;
+ private final Object m_key;
private final ValueDirective m_directive;
- private final ClassLoader m_classloader;
- private final Model m_model;
-
- private Object m_value;
+ private final CompositionController m_controller;
+ private final ValueEntry m_entry;

//--------------------------------------------------------------
// constructor
@@ -61,35 +63,29 @@
* @param classloader the assigned classloader
* @param directive the value directive from which we construct the value
model
* @param model the enclosing model
-
* @exception NullArgumentException if either the directive argument or
the
* context argument is null.
*/
- public ValueModel( String name, CompositionController controller,
ClassLoader classloader, ValueDirective directive, Model model )
+ public ValueModel(
+ String name, CompositionController controller, URI partition,
Manager manager, ClassLoader classloader,
+ ValueDirective directive, Model parent )
throws ModelException, NullPointerException
{
- super( controller, name );
- if( directive == null )
+ if( name == null )
{
- throw new NullPointerException( "directive" );
+ throw new NullPointerException( "name" );
}
- if( null == model )
+ if( controller == null )
{
- throw new NullPointerException( "model" );
+ throw new NullPointerException( "controller" );
}
- m_directive = directive;
- m_classloader = classloader;
- m_model = model;
-
- URI base = m_model.getURI();
- m_uri = CompositionController.createURI( base, name );
-
- //validate();
- }

- public URI getPartition()
- {
- return m_model.getURI();
+ m_key = name;
+ m_controller = controller;
+ m_directive = directive;
+ m_uri = CompositionController.createURI( partition, name );
+ m_partition = partition;
+ m_entry = new ValueEntry( this, name, manager, classloader,
directive, parent );
}

public URI getURI()
@@ -97,591 +93,41 @@
return m_uri;
}

- /*
- private void validate()
- throws ModelException
- {
- final String descriptorClassName = m_descriptor.getClassname();
- final String directiveClassName = m_directive.getClassname();
- validatePair( descriptorClassName, directiveClassName );
- }
-
- private void validatePair( String descriptorClassName, String
directiveClassName )
- throws ModelException
- {
- if( "int".equals( descriptorClassName ) )
- {
- if( ( null == directiveClassName ) || "int".equals(
directiveClassName ) )
- {
- return;
- }
- else
- {
- final String error =
- "Descriptor class ["
- + descriptorClassName
- + "] does not match the supplied directive class ["
- + directiveClassName
- + "].";
- throw new ModelException( error );
- }
- }
-
- if( null == directiveClassName )
- {
- return;
- }
-
- final String key = m_descriptor.getKey();
- Class target = null;
- try
- {
- target = getValueClass( classname );
- }
- catch( ClassNotFoundException e )
- {
- final String error =
- "Context entry return class ["
- + descriptorClassName
- + "] declared under the key ["
- + key
- + "] not found.";
- throw new ModelException( error );
- }
-
- Class source = null;
- try
- {
- source = getValueClass( classname );
- //source = m_classloader.loadClass( directiveClassName );
- }
- catch( ClassNotFoundException e )
- {
- final String error =
- "Context entry implementation class ["
- + directiveClassName
- + "] declared under the key ["
- + key
- + "] not found.";
- throw new ModelException( error );
- }
-
- if( !target.isAssignableFrom( source ) )
- {
- final String error =
- "Context entry implementation class ["
- + directiveClassName
- + "] declared under the key ["
- + key
- + "] is not assignable to the context entry return type ["
- + descriptorClassName
- + "].";
- throw new ModelException( error );
- }
- }
- */
-
- //--------------------------------------------------------------
- // EntryModel
- //--------------------------------------------------------------
-
/**
- * Return the context entry value.
- *
- * @return the context entry value
+ * Return the primary controller assigned to the model.
+ * @return the primary controller
*/
- public Object getValue()
- {
- if( m_value != null )
- {
- return m_value;
- }
-
- try
- {
- String argument = m_directive.getLocalValue();
- Object object = checkForURNReference( argument );
- if( null == object )
- {
- String classname = getReturnTypeClassname();
- Value[] params = m_directive.getValues();
- Class clazz = getValueClass( classname );
- object = getValue( clazz, argument, params );
- }
- //if( !m_descriptor.isVolatile() )
- //{
- // m_value = object;
- //}
- return object;
- }
- catch( Throwable e )
- {
- final String error =
- "Cannot establish a constructed value in the model ["
- + getURI()
- + "] withing the value ["
- + getKey()
- + "].";
- throw new ModelRuntimeException( error, e );
- }
- }
-
- private String getReturnTypeClassname()
+ public Controller getController()
{
- return m_directive.getClassname();
+ return m_controller;
}

/**
- * Return the context entry value.
- *
- * @return the context entry value
+ * Return the uri identifying the partition that this model is enclosed
within.
+ * @return the partition uri
*/
- public Object getValue( Value p )
- throws ModelException
- {
- String argument = p.getArgument();
- Object object = checkForURNReference( argument );
- if( null != object )
- {
- return object;
- }
- String classname = p.getClassname();
- Value[] params = p.getValueDirectives();
- Class clazz = getValueClass( classname );
- return getValue( clazz, argument, params );
- }
-
- /**
- * Return the derived parameter value.
- * @param clazz the constructor class
- * @param argument a single string constructor argument
- * @param parameters an alternative sequence of arguments
- * @return the value
- * @exception ModelException if the parameter value cannot be resolved
- */
- public Object getValue( Class clazz, String argument, Value[] parameters
)
- throws ModelException
- {
- if( parameters.length == 0 )
- {
- if( argument == null )
- {
- return getNullArgumentConstructorValue( clazz );
- }
- else
- {
- return getSingleArgumentConstructorValue( clazz, argument );
- }
- }
- else
- {
- return getMultiArgumentConstructorValue( clazz, parameters );
- }
- }
-
- private Object getMultiArgumentConstructorValue( Class clazz, Value[]
parameters )
- throws ModelException
- {
- //
- // getting here means we are dealing with 0..n types parameter
constructor where the
- // parameters are defined by the nested parameter definitions
- //
-
- if ( parameters.length == 0 )
- {
- try
- {
- return clazz.newInstance();
- }
- catch ( InstantiationException e )
- {
- final String error =
- "Unable to instantiate instance of class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- catch ( IllegalAccessException e )
- {
- final String error =
- "Cannot access null constructor for the class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- }
- else
- {
- Class[] params = new Class[ parameters.length ];
- for ( int i = 0; i < parameters.length; i++ )
- {
- Value value = parameters[i];
- try
- {
- params[i] = getValueClass( value );
- }
- catch ( Throwable e )
- {
- final String error =
- "Unable to resolve sub-parameter class ["
- + value.getClassname()
- + "] for the parameter ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- }
-
- Object[] values = new Object[ parameters.length ];
- for ( int i = 0; i < parameters.length; i++ )
- {
- Value p = parameters[i];
- String classname = p.getClassname();
- try
- {
- values[i] = getValue( p );
- }
- catch ( Throwable e )
- {
- final String error =
- "Unable to instantiate sub-parameter for value ["
- + classname
- + "] inside the parameter ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- }
- Constructor constructor = null;
- try
- {
- constructor = clazz.getConstructor( params );
- }
- catch ( NoSuchMethodException e )
- {
- final String error =
- "Supplied parameters class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "] does not match the available class constructors.";
- throw new ModelException( error, e );
- }
-
- try
- {
- return constructor.newInstance( values );
- }
- catch ( InstantiationException e )
- {
- final String error =
- "Unable to instantiate an instance of a multi-parameter
constructor for class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- catch ( IllegalAccessException e )
- {
- final String error =
- "Cannot access multi-parameter constructor for the class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- catch ( Throwable e )
- {
- final String error =
- "Unexpected error while attempting to instantiate a
multi-parameter constructor for the class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- }
- }
-
-
-
-
- private Object getNullArgumentConstructorValue( Class clazz )
- throws ModelException
- {
- try
- {
- return clazz.newInstance();
- }
- catch ( InstantiationException e )
- {
- final String error =
- "Unable to instantiate instance of class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- catch ( IllegalAccessException e )
- {
- final String error =
- "Cannot access null parameter constructor for the class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- catch ( Throwable e )
- {
- final String error =
- "Unexpected exception while creating the class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- }
-
- private Object getSingleArgumentConstructorValue( Class clazz, String
argument )
- throws ModelException
+ public URI getPartition()
{
- Object object = checkForURNReference( argument );
- if( null != object )
- {
- return object;
- }
- else
- {
- //
- // the argument is a simple type that takes a single String value
- // as a constructor argument
- //
-
- if( clazz.isPrimitive() )
- {
- return getPrimitiveValue( clazz, argument );
- }
-
- try
- {
- final Class[] params = new Class[]{ String.class };
- Constructor constructor = clazz.getConstructor( params );
- final Object[] values = new Object[]{ argument };
- return constructor.newInstance( values );
- }
- catch ( NoSuchMethodException e )
- {
- final String error =
- "Class: ["
- + clazz.getName()
- + "] referenced withing the value type ["
- + getURI()
- + "] does not implement a single string argument
constructor.";
- throw new ModelException( error );
- }
- catch ( InstantiationException e )
- {
- final String error =
- "Unable to instantiate instance of class ["
- + clazz.getName()
- + "] with the single argument ["
- + argument
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- catch ( IllegalAccessException e )
- {
- final String error =
- "Cannot access single string parameter constructor for the
class: ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- catch ( Throwable e )
- {
- final String error =
- "Unexpected exception while creating a single string
parameter value for the class ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- }
+ return m_partition;
}

- private Object getPrimitiveValue( Class clazz, String argument ) throws
ModelException
- {
- if( Integer.TYPE == clazz )
- {
- return Integer.valueOf( argument );
- }
- else if( Boolean.TYPE == clazz )
- {
- return Boolean.valueOf( argument );
- }
- else if( Byte.TYPE == clazz )
- {
- return Byte.valueOf( argument );
- }
- else if( Short.TYPE == clazz )
- {
- return Short.valueOf( argument );
- }
- else if( Long.TYPE == clazz )
- {
- return Long.valueOf( argument );
- }
- else if( Float.TYPE == clazz )
- {
- return Float.valueOf( argument );
- }
- else if( Double.TYPE == clazz )
- {
- return Double.valueOf( argument );
- }
- else
- {
- final String error =
- "The primitive return type ["
- + clazz.getName()
- + "] withing the value type ["
- + getURI()
- + "] is not supported.";
- throw new ModelException( error );
- }
- }
-
- /**
- * Return the classname of the parameter implementation to use.
- * @return the parameter class
- * @exception ModelException if the parameter class cannot be resolved
- */
- Class getValueClass( Value value ) throws ModelException
+ /**
+ * Return the model key
+ * @return the key
+ */
+ public Object getKey()
{
- String v = value.getArgument();
- Object object = checkForURNReference( v );
- if( null != object )
- {
- return object.getClass();
- }
- else
- {
- String classname = value.getClassname();
- return getValueClass( classname );
- }
+ return m_key;
}

- /**
- * Return the classname of the parameter implementation to use.
- * @return the parameter class
- * @exception ModelException if the parameter class cannot be resolved
- */
- Class getValueClass( String classname ) throws ModelException
+ public Component getComponent() throws ModelException
{
- try
- {
- return m_classloader.loadClass( classname );
- }
- catch ( final ClassNotFoundException e )
- {
- if ( classname.equals( "int" ) )
- {
- return int.class;
- }
- else if ( classname.equals( "short" ) )
- {
- return short.class;
- }
- else if ( classname.equals( "long" ) )
- {
- return long.class;
- }
- else if ( classname.equals( "byte" ) )
- {
- return byte.class;
- }
- else if ( classname.equals( "double" ) )
- {
- return double.class;
- }
- else if ( classname.equals( "byte" ) )
- {
- return byte.class;
- }
- else if ( classname.equals( "float" ) )
- {
- return float.class;
- }
- else if ( classname.equals( "char" ) )
- {
- return char.class;
- }
- else if ( classname.equals( "char" ) )
- {
- return char.class;
- }
- else if ( classname.equals( "boolean" ) )
- {
- return boolean.class;
- }
- else
- {
- final String error =
- "Could not locate the implementation for class ["
- + classname
- + "] withing the value type ["
- + getURI()
- + "].";
- throw new ModelException( error, e );
- }
- }
+ return m_entry;
}

- private Object checkForURNReference( String argument )
+ public Component getComponent( Object id ) throws ModelException
{
- if( null == argument )
- {
- return null;
- }
- else if ( argument.startsWith( "urn:system:" ) )
- {
- String arg = argument.substring( 11 );
- URI urn = CompositionController.createURI( "system", arg );
- return getParentResource( urn );
- }
- else if ( argument.startsWith( "urn:model:" ) )
- {
- String arg = argument.substring( 10 );
- URI urn = CompositionController.createURI( "model", arg );
- return getParentResource( urn );
- }
- else
- {
- return null;
- }
+ throw new UnsupportedOperationException( "getComponent/1" );
}

- private Object getParentResource( URI urn )
- {
- Controller modelController = m_model.getController();
- return modelController.getResource( m_model, urn );
- }
}

Modified:
development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java
==============================================================================
---
development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java
(original)
+++
development/main/metro/composition/part/src/main/net/dpml/composition/info/PartDescriptor.java
Thu Apr 28 04:11:16 2005
@@ -64,7 +64,7 @@

public static final String CONTEXT_MAP_KEY = "ContextMap";
public static final String CONTEXT_MANAGER_KEY = "ContextManager";
- public static final String MANAGER_KEY = "Manager";
+ public static final String COMPONENT_KEY = "Component";
public static final String MODEL_KEY = "Model";

public static String toString( int semantic )
@@ -98,9 +98,9 @@
{
return MODEL_KEY;
}
- else if( name.endsWith( MANAGER_KEY ) )
+ else if( name.endsWith( COMPONENT_KEY ) )
{
- return MANAGER_KEY;
+ return COMPONENT_KEY;
}
else
{
@@ -161,9 +161,9 @@
String substring = name.substring( 0, j );
return formatKey( substring, 6 );
}
- else if( name.endsWith( MANAGER_KEY ) )
+ else if( name.endsWith( COMPONENT_KEY ) )
{
- int n = MANAGER_KEY.length();
+ int n = COMPONENT_KEY.length();
int j = name.length() - n;
String substring = name.substring( 0, j );
return formatKey( substring, 6 );

Modified: development/main/metro/composition/testing/test/build.xml
==============================================================================
--- development/main/metro/composition/testing/test/build.xml (original)
+++ development/main/metro/composition/testing/test/build.xml Thu Apr 28
04:11:16 2005
@@ -218,7 +218,7 @@
name="container"
dest="target/test/managing-container.part">
<parts>
- <component key="component"
type="net.dpml.test.state.ManagedComponent"/>
+ <component key="test" type="net.dpml.test.state.ManagedComponent"/>
</parts>
</component>


Modified:
development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java
==============================================================================
---
development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java
(original)
+++
development/main/metro/composition/testing/test/src/main/net/dpml/test/config/ConfigurableContainer.java
Thu Apr 28 04:11:16 2005
@@ -29,7 +29,7 @@
import net.dpml.parts.control.Controller;
import net.dpml.parts.model.Model;

-import net.dpml.parts.state.Manager;
+import net.dpml.parts.control.Manager;

/**
* Demonstration of a component that uses a supplied configuration to
@@ -90,7 +90,7 @@
((Configurable)model).configure( conf );
}
}
- model.getController().resolve( model );
+ model.getComponent().resolve();
}

private Logger getLogger()

Modified:
development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java
==============================================================================
---
development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java
(original)
+++
development/main/metro/composition/testing/test/src/main/net/dpml/test/state/ManagingContainer.java
Thu Apr 28 04:11:16 2005
@@ -25,7 +25,8 @@

import net.dpml.configuration.Configuration;

-import net.dpml.parts.state.Manager;
+import net.dpml.parts.control.Manager;
+import net.dpml.parts.model.Component;
import net.dpml.parts.state.State;

import net.dpml.composition.state.DefaultState;
@@ -76,11 +77,11 @@
public void execute() throws Exception
{
Parts parts = getParts();
- Manager manager = parts.selectComponentManager();
- manager.initialize();
- manager.apply( "start" );
- manager.execute( "audit" );
- manager.terminate();
+ Component component = parts.selectTestComponent();
+ component.initialize();
+ component.apply( "start" );
+ component.execute( "audit" );
+ component.terminate();
}

private Logger getLogger()
@@ -99,6 +100,6 @@

public interface Parts
{
- Manager selectComponentManager();
+ Component selectTestComponent();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/CompositeTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/CompositeTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/CompositeTestCase.java
Thu Apr 28 04:11:16 2005
@@ -27,10 +27,9 @@

import net.dpml.parts.model.Model;
import net.dpml.parts.control.Controller;
-import net.dpml.composition.unit.CompositionHelper;
-
-import net.dpml.parts.state.Manager;
+import net.dpml.parts.control.Manager;

+import net.dpml.composition.unit.CompositionHelper;

/**
* Test a simple component case.
@@ -69,8 +68,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-bad-widget.part" );
Model model = helper.getCompositionManager().addPart( uri, "acme" );
- Controller controller = model.getController();
- AcmeContainer container = (AcmeContainer) controller.resolve( model,
null, false );
+ AcmeContainer container = (AcmeContainer)
model.getComponent().resolve( false );
try
{
container.execute();
@@ -81,7 +79,7 @@
}
finally
{
- controller.release( container );
+ model.getComponent().release( container );
helper.dispose();
}
}
@@ -91,16 +89,14 @@
CompositionHelper helper = new CompositionHelper( false );
URI uri = helper.toURI( path );
Model model = helper.getCompositionManager().addPart( uri, "acme" );
- Controller controller = model.getController();
- AcmeContainer container = (AcmeContainer) controller.resolve( model,
null, false );
-
+ AcmeContainer container = (AcmeContainer)
model.getComponent().resolve( false );
try
{
container.execute();
}
finally
{
- controller.release( container );
+ model.getComponent().release( container );
helper.dispose();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/ExampleTestCase.java
Thu Apr 28 04:11:16 2005
@@ -27,6 +27,7 @@

import net.dpml.parts.model.Model;
import net.dpml.parts.control.Controller;
+
import net.dpml.composition.unit.CompositionHelper;

/**
@@ -46,7 +47,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-one.part" );
Model model = helper.getCompositionManager().addPart( uri, "example"
);
- Example example = (Example) model.getValue();
+ Example example = (Example) model.getComponent().resolve();
example.doMyStuff();
}

@@ -60,7 +61,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-two.part" );
Model model = helper.getCompositionManager().addPart( uri, "example"
);
- Example example = (Example) model.getValue();
+ Example example = (Example) model.getComponent().resolve();
example.doMyStuff();
}

@@ -73,7 +74,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-three.part" );
Model model = helper.getCompositionManager().addPart( uri, "example"
);
- Example example = (Example) model.getValue();
+ Example example = (Example) model.getComponent().resolve();
example.doMyStuff();
}

@@ -87,7 +88,7 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-example-four.part" );
Model model = helper.getCompositionManager().addPart( uri, "example"
);
- Example example = (Example) model.getValue();
+ Example example = (Example) model.getComponent().resolve();
example.doMyStuff();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/composition/testing/SimpleTestCase.java
Thu Apr 28 04:11:16 2005
@@ -27,10 +27,9 @@

import net.dpml.parts.model.Model;
import net.dpml.parts.control.Controller;
-import net.dpml.composition.unit.CompositionHelper;
-
-import net.dpml.parts.state.Manager;
+import net.dpml.parts.control.Manager;

+import net.dpml.composition.unit.CompositionHelper;

/**
* Test a simple component case.
@@ -51,9 +50,9 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
- Widget widget = (Widget) model.getValue();
+ Widget widget = (Widget) model.getComponent().resolve();
widget.doWidgetStuff( "green" );
- model.getController().release( widget );
+ model.getComponent().release( widget );
}

/**
@@ -65,9 +64,9 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-widget.part" );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
- Widget widget = (Widget) model.getValue();
- widget.doWidgetStuff( "magenta" );
- model.getController().release( widget );
+ Widget widget = (Widget) model.getComponent().resolve();
+ widget.doWidgetStuff( "green" );
+ model.getComponent().release( widget );
}

/**
@@ -78,10 +77,10 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
- Object object = model.getValue();
+ Widget widget = (Widget) model.getComponent().resolve();
try
{
- WidgetComponent widget = (WidgetComponent) object;
+ WidgetComponent w = (WidgetComponent) widget;
fail( "Casting to implementation class!" );
}
catch( ClassCastException e )
@@ -90,7 +89,7 @@
}
finally
{
- model.getController().release( object );
+ model.getComponent().release( widget );
}
}

@@ -103,14 +102,13 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
- Controller controller = model.getController();
- WidgetComponent widget = (WidgetComponent) controller.resolve(
model, null, false );
+ WidgetComponent widget = (WidgetComponent)
model.getComponent().resolve( false );
String name = widget.getName();
assertEquals( "name", "widget", name );
String newName = "freight";
widget.setName( newName );
assertEquals( "name", newName, widget.getName() );
- controller.release( widget );
+ model.getComponent().release( widget );
}

/**
@@ -123,9 +121,8 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
- Controller controller = model.getController();
- WidgetComponent widget = (WidgetComponent) controller.resolve(
model, id, false );
- controller.release( widget );
+ WidgetComponent widget = (WidgetComponent) model.getComponent( id
).resolve( false );
+ model.getComponent( id ).release( widget );
}

/**
@@ -141,20 +138,20 @@
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
Controller controller = model.getController();
- Widget w1 = (Widget) controller.resolve( model, "acme-widget-one",
false );
- Widget w2 = (Widget) controller.resolve( model, "acme-widget-two",
false );
+ Widget w1 = (Widget) model.getComponent( "acme-widget-one"
).resolve( false );
+ Widget w2 = (Widget) model.getComponent( "acme-widget-two"
).resolve( false );
if( w1.equals( w2 ) )
{
fail( "Widget w1 and w2 are not unique!" );
}
- Widget w3 = (Widget) controller.resolve( model, "acme-widget-one",
false );
+ Widget w3 = (Widget) model.getComponent( "acme-widget-one"
).resolve( false );
if( !w1.equals( w3 ) )
{
System.out.println( "" + System.identityHashCode( w1 ) );
System.out.println( "" + System.identityHashCode( w3 ) );
fail( "Widget w1 and w3 are not the same!" );
}
- controller.release( w1 );
- controller.release( w2 );
+ model.getComponent( "acme-widget-one" ).terminate();
+ model.getComponent( "acme-widget-two" ).terminate();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/test/config/ConfigurationTestCase.java
Thu Apr 28 04:11:16 2005
@@ -27,9 +27,9 @@

import net.dpml.parts.model.Model;
import net.dpml.parts.control.Controller;
-import net.dpml.composition.unit.CompositionHelper;
+import net.dpml.parts.control.Manager;

-import net.dpml.parts.state.Manager;
+import net.dpml.composition.unit.CompositionHelper;

/**
* Test a simple component case.
@@ -48,9 +48,8 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "configurable-container.part" );
Model model = helper.getCompositionManager().addPart( uri );
- Controller controller = model.getController();
- ConfigurableContainer container = (ConfigurableContainer)
controller.resolve( model, null, false );
- controller.release( container );
+ ConfigurableContainer container = (ConfigurableContainer)
model.getComponent().resolve( false );
+ model.getComponent().release( container );
helper.dispose();
}
}

Modified:
development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java
==============================================================================
---
development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java
(original)
+++
development/main/metro/composition/testing/test/src/test/net/dpml/test/state/ManagementTestCase.java
Thu Apr 28 04:11:16 2005
@@ -26,12 +26,12 @@

import junit.framework.TestCase;

-import net.dpml.parts.model.Model;
-
import net.dpml.composition.unit.CompositionHelper;

+import net.dpml.parts.control.Manager;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.model.Model;
import net.dpml.parts.state.State;
-import net.dpml.parts.state.Manager;

/**
* Test a simple component case.
@@ -47,22 +47,22 @@
*/
public void testManagedComponent() throws Exception
{
- Manager manager = getComponentManager();
- manager.initialize();
+ Component component = getComponent();
+ component.initialize();
List list = new LinkedList();
- while ( false == list.contains( manager.getState() ) )
+ while ( false == list.contains( component.getState() ) )
{
- State state = manager.getState();
+ State state = component.getState();
list.add( state );
String[] transitions = state.getTransitionNames();
for( int i=0; i<transitions.length; i++ )
{
String name = transitions[i];
- manager.apply( name );
+ component.apply( name );
break;
}
}
- manager.terminate();
+ component.terminate();
}

public void testManagingContainer() throws Exception
@@ -70,22 +70,22 @@
CompositionHelper helper = new CompositionHelper( false );
URI uri = helper.toURI( "managing-container.part" );
Model model = helper.getCompositionManager().getModel( uri );
- Manager manager = model.getManager( this );
+ Component component = model.getComponent();
try
{
- manager.initialize();
+ component.initialize();
}
finally
{
- manager.terminate();
+ component.terminate();
}
}

- Manager getComponentManager() throws Exception
+ Component getComponent() throws Exception
{
CompositionHelper helper = new CompositionHelper( false );
URI uri = helper.toURI( "managed-component.part" );
Model model = helper.getCompositionManager().getModel( uri );
- return model.getManager( this );
+ return model.getComponent( this );
}
}

Modified:
development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java
==============================================================================
---
development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java
(original)
+++
development/main/metro/parts/src/main/net/dpml/parts/control/Controller.java
Thu Apr 28 04:11:16 2005
@@ -21,6 +21,7 @@
import java.net.URI;

import net.dpml.parts.model.Model;
+import net.dpml.parts.model.Component;
import net.dpml.parts.model.ModelException;
import net.dpml.parts.part.Part;

@@ -58,52 +59,45 @@
Object getResource( Model model, URI urn );

/**
- * Create a return a new model for a supplied part.
+ * Return a new model for a supplied part.
*
- * @param partition the enclosing partition
* @param parent the parent classloader
* @param part the part datastructure
* @param name the name to assign to the model
* @return the model
*/
Model getModel( ClassLoader parent, Part part, String name )
- throws ModelException;
-
- /**
- * Create and return a new instance of the component represented
- * by the supplied model.
- *
- * @param model the component model
- * @return the resolved instance
- */
- Object resolve( Model model ) throws Exception;
+ throws ModelException, HandlerNotFoundException, DelegationException;

/**
- * Return an identified instance of the component type represented
- * by the supplied model.
- *
- * @param model the component model
- * @param key the instance identifier
- * @return the resolved instance
+ * Return a default instance model.
+ *
+ * @param model the reference model
+ * @param identity the instance identity
+ * @return the model
*/
- Object resolve( Model model, Object key ) throws Exception;
+ Component getComponent( Model model )
+ throws ModelException;

/**
- * Return an identified instance of the component type represented
- * by the supplied model.
- *
- * @param model the component model
- * @param key the instance identifier
- * @param policy the proxy creation policy
- * @return the resolved instance
+ * Return a model relative to a supplied model and identity.
+ *
+ * @param model the reference model
+ * @param identity the instance identity
+ * @return the model
*/
- Object resolve( Model model, Object key, boolean policy ) throws
Exception;
+ Component getComponent( Model model, Object identity )
+ throws ModelException;

/**
- * Return a component instance
- *
- * @param instance the instance to release
+ * Return a component for a supplied part.
+ *
+ * @param parent the parent classloader
+ * @param part the part datastructure
+ * @param name the name to assign to the model
+ * @return the model
*/
- void release( Object instance );
+ Component getComponent( ClassLoader parent, Part part, String name )
+ throws ModelException, HandlerNotFoundException, DelegationException;

}

Modified:
development/main/metro/parts/src/main/net/dpml/parts/control/Manageable.java
==============================================================================
---
development/main/metro/parts/src/main/net/dpml/parts/control/Manageable.java
(original)
+++
development/main/metro/parts/src/main/net/dpml/parts/control/Manageable.java
Thu Apr 28 04:11:16 2005
@@ -20,8 +20,6 @@

import net.dpml.parts.model.Model;

-import net.dpml.parts.state.Manager;
-
/**
* The Manager interface is an interface representing a component controller.
*

Copied:
development/main/metro/parts/src/main/net/dpml/parts/control/Manager.java
(from r2429,
development/main/metro/parts/src/main/net/dpml/parts/state/Manager.java)
==============================================================================
--- development/main/metro/parts/src/main/net/dpml/parts/state/Manager.java
(original)
+++ development/main/metro/parts/src/main/net/dpml/parts/control/Manager.java
Thu Apr 28 04:11:16 2005
@@ -16,9 +16,11 @@
* limitations under the License.
*/

-package net.dpml.parts.state;
+package net.dpml.parts.control;

-import net.dpml.parts.control.Control;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.model.ResourceUnavailableException;
+import net.dpml.parts.state.State;

/**
* The Manager interface is an interface representing a component controller.
@@ -28,22 +30,14 @@
public interface Manager extends Control
{
/**
- * Return the instance managed by this manager.
- * @return the managed instance
- * @exception ResourceUnavailableException if the object is not available
+ * Return an instance of the component type represented
+ * by the supplied model.
+ *
+ * @param component the component model
+ * @param policy the proxy creation policy
+ * @return the resolved instance
*/
- Object getInstance() throws ResourceUnavailableException;
-
- /**
- * Initialize the component.
- */
- void initialize() throws Exception;
-
- /**
- * Return the current state of the component.
- * @return the current state
- */
- State getState();
+ Object resolve( Component component, boolean policy ) throws Exception;

/**
* Applies a state transition identified by a supplied transition key.
@@ -52,7 +46,7 @@
* @return the state resulting from the transition
* @exception if a transition error occurs
*/
- State apply( String key ) throws Exception;
+ State apply( Component instance, String key ) throws Exception;

/**
* Executes an operation identified by a supplied operation key.
@@ -60,11 +54,23 @@
* @param key the key identifying the operation to execute
* @exception if a transition error occurs
*/
- void execute( String key ) throws Exception;
+ void execute( Component instance, String key ) throws Exception;
+
+ /**
+ * Release a reference to an object managed by the instance.
+ *
+ * @param instance the instance to release
+ */
+ void release( Object object );
+
+ /**
+ * Initialize the component.
+ */
+ void initialize( Component entry ) throws Exception;

/**
* Termination of the component.
*/
- void terminate();
+ void terminate( Component entry );

}

Modified:
development/main/metro/parts/src/main/net/dpml/parts/control/SystemManager.java
==============================================================================
---
development/main/metro/parts/src/main/net/dpml/parts/control/SystemManager.java
(original)
+++
development/main/metro/parts/src/main/net/dpml/parts/control/SystemManager.java
Thu Apr 28 04:11:16 2005
@@ -39,7 +39,8 @@
* @param uri a part uri
* @return the management view of the loaded part
*/
- Model addPart( URI uri, String key ) throws IOException,
DelegationException, ModelException, PartNotFoundException;
+ Model addPart( URI uri, String key )
+ throws IOException, DelegationException, ModelException,
PartNotFoundException, HandlerNotFoundException;

/**
* Add a model to the system scope.

Added:
development/main/metro/parts/src/main/net/dpml/parts/model/Component.java
==============================================================================
--- (empty file)
+++ development/main/metro/parts/src/main/net/dpml/parts/model/Component.java
Thu Apr 28 04:11:16 2005
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.parts.model;
+
+import java.net.URI;
+import java.util.Map.Entry;
+
+import net.dpml.parts.control.Controller;
+import net.dpml.parts.control.Identifiable;
+import net.dpml.parts.control.Manager;
+
+import net.dpml.parts.state.State;
+
+/**
+ *
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public interface Component extends Entry, Identifiable
+{
+ /**
+ * Return a Manager for the component.
+ */
+ Manager getManager() throws Exception;
+
+ /**
+ * Return an initialized instance of the component.
+ * @return the resolved instance
+ */
+ Object resolve() throws Exception;
+
+ /**
+ * Return an initialized instance of the component using a supplied
isolation policy.
+ * If the isolation policy is TRUE an implementation shall make best
efforts to isolate
+ * implementation concerns under the object that is returned. Typically
isolation
+ * involves the creation of a proxy of a component implementation
instance that
+ * exposes a component's service interfaces to a client. If the
isolation policy if
+ * FALSE the implementation shall return the component implementation
instance.
+ *
+ * @param isolation the isolation policy
+ * @return the resolved instance
+ */
+ Object resolve( boolean isolation ) throws Exception;
+
+ /**
+ * Initialize the component.
+ */
+ void initialize() throws Exception;
+
+ /**
+ * Return the current state of the component.
+ * @return the current state
+ */
+ State getState();
+
+ /**
+ * Applies a state transition identified by a supplied transition key.
+ *
+ * @param key the key identifying the transition to apply to the
component's controller
+ * @return the state resulting from the transition
+ * @exception if a transition error occurs
+ */
+ State apply( String key ) throws Exception;
+
+ /**
+ * Executes an operation identified by a supplied operation key.
+ *
+ * @param key the key identifying the operation to execute
+ * @exception if a transition error occurs
+ */
+ void execute( String key ) throws Exception;
+
+ /**
+ * Release a reference to an object managed by the instance.
+ *
+ * @param instance the instance to release
+ */
+ void release( Object object );
+
+ /**
+ * Termination of the component.
+ */
+ void terminate();
+}

Modified:
development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
==============================================================================
--- development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
(original)
+++ development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
Thu Apr 28 04:11:16 2005
@@ -23,9 +23,7 @@

import net.dpml.parts.control.Controller;
import net.dpml.parts.control.Identifiable;
-
-import net.dpml.parts.state.Manager;
-
+import net.dpml.parts.control.Manager;

/**
* The Model interface defines a common view of a component part. Operations
@@ -34,7 +32,7 @@
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
* @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
*/
-public interface Model extends Entry, Identifiable
+public interface Model extends Identifiable
{
/**
* Return the primary controller assigned to the model.
@@ -49,14 +47,28 @@
URI getPartition();

/**
- * Return a Manager for the default instance.
+ * Return the model key
+ * @return the key
+ */
+ Object getKey();
+
+ /**
+ * Return a component representing the default component for this model.
+ *
+ * @return the default component
+ * @exception ModelException if a model related error occurs
*/
- Manager getManager( Object owner ) throws Exception;
+ Component getComponent() throws ModelException;

/**
- * Return a Manager for an identified instance.
- * @param id the instance identity
+ * Model capable of handling identifiable components may return a
component via
+ * this operation. Model implementations that do not support identity
may throw
+ * an UnsupportedOperationException.
+ *
+ * @param id the component identifier
+ * @return the identfied component
+ * @exception ModelException if a model related error occurs
*/
- Manager getManager( Object owner, Object id ) throws Exception;
+ Component getComponent( Object id ) throws ModelException;

}



  • svn commit: r2433 - in development/main/metro: composition/builder/src/main/net/dpml/composition/builder composition/control/src/main/net/dpml/composition/control composition/control/src/main/net/dpml/composition/model composition/part/src/main/net/dpml/composition/info composition/testing/test composition/testing/test/src/main/net/dpml/test/config composition/testing/test/src/main/net/dpml/test/state composition/testing/test/src/test/net/dpml/composition/testing composition/testing/test/src/test/net/dpml/test/config composition/testing/test/src/test/net/dpml/test/state parts/src/main/net/dpml/parts/control parts/src/main/net/dpml/parts/model parts/src/main/net/dpml/parts/state, mcconnell, 04/27/2005

Archive powered by MHonArc 2.6.24.

Top of Page