KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > ECG > test


1 /*
2  * test.java
3  *
4  * Created on 5. duben 2002, 21:02
5  */

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

19 public class test {
20
21     /** Creates new test */
22     public test() {
23     }
24
25     /**
26     * @param args the command line arguments
27     */

28     public static void main (String JavaDoc args[]) throws Exception JavaDoc {
29         javax.xml.parsers.DocumentBuilderFactory JavaDoc documentBuilderFactory=javax.xml.parsers.DocumentBuilderFactory.newInstance();
30         javax.xml.parsers.DocumentBuilder JavaDoc documentBuilder=documentBuilderFactory.newDocumentBuilder();
31     
32         Document JavaDoc configDoc=documentBuilder.parse(new java.io.File JavaDoc(args[0]));
33
34         SOFA.Connector.TIRAccess.TIRAccess.openTIR();
35         ECGenerator generator=new ECGenerator();
36
37         java.util.LinkedList JavaDoc toRemove=new java.util.LinkedList JavaDoc();
38         NodeList JavaDoc cons=configDoc.getElementsByTagName("connector");
39         int consLen=cons.getLength();
40         int i;
41
42         for (i=0;i<consLen;i++) {
43             Element JavaDoc curElement=(Element JavaDoc)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 JavaDoc 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 JavaDoc parentNode=curElement.getParentNode();
60             parentNode.insertBefore(outDesc.toXML(configDoc),curElement);
61             toRemove.add(curElement);
62         }
63
64         java.util.Iterator JavaDoc iter=toRemove.iterator();
65         while (iter.hasNext()) {
66             Node JavaDoc node=(Node JavaDoc)iter.next();
67             node.getParentNode().removeChild(node);
68         }
69
70         javax.xml.transform.TransformerFactory JavaDoc documentTransformerFactory=javax.xml.transform.TransformerFactory.newInstance();
71         javax.xml.transform.Transformer JavaDoc transformer=documentTransformerFactory.newTransformer();
72     
73         transformer.transform(new javax.xml.transform.dom.DOMSource JavaDoc(configDoc),new javax.xml.transform.stream.StreamResult JavaDoc(new java.io.File JavaDoc(args[1])));
74     }
75
76 }
77
Popular Tags