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-2006 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:
042: package org.netbeans.modules.websvc.registry.jaxrpc;
043:
044: public class Configuration {
045:
046: private WsdlType wsdl;
047:
048: public Configuration() {
049: }
050:
051: public void setWsdl(WsdlType value) {
052: wsdl = value;
053: }
054:
055: public WsdlType getWsdl() {
056: return wsdl;
057: }
058:
059: public void write(java.io.OutputStream out)
060: throws java.io.IOException {
061: write(out, null);
062: }
063:
064: public void write(java.io.OutputStream out, String encoding)
065: throws java.io.IOException {
066: java.io.Writer w;
067: if (encoding == null) {
068: encoding = "UTF-8"; // NOI18N
069: }
070: w = new java.io.BufferedWriter(new java.io.OutputStreamWriter(
071: out, encoding));
072: write(w, encoding);
073: w.flush();
074: }
075:
076: public void write(java.io.Writer out, String encoding)
077: throws java.io.IOException {
078: out.write("<?xml version='1.0'"); // NOI18N
079: if (encoding != null)
080: out.write(" encoding='" + encoding + "'"); // NOI18N
081: out.write(" ?>\n"); // NOI18N
082: writeNode(out, "configuration", ""); // NOI18N
083: }
084:
085: public void writeNode(java.io.Writer out, String nodeName,
086: String indent) throws java.io.IOException {
087: out.write(indent);
088: out.write("<");
089: out.write(nodeName);
090: out.write(" xmlns='"); // NOI18N
091: out.write("http://java.sun.com/xml/ns/jax-rpc/ri/config"); // NOI18N
092: out.write("'"); // NOI18N
093: out.write(">\n");
094: String nextIndent = indent + " ";
095: if (wsdl != null) {
096: wsdl.writeNode(out, "wsdl", nextIndent);
097: }
098: out.write(indent);
099: out.write("</" + nodeName + ">\n");
100: }
101:
102: public static Configuration read(java.io.InputStream in)
103: throws javax.xml.parsers.ParserConfigurationException,
104: org.xml.sax.SAXException, java.io.IOException {
105: return read(new org.xml.sax.InputSource(in), false, null, null);
106: }
107:
108: public static Configuration read(org.xml.sax.InputSource in,
109: boolean validate, org.xml.sax.EntityResolver er,
110: org.xml.sax.ErrorHandler eh)
111: throws javax.xml.parsers.ParserConfigurationException,
112: org.xml.sax.SAXException, java.io.IOException {
113: javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory
114: .newInstance();
115: dbf.setValidating(validate);
116: javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
117: if (er != null)
118: db.setEntityResolver(er);
119: if (eh != null)
120: db.setErrorHandler(eh);
121: org.w3c.dom.Document doc = db.parse(in);
122: return read(doc);
123: }
124:
125: public static Configuration read(org.w3c.dom.Document document) {
126: Configuration aConfiguration = new Configuration();
127: aConfiguration.readNode(document.getDocumentElement());
128: return aConfiguration;
129: }
130:
131: public void readNode(org.w3c.dom.Node node) {
132: if (node.hasAttributes()) {
133: org.w3c.dom.NamedNodeMap attrs = node.getAttributes();
134: org.w3c.dom.Attr attr;
135: java.lang.String attrValue;
136: attr = (org.w3c.dom.Attr) attrs
137: .getNamedItem("xsi:schemaLocation");
138: if (attr != null) {
139: attrValue = attr.getValue();
140: } else {
141: attrValue = null;
142: }
143: //schemaLocation = attrValue;
144: }
145: org.w3c.dom.NodeList children = node.getChildNodes();
146: for (int i = 0, size = children.getLength(); i < size; ++i) {
147: org.w3c.dom.Node childNode = children.item(i);
148: String childNodeName = (childNode.getLocalName() == null ? childNode
149: .getNodeName().intern()
150: : childNode.getLocalName().intern());
151: String childNodeValue = "";
152: if (childNode.getFirstChild() != null) {
153: childNodeValue = childNode.getFirstChild()
154: .getNodeValue();
155: } else if (childNodeName == "wsdl") {
156: wsdl = new WsdlType();
157: wsdl.readNode(childNode);
158: } else {
159: // Found extra unrecognized childNode
160: }
161: }
162: }
163:
164: public static void writeXML(java.io.Writer out, String msg)
165: throws java.io.IOException {
166: writeXML(out, msg, true);
167: }
168:
169: public static void writeXML(java.io.Writer out, String msg,
170: boolean attribute) throws java.io.IOException {
171: if (msg == null)
172: return;
173: int msgLength = msg.length();
174: for (int i = 0; i < msgLength; ++i) {
175: char c = msg.charAt(i);
176: writeXML(out, c, attribute);
177: }
178: }
179:
180: public static void writeXML(java.io.Writer out, char msg,
181: boolean attribute) throws java.io.IOException {
182: if (msg == '&')
183: out.write("&");
184: else if (msg == '<')
185: out.write("<");
186: else if (msg == '>')
187: out.write(">");
188: else if (attribute && msg == '"')
189: out.write(""");
190: else if (attribute && msg == '\'')
191: out.write("'");
192: else if (attribute && msg == '\n')
193: out.write("
");
194: else if (attribute && msg == '\t')
195: out.write("	");
196: else
197: out.write(msg);
198: }
199: }
|