1 28 29 package org.objectweb.util.launcher.option; 30 31 32 import java.util.Vector ; 33 34 import org.objectweb.util.cmdline.api.Iterator; 35 import org.objectweb.util.cmdline.lib.DefaultOptionArgument; 36 37 import org.objectweb.util.launcher.CommandJava; 38 import org.objectweb.util.launcher.CommandFactory; 39 40 import org.objectweb.util.launcher.parser.Repository; 41 import org.objectweb.util.launcher.parser.RunDescription; 42 import org.objectweb.util.trace.TraceSystem; 43 44 45 55 public class OptionRun 56 extends DefaultOptionArgument 57 implements OptionLauncher 58 { 59 60 public final static String shortTag = "-run" ; 61 62 public final static String longTag = "--runid" ; 63 64 65 protected Vector runs_ ; 66 67 70 public OptionRun() { 71 super(new String []{shortTag, longTag}, 72 "<RunID>", 73 "The identifier of the run to launch", 74 "default"); 75 runs_ = new Vector (); 76 } 77 78 84 protected class RunBuilder { 85 86 protected String argument_ ; 87 88 92 public RunBuilder(String arg) { 93 this.argument_ = arg ; 94 } 95 96 101 protected void completeRun(CommandJava cmd, RunDescription desc) { 102 cmd.setName(desc.getName()); 103 TraceSystem.get("launcher").info("Completing java command " + cmd.getName()); 104 cmd.setClassname(desc.getMainclass()); 105 cmd.setMode(desc.getMode()); 106 try { 107 cmd.getLoader().addURL(desc.getClasses().toStringArray()); 108 } catch (java.net.MalformedURLException ex) { 109 TraceSystem.get("launcher").error("Exception raised: " + ex); 110 } 111 cmd.addArguments(desc.getArguments()); 112 cmd.addProperties(desc.getProperties()); 113 } 114 115 116 122 public CommandJava complete(Repository repository) { 123 CommandJava cmd = CommandFactory.instance().create(); 124 completeRun(cmd,(RunDescription)repository.getDescription(argument_)); 125 return cmd; 126 } 127 } 128 129 130 136 141 public void consume(Iterator iterator) { 142 setArgument(consumeArgument(iterator)); 143 runs_.addElement(new RunBuilder(getArgument())); 144 } 145 146 147 148 154 public CommandJava[] complete(Repository repository) { 155 java.util.Iterator runs = runs_.iterator(); 156 Vector list = new Vector (); 157 while (runs.hasNext()) 158 list.addElement(((RunBuilder)runs.next()).complete(repository)); 159 return (CommandJava[])list.toArray(new CommandJava[0]); 160 } 161 162 167 public static String create(String run) { 168 return shortTag+" "+run+" " ; 169 } 170 } 171 | Popular Tags |