Commit in lcio/src/java/hep/lcio on MAIN
example/SimJob.java+2-21.21 -> 1.22
util/RunCommandHandler.java+73added 1.1
    /CommandLineTool.java+5-31.16 -> 1.17
+80-5
1 added + 2 modified, total 3 files
add run command to run example classes (requested by Tony)

lcio/src/java/hep/lcio/example
SimJob.java 1.21 -> 1.22
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
RunCommandHandler.java added at 1.1
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
CommandLineTool.java 1.16 -> 1.17
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());
 	}
 	
 	/**
CVSspam 0.2.8