KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > plugin > gui > GUIDescriptionParser


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23
24 package org.objectweb.clif.scenario.util.isac.plugin.gui;
25
26 import java.util.Enumeration JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 import javax.xml.parsers.DocumentBuilder JavaDoc;
31 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
32
33 import org.apache.log4j.Category;
34 import org.objectweb.clif.scenario.util.isac.plugin.ObjectDescription;
35 import org.objectweb.clif.scenario.util.isac.plugin.ParameterDescription;
36 import org.objectweb.clif.scenario.util.isac.plugin.PluginDescription;
37 import org.objectweb.clif.scenario.util.isac.plugin.SampleDescription;
38 import org.objectweb.clif.scenario.util.isac.plugin.TestDescription;
39 import org.objectweb.clif.scenario.util.isac.plugin.TimerDescription;
40 import org.w3c.dom.Document JavaDoc;
41 import org.w3c.dom.Node JavaDoc;
42 import org.w3c.dom.NodeList JavaDoc;
43
44 /**
45  * @author JC Meillaud
46  * @author A Peyrard
47  */

48 public class GUIDescriptionParser {
49     static Category cat = Category.getInstance(GUIDescriptionParser.class
50             .getName());
51
52     /*
53      * Definition of the name of the node we manipulate
54      *
55      */

56     private static final String JavaDoc OBJECT = "object";
57     private static final String JavaDoc TEST = org.objectweb.clif.scenario.util.isac.util.tree.Node.TEST;
58     private static final String JavaDoc SAMPLE = org.objectweb.clif.scenario.util.isac.util.tree.Node.SAMPLE;
59     private static final String JavaDoc TIMER = org.objectweb.clif.scenario.util.isac.util.tree.Node.TIMER;
60     private static final String JavaDoc GROUP = "group";
61     private static final String JavaDoc NAME = "name";
62     private static final String JavaDoc PARAM = "param";
63     private static final String JavaDoc CHOICE = "choice";
64     private static final String JavaDoc SELECTED = "selected";
65     private static final String JavaDoc ID = "id";
66     private static final String JavaDoc CHOICES = "choices";
67     private static final String JavaDoc TEXT = "text";
68     private static final String JavaDoc RADIOBUTTON = "radiobutton";
69     private static final String JavaDoc CHECKBOX = "checkbox";
70     private static final String JavaDoc COMBO = "combo";
71     private static final String JavaDoc VALUE = "value";
72     private static final String JavaDoc DEFAULT = "default";
73     private static final String JavaDoc FIELD = "field";
74     private static final String JavaDoc NFIELD = "nfield";
75     private static final String JavaDoc TABLE = "table";
76     private static final String JavaDoc COLS = "cols";
77     private static final String JavaDoc TRUE = "true";
78     private static final String JavaDoc SIZE = "size";
79     private static final String JavaDoc PLEASE_EDIT = "please edit this field...";
80     private static final String JavaDoc LABEL = "label";
81
82     /**
83      * Method which load a gui description file, and try to find desccription
84      * for the session object, the samples, the timers, and the tests. If there
85      * is a description, we build a ParametersWidgetNode from it, else, we build
86      * a default ParametersWidgetNode
87      *
88      * @param fileName
89      * Name of the file
90      * @param plugin
91      * The PLuginDescription
92      * @param panels
93      * an Hashtable of the ParametersWidgetNode
94      * @return a Vector containing the errors
95      */

96     public static Vector JavaDoc loadGUIDescriptionFile(String JavaDoc fileName,
97             PluginDescription plugin, Hashtable JavaDoc panels) {
98         Vector JavaDoc result = null;
99         Document JavaDoc document = null;
100         DocumentBuilderFactory JavaDoc factory = null;
101         Vector JavaDoc parametersNames = new Vector JavaDoc();
102         int intKey = 0;
103         cat.debug("Load a gui.xml file -> " + fileName);
104
105         try {
106             factory = DocumentBuilderFactory.newInstance();
107             DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
108             document = builder.parse(fileName);
109         } catch (Exception JavaDoc e) {
110             e.printStackTrace();
111         }
112         Vector JavaDoc nodesName = new Vector JavaDoc();
113         nodesName.add(OBJECT);
114         nodesName.add(SAMPLE);
115         nodesName.add(TEST);
116         nodesName.add(TIMER);
117         for (int i = 0; i < nodesName.size(); i++) {
118             cat.debug("Load a " + nodesName.get(i) + " gui description");
119             ParametersWidgetsNode parametersWidgetsNode = null;
120             if (nodesName.get(i).equals(OBJECT)) {
121                 ObjectDescription obj = plugin.getObject();
122                 Vector JavaDoc descriptionParams = obj.getParams();
123                 for (int j = 0; j < descriptionParams.size(); ++j) {
124                     parametersNames
125                             .addElement(((ParameterDescription) descriptionParams
126                                     .get(j)).getName());
127                 }
128                 parametersWidgetsNode = visitDOM(document, nodesName.get(i)
129                         .toString(), parametersNames);
130                 if (parametersWidgetsNode != null) {
131                     intKey = parametersWidgetsNode.hashCode();
132                     while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(intKey))
133                             .toString())))
134                         intKey++;
135                     panels.put((new Integer JavaDoc(intKey)).toString(),
136                             parametersWidgetsNode);
137                     obj.setGUIKey(new String JavaDoc((Integer.toString(intKey))));
138                 } else {
139                     parametersWidgetsNode = ParametersWidgetsNode
140                             .createParametersWidgetsNode(
141                                     descriptionParams.elements(),
142                                     org.objectweb.clif.scenario.util.isac.util.tree.Node.USE,
143                                     plugin.getName());
144                     intKey = parametersWidgetsNode.hashCode();
145                     while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(intKey))
146                             .toString())))
147                         intKey++;
148                     panels.put((new Integer JavaDoc(intKey)).toString(),
149                             parametersWidgetsNode);
150                     obj.setGUIKey(new String JavaDoc((Integer.toString(intKey))));
151                 }
152             } else if (nodesName.get(i).equals(TIMER)) {
153                 Hashtable JavaDoc timers = plugin.getTimers();
154                 Hashtable JavaDoc remaindingTimers = (Hashtable JavaDoc) timers.clone();
155                 Hashtable JavaDoc hashtablePWN = new Hashtable JavaDoc();
156                 visitDOM2(hashtablePWN, document, nodesName.get(i).toString(),
157                         timers);
158                 if (hashtablePWN.size() != 0) {
159                     Enumeration JavaDoc keys = hashtablePWN.keys();
160                     cat.debug("Printing of the Timers :" + hashtablePWN.size()
161                             + " timers");
162                     while (keys.hasMoreElements()) {
163                         String JavaDoc key = (String JavaDoc) keys.nextElement();
164                         cat.debug("Timer : " + key);
165                         cat
166                                 .debug((ParametersWidgetsNode) hashtablePWN
167                                         .get(key));
168                         if (timers.containsKey(key)) {
169                             TimerDescription temp = (TimerDescription) timers
170                                     .get(key);
171                             intKey = hashtablePWN.get(key).hashCode();
172                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
173                                     intKey)).toString())))
174                                 intKey++;
175                             temp.setGUIKey(new Integer JavaDoc(intKey).toString());
176                             panels.put((new Integer JavaDoc(intKey)).toString(),
177                                     hashtablePWN.get(key));
178                             remaindingTimers.remove(key);
179                         }
180                     }
181                 }
182                 if (remaindingTimers.size() != 0) {
183                     Enumeration JavaDoc timersKeys = remaindingTimers.keys();
184                     while (timersKeys.hasMoreElements()) {
185                         String JavaDoc timerKey = (String JavaDoc) timersKeys.nextElement();
186                         TimerDescription timer = (TimerDescription) remaindingTimers
187                                 .get(timerKey);
188                         Vector JavaDoc params = timer.getParams();
189                         if (params != null) {
190                             ParametersWidgetsNode tree = ParametersWidgetsNode
191                                     .createParametersWidgetsNode(params
192                                             .elements(), TIMER, plugin
193                                             .getName());
194                             intKey = tree.hashCode();
195                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
196                                     intKey)).toString())))
197                                 intKey++;
198                             panels.put(new String JavaDoc((new Integer JavaDoc(intKey))
199                                     .toString()), tree);
200                             timer.setGUIKey(new String JavaDoc((new Integer JavaDoc(intKey))
201                                     .toString()));
202                         } else {
203                             ParametersWidgetsNode tree = ParametersWidgetsNode
204                                     .createParametersWidgetsNode(null, TIMER,
205                                             plugin.getName());
206                             intKey = tree.hashCode();
207                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
208                                     intKey)).toString())))
209                                 intKey++;
210                             panels.put(new String JavaDoc((new Integer JavaDoc(intKey))
211                                     .toString()), tree);
212                             timer.setGUIKey(new String JavaDoc((new Integer JavaDoc(intKey))
213                                     .toString()));
214                         }
215                     }
216                 }
217
218             } else if (nodesName.get(i).equals(TEST)) {
219                 Hashtable JavaDoc tests = plugin.getTests();
220                 Hashtable JavaDoc remaindingTests = (Hashtable JavaDoc) tests.clone();
221                 Hashtable JavaDoc hashtablePWN = new Hashtable JavaDoc();
222                 visitDOM2(hashtablePWN, document, nodesName.get(i).toString(),
223                         tests);
224                 if (hashtablePWN.size() != 0) {
225                     Enumeration JavaDoc keys = hashtablePWN.keys();
226                     cat.debug("Printing of the tests :" + hashtablePWN.size()
227                             + " tests");
228                     while (keys.hasMoreElements()) {
229                         String JavaDoc key = (String JavaDoc) keys.nextElement();
230                         cat.debug("Test : " + key);
231                         cat
232                                 .debug((ParametersWidgetsNode) hashtablePWN
233                                         .get(key));
234                         if (tests.containsKey(key)) {
235                             TestDescription temp = (TestDescription) tests
236                                     .get(key);
237                             intKey = hashtablePWN.get(key).hashCode();
238                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
239                                     intKey)).toString())))
240                                 intKey++;
241                             temp.setGUIKey(new Integer JavaDoc(intKey).toString());
242                             panels.put((new Integer JavaDoc(intKey)).toString(),
243                                     hashtablePWN.get(key));
244                             remaindingTests.remove(key);
245                         }
246                     }
247                 }
248                 if (remaindingTests.size() != 0) {
249                     Enumeration JavaDoc testsKeys = remaindingTests.keys();
250                     while (testsKeys.hasMoreElements()) {
251                         String JavaDoc testKey = (String JavaDoc) testsKeys.nextElement();
252                         TestDescription test = (TestDescription) remaindingTests
253                                 .get(testKey);
254                         Vector JavaDoc params = test.getParams();
255                         if (params != null) {
256                             ParametersWidgetsNode tree = ParametersWidgetsNode
257                                     .createParametersWidgetsNode(params
258                                             .elements(), TEST, plugin.getName());
259                             intKey = tree.hashCode();
260                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
261                                     intKey)).toString())))
262                                 intKey++;
263                             panels.put(new String JavaDoc((new Integer JavaDoc(intKey))
264                                     .toString()), tree);
265                             test.setGUIKey(new String JavaDoc((new Integer JavaDoc(intKey))
266                                     .toString()));
267                         } else {
268                             ParametersWidgetsNode tree = ParametersWidgetsNode
269                                     .createParametersWidgetsNode(null, TEST,
270                                             plugin.getName());
271                             intKey = tree.hashCode();
272                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
273                                     intKey)).toString())))
274                                 intKey++;
275                             panels.put(new String JavaDoc((new Integer JavaDoc(intKey))
276                                     .toString()), tree);
277                             test.setGUIKey(new String JavaDoc((new Integer JavaDoc(intKey))
278                                     .toString()));
279                         }
280                     }
281                 }
282
283             } else if (nodesName.get(i).equals(SAMPLE)) {
284                 Hashtable JavaDoc samples = plugin.getSamples();
285                 Hashtable JavaDoc remaindingSamples = (Hashtable JavaDoc) samples.clone();
286                 Hashtable JavaDoc hashtablePWN = new Hashtable JavaDoc();
287                 visitDOM2(hashtablePWN, document, nodesName.get(i).toString(),
288                         samples);
289                 if (hashtablePWN.size() != 0) {
290                     Enumeration JavaDoc keys = hashtablePWN.keys();
291                     cat.debug("Printing of the Samples : "
292                             + hashtablePWN.size() + " samples");
293                     while (keys.hasMoreElements()) {
294                         String JavaDoc key = (String JavaDoc) keys.nextElement();
295                         cat.debug("Sample : " + key);
296                         if (samples.containsKey(key)) {
297                             SampleDescription temp = (SampleDescription) samples
298                                     .get(key);
299                             intKey = hashtablePWN.get(key).hashCode();
300                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
301                                     intKey)).toString())))
302                                 intKey++;
303                             temp.setGUIKey(new Integer JavaDoc(intKey).toString());
304                             panels.put((new Integer JavaDoc(intKey)).toString(),
305                                     hashtablePWN.get(key));
306                             remaindingSamples.remove(key);
307                         }
308                     }
309
310                 }
311                 if (remaindingSamples.size() != 0) {
312                     Enumeration JavaDoc samplesKeys = remaindingSamples.keys();
313                     while (samplesKeys.hasMoreElements()) {
314                         String JavaDoc sampleKey = (String JavaDoc) samplesKeys.nextElement();
315                         SampleDescription sample = (SampleDescription) remaindingSamples
316                                 .get(sampleKey);
317                         Vector JavaDoc params = sample.getParams();
318                         if (params != null) {
319                             ParametersWidgetsNode tree = ParametersWidgetsNode
320                                     .createParametersWidgetsNode(params
321                                             .elements(), SAMPLE, plugin
322                                             .getName());
323                             intKey = tree.hashCode();
324                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
325                                     intKey)).toString())))
326                                 intKey++;
327                             panels.put(new String JavaDoc((new Integer JavaDoc(intKey))
328                                     .toString()), tree);
329                             sample.setGUIKey(new String JavaDoc((new Integer JavaDoc(intKey))
330                                     .toString()));
331                         } else {
332                             ParametersWidgetsNode tree = ParametersWidgetsNode
333                                     .createParametersWidgetsNode(null, SAMPLE,
334                                             plugin.getName());
335                             intKey = tree.hashCode();
336                             while (panels.containsKey(new String JavaDoc((new Integer JavaDoc(
337                                     intKey)).toString())))
338                                 intKey++;
339                             panels.put(new String JavaDoc((new Integer JavaDoc(intKey))
340                                     .toString()), tree);
341                             sample.setGUIKey(new String JavaDoc((new Integer JavaDoc(intKey))
342                                     .toString()));
343                         }
344                     }
345                 }
346             }
347         }
348         return result;
349     }
350     /**
351      * Method to get the value of a certain attribut from a DOM's Node
352      *
353      * @param node
354      * The node
355      * @param attributName
356      * Name of the attribut
357      * @return An object representing the value
358      */

