KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > soap > impl > llom > SOAPHeaderImpl


1 /*
2 * Copyright 2004,2005 The Apache Software Foundation.
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 package org.apache.axis2.soap.impl.llom;
17
18 import org.apache.axis2.om.*;
19 import org.apache.axis2.soap.SOAPEnvelope;
20 import org.apache.axis2.soap.SOAPHeader;
21 import org.apache.axis2.soap.SOAPHeaderBlock;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 /**
27  * Class SOAPHeaderImpl
28  */

29 public abstract class SOAPHeaderImpl extends SOAPElement implements SOAPHeader {
30     /**
31      * @param envelope
32      */

33     public SOAPHeaderImpl(SOAPEnvelope envelope) throws SOAPProcessingException {
34         super(envelope, SOAPConstants.HEADER_LOCAL_NAME, true);
35
36     }
37
38     /**
39      * Constructor SOAPHeaderImpl
40      *
41      * @param envelope
42      * @param builder
43      */

44     public SOAPHeaderImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {
45         super(envelope, SOAPConstants.HEADER_LOCAL_NAME, builder);
46     }
47
48     /**
49      * Creates a new <CODE>SOAPHeaderBlock</CODE> object initialized with the
50      * specified name and adds it to this <CODE>SOAPHeader</CODE> object.
51      *
52      * @param localName
53      * @param ns
54      * @return the new <CODE>SOAPHeaderBlock</CODE> object that was inserted
55      * into this <CODE>SOAPHeader</CODE> object
56      * @throws org.apache.axis2.om.OMException if a SOAP error occurs
57      * @throws OMException
58      */

59     public abstract SOAPHeaderBlock addHeaderBlock(String JavaDoc localName, OMNamespace ns)
60             throws OMException;
61
62     /**
63      * Returns a list of all the <CODE>SOAPHeaderBlock</CODE> objects in this
64      * <CODE>SOAPHeader</CODE> object that have the the specified actor. An
65      * actor is a global attribute that indicates the intermediate parties to
66      * whom the message should be sent. An actor receives the message and then
67      * sends it to the next actor. The default actor is the ultimate intended
68      * recipient for the message, so if no actor attribute is included in a
69      * <CODE>SOAPHeader</CODE> object, the message is sent to its ultimate
70      * destination.
71      *
72      * @param paramRole a <CODE>String</CODE> giving the URI of the actor for
73      * which to search
74      * @return an <CODE>Iterator</CODE> object over all the <CODE>
75      * SOAPHeaderBlock</CODE> objects that contain the specified actor
76      * @see #extractHeaderBlocks(String) extractHeaderBlocks(java.lang.String)
77      */

78     public Iterator JavaDoc examineHeaderBlocks(String JavaDoc paramRole) {
79         Iterator JavaDoc headerBlocksIter = this.getChildren();
80         ArrayList JavaDoc headersWithGivenActor = new ArrayList JavaDoc();
81         while (headerBlocksIter.hasNext()) {
82             Object JavaDoc o = headerBlocksIter.next();
83             if (o instanceof SOAPHeaderBlock) {
84                 SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) o;
85                 String JavaDoc role = soapHeaderBlock.getRole();
86                 if ((role != null) && role.equalsIgnoreCase(paramRole)) {
87                     headersWithGivenActor.add(soapHeaderBlock);
88                 }
89             }
90         }
91         return headersWithGivenActor.iterator();
92     }
93
94     /**
95      * Returns a list of all the <CODE>SOAPHeaderBlock</CODE> objects in this
96      * <CODE>SOAPHeader</CODE> object that have the the specified role and
97      * detaches them from this <CODE> SOAPHeader</CODE> object. <P>This method
98      * allows an role to process only the parts of the <CODE>SOAPHeader</CODE>
99      * object that apply to it and to remove them before passing the message on
100      * to the next role.
101      *
102      * @param role a <CODE>String</CODE> giving the URI of the role for which to
103      * search
104      * @return an <CODE>Iterator</CODE> object over all the <CODE>
105      * SOAPHeaderBlock</CODE> objects that contain the specified role
106      * @see #examineHeaderBlocks(String) examineHeaderBlocks(java.lang.String)
107      */

