Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2358 - 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/management composition/control/src/main/net/dpml/composition/models composition/control/src/main/net/dpml/composition/state composition/control/src/test/net/dpml/composition/management composition/control/src/test/net/dpml/composition/state composition/testing/acme/src/main/net/dpml/composition/testing composition/testing/unit/src/main/net/dpml/test/state composition/testing/unit/src/test/net/dpml/composition/testing meta/api/src/main/net/dpml/meta/info meta/api/src/test/net/dpml/meta/info/test parts/src/main/net/dpml/parts/model

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: r2358 - 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/management composition/control/src/main/net/dpml/composition/models composition/control/src/main/net/dpml/composition/state composition/control/src/test/net/dpml/composition/management composition/control/src/test/net/dpml/composition/state composition/testing/acme/src/main/net/dpml/composition/testing composition/testing/unit/src/main/net/dpml/test/state composition/testing/unit/src/test/net/dpml/composition/testing meta/api/src/main/net/dpml/meta/info meta/api/src/test/net/dpml/meta/info/test parts/src/main/net/dpml/parts/model
  • Date: Fri, 22 Apr 2005 23:49:52 -0400

Author: mcconnell AT dpml.net
Date: Fri Apr 22 23:49:48 2005
New Revision: 2358

Added:

development/main/metro/composition/control/src/main/net/dpml/composition/management/DefaultManager.java
- copied, changed from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/management/ExecutableManager.java
- copied, changed from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/ExecutableManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/management/NullManager.java
- copied, changed from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/NullManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/management/StartableManager.java
- copied, changed from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/StartableManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/management/ValueManager.java
- copied, changed from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/ValueManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/models/ReferenceModel.java

development/main/metro/composition/control/src/test/net/dpml/composition/management/DefaultManagerTestCase.java
- copied, changed from r2353,
development/main/metro/composition/control/src/test/net/dpml/composition/state/DefaultManagerTestCase.java
Removed:

development/main/metro/composition/control/src/main/net/dpml/composition/models/EntryTable.java

development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/state/ExecutableManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/state/NullManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/state/StartableManager.java

development/main/metro/composition/control/src/main/net/dpml/composition/state/ValueManager.java

development/main/metro/composition/control/src/test/net/dpml/composition/state/DefaultManagerTestCase.java
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/TypesTask.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/ContextInvocationHandler.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/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/models/AbstractModel.java

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

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

development/main/metro/composition/control/src/main/net/dpml/composition/models/Holder.java

development/main/metro/composition/control/src/main/net/dpml/composition/models/PartsTable.java

development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultState.java

development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/AcmeContainer.java

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

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

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

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

development/main/metro/meta/api/src/main/net/dpml/meta/info/EntryDescriptor.java

development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java

development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java

development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
development/main/metro/parts/src/main/net/dpml/parts/model/Model.java
Log:
Tweaking, bumping, shuffling, but mainly committing prior to some subtle
reengineering of the instance table handling.

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
Fri Apr 22 23:49:48 2005
@@ -533,10 +533,6 @@

private Operation getOperation( String key, Method method ) throws
IntrospectionException
{
- //
- // TODO: pass key on to the validation methods to improve error
reporting
- //
-
final String name = method.getName();
final int semantic = PartDescriptor.getPartSemantic( method );
if( semantic == PartDescriptor.SELECT )
@@ -547,12 +543,7 @@
validateNonArrayReturnType( method, returnType );
String type = returnType.getName();
String postfix = PartDescriptor.getPartPostfix( method );
- if( PartDescriptor.ENTRY_KEY.equals( postfix ) )
- {
- validateEntryReturnType( method );
- validateAtMostOneParameter( method );
- }
- else if( PartDescriptor.MANAGER_KEY.equals( postfix ) )
+ if( PartDescriptor.MANAGER_KEY.equals( postfix ) )
{
validateNonNullReturnType( method );
validateAtMostOneParameter( method );
@@ -562,30 +553,12 @@
validateNonNullReturnType( method );
validateNoParameters( method );
}
- else if( PartDescriptor.PARTS_MAP_KEY.equals( postfix ) ||
PartDescriptor.CONTEXT_MAP_KEY.equals( postfix ) )
- {
- validateMapReturnType( method );
- validateAtMostOneParameter( method );
- }
- else if( PartDescriptor.PARTS_MANAGER_KEY.equals( postfix ) ||
PartDescriptor.CONTEXT_MANAGER_KEY.equals( postfix ) )
- {
- validateAtMostOneParameter( method );
- }
else
{
validateSelectPattern( method );
}
return new Operation( PartDescriptor.SELECT, postfix, type );
}
- else if( semantic == PartDescriptor.CREATE )
- {
- validateNoExceptions( method );
- validateAtMostOneParameter( method );
- Class returnType = method.getReturnType();
- validateReturnTypeIsAssignable( method, Entry.class );
- String type = returnType.getName();
- return new Operation( PartDescriptor.CREATE, type );
- }
else if( semantic == PartDescriptor.RELEASE )
{
validateNoExceptions( method );
@@ -665,7 +638,7 @@
validateMethodName( method );
validateNoExceptions( method );

- String key = PartDescriptor.getPartKey( method, PartDescriptor.GET );
+ String key = EntryDescriptor.getEntryKey( method );

Class returnType = method.getReturnType();
if( method.getParameterTypes().length == 0 )

Modified:
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypesTask.java
==============================================================================
---
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypesTask.java
(original)
+++
development/main/metro/composition/builder/src/main/net/dpml/composition/builder/TypesTask.java
Fri Apr 22 23:49:48 2005
@@ -113,10 +113,12 @@
{
throw e;
}
- catch( Exception e )
+ catch( Throwable e )
{
final String error =
- "Internal error while attempting to build types.";
+ "Internal error while attempting to build types."
+ + "\nCause: " + e.getClass().getName()
+ + "\nMessage: " + e.getMessage();
throw new BuildException( error, e, getLocation() );
}
}

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
Fri Apr 22 23:49:48 2005
@@ -48,10 +48,10 @@
import net.dpml.composition.data.ComponentProfile;
import net.dpml.composition.data.ValueDirective;
import net.dpml.composition.models.CompositionModel;
-import net.dpml.composition.models.EntryTable;
import net.dpml.composition.models.Holder;
import net.dpml.composition.models.ValueModel;
-import net.dpml.composition.state.ValueManager;
+
+import net.dpml.composition.management.ValueManager;

import net.dpml.system.SystemContext;

@@ -200,42 +200,14 @@
return m_partition.toString();
}

- public Entry getEntry( CompositionModel model, URI uri ) throws
EntryNotFoundException, UnknownSchemaException
+ public Model getPart( CompositionModel model, String key )
{
- if( null == uri )
- {
- throw new NullPointerException( "uri" );
- }
- URI ref = model.getURI();
- EntryTable table = getEntryTable( model, uri );
- String path = uri.getSchemeSpecificPart();
- Entry entry = table.getEntry( path );
- if( null == entry )
- {
- throw new EntryNotFoundException( ref, uri );
- }
- else
- {
- return entry;
- }
+ return model.getPartsTable().getModel( key );
}