359     private static Object JavaDoc returnAttributValue(Node JavaDoc node, String JavaDoc attributName) {
360         String JavaDoc result = null;
361         if (node.getAttributes() != null)
362             for (int i = 0; i < node.getAttributes().getLength(); i++) {
363                 if (node.getAttributes().item(i).getNodeName().equals(
364                         attributName)) {
365                     result = node.getAttributes().item(i).getNodeValue();
366                 }
367             }
368         return result;
369
370     }
371     /**
372      * Method to get a Vector with all the value of the attribut from certain
373      * nodes
374      *
375      * @param node
376      * The node
377      * @param tagName
378      * @param attributName
379      * @return
380      */

381     private static Vector JavaDoc returnParameters(Node JavaDoc node, String JavaDoc tagName,
382             String JavaDoc attributName) {
383         cat.info("[BEGIN] returnParameters : ");
384         Vector JavaDoc parametersNames = new Vector JavaDoc();
385         if (node.hasChildNodes()) {
386             NodeList JavaDoc fils = node.getChildNodes();
387             for (int i = 0; i < fils.getLength(); i++) {
388                 if (fils.item(i).getNodeName().equals(tagName)) {
389                     if (returnAttributValue(fils.item(i), attributName) != null) {
390                         parametersNames.add(returnAttributValue(fils.item(i),
391                                 attributName));
392                     }
393                 }
394             }
395         }
396         cat.info("[END] returnParameters for (" + tagName + "): "
397                 + parametersNames);
398         return parametersNames;
399     }
400     /**
401      * Method to get a Vector with all the value of the attribut from certain
402      * nodes which are set to 'true'
403      *
404      * @param node
405      * @param tagName
406      * @param attributName
407      * @return
408      */

