util.rmi
Class GenericInvoke

java.lang.Object
  extended by util.CommandLineParser
      extended by util.rmi.GenericInvoke

public class GenericInvoke
extends CommandLineParser

A class that allows very generic access to objects bound in the registry. The user can query and execute methods on any object bound. It requires profound knowledge of the object bound to invoke the correct methods with the correct arguments. It understands the following command line switches:

The binding name of the object that should be queried/invoked is the command name, as defined in the parental class. Calling the class without a -m switch dumps information of the bound object to system.out.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.CommandLineParser
CommandLineParser.Test
 
Field Summary
private static String FOOT
          A footer message.
private static String ONESWITCH
          The switch for the method name.
private static String THREESWITCH
          The switch for adding an object constructed via class name.
private static String TWOSWITCH
          The switches for adding objects as arguments to the method.
private static Map<String,String> USE
          Detailed use of switches.
 
Constructor Summary
GenericInvoke()
          Constructs the parser to the generic invocation class.
 
Method Summary
private static Field[] getFields(Remote rmi)
          Returns all implemented fields of the remote object.
private static Class getImplementation(Remote rmi)
          Returns the implementing class of a remote object.
private static Method[] getMethods(Remote rmi)
          Returns all implemented methods of the class.
private static Object invoke(Remote rmi, Method call, Object[] arg)
          Invokes the specified method.
static void main(String[] arg)
          Scans the command line arguments for the method to invoke.
 Object process(String[] arg)
          Parses the command line and invokes the specified method.
private static Method scanForMethod(Remote rmi, String name, Object[] arg)
          Scans all methods implemented by the remote argument for the one that matches the method name stated.
static void scanRemote(Remote rmi)
          Prints out generic information about the methods and fields available for the remote stated.
 
Methods inherited from class util.CommandLineParser
getArguments, getCommandLine, getCommands, getRegisteredSwitches, hasAnySwitch, hasSwitch, hasSwitch, haveAllSwitches, parse, printCommandLine, registerLine, registerSwitches, setCommands, staticUsage, usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONESWITCH

private static final String ONESWITCH
The switch for the method name.

See Also:
Constant Field Values

TWOSWITCH

private static final String TWOSWITCH
The switches for adding objects as arguments to the method.

See Also:
Constant Field Values

THREESWITCH

private static final String THREESWITCH
The switch for adding an object constructed via class name.

See Also:
Constant Field Values

USE

private static final Map<String,String> USE
Detailed use of switches.


FOOT

private static final String FOOT
A footer message.

See Also:
Constant Field Values
Constructor Detail

GenericInvoke

public GenericInvoke()
Constructs the parser to the generic invocation class. The living object is only needed for parsing the command line switches.

Method Detail

process

public Object process(String[] arg)
               throws ParseException,
                      NotBoundException,
                      RemoteException,
                      MalformedURLException,
                      ClassNotFoundException,
                      NoSuchMethodException,
                      InstantiationException,
                      IllegalAccessException,
                      InvocationTargetException
Parses the command line and invokes the specified method.

Throws:
ParseException
NotBoundException
RemoteException
MalformedURLException
ClassNotFoundException
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException

getImplementation

private static Class getImplementation(Remote rmi)
Returns the implementing class of a remote object.


getMethods

private static Method[] getMethods(Remote rmi)
Returns all implemented methods of the class.


getFields

private static Field[] getFields(Remote rmi)
Returns all implemented fields of the remote object.


scanForMethod

private static Method scanForMethod(Remote rmi,
                                    String name,
                                    Object[] arg)
                             throws NoSuchMethodException,
                                    InstantiationException,
                                    IllegalAccessException,
                                    InvocationTargetException
Scans all methods implemented by the remote argument for the one that matches the method name stated. Additionally, the supplied array of Objects is tested to be complieable with the method arguments. If the an object passed to this method is a string and does not match the required class, this required class is scanned if it has a single-string constructor. In the latter case, the method argument is thought compliant.

Parameters:
rmi - The remote object hosting the method.
name - The name of the method.
arg - The arguments to the method. For no arguments supply an empty array.
Returns:
The single matching method.
Throws:
IllegalArgumentException - If more than one methods match.
NullPointerException - If no method was found
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException

invoke

private static Object invoke(Remote rmi,
                             Method call,
                             Object[] arg)
                      throws NoSuchMethodException,
                             InstantiationException,
                             IllegalAccessException,
                             InvocationTargetException
Invokes the specified method. If the parameters required by this method do not match the stated arguments, the argument is a string and the parameter can be constructed with a single-string argument, the argument is replaced with the result of this construction.

Throws:
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException

scanRemote

public static void scanRemote(Remote rmi)
Prints out generic information about the methods and fields available for the remote stated. Invoked from the main method if no -m switch was found.


main

public static void main(String[] arg)
                 throws Exception
Scans the command line arguments for the method to invoke. Arguments may be supplied to the method call using the specific switches. For a brief summary, call main without arguments.

Throws:
Exception