- private EntryTable getEntryTable( CompositionModel model, URI uri )
throws UnknownSchemaException
+ public Entry getContextEntry( CompositionModel model, String key )
{
- final String scheme = uri.getScheme();
- if( "context".equals( scheme ) )
- {
- return model.getContextTable();
- }
- else if( "parts".equals( scheme ) )
- {
- return model.getPartsTable();
- }
- else
- {
- URI ref = model.getURI();
- throw new UnknownSchemaException( CONTROLLER_URI, ref, uri );
- }
+ return model.getContextTable().getEntry( key );
}

/**
@@ -320,67 +292,9 @@
}
}

-
-
- /**
- * Create and return an instance entry.
- *
- * @param model the component model
- * @return the resolved instance
- */
- //public Entry create( Model model ) throws Exception
- //{
- // return create( model, null, "create/1" );
- //}
-
- /**
- * Create and return an instance entry using a supplied instance
identifier.
- *
- * @param model the component model
- * @param key the instance identifier
- * @return the resolved instance
- */
- //public Entry create( Model model, Object key ) throws Exception
- //{
- // return create( model, key, "create/2" );
- //}
-
- /**
- * Create and return an instance entry using a supplied instance
identifier.
- *
- * @param model the component model
- * @param key the instance identifier
- * @return the resolved instance
- */
- //private Entry create( Model model, Object key, String method ) throws
Exception
- //{
- // if( model instanceof CompositionModel )
- // {
- // CompositionModel standard = (CompositionModel) model;
- // return getHolder( standard, key );
- // }
- // else
- // {
- // final String error =
- // "Unsupported model implementation class ["
- // + model.getClass().getName()
- // + "] passed to "
- // + method
- // + ".";
- // throw new UnsupportedOperationException( error );
- // }
- //}
-
public Manager getManager( Model model ) throws Exception
{
- if( model instanceof ValueModel )
- {
- return new ValueManager( (ValueModel) model );
- }
- else
- {
- return getManager( model, null );
- }
+ return getManager( model, null );
}

public Manager getManager( Model model, Object key ) throws Exception
@@ -391,12 +305,29 @@
Holder holder = getHolder( componentModel , key );
return getManager( holder );
}
+ else if(( model instanceof ValueModel ) )
+ {
+ if( null == key )
+ {
+ return new ValueManager( (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 );
+ }
+ }
else
{
- final String error =
- "Unsupported model implementation class ["
- + model.getClass().getName()
- + "] passed to getManager/n.";
+ final String error =
+ "Unsupported model type."
+ + "\nModel URI: " + model.getURI()
+ + "\nModel Class: " + model.getClass().getName()
+ + "\nRequested ID: " + key;
throw new UnsupportedOperationException( error );
}
}
@@ -450,6 +381,25 @@
if( model instanceof CompositionModel )
{
CompositionModel componentModel = (CompositionModel) model;
+
+ //
+ // PROBLEM HERE!
+ // The holder needs to be available aware. Available events
need to
+ // generated by the manager of instance and the holder registers
itself
+ // as a listener to the manager. When the manager posts an
available
+ // event it includes the instance. In turn the holder can
notify proxies
+ // of changes to availability status and state change.
+ //
+ //
+ // SECOND ISSUE!
+ // The controller needs to handle the initialization and
termination
+ // operations. The component can then take over intermidiate
state
+ // management functions. The best way to do that would be to
have the
+ // component declare a static state model, and to supply a
Manager as a
+ // constructor argument. The manager implementation would notify
the
+ // instance of its initiaization and termination.
+ //
+
Holder holder = getHolder( componentModel , key );
if( policy )
{

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
Fri Apr 22 23:49:48 2005
@@ -102,7 +102,7 @@
String name = method.getName();
String key = getKeyFromMethod( method );
Holder.ContextMap map = getHolder().getContextMap();
- return map.getValue( key, args );
+ return map.getValue( key, args );
}
}


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
Fri Apr 22 23:49:48 2005
@@ -38,10 +38,11 @@

import net.dpml.composition.models.CompositionModel;
import net.dpml.composition.models.Holder;
-import net.dpml.composition.state.NullManager;
-import net.dpml.composition.state.ValueManager;
-import net.dpml.composition.state.ExecutableManager;
-import net.dpml.composition.state.StartableManager;
+
+import net.dpml.composition.management.NullManager;
+import net.dpml.composition.management.ValueManager;
+import net.dpml.composition.management.ExecutableManager;
+import net.dpml.composition.management.StartableManager;

import net.dpml.meta.info.Type;


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
Fri Apr 22 23:49:48 2005
@@ -30,10 +30,12 @@
import net.dpml.activity.Disposable;

import net.dpml.composition.models.Holder;
+
import net.dpml.composition.data.ValueDirective;
-import net.dpml.composition.state.NullManager;

-import net.dpml.system.SystemContext;
+import net.dpml.composition.management.NullManager;
+
+import net.dpml.lang.DelegationRuntimeException;

import net.dpml.parts.state.State;
import net.dpml.parts.state.Manager;
@@ -42,7 +44,7 @@
import net.dpml.parts.state.NoSuchTransitionException;
import net.dpml.parts.state.NoSuchOperationException;

-import net.dpml.lang.DelegationRuntimeException;
+import net.dpml.system.SystemContext;

