notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r984 - in trunk/main/metro: part/api/src/main/net/dpml/part runtime/src/main/net/dpml/metro/runtime state/api/src/main/net/dpml/state state/impl/src/main/net/dpml/state/impl station/console/src/main/net/dpml/station/console
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r984 - in trunk/main/metro: part/api/src/main/net/dpml/part runtime/src/main/net/dpml/metro/runtime state/api/src/main/net/dpml/state state/impl/src/main/net/dpml/state/impl station/console/src/main/net/dpml/station/console
- Date: Fri, 27 Jan 2006 18:19:31 +0100
Author: mcconnell
Date: 2006-01-27 18:19:29 +0100 (Fri, 27 Jan 2006)
New Revision: 984
Modified:
trunk/main/metro/part/api/src/main/net/dpml/part/ProviderOperations.java
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
trunk/main/metro/state/api/src/main/net/dpml/state/StateMachine.java
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/DefaultStateMachine.java
trunk/main/metro/station/console/src/main/net/dpml/station/console/StationPlugin.java
Log:
add hooks into the state machine to support operation invocation
Modified:
trunk/main/metro/part/api/src/main/net/dpml/part/ProviderOperations.java
===================================================================
--- trunk/main/metro/part/api/src/main/net/dpml/part/ProviderOperations.java
2006-01-27 13:19:05 UTC (rev 983)
+++ trunk/main/metro/part/api/src/main/net/dpml/part/ProviderOperations.java
2006-01-27 17:19:29 UTC (rev 984)
@@ -93,4 +93,16 @@
Object exec( String name, Object[] args )
throws UnknownOperationException, InvocationTargetException,
RemoteException;
+ /**
+ * Invoke an operation on the instance.
+ * @param method the operation name
+ * @param args operation arguments
+ * @return the result of the operation invocation
+ * @exception UnknownOperationException if the supplied key does not map
to an available operation
+ * @exception InvocationTargetException if an invocation error occurs
+ * @exception RemoteException if a remote I/O error occurs
+ */
+ Object invoke( String method, Object[] args )
+ throws UnknownOperationException, InvocationTargetException,
IllegalStateException, RemoteException;
+
}
Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
2006-01-27 13:19:05 UTC (rev 983)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
2006-01-27 17:19:29 UTC (rev 984)
@@ -210,6 +210,21 @@
return m_machine.execute( name, m_value, args );
}
+ /**
+ * Invoke an operation on the instance.
+ * @param method the operation name
+ * @param args operation arguments
+ * @return the result of the operation invocation
+ * @exception UnknownOperationException if the supplied key does not map
to an available operation
+ * @exception InvocationTargetException if an invocation error occurs
+ * @exception RemoteException if a remote I/O error occurs
+ */
+ public Object invoke( String method, Object[] args )
+ throws UnknownOperationException, InvocationTargetException,
IllegalStateException
+ {
+ return m_machine.invoke( m_value, method, args );
+ }
+
//--------------------------------------------------------------------------
// EventProducer
//--------------------------------------------------------------------------
Modified: trunk/main/metro/state/api/src/main/net/dpml/state/StateMachine.java
===================================================================
--- trunk/main/metro/state/api/src/main/net/dpml/state/StateMachine.java
2006-01-27 13:19:05 UTC (rev 983)
+++ trunk/main/metro/state/api/src/main/net/dpml/state/StateMachine.java
2006-01-27 17:19:29 UTC (rev 984)
@@ -85,7 +85,7 @@
State initialize( Object object ) throws InvocationTargetException;
/**
- * Invoke execution of a named operation on the supplied object.
+ * Execute a named operation on the supplied object.
* @param name an operation name
* @param object the target object
* @param args operation argument array
@@ -98,6 +98,20 @@
throws UnknownOperationException, InvocationTargetException;
/**
+ * Invoke a management method on the supplied object.
+ * @param object the target object
+ * @param method the method name
+ * @param args method parameter arguments
+ * @return the return value
+ * @exception IllegalStateException if the method is recognized but not
available
+ * @exception UnknownOperationException if the operation is unknown
+ * @exception InvocationTargetException if an invocation error occurs as
a
+ * result of operation execution
+ */
+ Object invoke( Object object, String method, Object[] args )
+ throws UnknownOperationException, InvocationTargetException,
IllegalStateException;
+
+ /**
* Apply a named state transition.
* @param name the transition name
* @param object the object against which any transition handler action
are to be applied
Modified:
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/DefaultStateMachine.java
===================================================================
---
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/DefaultStateMachine.java
2006-01-27 13:19:05 UTC (rev 983)
+++
trunk/main/metro/state/impl/src/main/net/dpml/state/impl/DefaultStateMachine.java
2006-01-27 17:19:29 UTC (rev 984)
@@ -272,6 +272,39 @@
}
/**
+ * Invoke a management method on the supplied object.
+ * @param object the target object
+ * @param method the method name
+ * @param args method parameter arguments
+ * @return the return value
+ * @exception IllegalStateException if the method is recognized but not
available
+ * @exception UnknownOperationException if the operation is unknown
+ * @exception InvocationTargetException if an invocation error occurs as
a
+ * result of operation execution
+ */
+ public Object invoke( Object object, String method, Object[] args )
+ throws UnknownOperationException, InvocationTargetException,
IllegalStateException
+ {
+ checkDisposed();
+
+ // TODO: validate exposure of declaring interface
+
+ try
+ {
+ Expression expression = new Expression( object, method, args );
+ return expression.getValue();
+ }
+ catch( InvocationTargetException e )
+ {
+ throw e;
+ }
+ catch( Exception e )
+ {
+ throw new InvocationTargetException( e );
+ }
+ }
+
+ /**
* Apply a named transition to the target object.
* @param name the transition name
* @param object the object against which any transition handler action
are to be applied
Modified:
trunk/main/metro/station/console/src/main/net/dpml/station/console/StationPlugin.java
===================================================================
---
trunk/main/metro/station/console/src/main/net/dpml/station/console/StationPlugin.java
2006-01-27 13:19:05 UTC (rev 983)
+++
trunk/main/metro/station/console/src/main/net/dpml/station/console/StationPlugin.java
2006-01-27 17:19:29 UTC (rev 984)
@@ -820,6 +820,55 @@
System.out.println( e.toString() );
}
}
+ else if( commandline.hasOption( CONTROL_INVOKE_COMMAND )
)
+ {
+ String method = (String) commandline.getValues(
CONTROL_INVOKE_COMMAND ).get( 0 );
+ System.out.println( "\napplying operation: " +
method );
+ try
+ {
+ String[] applyArgs = getInvokeArgs( commandline
);
+ Object result =
application.getProvider().invoke( method, applyArgs );
+ if( null != result )
+ {
+ System.out.println( "listing return value\n"
);
+ if( result instanceof Object[] )
+ {
+ Object[] values = (Object[]) result;
+ for( int i=0; i<values.length; i++ )
+ {
+ System.out.println(
values[i].toString() );
+ }
+ }
+ else
+ {
+ System.out.println( result.toString() );
+ }
+ System.out.println( "\ndone" );
+ }
+ else
+ {
+ System.out.println( "done" );
+ }
+ }
+ catch( InvocationTargetException e )
+ {
+ Throwable cause = e.getCause();
+ if( null != cause )
+ {
+ String error =
ExceptionHelper.packException( cause, true );
+ System.out.println( error );
+ }
+ else
+ {
+ String error =
ExceptionHelper.packException( e, true );
+ System.out.println( error );
+ }
+ }
+ catch( Throwable e )
+ {
+ System.out.println( e.toString() );
+ }
+ }
}
catch( Exception e )
{
@@ -832,7 +881,17 @@
private String[] getExecArgs( CommandLine line )
{
- List args = line.getValues( CONTROL_EXEC_COMMAND );
+ return getArgs( CONTROL_EXEC_COMMAND, line );
+ }
+
+ private String[] getInvokeArgs( CommandLine line )
+ {
+ return getArgs( CONTROL_INVOKE_COMMAND, line );
+ }
+
+ private String[] getArgs( Option option, CommandLine line )
+ {
+ List args = line.getValues( option );
String[] elements = (String[]) args.toArray( new String[0] );
if( elements.length < 2 )
{
@@ -873,6 +932,12 @@
Operation operation = operations[i];
System.out.println( " [" + ( i+1 ) + "] " +
operation.getName() );
}
+ Interface[] interfaces = state.getInterfaces();
+ System.out.println( "Interfaces: " + interfaces.length );
+ for( int i=0; i<interfaces.length; i++ )
+ {
+ System.out.println( " [" + ( i+1 ) + "] " + interfaces[i] );
+ }
}
System.out.println( "" );
}
@@ -1666,6 +1731,18 @@
.create() )
.create();
+ private static final Option CONTROL_INVOKE_COMMAND =
+ COMMAND_BUILDER
+ .withName( "invoke" )
+ .withDescription( "Invoke a management operation." )
+ .withArgument(
+ ARGUMENT_BUILDER
+ .withDescription( "Operation name." )
+ .withName( "method" )
+ .withMinimum( 1 )
+ .create() )
+ .create();
+
private static final Option CONTROL_HELP_COMMAND =
COMMAND_BUILDER
.withName( "help" )
@@ -1677,6 +1754,7 @@
.withName( "options" )
.withOption( CONTROL_INFO_COMMAND )
.withOption( CONTROL_APPLY_COMMAND )
+ .withOption( CONTROL_INVOKE_COMMAND )
.withOption( CONTROL_EXEC_COMMAND )
.withOption( CONTROL_EXIT_COMMAND )
.withOption( CONTROL_HELP_COMMAND )
- r984 - in trunk/main/metro: part/api/src/main/net/dpml/part runtime/src/main/net/dpml/metro/runtime state/api/src/main/net/dpml/state state/impl/src/main/net/dpml/state/impl station/console/src/main/net/dpml/station/console, mcconnell at BerliOS, 01/27/2006
Archive powered by MHonArc 2.6.24.