409     private static Vector JavaDoc returnSelectedParameters(Node JavaDoc node, String JavaDoc tagName,
410             String JavaDoc attributName) {
411         cat.info("[BEGIN] returnSelectedParameters (" + attributName + "): ");
412         Vector JavaDoc parametersNames = new Vector JavaDoc();
413         if (node.hasChildNodes()) {
414             NodeList JavaDoc fils = node.getChildNodes();
415             for (int i = 0; i < fils.getLength(); i++) {
416                 //cat.debug("ParamsSelectedNode : " +
417
// fils.item(i).getNodeName());
418
if (fils.item(i).getNodeName().equals(tagName)) {
419                     String JavaDoc attribut = (String JavaDoc) returnAttributValue(
420                             fils.item(i), attributName);
421                     if (attribut != null && attribut.equals(TRUE)) {
422                         parametersNames.add(returnAttributValue(fils.item(i),
423                                 VALUE));
424                     }
425                 }
426             }
427         }
428         cat.info("[END] returnSelectedParameters for (" + tagName + "): "
429                 + parametersNames);
430         return parametersNames;
431     }
432
433     /**
434      * Method to complete the ParametersWidgetsNode description tree, if some of
435      * the parameters are not defined
436      *
437      * @param parent
438      * The cuurent description where we put the missing
439      * ParametersWidgetsNode
440      * @param parametersNames
441      * A vector of the name of the missing parameters
442      */