/**
* This makes a dynamic proxy for an state manager.

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
Fri Apr 22 23:49:48 2005
@@ -147,30 +147,35 @@
int semantic = PartDescriptor.getPartSemantic( method );
String postfix = PartDescriptor.getPartPostfix( method );
String key = PartDescriptor.getPartKey( method, semantic );
- Entry provider = getComponentModel().getPartsTable().getEntry( key );
+ Model provider = getComponentModel().getPartsTable().getModel( key );

if( PartDescriptor.SELECT == semantic )
{
if( null == postfix )
{
+ Controller controller = provider.getController();
if( null == args )
{
- return provider.getValue();
+ return controller.resolve( provider );
}
else if( args.length == 1 )
{
Object arg = args[0];
- Model model = getModelFromProvider( provider, key,
"select/1" );
- Controller controller = model.getController();
- return controller.resolve( model, arg );
+ if( arg.getClass() == Boolean.TYPE )
+ {
+ boolean policy = getBooleanValue( args[1] );
+ return controller.resolve( provider, null, policy );
+ }
+ else
+ {
+ return controller.resolve( provider, arg );
+ }
}
else if( args.length == 2 )
{
Object arg = args[0];
boolean policy = getBooleanValue( args[1] );
- Model model = getModelFromProvider( provider, key,
"select/2" );
- Controller controller = model.getController();
- return controller.resolve( model, arg, policy );
+ return controller.resolve( provider, arg, policy );
}
else
{
@@ -181,30 +186,11 @@
throw new IllegalStateException( error );
}
}
- /*
- else if( PartDescriptor.ENTRY_KEY.equals( postfix ) )
+ else if( PartDescriptor.MODEL_KEY.equals( postfix ) )
{
- if( null == args )
- {
- Model model = getModelFromProvider( provider, key,
"select/entry/0" );
- return invokeCreate( key, model );
- }
- else if( args.length == 1 )
- {
- Object arg = args[0];
- Model model = getModelFromProvider( provider, key,
"select/entry/1" );
- return invokeCreate( key, model, arg );
- }
- else
- {
- final String error =
- "Illegal number of parameters supplied under the
'select/entry' method ["
- + method.getName()
- + "].";
- throw new IllegalStateException( error );
- }
+ // TODO: wrap this is a proxy
+ return provider;
}
- */
else if( PartDescriptor.CONTEXT_MANAGER_KEY.equals( postfix )
|| PartDescriptor.CONTEXT_MAP_KEY.equals( postfix ) )
{
@@ -292,31 +278,6 @@
}
*/
}
- else if( PartDescriptor.MODEL_KEY.equals( postfix ) )
- {
- if( false == ( provider instanceof Model ) )
- {
- final String error =
- "Selected entry does not implement the Model
interface."
- + "\nClass: " + provider.getClass().getName()
- + "\nKey: " + provider.getKey()
- + "Instance: " + m_holder.getURI();
- throw new UnsupportedOperationException( error );
- }
- else
- {
- return (Model) provider;
- }
- }
- else if( PartDescriptor.PARTS_MANAGER_KEY.equals( postfix )
- || PartDescriptor.PARTS_MAP_KEY.equals( postfix ) )
- {
- //
- // TODO: write the implementation
- //
-
- throw new UnsupportedOperationException( method.getName() );
- }
else
{
final String error =
@@ -328,60 +289,6 @@
throw new IllegalStateException( error );
}
}
- /*
- else if( PartDescriptor.CREATE == semantic )
- {
- if( null == args )
- {
- if( provider instanceof Model )
- {
- Model model = (Model) provider;
- return invokeCreate( key, model );
- }
- else
- {
- final String error =
- "The request for the application of 'create/0' for the
key ["
- + key
- + "] 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 );
- }
- }
- else if( args.length == 1 )
- {
- Object arg = args[0];
- if( provider instanceof Model )
- {
- Model model = (Model) provider;
- return invokeCreate( key, model, arg );
- }
- else
- {
- final String error =
- "The request for the application of 'create/1' for the
key ["
- + key
- + "] in the component ["
- + getComponentModel().getURI()
- + "] could not be applied as the entry refereced by
the key is not an instance of "
- + Model.class.getName()
- + ".";
- throw new IllegalStateException( error );
- }
- }
- else
- {
- final String error =
- "Illegal number of parameters supplied under the 'create'
method ["
- + method.getName()
- + "].";
- throw new IllegalStateException( error );
- }
- }
- */
else if( PartDescriptor.RELEASE == semantic )
{
if( args.length == 1 )
@@ -426,38 +333,6 @@
}
}

- /*
- private Entry invokeCreate( String key, Model provider ) throws
DelegationException
- {
- Controller controller = provider.getController();
- try
- {
- return controller.create( provider );
- }
- catch( Throwable e )
- {
- final DelegationException exception =
- createDelegationException( key, provider, "create/0", e );
- throw exception;
- }
- }
-
- private Entry invokeCreate( String key, Model provider, Object arg )
throws DelegationException
- {
- Controller controller = provider.getController();
- try
- {
- return controller.create( provider, arg );
- }
- catch( Throwable e )
- {
- final DelegationException exception =
- createDelegationException( key, provider, "create/1", e );
- throw exception;
- }
- }
- */
-
private DelegationException createDelegationException( String key, Model
provider, String function, Throwable e )
{
URI uri = provider.getURI();
@@ -532,28 +407,6 @@
}
}

