Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2316 - in development/main/metro: composition/testing/activity/src/main/net/dpml/test state/impl/src/main/net/dpml/state/impl

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: r2316 - in development/main/metro: composition/testing/activity/src/main/net/dpml/test state/impl/src/main/net/dpml/state/impl
  • Date: Mon, 18 Apr 2005 19:22:30 -0400

Author: mcconnell AT dpml.net
Date: Mon Apr 18 19:22:27 2005
New Revision: 2316

Modified:

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

development/main/metro/state/impl/src/main/net/dpml/state/impl/AbstractStateManager.java
Log:
Add support for registered transition handlers and the corresponding
"handler:[key]" protocol.

Modified:
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Component.java
==============================================================================
---
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Component.java
(original)
+++
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Component.java
Mon Apr 18 19:22:27 2005
@@ -78,6 +78,22 @@
{
return STATE;
}
+
+ public void initialize() throws Exception
+ {
+ //
+ // An example of the registration of a handler instance
+ //
+
+ ExampleHandler terminator = new ExampleHandler( "terminator" );
+ addRegisteredHandler( "terminate", terminator );
+
+ //
+ // continue with normal initialization
+ //
+
+ super.initialize();
+ }
}

private Logger getLogger()
@@ -140,7 +156,7 @@
try
{
URI initialize = new URI( "method:null" );
- URI terminate = new URI( "method:terminate" );
+ URI terminate = new URI( "handler:terminate" );
URI start = new URI( "method:start" );
URI stop = new URI( "method:stop" );

@@ -170,4 +186,31 @@

return root;
}
+
+ //
+ // The following class is an example of a transition handler. Instances
+ // of this class may be registered with the state manager and referend
in
+ // transition via the urn "handler:[key]".
+ //
+
+ public static class ExampleHandler
+ {
+ final String m_name;
+
+ public ExampleHandler( String name )
+ {
+ m_name = name;
+ }
+
+ public void handle( Component instance, State state, State target,
Logger logger )
+ {
+ final String message =
+ "transitioning to ["
+ + target.getName()
+ + "] via handler ["
+ + m_name
+ + "]";
+ logger.info( message );
+ }
+ }
}

Modified:
development/main/metro/state/impl/src/main/net/dpml/state/impl/AbstractStateManager.java
==============================================================================
---
development/main/metro/state/impl/src/main/net/dpml/state/impl/AbstractStateManager.java
(original)
+++
development/main/metro/state/impl/src/main/net/dpml/state/impl/AbstractStateManager.java
Mon Apr 18 19:22:27 2005
@@ -84,10 +84,13 @@

/**
* Return an registered transition 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
+ protected Object getRegisteredHandler( String key ) throws
NoSuchHandlerException
{
if( null == key )
{
@@ -101,7 +104,21 @@
return handler;
}

- protected void addHandler( String key, Object handler )
+ /**
+ * Register a transtion handler with the manager. The handler object must
+ * implement a publically accessible method named 'handle'. Method
parameters
+ * may include java.net.Logger, up to two occurance of
net.dpml.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 option.
+ *
+ * @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
+ */
+ protected void addRegisteredHandler( String key, Object handler )
{
if( null == key )
{
@@ -277,13 +294,26 @@

throw new UnsupportedOperationException( uri.toString() );
}
- else if( "handler".equals( uri ) )
+ else if( "handler".equals( scheme ) )
{
//
// delegate execution to an registered handler
//

- throw new UnsupportedOperationException( uri.toString() );
+ String spec = uri.getSchemeSpecificPart();
+ if( "null".equals( spec ) )
+ {
+ return;
+ }
+ else
+ {
+ Object h = getRegisteredHandler( spec );
+ Class c = h.getClass();
+ Method method = locateMethod( c, "handle" );
+ Class[] parameters = method.getParameterTypes();
+ Object[] args = resolveArguments( parameters, state,
target, logger );
+ method.invoke( h, args );
+ }
}
else if( "method".equals( scheme ) )
{



  • svn commit: r2316 - in development/main/metro: composition/testing/activity/src/main/net/dpml/test state/impl/src/main/net/dpml/state/impl, mcconnell, 04/18/2005

Archive powered by MHonArc 2.6.24.

Top of Page