KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > EEG > ElementOutputDescriptor


1 /*
2  * ElementOutputDescriptor.java
3  *
4  * Created on 2. duben 2002, 20:56
5  */

6
7 package SOFA.Connector.EEG;
8
9 import org.w3c.dom.Document JavaDoc;
10 import org.w3c.dom.Element JavaDoc;
11 import org.w3c.dom.Node JavaDoc;
12
13 /**
14  *
15  * @author ghort
16  * @version
17  */

18 public class ElementOutputDescriptor {
19
20     public String JavaDoc name;
21     public String JavaDoc impl;
22
23     public SOFA.Connector.Property[] params;
24     
25     /** Creates new ElementOutputDescriptor */
26     public ElementOutputDescriptor() {
27     }
28
29     public ElementOutputDescriptor(Element JavaDoc element) throws ElementDescriptorXMLException {
30         fillFromXML(element);
31     }
32
33     static public ElementOutputDescriptor findFirst(ElementOutputDescriptor elems[], String JavaDoc nm) {
34         int i;
35         for (i=0;i<elems.length;i++) {
36             if (elems[i].name.equals(nm)) {
37                 return elems[i];
38             }
39         }
40         return null;
41     }
42
43     public Element JavaDoc toXML(Document JavaDoc parentDoc) throws ElementDescriptorXMLException {
44         Element JavaDoc ret=parentDoc.createElement("connector_element");
45         ret.setAttribute("name",name);
46         ret.setAttribute("impl",impl);
47
48         for (int i=0;i<params.length;i++) {
49             Element JavaDoc par=parentDoc.createElement("element_param");
50             par.setAttribute("name",params[i].name);
51             par.setAttribute("value",params[i].value);
52             ret.appendChild(par);
53         }
54         return ret;
55     }
56
57     public void fillFromXML(Element JavaDoc element) throws ElementDescriptorXMLException {
58         java.util.LinkedList JavaDoc pars=new java.util.LinkedList JavaDoc();
59
60         if (!element.hasAttribute("name")) {
61             throw new ElementDescriptorXMLException("Element doesn't have 'name' attribute.");
62         }
63         name=element.getAttribute("name");
64
65         if (!element.hasAttribute("impl")) {
66             throw new ElementDescriptorXMLException("Element doesn't have 'impl' attribute.");
67         }
68         impl=element.getAttribute("impl");
69         
70         Node JavaDoc node=element.getFirstChild();
71         while (node!=null) {
72             if (node.getNodeType()==Node.ELEMENT_NODE) {
73                 Element JavaDoc el=(Element JavaDoc)node;
74                 if (el.getNodeName().equals("element_param") && el.hasAttribute("name") && el.hasAttribute("value")) {
75                     pars.add(new SOFA.Connector.Property(el.getAttribute("name"),el.getAttribute("value")));
76                 }
77             }
78             node=node.getNextSibling();
79         }
80         
81         int i;
82         java.util.Iterator JavaDoc iter=pars.iterator();
83         params=new SOFA.Connector.Property[pars.size()];
84         for (i=0;iter.hasNext();i++) {
85             params[i]=(SOFA.Connector.Property)iter.next();
86         }
87     }
88         
89     
90 }
91
Popular Tags