443     public static void completeParametersWidgetDescription(
444             ParametersWidgetsNode parent, Vector JavaDoc parametersNames) {
445         cat.debug("taille :" + parametersNames);
446         for (int i = 0; i < parametersNames.size(); i++) {
447             if (!parametersNames.get(i).equals(ID)) {
448                 ParametersWidgetsNode result = new ParametersWidgetsNode(
449                         new WidgetDescription(WidgetDescription.TEXT_FIELD,
450                                 parametersNames.get(i).toString(), null, null));
451                 //parametersNames.remove(i);
452
parent.addChild(result);
453             }
454         }
455         cat.debug("taille :" + parametersNames.size());
456
457     }
458
459     /**
460      * Return an Object describing the apparence for the GUI
461      *
462      * @param parent
463      * @param node
464      * @param parentName
465      * @param labelValue
466      * @param parametersNames
467      */

468     private static void returnParametersWidgetDescription(
469             ParametersWidgetsNode parent, Node JavaDoc node, String JavaDoc parentName,
470             String JavaDoc labelValue, Vector JavaDoc parametersNames) {
471         ParametersWidgetsNode result = null;
472         String JavaDoc label = labelValue;
473         // test if it is a group
474
boolean isGroup = false;
475         // isFinalNode is set to true, if we found a node RADIOBUTTON | CHECKBOX
476
// | | COMBO | FIELD (see gui.dtd)
477
boolean isFinalNode = false;
478         Hashtable JavaDoc params = new Hashtable JavaDoc();
479         //while (node.hasChildNodes()) {
480
String JavaDoc tagName = node.getNodeName();
481
482         //cat.debug("ParamNode : " + tagName);
483
if (tagName.equals(GROUP)) {
484             parentName = (String JavaDoc) returnAttributValue(node, NAME);
485             isGroup = true;
486             result = new ParametersWidgetsNode(new WidgetDescription(
487                     WidgetDescription.GROUP, parentName, label, params));
488             result.setParent(parent);
489             parent.addChild(result);
490             if (node.hasChildNodes()) {
491                 NodeList JavaDoc fils = node.getChildNodes();
492                 for (int i = 0; i < fils.getLength(); i++) {
493                     returnParametersWidgetDescription(result, fils.item(i),
494                             parentName, label, parametersNames);
495                 }
496             }
497         } else if (tagName.equals(PARAM)) {
498             parentName = (String JavaDoc) returnAttributValue(node, NAME);
499             String JavaDoc labelTemp = (String JavaDoc) returnAttributValue(node, LABEL);
500             // only if this parameter is defined put it to the parameters vector
501
if (labelTemp != null) {
502                 label = labelTemp;
503             }
504             if (parametersNames.contains(parentName)) {
505                 parametersNames.remove(parentName);
506                 cat.debug("GUI description for the node " + parentName);
507             } else {
508                 cat
509                         .debug("We dont have to analyse description for this parameter :"
510                                 + parentName);
511                 return;
512             }
513             //parametersNames.
514

515             //result = new ParametersWidgetsNode(new WidgetDescription(
516
// WidgetDescription.TEXT_FIELD, parentName, params));
517
cat.debug("node " + tagName + " : " + parentName);
518         } else if (tagName.equals(RADIOBUTTON)) {
519             params.put(CHOICES, returnParameters(node, CHOICE, VALUE));
520             params.put(SELECTED,
521                     returnSelectedParameters(node, CHOICE, DEFAULT));
522             cat.debug("node " + tagName + " : " + params.toString());
523             result = new ParametersWidgetsNode(new WidgetDescription(
524                     WidgetDescription.RADIO_GROUP, parentName, label, params));
525             parentName = "";
526             parent.addChild(result);
527             isFinalNode = true;
528         } else if (tagName.equals(CHECKBOX)) {
529             params.put(CHOICES, returnParameters(node, CHOICE, VALUE));
530             params.put(SELECTED,
531                     returnSelectedParameters(node, CHOICE, DEFAULT));
532             cat.debug("node " + tagName + " : " + params.toString());
533             result = new ParametersWidgetsNode(new WidgetDescription(
534                     WidgetDescription.CHECK_BOX, parentName, label, params));
535             parentName = "";
536             parent.addChild(result);
537             isFinalNode = true;
538         } else if (tagName.equals(COMBO)) {
539             params.put(CHOICES, returnParameters(node, CHOICE, VALUE));
540             params.put(SELECTED,
541                     returnSelectedParameters(node, CHOICE, DEFAULT));
542             cat.debug("node " + tagName + " : " + params.toString());
543             result = new ParametersWidgetsNode(new WidgetDescription(
544                     WidgetDescription.COMBO, parentName, label, params));
545             parentName = "";
546             parent.addChild(result);
547             isFinalNode = true;
548         } else if (tagName.equals(FIELD)) {
549             params.put(SIZE, returnAttributValue(node, SIZE) != null
550                     ? returnAttributValue(node, SIZE)
551                     : "0");
552             params.put(TEXT, returnAttributValue(node, TEXT) != null
553                     ? returnAttributValue(node, TEXT)
554                     : PLEASE_EDIT);
555             cat.debug("node " + tagName + "(" + parentName + ") : "
556                     + params.toString());
557             result = new ParametersWidgetsNode(new WidgetDescription(
558                     WidgetDescription.TEXT_FIELD, parentName, label, params));
559             parentName = "";
560             parent.addChild(result);
561             isFinalNode = true;
562         } else if (tagName.equals(NFIELD)) {
563             cat.debug("node " + tagName + "(" + parentName + ") : "
564                     + params.toString());
565             result = new ParametersWidgetsNode(new WidgetDescription(
566                     WidgetDescription.NFIELD, parentName, label, params));
567             parentName = "";
568             parent.addChild(result);
569             isFinalNode = true;
570         } else if (tagName.equals(TABLE)) {
571             cat.debug("node " + tagName + "(" + parentName + ") : "
572                     + params.toString());
573             params.put(COLS, returnAttributValue(node, COLS) != null
574                     ? returnAttributValue(node, COLS)
575                     : "");
576             result = new ParametersWidgetsNode(new WidgetDescription(
577                     WidgetDescription.TABLE, parentName, label, params));
578             parentName = "";
579             parent.addChild(result);
580             isFinalNode = true;
581         }
582         if (node.hasChildNodes() && !isGroup && !isFinalNode) {
583             NodeList JavaDoc fils = node.getChildNodes();
584             for (int i = 0; i < fils.getLength(); i++) {
585                 returnParametersWidgetDescription(parent, fils.item(i),
586                         parentName, label, parametersNames);
587             }
588         }
589     }
590
591     /**
592      * Method wich return the ParametersWidgetsNode representing the whole
593      * parameters gui descriptions
594      *
595      * @param node
596      * @param tagName
597      * @return the ParametersWidgetsNode
598      */

