1 23 package org.objectweb.clif.scenario.util.isac.plugin; 24 25 import java.io.FileInputStream ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.util.Enumeration ; 29 import java.util.Hashtable ; 30 import java.util.Properties ; 31 import java.util.Vector ; 32 33 import javax.xml.parsers.SAXParser ; 34 import javax.xml.parsers.SAXParserFactory ; 35 36 import org.apache.log4j.Category; 37 import org.objectweb.clif.scenario.util.isac.FileName; 38 import org.objectweb.clif.scenario.util.isac.plugin.gui.PluginGUIManager; 39 import org.objectweb.clif.scenario.util.isac.plugin.parser.AnalyseSaxPlugin; 40 import org.objectweb.clif.scenario.util.isac.util.tree.Node; 41 import org.objectweb.clif.scenario.util.isac.util.tree.NodeDescription; 42 import org.objectweb.clif.scenario.util.isac.util.xml.IsacEntityResolver; 43 import org.xml.sax.InputSource ; 44 import org.xml.sax.XMLReader ; 45 51 public class PluginDescription { 52 static Category cat = Category.getInstance(PluginDescription.class 53 .getName()); 54 private String name; 55 private Hashtable samples; 56 private Hashtable tests; 57 private Hashtable timers; 58 private ObjectDescription object; 59 private Vector help; 60 61 73 public PluginDescription(String name, Hashtable s, 74 Hashtable tests, Hashtable t, ObjectDescription o, Vector h) { 75 cat.debug("-> constructor"); 76 this.name = name; 77 this.samples = s; 78 this.tests = tests; 79 this.timers = t; 80 this.object = o; 81 this.help = h; 82 } 83 84 90 public Vector createNodesDescriptions(String type) { 91 cat.debug("-> createNodesDescriptions"); 92 Vector result = new Vector (); 93 if (type.equals(Node.SAMPLE)) { 94 Enumeration e = this.samples.elements(); 95 while (e.hasMoreElements()) { 96 NodeDescription temp = new NodeDescription(Node.SAMPLE); 97 temp.setPlugin(this.name); 98 SampleDescription tempSample = (SampleDescription) e 99 .nextElement(); 100 tempSample.createNodeDescription(temp); 101 result.add(temp); 102 } 103 return result; 104 } 105 if (type.equals(Node.TIMER)) { 106 Enumeration e = this.timers.elements(); 107 while (e.hasMoreElements()) { 108 NodeDescription temp = new NodeDescription(Node.TIMER); 109 temp.setPlugin(this.name); 110 ((TimerDescription) e.nextElement()) 111 .createNodeDescription(temp); 112 result.add(temp); 113 } 114 return result; 115 } 116 if (type.equals(Node.TEST)) { 117 Enumeration e = this.tests.elements(); 118 while (e.hasMoreElements()) { 119 NodeDescription temp = new NodeDescription(Node.TEST); 120 temp.setPlugin(this.name); 121 ((TestDescription) e.nextElement()).createNodeDescription(temp); 122 result.add(temp); 123 } 124 return result; 125 } 126 if (type.equals(Node.USE)) { 127 if (object != null) { 128 NodeDescription temp = new NodeDescription(Node.USE); 129 temp.setPlugin(this.name); 130 object.createNodeDescription(temp); 131 result.add(temp); 132 } 133 return result; 134 } 135 return null; 136 } 137 138 148 public NodeDescription createNodeDescription(String type, String name) { 149 cat.debug("createNodeDescription"); 150 if (type.equals(Node.USE)) { 152 NodeDescription node = new NodeDescription(Node.USE); 153 node.setPlugin(this.name); 154 this.object.createNodeDescription(node); 155 return node; 156 } 157 if (type.equals(Node.TIMER)) { 158 NodeDescription node = new NodeDescription(Node.TIMER); 159 node.setPlugin(this.name); 160 if (this.timers.containsKey(name)) { 161 TimerDescription timer = (TimerDescription) this.timers 162 .get(name); 163 timer.createNodeDescription(node); 164 return node; 165 } else 166 return null; 167 } 168 if (type.equals(Node.SAMPLE)) { 169 NodeDescription node = new NodeDescription(Node.SAMPLE); 170 node.setPlugin(this.name); 171 if (this.samples.containsKey(name)) { 172 SampleDescription sample = (SampleDescription) this.samples 173 .get(name); 174 sample.createNodeDescription(node); 175 return node; 176 } else 177 return null; 178 } 179 if (Node.isControllerNode(type)) { 183 NodeDescription node = new NodeDescription(type); 184 node.setPlugin(this.name); 185 if (this.tests.containsKey(name)) { 186 TestDescription test = (TestDescription) this.tests.get(name); 187 test.createNodeDescription(node); 188 return node; 189 } else 190 return null; 191 } 192 return null; 193 } 194 195 203 public static PluginDescription loadPluginDescription(String dirName, ClassLoader cl) { 204 cat.debug("-> loadPluginDescription"); 205 Properties properties = new Properties (); 207 try { 208 InputStream is = new FileInputStream (dirName 209 + FileName.PLUGIN_PROPERTIES_FILE); 210 properties.load(is); 211 is.close(); 212 } catch (IOException ioe) { 213 cat.warn("Unable to analyse property file : " + dirName 214 + "plugin.properties"); 215 } 216 String pluginXMLFile = properties.getProperty("plugin.xmlFile"); 218 String guiXMLFile = properties.getProperty("plugin.guiFile"); 219 String pluginName = properties.getProperty("plugin.name"); 220 221 AnalyseSaxPlugin handler = new AnalyseSaxPlugin(); 223 try { 224 InputSource is = new InputSource (new FileInputStream (dirName 225 + pluginXMLFile)); 226 SAXParserFactory factory = SAXParserFactory.newInstance(); 227 factory.setValidating(true); 228 SAXParser saxParser = factory.newSAXParser(); 229 XMLReader reader = saxParser.getXMLReader(); 230 reader.setContentHandler(handler); 231 reader.setErrorHandler(handler); 232 reader.setEntityResolver(new IsacEntityResolver(cl)) ; 233 reader.parse(is); 234 } catch (Exception e) { 235 cat.warn(" ---> Parser error : " + dirName + pluginXMLFile); 236 e.printStackTrace(System.out); 237 return null; 238 } 239 PluginDescription tempDesc = handler.getPluginDescription(); 240 if ((guiXMLFile != null) && (!guiXMLFile.equals("null"))) 241 (PluginGUIManager.getPluginGUIManager(null)).createPanels(tempDesc, 242 dirName + guiXMLFile); 243 else 244 (PluginGUIManager.getPluginGUIManager(null)).createPanels(tempDesc, 245 null); 246 247 return tempDesc; 248 } 249 250 255 public String getName() { 256 cat.debug("-> getName"); 257 return name; 258 } 259 260 270 public Vector getActionHelp(String type, String action) { 271 cat.debug("-> getActionHelp"); 272 if (type.equals(Node.USE)) 273 return this.object.getHelp(); 274 if (type.equals(Node.SAMPLE)) { 275 if (this.samples.containsKey(action)) { 276 SampleDescription temp = (SampleDescription) this.samples 277 .get(action); 278 return temp.getHelp(); 279 } else 280 return null; 281 } 282 if (type.equals(Node.TIMER)) { 283 if (this.timers.containsKey(action)) { 284 TimerDescription temp = (TimerDescription) this.timers 285 .get(action); 286 return temp.getHelp(); 287 } else 288 return null; 289 } 290 if (type.equals(Node.TEST)) { 291 if (this.tests.containsKey(action)) { 292 TestDescription temp = (TestDescription) this.tests.get(action); 293 return temp.getHelp(); 294 } else 295 return null; 296 } 297 return null; 298 } 299 300 310 public void setActionGUIKey(String key, String type, String name) { 311 cat.debug("-> setActionGUIKey"); 312 } 313 314 323 public String getActionGUIKey(String type, String actionName) { 324 cat.debug("-> getActionGUIKey"); 325 if (type.equals(Node.USE)) { 326 return this.object.getGUIKey(); 327 } 328 if (type.equals(Node.SAMPLE)) { 329 if (this.samples.containsKey(actionName)) { 330 SampleDescription sample = (SampleDescription) this.samples 331 .get(actionName); 332 return sample.getGUIKey(); 333 } 334 return null; 335 } 336 if (type.equals(Node.TIMER)) { 337 if (this.timers.containsKey(actionName)) { 338 TimerDescription timer = (TimerDescription) this.timers 339 .get(actionName); 340 return timer.getGUIKey(); 341 } 342 return null; 343 } 344 if (type.equals(Node.TEST)) { 345 if (this.tests.containsKey(actionName)) { 346 TestDescription test = (TestDescription) this.tests 347 .get(actionName); 348 return test.getGUIKey(); 349 } 350 return null; 351 } 352 return null; 353 } 354 357 public ObjectDescription getObject() { 358 cat.debug("-> getObject"); 359 return object; 360 } 361 364 public Hashtable getSamples() { 365 cat.debug("-> getSamples"); 366 return samples; 367 } 368 371 public Hashtable getTests() { 372 cat.debug("-> getTests"); 373 return tests; 374 } 375 378 public Hashtable getTimers() { 379 cat.debug("-> getTimers"); 380 return timers; 381 } 382 } | Popular Tags |