KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > soap > impl > llom > builder > SOAPBuilderHelper


1 package org.apache.axis2.soap.impl.llom.builder;
2
3 import org.apache.axis2.om.OMElement;
4 import org.apache.axis2.om.OMNamespace;
5 import org.apache.axis2.om.impl.llom.exception.OMBuilderException;
6 import org.apache.axis2.soap.impl.llom.SOAPProcessingException;
7 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants;
8 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
9
10 import javax.xml.stream.XMLStreamReader;
11
12 /*
13  * Copyright 2004,2005 The Apache Software Foundation.
14  *
15  * Licensed under the Apache License, Version 2.0 (the "License");
16  * you may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at
18  *
19  * http://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  *
27  * author : Eran Chinthaka (chinthaka@apache.org)
28  */

29
30 public abstract class SOAPBuilderHelper {
31     protected StAXSOAPModelBuilder builder;
32     protected XMLStreamReader parser;
33
34     protected SOAPBuilderHelper(StAXSOAPModelBuilder builder) {
35         this.builder = builder;
36     }
37
38     public abstract OMElement handleEvent(XMLStreamReader parser, OMElement element, int elementLevel) throws SOAPProcessingException ;
39
40     protected void processNamespaceData(OMElement node, boolean isSOAPElement) {
41         int namespaceCount = parser.getNamespaceCount();
42         for (int i = 0; i < namespaceCount; i++) {
43             node.declareNamespace(parser.getNamespaceURI(i),
44                     parser.getNamespacePrefix(i));
45         }
46
47         // set the own namespace
48
String JavaDoc namespaceURI = parser.getNamespaceURI();
49         String JavaDoc prefix = parser.getPrefix();
50         OMNamespace namespace = null;
51         if (!"".equals(namespaceURI)) {
52             if (prefix == null) {
53                 // this means, this elements has a default namespace or it has inherited a default namespace from its parent
54
namespace = node.findNamespace(namespaceURI, "");
55                 if (namespace == null) {
56                     namespace = node.declareNamespace(namespaceURI, "");
57                 }
58             } else {
59                 namespace = node.findNamespace(namespaceURI, prefix);
60             }
61             node.setNamespace(namespace);
62         } else {
63
64         }
65
66
67
68         // TODO we got to have this to make sure OM reject mesagess that are not name space qualified
69
// But got to comment this to interop with Axis.1.x
70
// if (namespace == null) {
71
// throw new OMException("All elements must be namespace qualified!");
72
// }
73
if (isSOAPElement) {
74             if (node.getNamespace() != null && !node.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI) && !node.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
75                 throw new OMBuilderException("invalid SOAP namespace URI");
76             }
77         }
78
79     }
80
81     protected void processAttributes(OMElement node) {
82         int attribCount = parser.getAttributeCount();
83         for (int i = 0; i < attribCount; i++) {
84             OMNamespace ns = null;
85             String JavaDoc uri = parser.getAttributeNamespace(i);
86             if (uri.hashCode() != 0) {
87                 ns = node.findNamespace(uri,
88                         parser.getAttributePrefix(i));
89             }
90
91             // todo if the attributes are supposed to namespace qualified all the time
92
// todo then this should throw an exception here
93
node.addAttribute(parser.getAttributeLocalName(i),
94                     parser.getAttributeValue(i), ns);
95         }
96     }
97 }
98
Popular Tags