1 23 package org.objectweb.clif.scenario.util.isac.plugin.parser; 24 25 import java.util.Hashtable ; 26 import java.util.StringTokenizer ; 27 import java.util.Vector ; 28 29 import org.apache.log4j.Category; 30 import org.objectweb.clif.scenario.util.isac.plugin.ObjectDescription; 31 import org.objectweb.clif.scenario.util.isac.plugin.ParameterDescription; 32 import org.objectweb.clif.scenario.util.isac.plugin.PluginDescription; 33 import org.objectweb.clif.scenario.util.isac.plugin.SampleDescription; 34 import org.objectweb.clif.scenario.util.isac.plugin.TestDescription; 35 import org.objectweb.clif.scenario.util.isac.plugin.TimerDescription; 36 import org.objectweb.clif.scenario.util.isac.util.tree.Node; 37 import org.xml.sax.Attributes ; 38 import org.xml.sax.helpers.DefaultHandler ; 39 45 public class AnalyseSaxPlugin extends DefaultHandler { 46 static Category cat = Category.getInstance(AnalyseSaxPlugin.class.getName()) ; 47 48 private String pluginName; 49 private Hashtable samples; 50 private Hashtable timers; 51 private Hashtable tests; 52 private ObjectDescription object; 53 private String clazz; 54 private String method; 55 private String name; 56 private String number; 57 private String paramName; 58 private String paramType; 59 private Vector params; 60 private boolean inHelp; 61 private Vector help; 62 private PluginDescription plugin ; 63 64 67 public AnalyseSaxPlugin() { 68 super(); 69 cat.debug("-> constructor") ; 70 this.plugin = null ; 71 this.pluginName = null; 72 this.samples = new Hashtable (); 73 this.timers = new Hashtable (); 74 this.tests = new Hashtable (); 75 this.object = null; 76 this.name = null; 77 this.clazz = null; 78 this.method = null; 79 this.number = null; 80 this.paramName = null; 81 this.paramType = null; 82 this.params = new Vector (); 83 this.inHelp = false; 84 this.help = null; 85 } 86 87 public void startElement( 88 String namespaceURI, 89 String localName, 90 String qName, 91 Attributes atts) { 92 cat.debug("-> startElement") ; 93 if (qName.equals("sample")) { 94 this.name = atts.getValue(0); 95 this.clazz = atts.getValue(1); 96 this.method = atts.getValue(2); 97 } else if (qName.equals("object")) { 98 this.name = "SessionObject"; 100 this.clazz = atts.getValue(0); 101 } else if (qName.equals("timer")) { 102 this.name = atts.getValue(0); 103 this.number = atts.getValue(1); 104 } else if (qName.equals("test")) { 105 this.name = atts.getValue(0); 106 this.number = atts.getValue(1); 107 } else if (qName.equals("params")) { 108 } else if (qName.equals("param")) { 110 ParameterDescription param = 111 new ParameterDescription(atts.getValue(0), atts.getValue(1)); 112 this.params.add(param); 113 } else if (qName.equals("plugin")) { 114 this.pluginName = atts.getValue(0); 115 } else if (qName.equals("help")) { 116 this.inHelp = true; 117 this.help = new Vector (); 118 } 119 } 120 121 public void endElement( 122 String namespaceURI, 123 String localName, 124 String qName) { 125 cat.debug("-> endElement") ; 126 if (Node.isPluginNode(qName) || qName.equals("object")) { 128 cat.warn("ADD A PLUGIN ACTION ID PARAMETER !!! " + qName + " " + this.name) ; 129 this.params.add(new ParameterDescription("id", "String")) ; 130 } 131 if (qName.equals("sample")) { 132 SampleDescription temp = 133 new SampleDescription( 134 this.name, 135 this.clazz, 136 this.method, 137 (Vector )this.params.clone(), 138 this.help); 139 this.samples.put(this.name, temp); 140 this.params.clear() ; 141 this.help = null; 142 } else if (qName.equals("timer")) { 143 TimerDescription temp = 144 new TimerDescription( 145 this.name, 146 this.number, 147 (Vector )this.params.clone(), 148 this.help); 149 this.timers.put(this.name, temp); 150 this.params.clear(); 151 this.help = null; 152 } else if (qName.equals("test")) { 153 TestDescription temp = 154 new TestDescription( 155 this.name, 156 this.number, 157 (Vector )this.params.clone(), 158 this.help); 159 this.tests.put(this.name, temp); 160 this.params.clear(); 161 this.help = null; 162 } else if (qName.equals("object")) { 163 cat.warn("CREATE A NEW object " + this.name + " " + this.pluginName) ; 164 cat.warn("Size of params : " + this.params.size()) ; 165 this.object = 166 new ObjectDescription( 167 this.name, 168 this.clazz, 169 (Vector )this.params.clone(), 170 this.help); 171 this.params.clear(); 172 this.help = null; 173 } else if (qName.equals("help")) { 174 this.inHelp = false; 175 } else if (qName.equals("plugin")) { 176 this.plugin = new PluginDescription(this.pluginName, this.samples, this.tests, this.timers,this.object, this.help) ; 177 } 178 } 179 180 public void characters(char[] ch, int debut, int l) { 181 cat.debug("-> characters") ; 182 if (!this.inHelp) 184 return; 185 String sg; 187 sg = new String (ch, debut, l); 188 StringTokenizer st = new StringTokenizer (sg, "\\"); 190 while (st.hasMoreTokens()) { 191 String line = st.nextToken(); 192 this.help.add(line); 193 } 194 } 195 196 public PluginDescription getPluginDescription() { 197 return this.plugin ; 198 } 199 } 200 | Popular Tags |