599     private static ParametersWidgetsNode visitDOM(Node JavaDoc node, String JavaDoc tagName,
600             Vector JavaDoc parametersNames) {
601         //ParametersWidgetsNode result = new ParametersWidgetsNode(null);
602
//String tagName = node.getNodeName();
603
boolean EndNode = false;
604         switch (node.getNodeType()) {
605             case Node.ELEMENT_NODE :
606                 cat.info("Node : " + tagName);
607                 if (node.getNodeName().equals(tagName)) {
608
609                     ParametersWidgetsNode result = new ParametersWidgetsNode(
610                             null);
611                     EndNode = true;
612                     if (tagName.equals(OBJECT)) {
613                         result.addChild(new ParametersWidgetsNode(
614                                 new WidgetDescription(
615                                         WidgetDescription.TEXT_FIELD, ID, null,
616                                         null)));
617                     } else {
618                         result.addChild(new ParametersWidgetsNode(
619                                 new WidgetDescription(WidgetDescription.COMBO,
620                                         ID, null, null)));
621                     }
622
623                     returnParametersWidgetDescription(result, node, "", "",
624                             parametersNames);
625                     completeParametersWidgetDescription(result, parametersNames);
626
627                     if (result.getChildren().size() != 1) {
628                         cat.debug("We have a Winner");
629                         cat.debug(result);
630                         return result;
631                     }
632
633                 }
634                 break;
635             default :
636         }
637         if (node.hasChildNodes() && !EndNode) {
638             NodeList JavaDoc fils = node.getChildNodes();
639             for (int i = 0; i < fils.getLength(); i++) {
640                 ParametersWidgetsNode temp = visitDOM(fils.item(i), tagName,
641                         parametersNames);
642                 if (temp != null)
643                     return temp;
644             }
645
646         }
647         return null;
648     }
649     /**
650      * Method that visit a tree in order to find every (tagName) node
651      *
652      * @param hashtable
653      * @param node
654      * @param tagName
655      * @param plugins
656      */