- private Model getModelFromProvider( Entry entry, String key, String
operation )
- {
- if( entry instanceof Model )
- {
- return (Model) entry;
- }
- else
- {
- final String error =
- "The request for the application of '"
- + operation
- + "' for the key ["
- + key
- + "] 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 IllegalArgumentException( error );
- }
- }
-
private Manager getManager( CompositionModel model, Object[] args )
throws Exception
{
CompositionController controller = model.getCompositionController();

Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/management/DefaultManager.java
(from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultManager.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/management/DefaultManager.java
Fri Apr 22 23:49:48 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.state;
+package net.dpml.composition.management;

import java.util.Map;
import java.util.Hashtable;
@@ -29,9 +29,11 @@
import java.util.logging.Level;
import java.lang.reflect.Method;
import java.net.URI;
+import java.util.Observable;

import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
+
+import net.dpml.composition.state.*;

import net.dpml.parts.state.State;
import net.dpml.parts.state.Transition;
@@ -48,23 +50,22 @@
*
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
*/
-public class DefaultManager implements Manager
+public class DefaultManager extends Observable implements Manager
{
private final DefaultState m_graph;
private DefaultState m_state;
private Object m_instance;
- private ChangeListener m_listener;
private Map m_handlers = new Hashtable();
private Logger m_logger;

/**
- * Creation of a new AbstractStateManager.
+ * Creation of a new DefaultManager.
* @param graph the root state of a state graph
- * @param logger the assinged logging channel
+ * @param logger the assigned logging channel
* @param listener a change listener
* @param instance the managed instance
*/
- public DefaultManager( DefaultState graph, Logger logger, ChangeListener
listener, Object instance )
+ public DefaultManager( DefaultState graph, Logger logger, Object
instance )
{
if( null == logger )
{
@@ -74,16 +75,11 @@
{
throw new NullPointerException( "instance" );
}
- if( null == listener )
- {
- throw new NullPointerException( "listener" );
- }
if( null == graph )
{
throw new NullPointerException( "graph" );
}
m_instance = instance;
- m_listener = listener;
m_logger = logger;
m_graph = graph;
}
@@ -632,8 +628,9 @@
getLogger().fine( message );
}
m_state = state;
+ setChanged();
ChangeEvent event = new ChangeEvent( this );
- m_listener.stateChanged( event );
+ notifyObservers( event );
}
}


Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/management/ExecutableManager.java
(from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/ExecutableManager.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/state/ExecutableManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/management/ExecutableManager.java
Fri Apr 22 23:49:48 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.state;
+package net.dpml.composition.management;

import java.util.Map.Entry;


Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/management/NullManager.java
(from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/NullManager.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/state/NullManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/management/NullManager.java
Fri Apr 22 23:49:48 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.state;
+package net.dpml.composition.management;

import java.util.Map.Entry;


Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/management/StartableManager.java
(from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/StartableManager.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/state/StartableManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/management/StartableManager.java
Fri Apr 22 23:49:48 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.state;
+package net.dpml.composition.management;

import java.util.Map.Entry;


Copied:
development/main/metro/composition/control/src/main/net/dpml/composition/management/ValueManager.java
(from r2353,
development/main/metro/composition/control/src/main/net/dpml/composition/state/ValueManager.java)
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/state/ValueManager.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/management/ValueManager.java
Fri Apr 22 23:49:48 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.state;
+package net.dpml.composition.management;

import java.util.Map.Entry;


Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/models/AbstractModel.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/models/AbstractModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/models/AbstractModel.java
Fri Apr 22 23:49:48 2005
@@ -92,6 +92,15 @@
return getCompositionController().getManager( this );
}

+ /**
+ * Return a Manager for an identified instance.
+ * @param id the instance identity
+ */
+ public Manager getManager( Object id ) throws Exception
+ {
+ return getCompositionController().getManager( this, id );
+ }
+
//--------------------------------------------------------------
// Entry
//--------------------------------------------------------------
@@ -99,7 +108,7 @@
/**
* 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 a the set of context entries.
+ * of parts or within the set of context entries.
*
* @return the model key
*/

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/models/CompositionModel.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/models/CompositionModel.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/models/CompositionModel.java
Fri Apr 22 23:49:48 2005
@@ -30,16 +30,19 @@
import net.dpml.parts.model.TypeClassNotFoundException;
import net.dpml.parts.part.Part;
import net.dpml.parts.part.PartReference;
+
import net.dpml.composition.control.CompositionController;
import net.dpml.composition.data.ComponentProfile;
import net.dpml.composition.data.ContextDirective;
import net.dpml.configuration.Configuration;
import net.dpml.configuration.Configurable;
import net.dpml.configuration.impl.DefaultConfiguration;
+
import net.dpml.meta.info.DependencyDescriptor;
import net.dpml.meta.info.EntryDescriptor;
import net.dpml.meta.info.ServiceDescriptor;
import net.dpml.meta.info.Type;
+
import net.dpml.parameters.Parameters;
import net.dpml.parameters.Parameterizable;
import net.dpml.parameters.impl.DefaultParameters;
@@ -58,7 +61,7 @@
private final ClassLoader m_classloader;
private final URI m_partition;
private final PartsTable m_parts;
- private final EntryTable m_context;
+ private final ContextTable m_context;
private final InstanceTable m_instances;
private final Class m_class;
private final Type m_type;
@@ -175,15 +178,17 @@
PartReference reference = parts[i];
String key = reference.getKey();
Part part = reference.getPart();
- getPartsTable().addEntry( key, part );
+ getPartsTable().addPart( key, part );
}

//
// Build the context model. The initial population of the context
// model is establised by reading in the set of PartReference
instances
// contained within the ContextDirective. Each part reference is
located
- // using a context entry key. The part reference also holds the
part
- // that will be used to construct a context entry model.
+ // using a context entry key. The part reference holds the part
+ // that will be used to construct a context entry model. The
context
+ // entry model's getValue() operation is used to resolve the default
+ // context value accessible via the context key.
//

ContextDirective context = profile.getContextDirective();
@@ -198,11 +203,9 @@
if( entry.isRequired() )
{
final String error =
- "The component model ["
- + this
- + "] does not declare a context entry for the key "
- + key
- + "].";
+ "Unresolved context entry."
+ + "\nModel: " + getURI()
+ + "Context Key: " + key;
throw new ModelRuntimeException( error );
}
}
@@ -234,11 +237,9 @@
if( dependency.isRequired() )
{
final String error =
- "The component model ["
- + this
- + "] does not declare a context entry for the
dependency key "
- + key
- + "].";
+ "Unresolved dependency."
+ + "\nModel: " + getURI()
+ + "\nDependency key: " + key;
throw new ModelException( error );
}
}
@@ -347,12 +348,12 @@
return m_interfaces;
}

- public EntryTable getContextTable()
+ public ContextTable getContextTable()
{
return m_context;
}

- public EntryTable getPartsTable()
+ public PartsTable getPartsTable()
{
return m_parts;
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/models/ContextTable.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/models/ContextTable.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/models/ContextTable.java
Fri Apr 22 23:49:48 2005
@@ -19,10 +19,17 @@
package net.dpml.composition.models;

import java.net.URI;
+import java.util.Hashtable;
+import java.util.Map;
import java.util.Map.Entry;

+import net.dpml.parts.control.Controller;
+import net.dpml.parts.model.Model;
import net.dpml.parts.model.ModelException;
+import net.dpml.parts.model.ModelRuntimeException;
import net.dpml.parts.part.Part;
+
+import net.dpml.composition.control.CompositionController;
import net.dpml.composition.data.ReferenceDirective;

/**
@@ -31,20 +38,25 @@
* @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 ContextTable extends EntryTable
+public class ContextTable
{
private final CompositionModel m_parent;

+ private final CompositionModel m_model;
+
+ private final Map m_entries = new Hashtable();
+
/**
* Creation of a new context entry table.
*
- * @param model the composition model
- * @param parent the enclosing parent composition model
+ * @param model the composition model that this entry is part of
+ * @param parent the composition model enclosing the model from which
+ * part references may be resolved
*/
public ContextTable(
CompositionModel model, CompositionModel parent )
{
- super( model );
+ m_model = model;
m_parent = parent;
}

@@ -71,43 +83,154 @@
if( null == parent )
{
final String error =
- "The context entry ["
- + key
- + "] in the component ["
- + getModel().getURI()
- + "] is requesting a reference to a part ["
- + uri
- + "] which cannot be resolved as the component has no
enclosing composition model.";
+ "Cannot resolve a reference to peer part from a root
component."
+ + "\nModel: " + getModel().getURI()
+ + "\nContext Key: " + key;
throw new ModelException( error );
}
+
+ String ref = uri.getSchemeSpecificPart();
+ Model target = parent.getPartsTable().getModel( ref );
+ if( null == target )
+ {
+ final String error =
+ "Part not found."
+ + "\nParent Model: " + getParentModel().getURI()
+ + "\nModel: " + getModel().getURI()
+ + "\nContext Key: " + key;
+ throw new ModelException( error );
+ }
+
+ //
+ // Using the uri fragment we can resolve a lifestyle policy or
+ // instance identity and associate an entry containing the
instance key
+ // and the applicance invocation handler - which is rather nice
as we
+ // push down code concerning manager selection and instance
creation
+ // into the handler which means that the handler becomes
available
+ // aware.
+ //
+
+ CompositionController controller =
getModel().getCompositionController();
+ ReferenceModel entry = new ReferenceModel( controller, key,
target, uri );
+ addEntry( key, entry );
+ }
+ else
+ {
+ ClassLoader classloader = getModel().getClassLoader();
+ CompositionModel model = getModel();
+ CompositionController controller =
model.getCompositionController();
+ Model entry = controller.getModel( model, classloader, part, key
);
+ addEntry( key, entry );
+ }
+ }
+
+ public void addEntry( String key, Entry entry ) throws ModelException
+ {
+ if( null == key )
+ {
+ throw new NullPointerException( "key" );
+ }
+ if( null == entry )
+ {
+ throw new NullPointerException( "entry" );
+ }
+ if( m_entries.containsKey( key ) )
+ {
+ throw new DuplicateKeyException( key );
+ }
+ setEntry( key, entry );
+ }
+
+ public void setEntry( String key, Entry value )
+ {
+ if( null == key )
+ {
+ throw new NullPointerException( "key" );
+ }
+ synchronized( m_entries )
+ {
+ m_entries.put( key, value );
+ }
+ }
+
+ public Entry getEntry( String key )
+ {
+ return (Entry) m_entries.get( key );
+ }
+
+ public boolean containsKey( String key )
+ {
+ if( null == key )
+ {
+ throw new NullPointerException( "key" );
+ }
+ return m_entries.containsKey( key );
+ }
+
+ public Object getValue( String key, Object[] args )
+ {
+ Entry entry = getEntry( key );
+ if( null == entry )
+ {
+ return getDefaultValueUsingArgs( args );
+ }
+ else if( entry instanceof ReferenceModel )
+ {
+ // TODO: move this to the controller
+ ReferenceModel reference = (ReferenceModel) entry;
+ URI ref = reference.getReferenceURI();
+ Model provider = reference.getProviderModel();
+ try
+ {
+ Controller controller = provider.getController();
+ return controller.resolve( provider, ref.getFragment(), true
);
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to resolve the value of
context entry."
+ + "\nModel: " + getModel().getURI()
+ + "\nContext Key: " + key
+ + "\nReference URI: " + ref
+ + "\nProvider: " + provider.getURI();
+ throw new ModelRuntimeException( error, e );
+ }
+ }
+ else
+ {
+ Object value = entry.getValue();
+ if( null == value )
+ {
+ return getDefaultValueUsingArgs( args );
+ }
else
{
- String ref = uri.getSchemeSpecificPart();
- Entry entry = parent.getPartsTable().getEntry( ref );
- if( null == entry )
- {
- final String error =
- "Could not add part under the key ["
- + key
- + "] in the model ["
- + getModel().getURI()
- + "] because the reference ["
- + uri
- + "] was not found.";
- throw new ModelException( error );
- }
- else
- {
- addEntry( key, entry );
- }
+ return value;
}
}
+ }
+
+ private Object getDefaultValueUsingArgs( Object[] args )
+ {
+ if( null == args )
+ {
+ return null;
+ }
+ else if( args.length < 1 )
+ {
+ return null;
+ }
else
{
- super.addEntry( key, part );
+ return args[0];
}
}

