< prev index next >
src/share/jaxws_classes/com/sun/xml/internal/ws/util/DOMUtil.java
Print this page
rev 1143 : 8182054: Improve wsdl support
Summary: Also reviewed by Roman Grigoriadi <roman.grigoriadi@oracle.com>
Reviewed-by: joehw, lancea
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -23,33 +23,31 @@
* questions.
*/
package com.sun.xml.internal.ws.util;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
+import com.sun.istack.internal.NotNull;
+import com.sun.istack.internal.Nullable;
+import com.sun.xml.internal.ws.util.xml.XmlUtil;
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
-import javax.xml.XMLConstants;
-import javax.xml.namespace.NamespaceContext;
-import java.io.IOException;
-import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.ArrayList;
-import com.sun.istack.internal.NotNull;
-import com.sun.istack.internal.Nullable;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author: JAXWS Development Team
*/
public class DOMUtil {
@@ -61,43 +59,20 @@
*/
public static Document createDom() {
synchronized (DOMUtil.class) {
if (db == null) {
try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
+ DocumentBuilderFactory dbf = XmlUtil.newDocumentBuilderFactory();
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new FactoryConfigurationError(e);
}
}
return db.newDocument();
}
}
- public static Node createDOMNode(InputStream inputStream) {
-
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- dbf.setValidating(false);
- try {
- DocumentBuilder builder = dbf.newDocumentBuilder();
- try {
- return builder.parse(inputStream);
- } catch (SAXException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- } catch (IOException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- } catch (ParserConfigurationException pce) {
- IllegalArgumentException iae = new IllegalArgumentException(pce.getMessage());
- iae.initCause(pce);
- throw iae;
- }
- return null;
- }
-
/**
* Traverses a DOM node and writes out on a streaming writer.
*
* @param node
* @param writer
@@ -110,10 +85,11 @@
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
switch (child.getNodeType()) {
case Node.PROCESSING_INSTRUCTION_NODE:
writer.writeProcessingInstruction(child.getNodeValue());
+ break;
case Node.DOCUMENT_TYPE_NODE:
break;
case Node.CDATA_SECTION_NODE:
writer.writeCData(child.getNodeValue());
break;
@@ -124,10 +100,11 @@
writer.writeCharacters(child.getNodeValue());
break;
case Node.ELEMENT_NODE:
serializeNode((Element) child, writer);
break;
+ default: break;
}
}
}
writer.writeEndElement();
}
@@ -220,22 +197,26 @@
*/
public static Element getFirstChild(Element e, String nsUri, String local) {
for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element c = (Element) n;
- if (c.getLocalName().equals(local) && c.getNamespaceURI().equals(nsUri))
+ if (c.getLocalName().equals(local) && c.getNamespaceURI().equals(nsUri)) {
return c;
}
}
+ }
return null;
}
private static
@NotNull
String fixNull(@Nullable String s) {
- if (s == null) return "";
- else return s;
+ if (s == null) {
+ return "";
+ } else {
+ return s;
+ }
}
/**
* Gets the first element child.
*/
< prev index next >