657     private static void visitDOM2(Hashtable JavaDoc hashtable, Node JavaDoc node,
658             String JavaDoc tagName, Hashtable JavaDoc plugins) {
659         boolean EndNode = false;
660         //ParameterDescription parameterDescription = null;
661
Vector JavaDoc descriptionParams = null;
662         Vector JavaDoc parametersNames = new Vector JavaDoc();
663
664         switch (node.getNodeType()) {
665             case Node.ELEMENT_NODE :
666                 if (node.getNodeName().equals(tagName)) {
667                     Object JavaDoc name = returnAttributValue(node, NAME);
668                     cat.debug("Node : " + tagName + " ("
669                             + name + ")");
670                     ParametersWidgetsNode result = null;
671                     EndNode = true;
672
673                     if (plugins.containsKey(name)) {
674                         if (tagName.equals(TIMER)) {
675                             descriptionParams = ((TimerDescription) plugins
676                                     .get(name))
677                                     .getParams();
678                         } else if (tagName.equals(TEST)) {
679                             descriptionParams = ((TestDescription) plugins
680                                     .get(name))
681                                     .getParams();
682                         } else if (tagName.equals(SAMPLE)) {
683                             descriptionParams = ((SampleDescription) plugins
684                                     .get(name))
685                                     .getParams();
686                         } else {
687                             cat.debug("Error");
688                         }
689                         if (descriptionParams != null) {
690                             for (int i = 0; i < descriptionParams.size(); ++i) {
691                                 parametersNames
692                                         .addElement(((ParameterDescription) descriptionParams
693                                                 .get(i)).getName());
694                             }
695                         }
696                         result = visitDOM(node, tagName, parametersNames);
697                         if (result != null) {
698 // completeParametersWidgetDescription(result,
699
// parametersNames);
700
hashtable.put(name,
701                                     result);
702                         }
703                     }
704
705                 }
706                 break;
707             default :
708         }
709
710         if (node.hasChildNodes() && !EndNode) {
711             NodeList JavaDoc fils = node.getChildNodes();
712             for (int i = 0; i < fils.getLength(); ++i) {
713                 visitDOM2(hashtable, fils.item(i), tagName, plugins);
714             }
715
716         }
717         //return parametersWidgetsNodeVector;
718

719     }
720
721 }
Popular Tags