< prev index next >

src/com/sun/javatest/agent/AgentFrame.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  77      */
  78     public static void main(String[] args) {
  79         ModeOptions mode = null;
  80         String activeHost = null;
  81         int activePort = -1;
  82         int passivePort = -1;
  83         String serialPort = null;
  84         int concurrency = -1;
  85         String mapFile = null;
  86         int history = -1;
  87         boolean start = false;
  88         boolean useSharedFrame = true;
  89         String observerClassName = null;
  90         boolean tracing = false;
  91 
  92         ActiveModeOptions amo = new ActiveModeOptions();
  93         PassiveModeOptions pmo = new PassiveModeOptions();
  94         ModeOptions smo = null;
  95 
  96         try {
  97             Class serial = Class.forName("com.sun.javatest.agent.SerialPortModeOptions");
  98             smo = (ModeOptions)serial.newInstance();
  99         } catch (Exception e) {
 100             System.err.println("There is no support for serial port");
 101         }
 102 
 103         for (int i = 0; i < args.length; i++) {
 104             try {
 105                 if (args[i].equalsIgnoreCase("-active")) {
 106                     mode = amo;
 107                 }
 108                 else if (args[i].equalsIgnoreCase("-passive")) {
 109                     mode = pmo;
 110                 }
 111                 else if (args[i].equalsIgnoreCase("-activeHost")) {
 112                     mode = amo;
 113                     activeHost = args[++i];
 114                 }
 115                 else if (args[i].equalsIgnoreCase("-activePort")) {
 116                     mode = amo;
 117                     activePort = Integer.parseInt(args[++i]);


 191                 try {
 192                     Method setPortMethod = smo.getClass().getMethod("setPort", String.class);
 193                     setPortMethod.invoke(smo, serialPort);
 194                 }
 195                 catch (SecurityException | NoSuchMethodException |
 196                         IllegalArgumentException| InvocationTargetException |
 197                         IllegalAccessException e) {
 198                     System.err.println("Could not set serial port:");
 199                     e.printStackTrace();
 200                 }
 201             }
 202         }
 203 
 204 
 205         ModeOptions[] modeOptions = new ModeOptions[] {amo, pmo, smo};
 206 
 207         final AgentFrame sf = new AgentFrame(modeOptions);
 208 
 209         if (observerClassName != null) {
 210             try {
 211                 Class observerClass = Class.forName(observerClassName);
 212                 Agent.Observer observer = (Agent.Observer)(observerClass.newInstance());
 213                 sf.panel.addObserver(observer);
 214             }
 215             catch (ClassCastException e) {
 216                 System.err.println("observer is not of type " +
 217                         Agent.Observer.class.getName() + ": " + observerClassName);
 218                 System.exit(1);
 219             }
 220             catch (ClassNotFoundException e) {
 221                 System.err.println("cannot find observer class: " + observerClassName);
 222                 System.exit(1);
 223             }
 224             catch (IllegalAccessException e) {
 225                 System.err.println("problem instantiating observer: " + e);
 226                 System.exit(1);
 227             }
 228             catch (InstantiationException e) {
 229                 System.err.println("problem instantiating observer: " + e);
 230                 System.exit(1);
 231             }


 244             sp.setConcurrency(concurrency);
 245 
 246         if (mapFile != null)
 247             sp.setMapFile(mapFile);
 248 
 249         if (history != -1)
 250             sp.setHistoryLimit(history);
 251 
 252         Integer delay = Integer.getInteger("agent.retry.delay");
 253         if (delay != null)
 254             sp.setRetryDelay(delay.intValue());
 255 
 256         // install our own permissive security manager, to prevent anyone else
 257         // installing a less permissive one; moan if it can't be installed.
 258         JavaTestSecurityManager.install();
 259 
 260         if (start)
 261             sp.start();
 262 
 263         try {
 264             Method invokeLater = EventQueue.class.getMethod("invokeLater", new Class[] { Runnable.class });
 265             invokeLater.invoke(null, new Object[] { new Runnable() {
 266                     public void run() {
 267                         sf.showCentered();
 268                     }
 269                 } });
 270         }
 271         catch (NoSuchMethodException e) {
 272             // must be JDK 1.1
 273             sf.showCentered();
 274         }
 275         catch (Throwable t) {
 276             t.printStackTrace();
 277         }
 278 
 279     }
 280 
 281     /**
 282      * Display the set of options recognized by main(), and exit.
 283      *
 284      * @param out       The output stream to which to write the




  77      */
  78     public static void main(String[] args) {
  79         ModeOptions mode = null;
  80         String activeHost = null;
  81         int activePort = -1;
  82         int passivePort = -1;
  83         String serialPort = null;
  84         int concurrency = -1;
  85         String mapFile = null;
  86         int history = -1;
  87         boolean start = false;
  88         boolean useSharedFrame = true;
  89         String observerClassName = null;
  90         boolean tracing = false;
  91 
  92         ActiveModeOptions amo = new ActiveModeOptions();
  93         PassiveModeOptions pmo = new PassiveModeOptions();
  94         ModeOptions smo = null;
  95 
  96         try {
  97             Class<?> serial = Class.forName("com.sun.javatest.agent.SerialPortModeOptions");
  98             smo = (ModeOptions)serial.newInstance();
  99         } catch (Exception e) {
 100             System.err.println("There is no support for serial port");
 101         }
 102 
 103         for (int i = 0; i < args.length; i++) {
 104             try {
 105                 if (args[i].equalsIgnoreCase("-active")) {
 106                     mode = amo;
 107                 }
 108                 else if (args[i].equalsIgnoreCase("-passive")) {
 109                     mode = pmo;
 110                 }
 111                 else if (args[i].equalsIgnoreCase("-activeHost")) {
 112                     mode = amo;
 113                     activeHost = args[++i];
 114                 }
 115                 else if (args[i].equalsIgnoreCase("-activePort")) {
 116                     mode = amo;
 117                     activePort = Integer.parseInt(args[++i]);


 191                 try {
 192                     Method setPortMethod = smo.getClass().getMethod("setPort", String.class);
 193                     setPortMethod.invoke(smo, serialPort);
 194                 }
 195                 catch (SecurityException | NoSuchMethodException |
 196                         IllegalArgumentException| InvocationTargetException |
 197                         IllegalAccessException e) {
 198                     System.err.println("Could not set serial port:");
 199                     e.printStackTrace();
 200                 }
 201             }
 202         }
 203 
 204 
 205         ModeOptions[] modeOptions = new ModeOptions[] {amo, pmo, smo};
 206 
 207         final AgentFrame sf = new AgentFrame(modeOptions);
 208 
 209         if (observerClassName != null) {
 210             try {
 211                 Class<?> observerClass = Class.forName(observerClassName);
 212                 Agent.Observer observer = (Agent.Observer)(observerClass.newInstance());
 213                 sf.panel.addObserver(observer);
 214             }
 215             catch (ClassCastException e) {
 216                 System.err.println("observer is not of type " +
 217                         Agent.Observer.class.getName() + ": " + observerClassName);
 218                 System.exit(1);
 219             }
 220             catch (ClassNotFoundException e) {
 221                 System.err.println("cannot find observer class: " + observerClassName);
 222                 System.exit(1);
 223             }
 224             catch (IllegalAccessException e) {
 225                 System.err.println("problem instantiating observer: " + e);
 226                 System.exit(1);
 227             }
 228             catch (InstantiationException e) {
 229                 System.err.println("problem instantiating observer: " + e);
 230                 System.exit(1);
 231             }


 244             sp.setConcurrency(concurrency);
 245 
 246         if (mapFile != null)
 247             sp.setMapFile(mapFile);
 248 
 249         if (history != -1)
 250             sp.setHistoryLimit(history);
 251 
 252         Integer delay = Integer.getInteger("agent.retry.delay");
 253         if (delay != null)
 254             sp.setRetryDelay(delay.intValue());
 255 
 256         // install our own permissive security manager, to prevent anyone else
 257         // installing a less permissive one; moan if it can't be installed.
 258         JavaTestSecurityManager.install();
 259 
 260         if (start)
 261             sp.start();
 262 
 263         try {
 264             Method invokeLater = EventQueue.class.getMethod("invokeLater", new Class<?>[] { Runnable.class });
 265             invokeLater.invoke(null, new Object[] { new Runnable() {
 266                     public void run() {
 267                         sf.showCentered();
 268                     }
 269                 } });
 270         }
 271         catch (NoSuchMethodException e) {
 272             // must be JDK 1.1
 273             sf.showCentered();
 274         }
 275         catch (Throwable t) {
 276             t.printStackTrace();
 277         }
 278 
 279     }
 280 
 281     /**
 282      * Display the set of options recognized by main(), and exit.
 283      *
 284      * @param out       The output stream to which to write the


< prev index next >