001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.soap.marshalers;
018:
019: import javax.xml.namespace.QName;
020: import javax.xml.stream.XMLInputFactory;
021: import javax.xml.stream.XMLOutputFactory;
022:
023: import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
024:
025: /**
026: *
027: * @author Guillaume Nodet
028: * @version $Revision: 359186 $
029: * @since 3.0
030: */
031: public class SoapMarshaler {
032:
033: public static final String MIME_CONTENT_TYPE = "Content-Type";
034: public static final String MULTIPART_CONTENT = "multipart/";
035: public static final String SOAP_PART_ID = "soap-request";
036: public static final String SOAP_11_URI = "http://schemas.xmlsoap.org/soap/envelope/";
037: public static final String SOAP_12_URI = "http://www.w3.org/2003/05/soap-envelope";
038: public static final String SOAP_PREFIX = "env";
039: public static final String ENVELOPE = "Envelope";
040: public static final String HEADER = "Header";
041: public static final String BODY = "Body";
042: public static final String FAULT = "Fault";
043:
044: public static final QName SOAP_11_FAULTCODE = new QName("faultcode");
045: public static final QName SOAP_11_FAULTSTRING = new QName(
046: "faultstring");
047: public static final QName SOAP_11_FAULTACTOR = new QName(
048: "faultactor");
049: public static final QName SOAP_11_FAULTDETAIL = new QName("detail");
050: public static final QName SOAP_11_CODE_VERSIONMISMATCH = new QName(
051: SOAP_11_URI, "VersionMismatch");
052: public static final QName SOAP_11_CODE_MUSTUNDERSTAND = new QName(
053: SOAP_11_URI, "MustUnderstand");
054: public static final QName SOAP_11_CODE_CLIENT = new QName(
055: SOAP_11_URI, "Client");
056: public static final QName SOAP_11_CODE_SERVER = new QName(
057: SOAP_11_URI, "Server");
058:
059: public static final QName SOAP_12_FAULTCODE = new QName(
060: SOAP_12_URI, "Code");
061: public static final QName SOAP_12_FAULTSUBCODE = new QName(
062: SOAP_12_URI, "Subcode");
063: public static final QName SOAP_12_FAULTVALUE = new QName(
064: SOAP_12_URI, "Value");
065: public static final QName SOAP_12_FAULTREASON = new QName(
066: SOAP_12_URI, "Reason");
067: public static final QName SOAP_12_FAULTTEXT = new QName(
068: SOAP_12_URI, "Text");
069: public static final QName SOAP_12_FAULTNODE = new QName(
070: SOAP_12_URI, "Node");
071: public static final QName SOAP_12_FAULTROLE = new QName(
072: SOAP_12_URI, "Role");
073: public static final QName SOAP_12_FAULTDETAIL = new QName(
074: SOAP_12_URI, "Detail");
075: public static final QName SOAP_12_CODE_DATAENCODINGUNKNOWN = new QName(
076: SOAP_12_URI, "DataEncodingUnknown");
077: public static final QName SOAP_12_CODE_VERSIONMISMATCH = new QName(
078: SOAP_12_URI, "VersionMismatch");
079: public static final QName SOAP_12_CODE_MUSTUNDERSTAND = new QName(
080: SOAP_12_URI, "MustUnderstand");
081: public static final QName SOAP_12_CODE_RECEIVER = new QName(
082: SOAP_12_URI, "Receiver");
083: public static final QName SOAP_12_CODE_SENDER = new QName(
084: SOAP_12_URI, "Sender");
085:
086: protected XMLInputFactory inputFactory;
087: protected XMLOutputFactory outputFactory;
088: protected StAXSourceTransformer sourceTransformer;
089: protected boolean repairingNamespace;
090: protected String prefix = SOAP_PREFIX;
091: protected boolean soap = true;
092: protected boolean useDom = false;
093: protected String soapUri = SOAP_12_URI;
094:
095: public static final String MULTIPLE_DETAILS_NODE_WRAPPER = "multiple-details";
096:
097: public SoapMarshaler() {
098: }
099:
100: public SoapMarshaler(boolean soap) {
101: this .soap = soap;
102: }
103:
104: public SoapMarshaler(boolean soap, boolean useDom) {
105: this .soap = soap;
106: this .useDom = useDom;
107: }
108:
109: public XMLInputFactory getInputFactory() {
110: if (inputFactory == null) {
111: inputFactory = XMLInputFactory.newInstance();
112: inputFactory.setProperty(
113: XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
114: }
115: return inputFactory;
116: }
117:
118: public XMLOutputFactory getOutputFactory() {
119: if (outputFactory == null) {
120: outputFactory = XMLOutputFactory.newInstance();
121: if (isRepairingNamespace()) {
122: outputFactory.setProperty(
123: XMLOutputFactory.IS_REPAIRING_NAMESPACES,
124: Boolean.valueOf(isRepairingNamespace()));
125: }
126: }
127: return outputFactory;
128: }
129:
130: public StAXSourceTransformer getSourceTransformer() {
131: if (sourceTransformer == null) {
132: sourceTransformer = new StAXSourceTransformer();
133: }
134: return sourceTransformer;
135: }
136:
137: public boolean isRepairingNamespace() {
138: return repairingNamespace;
139: }
140:
141: public void setRepairingNamespace(boolean repairingNamespace) {
142: this .repairingNamespace = repairingNamespace;
143: }
144:
145: public boolean isSoap() {
146: return soap;
147: }
148:
149: public void setSoap(boolean soap) {
150: this .soap = soap;
151: }
152:
153: /**
154: * @return the useDom
155: */
156: public boolean isUseDom() {
157: return useDom;
158: }
159:
160: /**
161: * @param useDom the useDom to set
162: */
163: public void setUseDom(boolean useDom) {
164: this .useDom = useDom;
165: }
166:
167: public String getPrefix() {
168: return prefix;
169: }
170:
171: public void setPrefix(String prefix) {
172: this .prefix = prefix;
173: }
174:
175: public String getSoapUri() {
176: return soapUri;
177: }
178:
179: public void setSoapUri(String soapUri) {
180: this .soapUri = soapUri;
181: }
182:
183: public SoapReader createReader() {
184: return new SoapReader(this );
185: }
186:
187: public SoapWriter createWriter(SoapMessage message) {
188: return new SoapWriter(this, message);
189: }
190: }
|