001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.sql.project.wsdl;
021:
022: import java.io.File;
023: import java.util.ArrayList;
024: import java.util.List;
025:
026: import javax.xml.parsers.DocumentBuilderFactory;
027:
028: import org.w3c.dom.Document;
029: import org.w3c.dom.Element;
030: import org.w3c.dom.NamedNodeMap;
031: import org.w3c.dom.Node;
032: import org.w3c.dom.NodeList;
033:
034: public class SQLMapReader {
035:
036: /*
037: *
038: *
039: * sample etlmap.xml
040: *
041: * <?xml version="1.0" encoding="UTF-8"?> <etlmap
042: * xmlns:tns="http://com.sun.com/etl/etlengine"
043: * targetNamespace="http://com.sun.com/etl/etlengine" > <etl
044: * partnerLink="{http://com.sun.com/etl/etlengine}Client2ETELLink"
045: * portType="{http://com.sun.com/etl/etlengine}etlPortType"
046: * operation="execute" file="etl-engine.xml" type="requestReplyService"/>
047: * </etlmap>
048: *
049: */
050:
051: public static List parse(String sqlmapfile) throws Exception {
052:
053: List etlmapEntryList = new ArrayList();
054: DocumentBuilderFactory factory = DocumentBuilderFactory
055: .newInstance();
056: Document doc = factory.newDocumentBuilder().parse(sqlmapfile);
057: Element elem = doc.getDocumentElement();
058: NodeList etlmaps = elem
059: .getElementsByTagName(SQLMapEntry.SQLMAP_TAG);
060:
061: for (int i = 0; i < etlmaps.getLength(); i++) {
062: Node n = etlmaps.item(i);
063: NamedNodeMap attrMap = n.getAttributes();
064: String partnerlink = attrMap.getNamedItem(
065: SQLMapEntry.PARTNERLINK_TAG).getNodeValue();
066: String portType = attrMap.getNamedItem(
067: SQLMapEntry.PORTTYPE_TAG).getNodeValue();
068: String operation = attrMap.getNamedItem(
069: SQLMapEntry.OPERATION_TAG).getNodeValue();
070: String sqlfile = attrMap.getNamedItem(
071: SQLMapEntry.SQL_FILE_TAG).getNodeValue();
072: String wsdlfile = attrMap.getNamedItem(
073: SQLMapEntry.WSDL_FILE_TAG).getNodeValue();
074: String type = attrMap.getNamedItem(SQLMapEntry.TYPE_TAG)
075: .getNodeValue();
076:
077: SQLMapEntry e = new SQLMapEntry(partnerlink, portType,
078: operation, sqlfile, wsdlfile, type);
079: etlmapEntryList.add(e);
080:
081: }
082:
083: return etlmapEntryList;
084:
085: }
086:
087: public static List parse(String sqlmapfile, String mbuildDir)
088: throws Exception {
089:
090: List etlmapEntryList = new ArrayList();
091:
092: //Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(sqlmapfile);
093: DocumentBuilderFactory factory = DocumentBuilderFactory
094: .newInstance();
095: Document doc = factory.newDocumentBuilder().parse(
096: new File(mbuildDir, sqlmapfile));
097: Element elem = doc.getDocumentElement();
098: NodeList etlmaps = elem
099: .getElementsByTagName(SQLMapEntry.SQLMAP_TAG);
100:
101: for (int i = 0; i < etlmaps.getLength(); i++) {
102: Node n = etlmaps.item(i);
103: NamedNodeMap attrMap = n.getAttributes();
104: String partnerlink = attrMap.getNamedItem(
105: SQLMapEntry.PARTNERLINK_TAG).getNodeValue();
106: String portType = attrMap.getNamedItem(
107: SQLMapEntry.PORTTYPE_TAG).getNodeValue();
108: String operation = attrMap.getNamedItem(
109: SQLMapEntry.OPERATION_TAG).getNodeValue();
110: String sqlfile = attrMap.getNamedItem(
111: SQLMapEntry.SQL_FILE_TAG).getNodeValue();
112: String wsdlfile = attrMap.getNamedItem(
113: SQLMapEntry.WSDL_FILE_TAG).getNodeValue();
114: String type = attrMap.getNamedItem(SQLMapEntry.TYPE_TAG)
115: .getNodeValue();
116:
117: SQLMapEntry e = new SQLMapEntry(partnerlink, portType,
118: operation, sqlfile, wsdlfile, type);
119: etlmapEntryList.add(e);
120:
121: }
122:
123: return etlmapEntryList;
124:
125: }
126:
127: public static void main(String[] args) {
128: try {
129: List l = SQLMapReader.parse("test/sqlmap.xml");
130: SQLMapEntry entry = (SQLMapEntry) l.get(0);
131: entry.getPortType();
132: entry.getPartnerLink();
133: } catch (Exception e) {
134: // TODO Auto-generated catch block
135: e.printStackTrace();
136: }
137: }
138:
139: }
|