< prev index next >

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

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


 111                 return;
 112             }
 113         }
 114         else
 115             appletName = null;
 116 
 117         setLayout(new GridBagLayout());
 118 
 119         GridBagConstraints c = new GridBagConstraints();
 120 
 121         ActiveModeOptions amo = new ActiveModeOptions();
 122         if (activeHost != null)
 123             amo.setHost(activeHost);
 124         amo.setPort(activePort);
 125 
 126         PassiveModeOptions pmo = new PassiveModeOptions();
 127         pmo.setPort(passivePort);
 128 
 129         ModeOptions smo = null;
 130         try {
 131             Class serial = Class.forName("com.sun.javatest.agent.SerialPortModeOptions");
 132             smo = (ModeOptions)serial.newInstance();
 133         } catch (Exception e) {
 134             System.err.println("There is no support for serial port");
 135         }
 136         if (serialPort != null){
 137             try {
 138                 Method setPortMethod = smo.getClass().getMethod("setPort", String.class);
 139                 setPortMethod.invoke(smo, serialPort);
 140             }
 141             catch (SecurityException | NoSuchMethodException |
 142                     IllegalArgumentException| InvocationTargetException |
 143                     IllegalAccessException e) {
 144                 System.err.println("Could not set serial port:");
 145                 e.printStackTrace();
 146             }
 147         }
 148 
 149         ModeOptions[] modeOptions = new ModeOptions[] {amo, pmo, smo};
 150 
 151         AgentPanel.MapReader mapReader = new AgentPanel.MapReader() {
 152             public Map read(String name) throws IOException {
 153                 if (name == null || name.length() == 0)
 154                     return null;
 155                 else {
 156                     Map m = Map.readURL(new URL(getDocumentBase(), name));
 157                     m.setTracing(tracing, System.out);
 158                     return m;
 159                 }
 160             }
 161         };
 162         AgentPanel ap = new AgentPanel(modeOptions, mapReader);
 163 
 164         if (observerClassName != null) {
 165             try {
 166                 Class observerClass = Class.forName(observerClassName);
 167                 Agent.Observer observer = (Agent.Observer)(observerClass.newInstance());
 168                 ap.addObserver(observer);
 169             }
 170             catch (ClassCastException e) {
 171                 showStatus("observer is not of type " +
 172                         Agent.Observer.class.getName() + ": " + observerClassName);
 173             }
 174             catch (ClassNotFoundException e) {
 175                 showStatus("cannot find observer class: " + observerClassName);
 176             }
 177             catch (IllegalAccessException e) {
 178                 showStatus("problem instantiating observer: " + e);
 179             }
 180             catch (InstantiationException e) {
 181                 showStatus("problem instantiating observer: " + e);
 182             }
 183         }
 184 
 185         ap.setMode(mode);
 186         ap.setConcurrency(concurrency);




 111                 return;
 112             }
 113         }
 114         else
 115             appletName = null;
 116 
 117         setLayout(new GridBagLayout());
 118 
 119         GridBagConstraints c = new GridBagConstraints();
 120 
 121         ActiveModeOptions amo = new ActiveModeOptions();
 122         if (activeHost != null)
 123             amo.setHost(activeHost);
 124         amo.setPort(activePort);
 125 
 126         PassiveModeOptions pmo = new PassiveModeOptions();
 127         pmo.setPort(passivePort);
 128 
 129         ModeOptions smo = null;
 130         try {
 131             Class<?> serial = Class.forName("com.sun.javatest.agent.SerialPortModeOptions");
 132             smo = (ModeOptions)serial.newInstance();
 133         } catch (Exception e) {
 134             System.err.println("There is no support for serial port");
 135         }
 136         if (serialPort != null){
 137             try {
 138                 Method setPortMethod = smo.getClass().getMethod("setPort", String.class);
 139                 setPortMethod.invoke(smo, serialPort);
 140             }
 141             catch (SecurityException | NoSuchMethodException |
 142                     IllegalArgumentException| InvocationTargetException |
 143                     IllegalAccessException e) {
 144                 System.err.println("Could not set serial port:");
 145                 e.printStackTrace();
 146             }
 147         }
 148 
 149         ModeOptions[] modeOptions = new ModeOptions[] {amo, pmo, smo};
 150 
 151         AgentPanel.MapReader mapReader = new AgentPanel.MapReader() {
 152             public Map read(String name) throws IOException {
 153                 if (name == null || name.length() == 0)
 154                     return null;
 155                 else {
 156                     Map m = Map.readURL(new URL(getDocumentBase(), name));
 157                     m.setTracing(tracing, System.out);
 158                     return m;
 159                 }
 160             }
 161         };
 162         AgentPanel ap = new AgentPanel(modeOptions, mapReader);
 163 
 164         if (observerClassName != null) {
 165             try {
 166                 Class<?> observerClass = Class.forName(observerClassName);
 167                 Agent.Observer observer = (Agent.Observer)(observerClass.newInstance());
 168                 ap.addObserver(observer);
 169             }
 170             catch (ClassCastException e) {
 171                 showStatus("observer is not of type " +
 172                         Agent.Observer.class.getName() + ": " + observerClassName);
 173             }
 174             catch (ClassNotFoundException e) {
 175                 showStatus("cannot find observer class: " + observerClassName);
 176             }
 177             catch (IllegalAccessException e) {
 178                 showStatus("problem instantiating observer: " + e);
 179             }
 180             catch (InstantiationException e) {
 181                 showStatus("problem instantiating observer: " + e);
 182             }
 183         }
 184 
 185         ap.setMode(mode);
 186         ap.setConcurrency(concurrency);


< prev index next >