+ protected CompositionModel getModel()
+ {
+ return m_model;
+ }
+
protected CompositionModel getParentModel()
{
return m_parent;

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/models/Holder.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/models/Holder.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/models/Holder.java
Fri Apr 22 23:49:48 2005
@@ -260,6 +260,13 @@
}
}

+ /**
+ * The context map is a wrapper around the model's context map.
+ * If a local value is declared in this map that value is returned,
otherwise
+ * the returned value defaults to the model's value. One aspect of this
+ * is that modifications to shared (model level) entries will impact all
+ * other instances backed by the same model.
+ */
public static class ContextMap extends Hashtable
{
private CompositionModel m_model;
@@ -278,7 +285,7 @@
}
else
{
- EntryTable table = getModel().getContextTable();
+ ContextTable table = getModel().getContextTable();
return table.getValue( key, args );
}
}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/models/PartsTable.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/models/PartsTable.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/models/PartsTable.java
Fri Apr 22 23:49:48 2005
@@ -18,29 +18,39 @@

package net.dpml.composition.models;

+import java.util.Map;
+import java.util.Hashtable;
+
import net.dpml.parts.model.ModelException;
+import net.dpml.parts.model.Model;
import net.dpml.parts.part.Part;
+
import net.dpml.composition.data.ReferenceDirective;
+import net.dpml.composition.control.CompositionController;

/**
- * The parts model is a model of the set of parts maintained by a parent
model.
+ * The parts table contains the subsidiary parts of an enclosing model.
*
* @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 PartsTable extends EntryTable
+public class PartsTable
{
+ private final CompositionModel m_model;
+
+ private final Hashtable m_parts = new Hashtable(); // map of Model
instances keyed by part key
+
/**
* Creation of a new parts table.
*
- * @param model the composition model
+ * @param model the enclosing composition model
*/
public PartsTable( CompositionModel model )
{
- super( model );
+ m_model = model;
}

- public void addEntry( String key, Part part ) throws ModelException
+ public void addPart( String key, Part part ) throws ModelException
{
if( null == key )
{
@@ -53,15 +63,50 @@
if( part instanceof ReferenceDirective )
{
final String error =
- "Illegal attempt to add a parts reference parts within ["
- + getModel().getURI()
- + "] under the key ["
- + key
- + "].";
+ "Illegal attempt to add a part reference to a parts
collection."
+ + "\nModel: " + getModel().getURI()
+ + "\nParts Key: " + key;
+ throw new IllegalArgumentException( error );
+ }
+ synchronized( m_parts )
+ {
+ ClassLoader classloader = getModel().getClassLoader();
+ CompositionModel enclosing = getModel();
+ CompositionController controller =
enclosing.getCompositionController();
+ Model model = controller.getModel( enclosing, classloader, part,
key );
+ addModel( key, model );
}
- else
+ }
+
+ public void addModel( String key, Model model ) throws ModelException
+ {
+ synchronized( m_parts )
{
- super.addEntry( key, part );
+ if( m_parts.containsKey( key ) )
+ {
+ throw new DuplicateKeyException( key );
+ }
+ m_parts.put( key, model );
}
}
+
+ public boolean containsKey( String key )
+ {
+ if( null == key )
+ {
+ throw new NullPointerException( "key" );
+ }
+ return m_parts.containsKey( key );
+ }
+
+ public Model getModel( String key )
+ {
+ return (Model) m_parts.get( key );
+ }
+
+ protected CompositionModel getModel()
+ {
+ return m_model;
+ }
+
}

