View Javadoc

1   /*
2    * Copyright 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.saaj;
18  
19  import java.io.IOException;
20  import java.io.OutputStream;
21  import java.util.Iterator;
22  import java.util.Locale;
23  import javax.activation.DataHandler;
24  import javax.xml.namespace.QName;
25  import javax.xml.soap.AttachmentPart;
26  import javax.xml.soap.Detail;
27  import javax.xml.soap.DetailEntry;
28  import javax.xml.soap.MimeHeaders;
29  import javax.xml.soap.SOAPBody;
30  import javax.xml.soap.SOAPElement;
31  import javax.xml.soap.SOAPEnvelope;
32  import javax.xml.soap.SOAPException;
33  import javax.xml.soap.SOAPFault;
34  import javax.xml.soap.SOAPHeader;
35  import javax.xml.soap.SOAPHeaderElement;
36  import javax.xml.soap.SOAPMessage;
37  import javax.xml.transform.Result;
38  import javax.xml.transform.Source;
39  
40  /**
41   * Forms a bridge between the SOAP class hierarchy and a specific version of SAAJ.
42   *
43   * @author Arjen Poutsma
44   * @since 1.0.0
45   */
46  abstract class SaajImplementation {
47  
48      /*
49       * SOAPElement
50       */
51  
52      /** Returns the name of the given element. */
53      abstract QName getName(SOAPElement element);
54  
55      /** Returns the readable <code>Source</code> of the given element. */
56      abstract Source getSource(SOAPElement element);
57  
58      /** Returns the writable <code>Result</code> of the given element. */
59      abstract Result getResult(SOAPElement element);
60  
61      /** Returns the text of the given element */
62      abstract String getText(SOAPElement element);
63  
64      /** Returns the text of the given element */
65      abstract void setText(SOAPElement element, String content) throws SOAPException;
66  
67      /** Adds an attribute to the specified element. */
68      abstract void addAttribute(SOAPElement element, QName name, String value) throws SOAPException;
69  
70      /** Removes an attribute from the specified element. */
71      abstract void removeAttribute(SOAPElement element, QName name) throws SOAPException;
72  
73      /** Returns the attribute value * */
74      abstract String getAttributeValue(SOAPElement element, QName name) throws SOAPException;
75  
76      /** Returns all attributes as an iterator of QNames. * */
77      abstract Iterator getAllAttibutes(SOAPElement element);
78  
79      /** Removes the contents (i.e. children) of the element. */
80      abstract void removeContents(SOAPElement element);
81  
82      /** Returns an iterator over all the child elements with the specified name. */
83      abstract Iterator getChildElements(SOAPElement element, QName name) throws SOAPException;
84  
85      /** Declares a namespace. */
86      abstract void addNamespaceDeclaration(SOAPElement element, String prefix, String namespaceUri) throws SOAPException;
87  
88      /*
89       * SOAPMessage
90       */
91  
92      /** Returns the envelope of the given message. */
93      abstract SOAPEnvelope getEnvelope(SOAPMessage message) throws SOAPException;
94  
95      /** Writes the given message to the given stream. */
96      abstract void writeTo(SOAPMessage message, OutputStream outputStream) throws SOAPException, IOException;
97  
98      /** Returns the MIME headers of the message. */
99      abstract MimeHeaders getMimeHeaders(SOAPMessage message);
100 
101     /** Returns an iteration over all attachments in the message. */
102     abstract Iterator getAttachments(SOAPMessage message);
103 
104     /** Returns an iteration over all attachments in the message with the given headers. */
105     abstract Iterator getAttachment(SOAPMessage message, MimeHeaders mimeHeaders);
106 
107     /** Adds an attachment to the given message. */
108     abstract AttachmentPart addAttachmentPart(SOAPMessage message, DataHandler dataHandler);
109 
110     /*
111      * SOAPEnvelope
112      */
113 
114     /** Returns the header of the given envelope. */
115     abstract SOAPHeader getHeader(SOAPEnvelope envelope) throws SOAPException;
116 
117     /** Returns the body of the given envelope. */
118     abstract SOAPBody getBody(SOAPEnvelope envelope) throws SOAPException;
119 
120     /*
121      * SOAPHeader
122      */
123 
124     /** Adds a header element to the given header. */
125     abstract SOAPHeaderElement addHeaderElement(SOAPHeader header, QName name) throws SOAPException;
126 
127     /** Returns all header elements. */
128     abstract Iterator examineAllHeaderElements(SOAPHeader header);
129 
130     /** Returns all header elements for which the must understand attribute is true, given the actor or role. */
131     abstract Iterator examineMustUnderstandHeaderElements(SOAPHeader header, String actorOrRole);
132 
133     /** Adds a not understood header element to the given header. */
134     abstract SOAPHeaderElement addNotUnderstoodHeaderElement(SOAPHeader header, QName name) throws SOAPException;
135 
136     /** Adds a upgrade header element to the given header. */
137     abstract SOAPHeaderElement addUpgradeHeaderElement(SOAPHeader header, String[] supportedSoapUris)
138             throws SOAPException;
139 
140     /*
141      * SOAPHeaderElement
142      */
143 
144     /** Returns the SOAP 1.1 actor or SOAP 1.2 role attribute for the given header element. */
145     abstract String getActorOrRole(SOAPHeaderElement headerElement);
146 
147     /** Sets the SOAP 1.1 actor or SOAP 1.2 role attribute for the given header element. */
148     abstract void setActorOrRole(SOAPHeaderElement headerElement, String actorOrRole);
149 
150     /** Gets the must understand attribute for the given header element. */
151     abstract boolean getMustUnderstand(SOAPHeaderElement headerElement);
152 
153     /** Sets the must understand attribute for the given header element. */
154     abstract void setMustUnderstand(SOAPHeaderElement headerElement, boolean mustUnderstand);
155 
156     /*
157      * SOAPBody
158      */
159 
160     /** Returns <code>true</code> if the body has a fault, <code>false</code> otherwise. */
161     abstract boolean hasFault(SOAPBody body);
162 
163     /** Returns the fault for the given body, if any. */
164     abstract SOAPFault getFault(SOAPBody body);
165 
166     /** Adds a fault to the given body. */
167     abstract SOAPFault addFault(SOAPBody body, QName faultCode, String faultString, Locale locale) throws SOAPException;
168 
169     /** Returns the first child element of the given body. */
170     abstract SOAPElement getFirstBodyElement(SOAPBody body);
171 
172     /*
173      * SOAPFault
174      */
175 
176     /** Returns the fault code for the given fault. */
177     abstract QName getFaultCode(SOAPFault fault);
178 
179     /** Returns the actor for the given fault. */
180     abstract String getFaultActor(SOAPFault fault);
181 
182     /** Sets the actor for the given fault. */
183     abstract void setFaultActor(SOAPFault fault, String actorOrRole) throws SOAPException;
184 
185     /** Returns the fault string for the given fault. */
186     abstract String getFaultString(SOAPFault fault);
187 
188     /** Returns the fault string language for the given fault. */
189     abstract Locale getFaultStringLocale(SOAPFault fault);
190 
191     /** Returns the fault detail for the given fault. */
192     abstract Detail getFaultDetail(SOAPFault fault);
193 
194     /** Adds a fault detail for the given fault. */
195     abstract Detail addFaultDetail(SOAPFault fault) throws SOAPException;
196 
197     /** Returns the fault role. */
198     abstract String getFaultRole(SOAPFault fault);
199 
200     /** Sets the fault role. */
201     abstract void setFaultRole(SOAPFault fault, String role) throws SOAPException;
202 
203     /** Returns the fault sub code. */
204     abstract Iterator getFaultSubcodes(SOAPFault fault);
205 
206     /** Adds a fault sub code. */
207     abstract void appendFaultSubcode(SOAPFault fault, QName subcode) throws SOAPException;
208 
209     /** Returns the fault node. */
210     abstract String getFaultNode(SOAPFault fault);
211 
212     /** Sets the fault node. */
213     abstract void setFaultNode(SOAPFault fault, String uri) throws SOAPException;
214 
215     /** Returns the fault reason text. */
216     abstract String getFaultReasonText(SOAPFault fault, Locale locale) throws SOAPException;
217 
218     /** Sets the fault reason text. */
219     abstract void setFaultReasonText(SOAPFault fault, Locale locale, String text) throws SOAPException;
220 
221     /*
222      * Detail
223      */
224 
225     /** Adds a detail entry to the given detail. */
226     abstract DetailEntry addDetailEntry(Detail detail, QName name) throws SOAPException;
227 
228     /** Returns an iteration over all detail entries. */
229     abstract Iterator getDetailEntries(Detail detail);
230 
231     /*
232      * DetailEntry
233      */
234 
235     /** Adds a text node to the given detail entry. */
236     abstract void addTextNode(DetailEntry detailEntry, String text) throws SOAPException;
237 }