public static String[] setOptions(Object target,
String[] args) {
ArrayList< String > rc = new ArrayList< String >();
for (int i = 0; i < args.length; i++) {
if (args[i] == null) {
continue;
}
if (args[i].startsWith("--")) {
// --options without a specified value are considered boolean
// flags that are enabled.
String value = "true";
String name = args[i].substring(2);
// if --option=value case
int p = name.indexOf("=");
if (p > 0) {
value = name.substring(p + 1);
name = name.substring(0, p);
}
// name not set, then it's an unrecognized option
if (name.length() == 0) {
rc.add(args[i]);
continue;
}
String propName = convertOptionToPropertyName(name);
if (!IntrospectionSupport.setProperty(target, propName, value)) {
rc.add(args[i]);
continue;
}
} else {
rc.add(args[i]);
}
}
String r[] = new String[rc.size()];
rc.toArray(r);
return r;
}
Sets the properties of an object given the command line args.
if args contains: --ack-mode=AUTO --url=tcp://localhost:61616 --persistent
then it will try to call the following setters on the target object.
target.setAckMode("AUTO");
target.setURL(new URI("tcp://localhost:61616") );
target.setPersistent(true);
Notice the the proper conversion for the argument is determined by examining the
setter arguement type. |