Added:
development/main/metro/composition/control/src/main/net/dpml/composition/models/ReferenceModel.java
==============================================================================
--- (empty file)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/models/ReferenceModel.java
Fri Apr 22 23:49:48 2005
@@ -0,0 +1,118 @@
+/*
+ * 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.models;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import net.dpml.parts.control.Controller;
+import net.dpml.parts.model.Model;
+import net.dpml.parts.model.ModelException;
+import net.dpml.parts.model.ModelRuntimeException;
+import net.dpml.composition.control.CompositionController;
+import net.dpml.composition.data.ValueDirective;
+import net.dpml.composition.data.ValueDirective.Value;
+
+/**
+ * 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 ReferenceModel extends AbstractModel
+{
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final URI m_reference;
+ private final Model m_provider;
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ /**
+ * Creation of a new reference model. Reference model are used to
describe
+ * the strategy used to select a provider, and the policy concerning the
+ * aquisition of an identifiable manager. The getValue method will
return
+ * a proxied reference containing this model. This model listens to the
+ * manager for availability events ensuring that invocation of service
+ * methods are only passed on to the provider after the provider is fully
+ * initialized.
+ *
+ * @param controller this model's controller
+ * @param key the entry key
+ * @param model the default provider model
+ * @param ref the reference uri used to establish the default provider
model
+
+ * @exception NullArgumentException if either the directive argument or
the
+ * context argument is null.
+ */
+ public ReferenceModel( CompositionController controller, String key,
Model provider, URI ref )
+ throws ModelException, NullPointerException
+ {
+ super( controller, key );
+ if( null == provider )
+ {
+ throw new NullPointerException( "model" );
+ }
+ if( null == ref )
+ {
+ throw new NullPointerException( "ref" );
+ }
+ m_reference = ref;
+ m_provider = provider;
+ }
+
+ public URI getPartition()
+ {
+ return m_provider.getPartition();
+ }
+
+ public URI getURI()
+ {
+ return m_provider.getURI();
+ }
+
+ public URI getReferenceURI()
+ {
+ return m_reference;
+ }
+
+ public Model getProviderModel()
+ {
+ return m_provider;
+ }
+
+ //--------------------------------------------------------------
+ // EntryModel
+ //--------------------------------------------------------------
+
+ /**
+ * Return the context entry value.
+ *
+ * @return the context entry value
+ */
+ public Object getValue()
+ {
+ throw new UnsupportedOperationException( "getValue/0" );
+ }
+
+}

Modified:
development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultState.java
==============================================================================
---
development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultState.java
(original)
+++
development/main/metro/composition/control/src/main/net/dpml/composition/state/DefaultState.java
Fri Apr 22 23:49:48 2005
@@ -534,7 +534,7 @@
* Return the list of transition names local to this state.
* @return the array of transition names
*/
- protected String[] getLocalTransitionNames()
+ public String[] getLocalTransitionNames()
{
return (String[]) m_transitions.keySet().toArray( new String[0] );
}
@@ -678,7 +678,7 @@
* Return the list of operation names local to this state.
* @return the array of operation names
*/
- protected String[] getLocalOperationNames()
+ public String[] getLocalOperationNames()
{
return (String[]) m_operations.keySet().toArray( new String[0] );
}

Copied:
development/main/metro/composition/control/src/test/net/dpml/composition/management/DefaultManagerTestCase.java
(from r2353,
development/main/metro/composition/control/src/test/net/dpml/composition/state/DefaultManagerTestCase.java)
==============================================================================
---
development/main/metro/composition/control/src/test/net/dpml/composition/state/DefaultManagerTestCase.java
(original)
+++
development/main/metro/composition/control/src/test/net/dpml/composition/management/DefaultManagerTestCase.java
Fri Apr 22 23:49:48 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.composition.state;
+package net.dpml.composition.management;

import java.net.URI;
import java.util.logging.Logger;
@@ -26,6 +26,8 @@

import junit.framework.TestCase;

+import net.dpml.composition.state.*;
+
import net.dpml.parts.state.State;
import net.dpml.parts.state.Manager;
import net.dpml.parts.state.DuplicateKeyException;
@@ -355,8 +357,7 @@
private DefaultManager setupManager( DefaultState graph, MockComponent
instance )
{
Logger logger = Logger.getAnonymousLogger();
- ChangeListener listener = new MockChangeListener();
- return new DefaultManager( graph, logger, listener, instance );
+ return new DefaultManager( graph, logger, instance );
}

public static class MockChangeListener implements ChangeListener

Modified:
development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/AcmeContainer.java
==============================================================================
---
development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/AcmeContainer.java
(original)
+++
development/main/metro/composition/testing/acme/src/main/net/dpml/composition/testing/AcmeContainer.java
Fri Apr 22 23:49:48 2005
@@ -113,9 +113,13 @@
debug( "getting identified gizmo" );
Gizmo myGizmo = parts.selectGizmo( "my-gizmo" );

+ debug( "getting identified non-proxied gizmo" );
+ Gizmo myProxiedGizmo = parts.selectGizmo( "my-gizmo", true );
+
debug( "cleaning up" );
parts.releaseGizmo( gizmo );
parts.releaseGizmo( myGizmo );
+ parts.releaseGizmo( myProxiedGizmo );
}

private Logger getLogger()
@@ -176,6 +180,14 @@
Gizmo selectGizmo( Object key );

/**
+ * Return an identified instance of gizmo using a supplied proxy
policy.
+ *
+ * @param key the instance identifier
+ * @return the gizmo service
+ */
+ Gizmo selectGizmo( Object key, boolean policy );
+
+ /**
* Optional release of an instance of the gizmo component.
*
* @param the gizmo to release

Modified:
development/main/metro/composition/testing/unit/src/main/net/dpml/test/state/ManagedComponent.java
==============================================================================
---
development/main/metro/composition/testing/unit/src/main/net/dpml/test/state/ManagedComponent.java
(original)
+++
development/main/metro/composition/testing/unit/src/main/net/dpml/test/state/ManagedComponent.java
Fri Apr 22 23:49:48 2005
@@ -26,7 +26,7 @@

import net.dpml.parts.state.State;
import net.dpml.composition.state.DefaultState;
-import net.dpml.composition.state.DefaultManager;
+import net.dpml.composition.management.DefaultManager;

/**
* Experimental component dealing with state management.
@@ -46,6 +46,7 @@
// ------------------------------------------------------------------

private final Logger m_logger;
+
// ------------------------------------------------------------------
// constructor
// ------------------------------------------------------------------
@@ -66,9 +67,9 @@

public class Controller extends DefaultManager
{
- public Controller( Logger logger, ChangeListener listener,
ManagedComponent instance )
+ public Controller( Logger logger, ManagedComponent instance )
{
- super( COMPONENT_STATE_MODEL, logger, listener, instance );
+ super( COMPONENT_STATE_MODEL, logger, instance );
}

//
@@ -93,7 +94,7 @@
}

//
- // The following component methods are invoked by the state manager
based on
+ // The following methods are invoked by the state manager based on
// uris assigned to transitions. The state manager locates the method
// from the uri and invokes the operation after constructing arguments
// from the possible set of Logger, Object (component impl), State
(initial),
@@ -119,8 +120,8 @@
}

//
- // The following two methods are examples of methods invoked
- // via operation declarations. Operations do not trigger state
+ // The following method is an example of a method invoked
+ // via an operation declaration. Operations do not trigger state
// change - instead they are gaurded methods that become visible
// to a controlling application when the state to which the operation
// is assigned becomes visible in the active state chain.

Modified:
development/main/metro/composition/testing/unit/src/main/net/dpml/test/state/ManagingContainer.java
==============================================================================
---
development/main/metro/composition/testing/unit/src/main/net/dpml/test/state/ManagingContainer.java
(original)
+++
development/main/metro/composition/testing/unit/src/main/net/dpml/test/state/ManagingContainer.java
Fri Apr 22 23:49:48 2005
@@ -18,18 +18,26 @@

package net.dpml.test.state;

+import java.net.URI;
import java.util.logging.Logger;

+import javax.swing.event.ChangeListener;
+
import net.dpml.configuration.Configuration;
-import net.dpml.activity.Executable;
+
import net.dpml.parts.state.Manager;
+import net.dpml.parts.state.State;
+
+import net.dpml.composition.state.DefaultState;
+
+import net.dpml.composition.management.DefaultManager;

/**
* Demonstration of a component that manages the state of a contained part.
*
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
*/
-public class ManagingContainer implements Executable
+public class ManagingContainer
{
//------------------------------------------------------------------
// static
@@ -94,4 +102,29 @@
Manager selectTestManager();
}