108     public abstract Iterator JavaDoc extractHeaderBlocks(String JavaDoc role);
109
110     /**
111      * Returns an <code>Iterator</code> over all the <code>SOAPHeaderBlock</code>
112      * objects in this <code>SOAPHeader</code> object that have the specified
113      * actor and that have a MustUnderstand attribute whose value is equivalent
114      * to <code>true</code>.
115      *
116      * @param actor a <code>String</code> giving the URI of the actor for which
117      * to search
118      * @return an <code>Iterator</code> object over all the
119      * <code>SOAPHeaderBlock</code> objects that contain the specified
120      * actor and are marked as MustUnderstand
121      */

122     public Iterator JavaDoc examineMustUnderstandHeaderBlocks(String JavaDoc actor){
123         Iterator JavaDoc headerBlocksIter = this.getChildren();
124         ArrayList JavaDoc mustUnderstandHeadersWithGivenActor = new ArrayList JavaDoc();
125         while (headerBlocksIter.hasNext()) {
126             Object JavaDoc o = headerBlocksIter.next();
127             if (o instanceof SOAPHeaderBlock) {
128                 SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) o;
129                 String JavaDoc role = soapHeaderBlock.getRole();
130                 boolean mustUnderstand = soapHeaderBlock.getMustUnderstand();
131                 if ((role != null) && role.equalsIgnoreCase(actor) && mustUnderstand) {
132                     mustUnderstandHeadersWithGivenActor.add(soapHeaderBlock);
133                 }
134             }
135         }
136         return mustUnderstandHeadersWithGivenActor.iterator();
137     }
138
139     /**
140      * Returns an <code>Iterator</code> over all the <code>SOAPHeaderBlock</code>
141      * objects in this <code>SOAPHeader</code> object. Not that this will return
142      * elements containing the QName (http://schemas.xmlsoap.org/soap/envelope/,
143      * Header)
144      *
145      * @return an <code>Iterator</code> object over all the
146      * <code>SOAPHeaderBlock</code> objects contained by this
147      * <code>SOAPHeader</code>
148      */

149     public Iterator JavaDoc examineAllHeaderBlocks() {
150         return this.getChildrenWithName(null);
151     }
152
153     /**
154      * Returns an <code>Iterator</code> over all the <code>SOAPHeaderBlock</code>
155      * objects in this <code>SOAPHeader </code> object and detaches them from
156      * this <code>SOAPHeader</code> object.
157      *
158      * @return an <code>Iterator</code> object over all the
159      * <code>SOAPHeaderBlock</code> objects contained by this
160      * <code>SOAPHeader</code>
161      */

162     public Iterator JavaDoc extractAllHeaderBlocks() {
163         throw new UnsupportedOperationException JavaDoc(); // TODO implement this
164
}
165
166     public ArrayList JavaDoc getHeaderBolcksWithNSURI(String JavaDoc nsURI) {
167         ArrayList JavaDoc headers = null;
168         OMNode node = null;
169         OMElement header = this.getFirstElement();
170
171         if (header != null) {
172             headers = new ArrayList JavaDoc();
173         }
174
175         node = header;
176
177         while (node != null) {
178             if (node.getType() == OMNode.ELEMENT_NODE) {
179                 header = (OMElement) node;
180                 if (nsURI.equals(header.getNamespace().getName())) {
181                     headers.add(header);
182                 }
183             }
184             node = node.getNextSibling();
185
186         }
187         return headers;
188
189     }
190
191     protected void checkParent(OMElement parent) throws SOAPProcessingException {
192         if (!(parent instanceof SOAPEnvelopeImpl)) {
193             throw new SOAPProcessingException("Expecting an implementation of SOAP Envelope as the parent. But received some other implementation");
194         }
195     }
196
197 }
198
Popular Tags