KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > jaxrpc > Configuration


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.jaxrpc;
21
22
23 public class Configuration {
24
25     private WsdlType wsdl;
26
27     public Configuration() {
28     }
29
30     public void setWsdl(WsdlType value) {
31         wsdl = value;
32     }
33
34     public WsdlType getWsdl() {
35         return wsdl;
36     }
37
38     public void write(java.io.OutputStream JavaDoc out) throws java.io.IOException JavaDoc {
39         write(out, null);
40     }
41
42     public void write(java.io.OutputStream JavaDoc out, String JavaDoc encoding) throws java.io.IOException JavaDoc {
43         java.io.Writer JavaDoc w;
44         if (encoding == null) {
45             encoding = "UTF-8"; // NOI18N
46
}
47         w = new java.io.BufferedWriter JavaDoc(new java.io.OutputStreamWriter JavaDoc(out, encoding));
48         write(w, encoding);
49         w.flush();
50     }
51     
52     public void write(java.io.Writer JavaDoc out, String JavaDoc encoding) throws java.io.IOException JavaDoc {
53         out.write("<?xml version='1.0'"); // NOI18N
54
if (encoding != null)
55             out.write(" encoding='"+encoding+"'"); // NOI18N
56
out.write(" ?>\n"); // NOI18N
57
writeNode(out, "configuration", ""); // NOI18N
58
}
59     
60     public void writeNode(java.io.Writer JavaDoc out, String JavaDoc nodeName, String JavaDoc indent) throws java.io.IOException JavaDoc {
61         out.write(indent);
62         out.write("<");
63         out.write(nodeName);
64         out.write(" xmlns='"); // NOI18N
65
out.write("http://java.sun.com/xml/ns/jax-rpc/ri/config"); // NOI18N
66
out.write("'"); // NOI18N
67
out.write(">\n");
68         String JavaDoc nextIndent = indent + " ";
69         if (wsdl != null) {
70             wsdl.writeNode(out, "wsdl", nextIndent);
71         }
72         out.write(indent);
73         out.write("</"+nodeName+">\n");
74     }
75     
76     public static Configuration read(java.io.InputStream JavaDoc in) throws javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc, java.io.IOException JavaDoc {
77         return read(new org.xml.sax.InputSource JavaDoc(in), false, null, null);
78     }
79     
80     public static Configuration read(org.xml.sax.InputSource JavaDoc in, boolean validate, org.xml.sax.EntityResolver JavaDoc er, org.xml.sax.ErrorHandler JavaDoc eh) throws javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc, java.io.IOException JavaDoc {
81         javax.xml.parsers.DocumentBuilderFactory JavaDoc dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
82         dbf.setValidating(validate);
83         javax.xml.parsers.DocumentBuilder JavaDoc db = dbf.newDocumentBuilder();
84         if (er != null) db.setEntityResolver(er);
85         if (eh != null) db.setErrorHandler(eh);
86         org.w3c.dom.Document JavaDoc doc = db.parse(in);
87         return read(doc);
88     }
89     
90     public static Configuration read(org.w3c.dom.Document JavaDoc document) {
91         Configuration aConfiguration = new Configuration();
92         aConfiguration.readNode(document.getDocumentElement());
93         return aConfiguration;
94     }
95     
96     public void readNode(org.w3c.dom.Node JavaDoc node) {
97         if (node.hasAttributes()) {
98             org.w3c.dom.NamedNodeMap JavaDoc attrs = node.getAttributes();
99             org.w3c.dom.Attr JavaDoc attr;
100             java.lang.String JavaDoc attrValue;
101             attr = (org.w3c.dom.Attr JavaDoc) attrs.getNamedItem("xsi:schemaLocation");
102             if (attr != null) {
103                 attrValue = attr.getValue();
104             } else {
105                 attrValue = null;
106             }
107             //schemaLocation = attrValue;
108
}
109         org.w3c.dom.NodeList JavaDoc children = node.getChildNodes();
110         for (int i = 0, size = children.getLength(); i < size; ++i) {
111             org.w3c.dom.Node JavaDoc childNode = children.item(i);
112             String JavaDoc childNodeName = (childNode.getLocalName() == null ? childNode.getNodeName().intern() : childNode.getLocalName().intern());
113             String JavaDoc childNodeValue = "";
114             if (childNode.getFirstChild() != null) {
115                 childNodeValue = childNode.getFirstChild().getNodeValue();
116             }else if (childNodeName == "wsdl") {
117                 wsdl = new WsdlType();
118                 wsdl.readNode(childNode);
119             }else {
120                 // Found extra unrecognized childNode
121
}
122         }
123     }
124     
125     public static void writeXML(java.io.Writer JavaDoc out, String JavaDoc msg) throws java.io.IOException JavaDoc {
126         writeXML(out, msg, true);
127     }
128     
129     public static void writeXML(java.io.Writer JavaDoc out, String JavaDoc msg, boolean attribute) throws java.io.IOException JavaDoc {
130         if (msg == null)
131             return;
132         int msgLength = msg.length();
133         for (int i = 0; i < msgLength; ++i) {
134             char c = msg.charAt(i);
135             writeXML(out, c, attribute);
136         }
137     }
138     
139     public static void writeXML(java.io.Writer JavaDoc out, char msg, boolean attribute) throws java.io.IOException JavaDoc {
140         if (msg == '&')
141             out.write("&amp;");
142         else if (msg == '<')
143             out.write("&lt;");
144         else if (msg == '>')
145             out.write("&gt;");
146         else if (attribute && msg == '"')
147             out.write("&quot;");
148         else if (attribute && msg == '\'')
149             out.write("&apos;");
150         else if (attribute && msg == '\n')
151             out.write("&#xA;");
152         else if (attribute && msg == '\t')
153             out.write("&#x9;");
154         else
155             out.write(msg);
156     }
157 }
158
159
160
Popular Tags