+ public class Controller extends DefaultManager
+ {
+ public Controller( Logger logger, ManagingContainer instance )
+ {
+ super( createStateModel(), logger, instance );
+ }
+ }
+
+ private static DefaultState createStateModel()
+ {
+ DefaultState root = new DefaultState();
+ DefaultState initialized = root.addState( "initialized" );
+ try
+ {
+ root.setInitialization( new URI( "method:execute" ), initialized
);
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace(); // will not happen
+ }
+ finally
+ {
+ return root;
+ }
+ }
}

Modified:
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/CompositeTestCase.java
==============================================================================
---
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/CompositeTestCase.java
(original)
+++
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/CompositeTestCase.java
Fri Apr 22 23:49:48 2005
@@ -47,16 +47,16 @@
*/
public void testAcmeContainerUsingComponent() throws Exception
{
- execute( "acme-container.part" );
+ executeTestOnPart( "acme-container.part" );
}

/**
* Test the construction of a component that contains two child components
* (widget and gizmo) where the widget is a value object.
*/
- public void testAcmeContainerUsingvalue() throws Exception
+ public void testAcmeContainerUsingValue() throws Exception
{
- execute( "acme-test-container.part" );
+ executeTestOnPart( "acme-test-container.part" );
}

/**
@@ -69,14 +69,8 @@
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( "acme-bad-widget.part" );
Model model = helper.getCompositionManager().addPart( uri, "acme" );
-
- //Controller controller = model.getController();
- //Entry entry = controller.create( model );
- //AcmeContainer container = (AcmeContainer) entry.getValue();
-
Manager manager = model.getManager();
AcmeContainer container = (AcmeContainer) manager.initialize();
-
try
{
container.execute();
@@ -87,13 +81,12 @@
}
finally
{
- //controller.release( container );
manager.terminate();
helper.dispose();
}
}

- private void execute( String path ) throws Exception
+ private void executeTestOnPart( String path ) throws Exception
{
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( path );
@@ -102,10 +95,6 @@
Manager manager = model.getManager();
AcmeContainer container = (AcmeContainer) manager.initialize();

- //Controller controller = model.getController();
- //Entry entry = controller.create( model );
- //AcmeContainer container = (AcmeContainer) entry.getValue();
-
try
{
container.execute();

Modified:
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/SimpleTestCase.java
==============================================================================
---
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/SimpleTestCase.java
(original)
+++
development/main/metro/composition/testing/unit/src/test/net/dpml/composition/testing/SimpleTestCase.java
Fri Apr 22 23:49:48 2005
@@ -98,43 +98,35 @@
* Test the construction of the widget implementation and invocation
* of a non-service public method on the implementation class.
*/
- public void testEntryCreation() throws Exception
+ public void testNonProxiedCreation() throws Exception
{
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
- Manager manager = model.getManager();
- //Controller controller = model.getController();
- //Entry entry = controller.create( model );
- //WidgetComponent widget = (WidgetComponent) entry.getValue();
-
- WidgetComponent widget = (WidgetComponent) manager.initialize();
+ Controller controller = model.getController();
+ WidgetComponent widget = (WidgetComponent) controller.resolve(
model, null, false );
String name = widget.getName();
assertEquals( "name", "widget", name );
String newName = "freight";
widget.setName( newName );
assertEquals( "name", newName, widget.getName() );
- //controller.release( widget );
+ controller.release( widget );
}

/**
* Test the construction of the widget implementation and invocation
* of a non-service public method on the implementation class.
*/
- /*
- public void testIdentifiableEntryCreation() throws Exception
+ public void testIdentifiableManagerCreation() throws Exception
{
String id = "niclas";
CompositionHelper helper = new CompositionHelper();
URI uri = helper.toURI( PATH );
Model model = helper.getCompositionManager().addPart( uri, "widget"
);
Controller controller = model.getController();
- Entry entry = controller.create( model, id );
- Object key = entry.getKey();
- assertEquals( "key", id, key );
- controller.release( entry );
+ WidgetComponent widget = (WidgetComponent) controller.resolve(
model, id, false );
+ controller.release( widget );
}
- */

