1 26 package org.coach.actor.commandline; 27 28 import org.objectweb.util.cmdline.lib.ApplicationBase; 29 import org.objectweb.util.cmdline.lib.DefaultCommandLine; 30 import org.objectweb.util.misc.api.ExceptionWrapper; 31 import org.coach.actor.Main; 32 import java.io.File ; 33 import java.util.Vector ; 34 import java.util.List ; 35 36 42 public class ActorApplication extends ApplicationBase implements DefaultApplication, ConfigApplication { 43 44 45 protected String actor_ = ""; 46 47 48 protected String context_ = ""; 49 50 51 protected String config_ = null; 52 53 56 public ActorApplication() { 57 super(new DefaultCommandLine(new String [] { "ccm_actor" }, new String [0], new String [] { "Display the OpenCCM actor console" }, true)); 58 getCommandLine().addOption(new DefaultActorOption(this)); 61 } 63 64 69 private String [] removeORBArgument(String [] args) { 70 int nb = 0; 71 String [] tmp = new String [args.length]; 72 for (int i = 0; i < args.length; i++) { 73 if (!args[i].startsWith("-ORB")) { 74 tmp[nb] = args[i]; 75 nb++; 76 } else { 77 i++; 78 } 79 } 80 String [] tmp2 = new String [nb]; 81 for (int i = 0; i < nb; i++) 82 tmp2[i] = tmp[i]; 83 return tmp2; 84 } 85 86 90 public void setConfigFile(String file) { 91 config_ = file; 92 } 93 94 98 public void setDefaultContextConfigFile(String file) { 99 context_ = file; 100 } 101 102 106 public void setDefaultActorConfigFile(String file) { 107 actor_ = file; 108 } 109 110 114 public void runMain(String [] args) { 115 org.omg.CORBA.ORB orb = org.objectweb.openccm.Components.Runtime.init(args); 117 119 try { 121 String [] arguments = getCommandLine().parse(removeORBArgument(args)); 122 int ret = start(arguments); 123 } catch (ExceptionWrapper exc) { 124 report_exception(exc.getException()); 125 } catch (Exception exc) { 126 report_exception(exc); 127 } 128 } 129 130 134 public int start(String [] args) { 135 List fileList = new Vector (); 136 fileList.add(new File (actor_)); 137 if (config_ != null) { 138 fileList.add(new File (config_)); 139 } 140 new Main(new File (context_), (File []) fileList.toArray(new File [0])); 141 return 0; 142 } 143 144 148 public static void main(String [] args) { 149 ActorApplication application = new ActorApplication(); 150 application.runMain(args); 151 } 152 153 } | Popular Tags |