001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.etl.project.anttasks;
042:
043: import java.io.ByteArrayInputStream;
044: import java.io.FileOutputStream;
045: import java.io.IOException;
046: import java.io.InputStream;
047: import java.io.OutputStream;
048: import java.util.Iterator;
049: import java.util.Map;
050:
051: import javax.wsdl.Definition;
052:
053: /**
054: *
055: */
056: public class ETLMapWriter {
057:
058: Map<String, Definition> wsdlMap;
059: String etlmapLocation;
060:
061: public ETLMapWriter(Map<String, Definition> wsdlMap,
062: String etlmapLocation) {
063: this .wsdlMap = wsdlMap;
064: this .etlmapLocation = etlmapLocation;
065: }
066:
067: /**
068: *
069: * <?xml version="1.0" encoding="UTF-8"?> <etlmap
070: * xmlns:tns="http://com.sun.com/etl/etlengine"
071: * targetNamespace="http://com.sun.com/etl/etlengine" > <etl
072: * partnerLink="{http://com.sun.com/etl/etlengine}Client2ETELLink"
073: * portType="{http://com.sun.com/etl/etlengine}etlPortType"
074: * operation="execute" file="etl-engine.xml" type="requestReplyService"/>
075: *
076: */
077:
078: public void writeMap() {
079:
080: StringBuffer sb = new StringBuffer();
081:
082: sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
083: sb
084: .append("<etlmap xmlns:tns=\"http://com.sun.jbi/etl/etlengine\" \n");
085: sb
086: .append("\t targetNamespace=\"http://com.sun.jbi/etl/etlengine\" > \n");
087:
088: Iterator<String> iter = wsdlMap.keySet().iterator();
089: while (iter.hasNext()) {
090:
091: String element = (String) iter.next();
092: Definition def = wsdlMap.get(element);
093: sb.append("\t <etl partnerLink=\"" + def.getQName()
094: + "_etlPartnerLink" + "\"\n");
095: sb.append("\t \t partnerLinkType=\"" + def.getQName()
096: + "_etlPartnerLinkType" + "\"\n");
097: sb.append("\t \t roleName=\"" + def.getQName() + "_myrole"
098: + "\"\n");
099: sb.append("\t \t portType=\"" + def.getQName()
100: + "_etlPortType" + "\"\n");
101: sb.append("\t \t operation= \"execute\" \n");
102: sb.append("\t \t file=\"" + def.getQName().getLocalPart()
103: + ".xml" + "\"\n");
104: sb.append("\t \t type= \"requestReplyService\" /> \n");
105:
106: }
107:
108: sb.append("</etlmap>");
109:
110: String content = sb.toString();
111: try {
112: FileOutputStream fos = new FileOutputStream(etlmapLocation
113: + "/etlmap.xml");
114: copy(content.getBytes("UTF-8"), fos);
115: } catch (Exception e) {
116: // TODO Auto-generated catch block
117: e.printStackTrace();
118: }
119:
120: }
121:
122: public static void copy(byte[] input, OutputStream output)
123: throws IOException {
124: ByteArrayInputStream in = new ByteArrayInputStream(input);
125: copy(in, output);
126: }
127:
128: public static void copy(InputStream input, OutputStream output)
129: throws IOException {
130: byte[] buf = new byte[1024 * 4];
131: int n = 0;
132: while ((n = input.read(buf)) != -1) {
133: output.write(buf, 0, n);
134: }
135: output.flush();
136: }
137:
138: }
|