/**
* Test the construction of an identifiable widget instance. We create
@@ -149,13 +141,13 @@
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" );
- Widget w2 = (Widget) controller.resolve( model, "acme-widget-two" );
+ Widget w1 = (Widget) controller.resolve( model, "acme-widget-one",
false );
+ Widget w2 = (Widget) controller.resolve( model, "acme-widget-two",
false );
if( w1.equals( w2 ) )
{
fail( "Widget w1 and w2 are not unique!" );
}
- Widget w3 = (Widget) controller.resolve( model, "acme-widget-one" );
+ Widget w3 = (Widget) controller.resolve( model, "acme-widget-one",
false );
if( !w1.equals( w3 ) )
{
System.out.println( "" + System.identityHashCode( w1 ) );

Modified:
development/main/metro/meta/api/src/main/net/dpml/meta/info/EntryDescriptor.java
==============================================================================
---
development/main/metro/meta/api/src/main/net/dpml/meta/info/EntryDescriptor.java
(original)
+++
development/main/metro/meta/api/src/main/net/dpml/meta/info/EntryDescriptor.java
Fri Apr 22 23:49:48 2005
@@ -20,6 +20,9 @@
package net.dpml.meta.info;

import java.io.Serializable;
+import java.beans.Introspector;
+import java.lang.reflect.Method;
+

/**
* A descriptor that describes a value that must be placed
@@ -36,6 +39,26 @@
public final class EntryDescriptor
implements Serializable
{
+ public static final String GET = "get";
+
+ public static String getEntryKey( Method method )
+ {
+ String name = method.getName();
+ if( name.startsWith( GET ) )
+ {
+ String remainder = name.substring( GET.length() );
+ return Introspector.decapitalize( remainder );
+ }
+ else
+ {
+ final String error =
+ "Unrecognized context accessor method signature ["
+ + name
+ + "]";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
public static final boolean OPTIONAL = true;
public static final boolean REQUIRED = false;


Modified:
development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java
==============================================================================
---
development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java
(original)
+++
development/main/metro/meta/api/src/main/net/dpml/meta/info/PartDescriptor.java
Fri Apr 22 23:49:48 2005
@@ -21,6 +21,7 @@

import java.io.Serializable;
import java.lang.reflect.Method;
+import java.beans.Introspector;

/**
* A part descriptor identifies a key, access semantics and return type
@@ -55,38 +56,23 @@
public final class PartDescriptor
implements Serializable
{
- public static final int GET = 0;
public static final int SELECT = 1;
- public static final int CREATE = 2;
public static final int RELEASE = -1;

- public static final String GET_KEY = "get";
public static final String SELECT_KEY = "select";
- public static final String CREATE_KEY = "create";
public static final String RELEASE_KEY = "release";

public static final String CONTEXT_MAP_KEY = "ContextMap";
public static final String CONTEXT_MANAGER_KEY = "ContextManager";
- public static final String PARTS_MANAGER_KEY = "PartsManager";
- public static final String PARTS_MAP_KEY = "PartsMap";
public static final String MANAGER_KEY = "Manager";
public static final String MODEL_KEY = "Model";
- public static final String ENTRY_KEY = "Entry";

public static String toString( int semantic )
{
- if( CREATE == semantic )
- {
- return "create";
- }
- else if( SELECT == semantic )
+ if( SELECT == semantic )
{
return "select";
}
- else if( GET == semantic )
- {
- return "get";
- }
else if( RELEASE == semantic )
{
return "release";
@@ -108,14 +94,6 @@
{
return CONTEXT_MAP_KEY;
}
- else if( name.endsWith( PARTS_MANAGER_KEY ) )
- {
- return PARTS_MANAGER_KEY;
- }
- else if( name.endsWith( PARTS_MAP_KEY ) )
- {
- return PARTS_MAP_KEY;
- }
else if( name.endsWith( MODEL_KEY ) )
{
return MODEL_KEY;
@@ -124,10 +102,6 @@
{
return MANAGER_KEY;
}
- else if( name.endsWith( ENTRY_KEY ) )
- {
- return ENTRY_KEY;
- }
else
{
return null;
@@ -141,14 +115,6 @@
{
return SELECT;
}
- else if( name.startsWith( GET_KEY ) )
- {
- return GET;
- }
- else if( name.startsWith( CREATE_KEY ) )
- {
- return CREATE;
- }
else if( name.startsWith( RELEASE_KEY ) )
{
return RELEASE;
@@ -174,14 +140,7 @@
String name = method.getName();
if( SELECT == semantic )
{
- if( name.endsWith( ENTRY_KEY ) )
- {
- int n = ENTRY_KEY.length();
- int j = name.length() - n;
- String substring = name.substring( 0, j );
- return formatKey( substring, 6 );
- }
- else if( name.endsWith( CONTEXT_MANAGER_KEY ) )
+ if( name.endsWith( CONTEXT_MANAGER_KEY ) )
{
int n = CONTEXT_MANAGER_KEY.length();
int j = name.length() - n;
@@ -195,16 +154,9 @@
String substring = name.substring( 0, j );
return formatKey( substring, 6 );
}
- else if( name.endsWith( PARTS_MANAGER_KEY ) )
- {
- int n = PARTS_MANAGER_KEY.length();
- int j = name.length() - n;
- String substring = name.substring( 0, j );
- return formatKey( substring, 6 );
- }
- else if( name.endsWith( PARTS_MAP_KEY ) )
+ else if( name.endsWith( MODEL_KEY ) )
{
- int n = PARTS_MAP_KEY.length();
+ int n = MODEL_KEY.length();
int j = name.length() - n;
String substring = name.substring( 0, j );
return formatKey( substring, 6 );
@@ -216,26 +168,11 @@
String substring = name.substring( 0, j );
return formatKey( substring, 6 );
}
- else if( name.endsWith( MODEL_KEY ) )
- {
- int n = MODEL_KEY.length();
- int j = name.length() - n;
- String substring = name.substring( 0, j );
- return formatKey( substring, 6 );
- }
else
{
return formatKey( name, 6 );
}
}
- else if( GET == semantic )
- {
- return formatKey( name, 3 );
- }
- else if( CREATE == semantic )
- {
- return formatKey( name, 6 );
- }
else if( RELEASE == semantic )
{
return formatKey( name, 7 );
@@ -496,16 +433,10 @@
{
String string = method.substring( offset );
return formatKey( string );
- }
+ }

private static String formatKey( String key )
{
- if( key.length() < 1 )
- {
- throw new IllegalArgumentException( "key" );
- }
- String first = key.substring( 0, 1 ).toLowerCase();
- String remainder = key.substring( 1 );
- return first + remainder;
+ return Introspector.decapitalize( key );
}
}

Modified:
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java
==============================================================================
---
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java
(original)
+++
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/PartDescriptorTestCase.java
Fri Apr 22 23:49:48 2005
@@ -41,7 +41,7 @@
{
private static final String m_key = "key";
private static final String m_type = PartDescriptor.class.getName();
- private static final int m_semantic = PartDescriptor.GET;
+ private static final int m_semantic = PartDescriptor.SELECT;
private static final Operation m_operation = new Operation( m_semantic,
m_type );
private static final Operation[] m_operations = new Operation[]{
m_operation };


Modified:
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
==============================================================================
---
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
(original)
+++
development/main/metro/meta/api/src/test/net/dpml/meta/info/test/TypeTestCase.java
Fri Apr 22 23:49:48 2005
@@ -87,7 +87,7 @@
};
m_defaults = new DefaultConfiguration("default");
m_parts = new PartDescriptor[] {
- new PartDescriptor( "key", new Operation[]{ new Operation(
PartDescriptor.GET, ReferenceDescriptor.class.getName() ) } )
+ new PartDescriptor( "key", new Operation[]{ new Operation(
PartDescriptor.SELECT, ReferenceDescriptor.class.getName() ) } )
};
}


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
Fri Apr 22 23:49:48 2005
@@ -53,4 +53,10 @@
*/
Manager getManager() throws Exception;

+ /**
+ * Return a Manager for an identified instance.
+ * @param id the instance identity
+ */
+ Manager getManager( Object id ) throws Exception;
+
}



  • svn commit: r2358 - 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/management composition/control/src/main/net/dpml/composition/models composition/control/src/main/net/dpml/composition/state composition/control/src/test/net/dpml/composition/management composition/control/src/test/net/dpml/composition/state composition/testing/acme/src/main/net/dpml/composition/testing composition/testing/unit/src/main/net/dpml/test/state composition/testing/unit/src/test/net/dpml/composition/testing meta/api/src/main/net/dpml/meta/info meta/api/src/test/net/dpml/meta/info/test parts/src/main/net/dpml/parts/model, mcconnell, 04/22/2005

Archive powered by MHonArc 2.6.24.

Top of Page