1 6 7 package SOFA.Connector.EEG; 8 9 import org.w3c.dom.Document ; 10 import org.w3c.dom.Element ; 11 import org.w3c.dom.Node ; 12 13 18 public class ElementOutputDescriptor { 19 20 public String name; 21 public String impl; 22 23 public SOFA.Connector.Property[] params; 24 25 26 public ElementOutputDescriptor() { 27 } 28 29 public ElementOutputDescriptor(Element element) throws ElementDescriptorXMLException { 30 fillFromXML(element); 31 } 32 33 static public ElementOutputDescriptor findFirst(ElementOutputDescriptor elems[], String 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 toXML(Document parentDoc) throws ElementDescriptorXMLException { 44 Element 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 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 element) throws ElementDescriptorXMLException { 58 java.util.LinkedList pars=new java.util.LinkedList (); 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 node=element.getFirstChild(); 71 while (node!=null) { 72 if (node.getNodeType()==Node.ELEMENT_NODE) { 73 Element el=(Element )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 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 |