lcio/src/java/hep/lcio/example
diff -u -r1.21 -r1.22
--- SimJob.java 8 Nov 2007 19:35:37 -0000 1.21
+++ SimJob.java 30 Jun 2010 17:35:30 -0000 1.22
@@ -15,7 +15,7 @@
/**
*
* @author Tony Johnson
- * @version $Id: SimJob.java,v 1.21 2007/11/08 19:35:37 gaede Exp $
+ * @version $Id: SimJob.java,v 1.22 2010/06/30 17:35:30 jeremy Exp $
*/
public class SimJob
{
@@ -31,7 +31,7 @@
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException
- {
+ {
if (args.length == 0)
help();
lcio/src/java/hep/lcio/util
diff -N RunCommandHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RunCommandHandler.java 30 Jun 2010 17:35:30 -0000 1.1
@@ -0,0 +1,73 @@
+package hep.lcio.util;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: RunCommandHandler.java,v 1.1 2010/06/30 17:35:30 jeremy Exp $
+ */
+public class RunCommandHandler extends CommandHandler
+{
+ String className;
+ List<String> args;
+
+ public RunCommandHandler()
+ {
+ super("run", "Run a class in the LCIO jar.");
+ }
+
+ public void execute() throws Exception
+ {
+ // Get the class and make a new instance.
+ Class klass = Class.forName(className);
+ Object object = klass.newInstance();
+
+ // Find the main method to be called.
+ Method mainMethod = null;
+ for (Method method : klass.getMethods())
+ {
+ // Check if this looks like the main method.
+ // FIXME: Could have overloaded main methods with different signature,
+ // so need to check for single String array as parameter.
+ if (method.getName().equals("main"))
+ {
+ int modifiers = method.getModifiers();
+ Modifier modifier = new Modifier();
+ if (modifier.isStatic(modifiers) && modifier.isPublic(modifiers))
+ {
+ mainMethod = method;
+ break;
+ }
+ }
+ }
+
+ // Setup the arguments and invoke the main routine.
+ Object pargs[] = new Object[1];
+ pargs[0] = args.toArray(new String[0]);
+ mainMethod.invoke(object, pargs);
+ }
+
+ public void parse(String[] argv) throws Exception
+ {
+ if (argv.length < 1)
+ throw new RuntimeException("Not enough arguments. Missing class name to run.");
+
+ // Get class name to run.
+ className = argv[0];
+
+ // New argument list.
+ args = new ArrayList<String>();
+
+ // Add command line arguments.
+ if (argv.length > 1)
+ {
+ for (int i=1; i<argv.length; i++)
+ {
+ args.add(argv[i]);
+ }
+ }
+ }
+}
\ No newline at end of file
lcio/src/java/hep/lcio/util
diff -u -r1.16 -r1.17
--- CommandLineTool.java 6 Feb 2008 23:37:39 -0000 1.16
+++ CommandLineTool.java 30 Jun 2010 17:35:30 -0000 1.17
@@ -51,11 +51,12 @@
*
* @see hep.lcio.util.PrintEvent print
* -dump lcio file (similar to C++ dump cmd)
- *
- * FIXME: Implement all of the above commands.
+ *
+ * @see hep.lcio.util.RunCommandHandler
+ * -run a class within the LCIO distribution
*
* @author jeremym
- * @version $Id: CommandLineTool.java,v 1.16 2008/02/06 23:37:39 jeremy Exp $
+ * @version $Id: CommandLineTool.java,v 1.17 2010/06/30 17:35:30 jeremy Exp $
*/
public class CommandLineTool
{
@@ -101,6 +102,7 @@
addCommandHandler(new PrintCommandHandler());
addCommandHandler(new SelectCommandHandler());
addCommandHandler(new SizeCommandHandler());
+ addCommandHandler(new RunCommandHandler());
}
/**