src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/impl/ElementFactory.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

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

mercurial