1 6 7 package SOFA.Connector.ECG; 8 9 import org.w3c.dom.Element ; 10 import org.w3c.dom.Node ; 11 12 17 public class ConnectorInputDescriptor { 18 19 public String instanceName; 20 21 public String unit; 22 23 public String implementation; 24 25 public SOFA.Connector.Property[] props; 26 27 public SOFA.Connector.Property[] techProps; 29 public UnitInterface provides[]; 30 public UnitInterface requires[]; 31 32 public SOFA.Connector.EEG.ElementInputDescriptor[] elements; 33 34 35 public ConnectorInputDescriptor() { 36 } 37 38 static public ConnectorInputDescriptor fromXML(Element rootElement) throws ConnectorDescriptorXMLException { 39 ConnectorInputDescriptor cid=new ConnectorInputDescriptor(); 40 java.util.LinkedList descrProps=new java.util.LinkedList (); 41 java.util.LinkedList provIfaces=new java.util.LinkedList (); 42 java.util.LinkedList reqIfaces=new java.util.LinkedList (); 43 java.util.LinkedList elems=new java.util.LinkedList (); 44 45 if (!rootElement.hasAttribute("name")) { 46 throw new ConnectorDescriptorXMLException("Element doesn't have 'name' attribute."); 47 } 48 cid.instanceName=rootElement.getAttribute("name"); 49 50 if (!rootElement.hasAttribute("unit")) { 51 throw new ConnectorDescriptorXMLException("Element doesn't have 'unit' attribute."); 52 } 53 cid.unit=rootElement.getAttribute("unit"); 54 55 if (!rootElement.hasAttribute("impl")) { 56 throw new ConnectorDescriptorXMLException("Element doesn't have 'impl' attribute."); 57 } 58 cid.implementation=rootElement.getAttribute("impl"); 59 60 if (rootElement.hasAttribute("provides")) { 61 provIfaces.add(new UnitInterface(rootElement.getAttribute("provides"),cid.unit)); 62 } 63 64 if (rootElement.hasAttribute("requires")) { 65 reqIfaces.add(new UnitInterface(rootElement.getAttribute("requires"),cid.unit)); 66 } 67 68 Node node=rootElement.getFirstChild(); 69 while (node!=null) { 70 if (node.getNodeType()==Node.ELEMENT_NODE) { 71 Element el=(Element )node; 72 if (((Element )el).getNodeName().equals("property") && el.hasAttribute("name") && el.hasAttribute("value")) { 73 descrProps.add(new SOFA.Connector.Property(el.getAttribute("name"),el.getAttribute("value"))); 74 } 75 else if (el.getNodeName().equals("otherUnit") && el.hasAttribute("name")) { 76 if (el.hasAttribute("provides")) { 77 provIfaces.add(new UnitInterface(el.getAttribute("provides"),el.getAttribute("name"))); 78 } 79 if (rootElement.hasAttribute("requires")) { 80 reqIfaces.add(new UnitInterface(rootElement.getAttribute("requires"),el.getAttribute("name"))); 81 } 82 } 83 else if (el.getNodeName().equals("element") && el.hasAttribute("name") && el.hasAttribute("impl")) { 84 try { 85 elems.add(SOFA.Connector.EEG.ElementInputDescriptor.fromXML(el)); 86 } catch (Exception e) { 87 throw new ConnectorDescriptorXMLException("Can't parse connector element.",e); 88 } 89 } 90 } 91 node=node.getNextSibling(); 92 } 93 94 int i; 95 Object [] arr; 96 97 cid.techProps=new SOFA.Connector.Property[0]; 99 cid.props=new SOFA.Connector.Property[(arr=descrProps.toArray()).length]; 100 for (i=0;i<arr.length;i++) { 101 cid.props[i]=(SOFA.Connector.Property)arr[i]; 102 } 103 104 cid.elements=new SOFA.Connector.EEG.ElementInputDescriptor[(arr=elems.toArray()).length]; 105 for (i=0;i<arr.length;i++) { 106 cid.elements[i]=(SOFA.Connector.EEG.ElementInputDescriptor)arr[i]; 107 } 108 109 cid.provides=new UnitInterface[(arr=provIfaces.toArray()).length]; 110 for (i=0;i<arr.length;i++) { 111 cid.provides[i]=(UnitInterface)arr[i]; 112 } 113 114 cid.requires=new UnitInterface[(arr=reqIfaces.toArray()).length]; 115 for (i=0;i<arr.length;i++) { 116 cid.requires[i]=(UnitInterface)arr[i]; 117 } 118 119 return cid; 120 } 121 } 122 | Popular Tags |