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 javax.wsdl.Definition;
023: import java.util.Map;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.io.FileOutputStream;
027: import java.io.File;
028:
029: public class SQLMapWriter {
030:
031: private Definition wsdlDefinition;
032: private String sqlmapLocation;
033: private List sqlFilesList;
034:
035: public SQLMapWriter(List sqlFilesList, Definition def,
036: String canonicalPath) {
037: this .sqlFilesList = sqlFilesList;
038: this .wsdlDefinition = def;
039: this .sqlmapLocation = canonicalPath;
040: }
041:
042: /**
043: *
044: * <?xml version="1.0" encoding="UTF-8"?> <sqlmap
045: * xmlns:tns="http://com.sun.com/sqlse/sqlengine"
046: * targetNamespace="http://com.sun.com/sqlse/sqlengine" > <sql
047: * partnerLink="{http://com.sun.com/sqlse/sqlengine}Client2ETELLink"
048: * portType="{http://com.sun.com/sqlse/sqlengine}sqlsePortType"
049: * operation="execute" file="sqlse-engine.xml" type="requestReplyService"/>
050: *
051: */
052:
053: public String writeMap() throws Exception {
054:
055: StringBuffer sb = new StringBuffer();
056:
057: sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
058: sb
059: .append("<sqlmap xmlns:tns=\"http://com.sun.jbi/sqlse/sqlengine\" \n");
060: sb
061: .append("\t targetNamespace=\"http://com.sun.jbi/sqlse/sqlengine\" > \n");
062:
063: if (sqlFilesList != null) {
064: Iterator iter = sqlFilesList.iterator();
065: while (iter.hasNext()) {
066:
067: String sqlFilePath = ((File) iter.next()).getName();
068: int beginIndex = sqlFilePath
069: .lastIndexOf(File.separator);
070: String sqlFileName = sqlFilePath.substring(
071: beginIndex + 1, sqlFilePath.length());
072: sb.append("\t <sql partnerLink=\""
073: + wsdlDefinition.getQName()
074: + "_sqlsePartnerLink" + "\"\n");
075: sb.append("\t \t partnerLinkType=\""
076: + wsdlDefinition.getQName()
077: + "_sqlsePartnerLinkType" + "\"\n");
078: sb.append("\t \t roleName=\""
079: + wsdlDefinition.getQName() + "_myrole"
080: + "\"\n");
081: sb.append("\t \t portType=\""
082: + wsdlDefinition.getQName() + "_sqlsePortType"
083: + "\"\n");
084: sb
085: .append("\t \t operation= \"" + sqlFileName
086: + "\" \n");
087: sb.append("\t \t wsdlfile=\""
088: + wsdlDefinition.getQName().getLocalPart()
089: + ".wsdl" + "\"\n");
090: sb.append("\t \t sqlfile=\"" + sqlFilePath + "\"\n");
091: sb.append("\t \t type= \"requestReplyService\" /> \n");
092:
093: }
094: } else {
095: throw new Exception(
096: "No SQL Files found to generate SQL Map");
097: }
098: sb.append("</sqlmap>");
099:
100: String content = sb.toString();
101:
102: try {
103: FileOutputStream fos = new FileOutputStream(sqlmapLocation
104: + "/sqlmap.xml");
105: FileUtil.copy(content.getBytes("UTF-8"), fos);
106: } catch (Exception e) {
107: throw new Exception("Unable to generate sqlmap file", e);
108: }
109:
110: return content;
111: }
112: }
|