KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > 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.saaj;
17
18 import org.apache.axis2.om.OMAbstractFactory;
19 import org.apache.axis2.om.OMFactory;
20 import org.apache.axis2.om.OMNamespace;
21
22 import javax.xml.soap.Name JavaDoc;
23 import javax.xml.soap.SOAPException JavaDoc;
24 import javax.xml.soap.SOAPHeader JavaDoc;
25 import javax.xml.soap.SOAPHeaderElement JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 /**
30  * Class SOAPHeaderImpl
31  *
32  * @author Ashutosh Shahi
33  * ashutosh.shahi@gmail.com
34  */

35 public class SOAPHeaderImpl extends SOAPElementImpl implements SOAPHeader JavaDoc {
36
37     /**
38      * Field omHeader OM's SOAPHeader field
39      */

40     private org.apache.axis2.soap.SOAPHeader omHeader;
41     
42     /**
43      * Constructor SOAPHeaderImpl
44      * @param header
45      */

46     public SOAPHeaderImpl(org.apache.axis2.soap.SOAPHeader header){
47         super(header);
48         this.omHeader = header;
49     }
50     
51     /**
52      * Method addHeaderElement
53      *
54      * @param name
55      * @return
56      * @throws SOAPException
57      * @see javax.xml.soap.SOAPHeader#addHeaderElement(javax.xml.soap.Name)
58      */

59     public SOAPHeaderElement JavaDoc addHeaderElement(Name JavaDoc name) throws SOAPException JavaDoc {
60         // Create an OMHeaderBlock out of name and add it a SOAPHeaderElement
61
//to SOAPHeader
62
String JavaDoc localName = name.getLocalName();
63         OMFactory omFactory = OMAbstractFactory.getOMFactory();
64         OMNamespace ns = omFactory.createOMNamespace(name.getURI(), name.getPrefix());
65         org.apache.axis2.soap.SOAPHeaderBlock headerBlock = omHeader.addHeaderBlock(localName, ns);
66         return (new SOAPHeaderElementImpl(headerBlock));
67     }
68
69     /**
70      * method examineHeaderElements
71      *
72      * @param actor
73      * @return
74      * @see javax.xml.soap.SOAPHeader#examineHeaderElements(java.lang.String)
75      */

76     public Iterator JavaDoc examineHeaderElements(String JavaDoc actor) {
77         // Get all the om specific header elements in an iterator and wrap it
78
// in a soap specific iterator and return
79
Iterator JavaDoc headerElementsIter = omHeader.examineHeaderBlocks(actor);
80         ArrayList JavaDoc aList = new ArrayList JavaDoc();
81         while(headerElementsIter.hasNext()){
82             Object JavaDoc o = headerElementsIter.next();
83             if(o instanceof org.apache.axis2.soap.SOAPHeaderBlock){
84                 org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock)o;
85                 SOAPHeaderElement JavaDoc element = (new SOAPHeaderElementImpl(headerBlock));
86                 aList.add(element);
87             }
88         }
89         return aList.iterator();
90     }
91
92     /**
93      * method extractHeaderElements
94      *
95      * @param actor
96      * @return
97      * @see javax.xml.soap.SOAPHeader#extractHeaderElements(java.lang.String)
98      */

99     public Iterator JavaDoc extractHeaderElements(String JavaDoc actor) {
100         // Get all the om specific header elements in an iterator and wrap it
101
// in a soap specific iterator and return
102
Iterator JavaDoc headerElementsIter = omHeader.extractHeaderBlocks(actor);
103         ArrayList JavaDoc aList = new ArrayList JavaDoc();
104         while(headerElementsIter.hasNext()){
105             Object JavaDoc o = headerElementsIter.next();
106             if(o instanceof org.apache.axis2.soap.SOAPHeaderBlock){
107                 org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock)o;
108                 SOAPHeaderElement JavaDoc element = (new SOAPHeaderElementImpl(headerBlock));
109                 aList.add(element);
110             }
111         }
112         return aList.iterator();
113     }
114
115     /**
116      * method examineMustUnderstandHeaderElements
117      *
118      * @param actor
119      * @return
120      * @see javax.xml.soap.SOAPHeader#examineMustUnderstandHeaderElements(java.lang.String)
121      */

122     public Iterator JavaDoc examineMustUnderstandHeaderElements(String JavaDoc actor) {
123         // Get all the om specific header elements in an iterator and wrap it
124
// in a soap specific iterator and return
125
Iterator JavaDoc headerElementsIter = omHeader.examineMustUnderstandHeaderBlocks(actor);
126         ArrayList JavaDoc aList = new ArrayList JavaDoc();
127         while(headerElementsIter.hasNext()){
128             Object JavaDoc o = headerElementsIter.next();
129             if(o instanceof org.apache.axis2.soap.SOAPHeaderBlock){
130                 org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock)o;
131                 SOAPHeaderElement JavaDoc element = (new SOAPHeaderElementImpl(headerBlock));
132                 aList.add(element);
133             }
134         }
135         return aList.iterator();
136     }
137
138     /**
139      * method examineAllHeaderElements
140      *
141      * @return
142      * @see javax.xml.soap.SOAPHeader#examineAllHeaderElements()
143      */

144     public Iterator JavaDoc examineAllHeaderElements() {
145         // Get all the om specific header elements in an iterator and wrap it
146
// in a soap specific iterator and return
147
Iterator JavaDoc headerElementsIter = omHeader.examineAllHeaderBlocks();
148         ArrayList JavaDoc aList = new ArrayList JavaDoc();
149         while(headerElementsIter.hasNext()){
150             Object JavaDoc o = headerElementsIter.next();
151             if(o instanceof org.apache.axis2.soap.SOAPHeaderBlock){
152                 org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock)o;
153                 SOAPHeaderElement JavaDoc element = (new SOAPHeaderElementImpl(headerBlock));
154                 aList.add(element);
155             }
156         }
157         return aList.iterator();
158     }
159
160     /**
161      * method extractAllHeaderElements
162      *
163      * @return
164      * @see javax.xml.soap.SOAPHeader#extractAllHeaderElements()
165      */

166     public Iterator JavaDoc extractAllHeaderElements() {
167         // Get all the om specific header elements in an iterator and wrap it
168
// in a soap specific iterator and return
169
Iterator JavaDoc headerElementsIter = omHeader.extractAllHeaderBlocks();
170         ArrayList JavaDoc aList = new ArrayList JavaDoc();
171         while(headerElementsIter.hasNext()){
172             Object JavaDoc o = headerElementsIter.next();
173             if(o instanceof org.apache.axis2.soap.SOAPHeaderBlock){
174                 org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock)o;
175                 SOAPHeaderElement JavaDoc element = (new SOAPHeaderElementImpl(headerBlock));
176                 aList.add(element);
177             }
178         }
179         return aList.iterator();
180     }
181     
182     /*public boolean equals(Object o){
183         if(o instanceof SOAPHeaderImpl){
184             if(this.omHeader.equals(((SOAPHeaderImpl)o).omHeader))
185                     return true;
186         }
187         return false;
188     }*/

189
190 }
191
Popular Tags