1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.messaging.saaj.soap.impl;
27
28 import javax.xml.namespace.QName;
29 import javax.xml.soap.*;
30
31 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
32 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
33 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.*;
34 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.*;
35
36
37 public class ElementFactory {
38 public static SOAPElement createElement(
39 SOAPDocumentImpl ownerDocument,
40 Name name) {
41 return createElement(
42 ownerDocument,
43 name.getLocalName(),
44 name.getPrefix(),
45 name.getURI());
46 }
47 public static SOAPElement createElement(
48 SOAPDocumentImpl ownerDocument,
49 QName name) {
50 return createElement(
51 ownerDocument,
52 name.getLocalPart(),
53 name.getPrefix(),
54 name.getNamespaceURI());
55 }
56
57 public static SOAPElement createElement(
58 SOAPDocumentImpl ownerDocument,
59 String localName,
60 String prefix,
61 String namespaceUri) {
62
63
64 if (ownerDocument == null) {
65 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
66 ownerDocument = new SOAPPart1_1Impl().getDocument();
67 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
68 ownerDocument = new SOAPPart1_2Impl().getDocument();
69 } else {
70 ownerDocument = new SOAPDocumentImpl(null);
71 }
72 }
73
74 SOAPElement newElement =
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.messaging.saaj.soap.impl;
27
28 import javax.xml.namespace.QName;
29 import javax.xml.soap.*;
30
31 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
32 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
33 import com.sun.xml.internal.messaging.saaj.soap.ver1_1.*;
34 import com.sun.xml.internal.messaging.saaj.soap.ver1_2.*;
35 import org.w3c.dom.Element;
36
37 import java.util.Objects;
38
39
40 public class ElementFactory {
41 public static SOAPElement createElement(
42 SOAPDocumentImpl ownerDocument,
43 Name name) {
44 return createElement(
45 ownerDocument,
46 name.getLocalName(),
47 name.getPrefix(),
48 name.getURI());
49 }
50 public static SOAPElement createElement(
51 SOAPDocumentImpl ownerDocument,
52 QName name) {
53 return createElement(
54 ownerDocument,
55 name.getLocalPart(),
56 name.getPrefix(),
57 name.getNamespaceURI());
58 }
59
60 /**
61 * Create element wrapper for existing DOM element.
62 *
63 * @param ownerDocument SOAP document wrapper not null
64 * @param element DOM element not null
65 * @return SOAP wrapper for DOM element
66 */
67 public static SOAPElement createElement(SOAPDocumentImpl ownerDocument, Element element) {
68 Objects.requireNonNull(ownerDocument);
69 Objects.requireNonNull(element);
70
71 String localName = element.getLocalName();
72 String namespaceUri = element.getNamespaceURI();
73 String prefix = element.getPrefix();
74
75 if (localName.equalsIgnoreCase("Envelope")) {
76 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
77 return new Envelope1_1Impl(ownerDocument, element);
78 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
79 return new Envelope1_2Impl(ownerDocument, element);
80 }
81 }
82 if (localName.equalsIgnoreCase("Body")) {
83 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
84 return new Body1_1Impl(ownerDocument, element);
85 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
86 return new Body1_2Impl(ownerDocument, element);
87 }
88 }
89 if (localName.equalsIgnoreCase("Header")) {
90 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
91 return new Header1_1Impl(ownerDocument, element);
92 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
93 return new Header1_2Impl(ownerDocument, element);
94 }
95 }
96 if (localName.equalsIgnoreCase("Fault")) {
97 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
98 return new Fault1_1Impl(element, ownerDocument);
99 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
100 return new Fault1_2Impl(element, ownerDocument);
101 }
102
103 }
104 if (localName.equalsIgnoreCase("Detail")) {
105 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
106 return new Detail1_1Impl(ownerDocument, element);
107 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
108 return new Detail1_2Impl(ownerDocument, element);
109 }
110 }
111 if (localName.equalsIgnoreCase("faultcode")
112 || localName.equalsIgnoreCase("faultstring")
113 || localName.equalsIgnoreCase("faultactor")) {
114 // SOAP 1.2 does not have fault(code/string/actor)
115 // So there is no else case required
116 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
117 return new FaultElement1_1Impl(ownerDocument,
118 localName,
119 prefix);
120 }
121 }
122
123 return new ElementImpl(ownerDocument, element);
124 }
125
126 public static SOAPElement createElement(
127 SOAPDocumentImpl ownerDocument,
128 String localName,
129 String prefix,
130 String namespaceUri) {
131
132
133 if (ownerDocument == null) {
134 if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
135 ownerDocument = new SOAPPart1_1Impl().getDocument();
136 } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
137 ownerDocument = new SOAPPart1_2Impl().getDocument();
138 } else {
139 ownerDocument = new SOAPDocumentImpl(null);
140 }
141 }
142
143 SOAPElement newElement =
|