KickJava   Java API By Example, From Geeks To Geeks.

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


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

31
32 public class SOAP11BuilderHelper extends SOAPBuilderHelper implements SOAP11Constants {
33     private SOAPFactory factory;
34     private boolean faultcodePresent = false;
35     private boolean faultstringPresent = false;
36
37     private OMElement lastProcessedSOAPElement;
38
39     public SOAP11BuilderHelper(StAXSOAPModelBuilder builder) {
40         super(builder);
41         factory = OMAbstractFactory.getSOAP11Factory();
42     }
43
44     public OMElement handleEvent(XMLStreamReader parser, OMElement parent, int elementLevel) throws SOAPProcessingException {
45         this.parser = parser;
46
47         OMElement element = null;
48         String JavaDoc localName = parser.getLocalName();
49
50         if (elementLevel == 4) {
51
52             if (SOAP_FAULT_CODE_LOCAL_NAME.equals(localName)) {
53                 if (faultstringPresent) {
54                     builder.setBooleanProcessingMandatoryFaultElements(false);
55                 }
56                 SOAPFaultCode code = factory.createSOAPFaultCode((SOAPFault) parent, builder);
57                 SOAPFaultValue value = factory.createSOAPFaultValue(code);
58                 processNamespaceData(code, true);
59                 processAttributes(code);
60
61                 processText(parser, value);
62                 code.setComplete(true);
63                 element = code;
64                 builder.elementLevel--;
65
66                 faultcodePresent = true;
67             } else if (SOAP_FAULT_STRING_LOCAL_NAME.equals(localName)) {
68                 if (faultcodePresent) {
69                     builder.setBooleanProcessingMandatoryFaultElements(false);
70                 }
71
72
73                 SOAPFaultReason reason = factory.createSOAPFaultReason((SOAPFault) parent, builder);
74                 SOAPFaultText faultText = factory.createSOAPFaultText(reason);
75                 processNamespaceData(reason, true);
76                 processAttributes(reason);
77
78                 processText(parser, faultText);
79                 reason.setComplete(true);
80                 element = reason;
81                 builder.elementLevel--;
82
83
84                 faultstringPresent = true;
85             } else if (SOAP_FAULT_ACTOR_LOCAL_NAME.equals(localName)) {
86                 element = factory.createSOAPFaultRole((SOAPFault) parent, builder);
87                 processNamespaceData(element, true);
88                 processAttributes(element);
89             } else if (SOAP_FAULT_DETAIL_LOCAL_NAME.equals(localName)) {
90                 element = factory.createSOAPFaultDetail((SOAPFault) parent, builder);
91                 processNamespaceData(element, true);
92                 processAttributes(element);
93             } else {
94                 element = OMAbstractFactory.getOMFactory().createOMElement(localName, null, parent, builder);
95                 processNamespaceData(element, false);
96                 processAttributes(element);
97             }
98
99         } else if (elementLevel == 5) {
100
101             if (parent.getLocalName().equals(SOAP_FAULT_CODE_LOCAL_NAME)) {
102                 throw new OMBuilderException("faultcode element should not have children");
103             } else if (parent.getLocalName().equals(SOAP_FAULT_STRING_LOCAL_NAME)) {
104                 throw new OMBuilderException("faultstring element should not have children");
105             } else if (parent.getLocalName().equals(SOAP_FAULT_ACTOR_LOCAL_NAME)) {
106                 throw new OMBuilderException("faultactor element should not have children");
107             } else {
108                 element = OMAbstractFactory.getOMFactory().createOMElement(localName, null, parent, builder);
109                 processNamespaceData(element, false);
110                 processAttributes(element);
111             }
112
113         } else if (elementLevel > 5) {
114             element = OMAbstractFactory.getOMFactory().createOMElement(localName, null, parent, builder);
115             processNamespaceData(element, false);
116             processAttributes(element);
117         }
118
119         return element;
120     }
121
122     private void processText(XMLStreamReader parser, OMElement value) {
123         try {
124             int token = parser.next();
125             while (token != XMLStreamReader.END_ELEMENT) {
126                 if (token == XMLStreamReader.CHARACTERS) {
127                     OMText text = factory.createText(value, parser.getText());
128                     value.addChild(text);
129                 } else {
130                     throw new SOAPProcessingException("Only Characters are allowed here");
131                 }
132                 token = parser.next();
133             }
134
135
136         } catch (XMLStreamException e) {
137             throw new SOAPProcessingException(e);
138         }
139     }
140
141 }
Popular Tags