1 6 7 package SOFA.Connector.ECG; 8 9 import org.w3c.dom.Document ; 10 import org.w3c.dom.Element ; 11 import org.w3c.dom.Node ; 12 import org.w3c.dom.NodeList ; 13 14 19 public class test { 20 21 22 public test() { 23 } 24 25 28 public static void main (String args[]) throws Exception { 29 javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory=javax.xml.parsers.DocumentBuilderFactory.newInstance(); 30 javax.xml.parsers.DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); 31 32 Document configDoc=documentBuilder.parse(new java.io.File (args[0])); 33 34 SOFA.Connector.TIRAccess.TIRAccess.openTIR(); 35 ECGenerator generator=new ECGenerator(); 36 37 java.util.LinkedList toRemove=new java.util.LinkedList (); 38 NodeList cons=configDoc.getElementsByTagName("connector"); 39 int consLen=cons.getLength(); 40 int i; 41 42 for (i=0;i<consLen;i++) { 43 Element curElement=(Element )cons.item(i); 44 45 ConnectorInputDescriptor cDescr; 46 47 System.out.println(); 48 System.out.print("Reading input descriptor for '"+curElement.getAttribute("name")+"' ["+curElement.getAttribute("unit")+"] ... "); 49 try { 50 cDescr=ConnectorInputDescriptor.fromXML(curElement); 51 } catch (Exception e) { 52 System.out.println("failed"); 53 throw e; 54 } 55 System.out.println("OK"); 56 57 ConnectorOutputDescriptor outDesc=generator.generate(cDescr); 58 59 Node parentNode=curElement.getParentNode(); 60 parentNode.insertBefore(outDesc.toXML(configDoc),curElement); 61 toRemove.add(curElement); 62 } 63 64 java.util.Iterator iter=toRemove.iterator(); 65 while (iter.hasNext()) { 66 Node node=(Node )iter.next(); 67 node.getParentNode().removeChild(node); 68 } 69 70 javax.xml.transform.TransformerFactory documentTransformerFactory=javax.xml.transform.TransformerFactory.newInstance(); 71 javax.xml.transform.Transformer transformer=documentTransformerFactory.newTransformer(); 72 73 transformer.transform(new javax.xml.transform.dom.DOMSource (configDoc),new javax.xml.transform.stream.StreamResult (new java.io.File (args[1]))); 74 } 75 76 } 77 | Popular Tags |