de.fhg.igd.semoa.bin
Class Configure

java.lang.Object
  extended byde.fhg.igd.semoa.bin.Configure

public class Configure
extends Object

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.

Version:
"$Id: Configure.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth

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

Configure

public Configure()
Method Detail

configure

public static boolean configure(Object target,
                                String[] argv,
                                boolean spawn)
                         throws ArgsParserException,
                                NoSuchMethodException,
                                InvocationTargetException,
                                IllegalAccessException
Configures target based on the given arguments and an option descriptor derived from target by means of Java Reflection.

Parameters:
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.
Throws:
ArgsParserException
NoSuchMethodException
InvocationTargetException
IllegalAccessException

invoke

public static void invoke(Object target,
                          String m,
                          boolean spawn)
                   throws NoSuchMethodException,
                          IllegalAccessException,
                          InvocationTargetException
Invokes a method with name m on target. The invoked method must be public and not static, and it must have no parameters. The return type is ignored.

Parameters:
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.
Throws:
NoSuchMethodException
IllegalAccessException
InvocationTargetException

invoke

public static void invoke(Object target,
                          String m,
                          Object[] argv)
                   throws NoSuchMethodException,
                          IllegalAccessException,
                          InvocationTargetException
Invokes a method on 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.

Throws:
NoSuchMethodException
IllegalAccessException
InvocationTargetException

getArgsDescriptor

public static String getArgsDescriptor(Class target)
Derives an argument descriptor string from the given class that is suitable for use with an ArgsParser. The args descriptor can be used to parse options that correspond to public setter methods and simple invocations of the given class.

Returns:
A descriptor string for use with 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.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.