|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.fhg.igd.semoa.bin.Configure
Derives option descriptor string compatible to
ArgsParser from a given class, and supports
invocation of method calls on objects based on the
parsed options. This class makes heavy use of the
Java Reflection framework.
Options are derived from a class as follows:
For each method with signature public void name()
, an option -name is generated.
For each method with signature public void
setName(type param), an option -Name
<type> is generated. type
must be a type understood by ArgsParser
(array types are allowed, but no arrays of arrays).
Specifying -name will then invoke method
name(), and specifying -Name <args>
will invoke method setName(<args>
) on an instantiated object of the class for
which options were generated.
| Constructor Summary | |
Configure()
|
|
| Method Summary | |
static boolean |
configure(Object target,
String[] argv,
boolean spawn)
Configures target based on the given
arguments and an option descriptor derived from
target by means of Java Reflection. |
static String |
getArgsDescriptor(Class target)
Derives an argument descriptor string from the given class that is suitable for use with an ArgsParser. |
static void |
invoke(Object target,
String m,
boolean spawn)
Invokes a method with name m on
target. |
static void |
invoke(Object target,
String m,
Object[] argv)
Invokes a method on target with the arguments
in argv. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Configure()
| Method Detail |
public static boolean configure(Object target,
String[] argv,
boolean spawn)
throws ArgsParserException,
NoSuchMethodException,
InvocationTargetException,
IllegalAccessException
target based on the given
arguments and an option descriptor derived from
target by means of Java Reflection.
target - The object on which methods are invoked.argv - The command line options.spawn - If true and target
is a Runnable and "-run" is
specified as an option then target is
run in a separate thread.
ArgsParserException
NoSuchMethodException
InvocationTargetException
IllegalAccessException
public static void invoke(Object target,
String m,
boolean spawn)
throws NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
m on
target. The invoked method must be
public and not static, and it
must have no parameters. The return type is ignored.
target - The object whose methods are invoked.m - The name of the method that is invoked. The
method must have no arguments and void
as the return type. Furthermore it must be
public and not static.spawn - If true and target
is Runnable and m
equals "run" then target is
run in a separate thread.
NoSuchMethodException
IllegalAccessException
InvocationTargetException
public static void invoke(Object target,
String m,
Object[] argv)
throws NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
target with the arguments
in argv. The name of the method is created by
prepending m with "set", and the
signature of the method is determined by the types of the
arguments.
NoSuchMethodException
IllegalAccessException
InvocationTargetExceptionpublic static String getArgsDescriptor(Class target)
ArgsParser.
The args descriptor can be used to parse options that
correspond to public setter methods and simple invocations
of the given class.
ArgsParser. The descriptor defines options for all
public setter methods with a single argument that can
be parsed by ArgsParser (arrays of arrays
are not allowed), and for public methods with no
arguments and a return type of void.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||