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.impl.llom.exception.OMBuilderException; 6 import org.apache.axis2.soap.*; 7 import org.apache.axis2.soap.impl.llom.SOAPProcessingException; 8 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants; 9 10 import javax.xml.stream.XMLStreamReader; 11 import java.util.Vector ; 12 13 30 31 public class SOAP12BuilderHelper extends SOAPBuilderHelper { 32 33 private SOAPFactory factory; 34 private boolean codePresent = false; 35 private boolean reasonPresent = false; 36 private boolean nodePresent = false; 37 private boolean rolePresent = false; 38 private boolean detailPresent = false; 39 private boolean subcodeValuePresent = false; 40 private boolean subSubcodePresent = false; 41 private boolean valuePresent = false; 42 private boolean subcodePresent = false; 43 private boolean codeprocessing = false; 44 private boolean subCodeProcessing = false; 45 private boolean reasonProcessing = false; 46 private Vector detailElementNames; 47 48 public SOAP12BuilderHelper(StAXSOAPModelBuilder builder) { 49 super(builder); 50 factory = OMAbstractFactory.getSOAP12Factory(); 51 } 52 53 public OMElement handleEvent(XMLStreamReader parser, OMElement parent, int elementLevel) throws SOAPProcessingException { 54 55 this.parser = parser; 56 OMElement element = null; 57 58 if (elementLevel == 4) { 59 if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) { 60 if (codePresent) { 61 throw new OMBuilderException("Multiple Code element encountered"); 62 } else { 63 element = factory.createSOAPFaultCode((SOAPFault) parent, builder); 64 codePresent = true; 65 codeprocessing = true; 66 } 67 } else if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) { 68 if (!codeprocessing && !subCodeProcessing) { 69 if (codePresent) { 70 if (reasonPresent) { 71 throw new OMBuilderException("Multiple Reason Element encountered"); 72 } else { 73 element = factory.createSOAPFaultReason((SOAPFault) parent, builder); 74 reasonPresent = true; 75 reasonProcessing = true; 76 } 77 } else { 78 throw new OMBuilderException("Wrong element order encountred at " + parser.getLocalName()); 79 } 80 } else { 81 if (codeprocessing) { 82 throw new OMBuilderException("Code doesn't have a value"); 83 } else { 84 throw new OMBuilderException("A subcode doesn't have a Value"); 85 } 86 } 87 88 } else if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME)) { 89 if (!reasonProcessing) { 90 if (reasonPresent && !rolePresent && !detailPresent) { 91 if (nodePresent) { 92 throw new OMBuilderException("Multiple Node element encountered"); 93 } else { 94 element = factory.createSOAPFaultNode((SOAPFault) parent, builder); 95 nodePresent = true; 96 } 97 } else { 98 throw new OMBuilderException("wrong element order encountered at " + parser.getLocalName()); 99 } 100 } else { 101 throw new OMBuilderException("Reason element Should have a text"); 102 } 103 } else if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME)) { 104 if (!reasonProcessing) { 105 if (reasonPresent && !detailPresent) { 106 if (rolePresent) { 107 throw new OMBuilderException("Multiple Role element encountered"); 108 } else { 109 element = factory.createSOAPFaultRole((SOAPFault) parent, builder); 110 rolePresent = true; 111 } 112 } else { 113 throw new OMBuilderException("Wrong element order encountered at " + parser.getLocalName()); 114 } 115 } else { 116 throw new OMBuilderException("Reason element should have a text"); 117 } 118 } else if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) { 119 if (!reasonProcessing) { 120 if (reasonPresent) { 121 if (detailPresent) { 122 throw new OMBuilderException("Multiple detail element encountered"); 123 } else { 124 element = factory.createSOAPFaultDetail((SOAPFault) parent, builder); 125 detailPresent = true; 126 } 127 } else { 128 throw new OMBuilderException("wrong element order encountered at " + parser.getLocalName()); 129 } 130 } else { 131 throw new OMBuilderException("Reason element should have a text"); 132 } 133 } else { 134 throw new OMBuilderException(parser.getLocalName() + " unsupported element in SOAPFault element"); 135 } 136 137 } else if (elementLevel == 5) { 138 if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) { 139 if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) { 140 if (!valuePresent) { 141 element = factory.createSOAPFaultValue((SOAPFaultCode) parent, builder); 142 valuePresent = true; 143 codeprocessing = false; 144 } else { 145 throw new OMBuilderException("Multiple value Encountered in code element"); 146 } 147 148 } else if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) { 149 if (!subcodePresent) { 150 if (valuePresent) { 151 element = factory.createSOAPFaultSubCode((SOAPFaultCode) parent, builder); 152 subcodePresent = true; 153 subCodeProcessing = true; 154 } else { 155 throw new OMBuilderException("Value should present before the subcode"); 156 } 157 158 } else { 159 throw new OMBuilderException("multiple subcode Encountered in code element"); 160 } 161 } else { 162 throw new OMBuilderException(parser.getLocalName() + " is not supported inside the code element"); 163 } 164 165 } else if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) { 166 if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME)) { 167 element = factory.createSOAPFaultText((SOAPFaultReason) parent, builder); 168 element.setComplete(false); 169 reasonProcessing = false; 170 builder.setBooleanProcessingMandatoryFaultElements(false); 171 } else { 172 throw new OMBuilderException(parser.getLocalName() + " is not supported inside the reason"); 173 } 174 } else if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) { 175 element = OMAbstractFactory.getOMFactory().createOMElement(parser.getLocalName(), null, parent, builder); 176 builder.setProcessingDetailElements(true); 177 detailElementNames = new Vector (); 178 detailElementNames.add(parser.getLocalName()); 179 180 } else { 181 throw new OMBuilderException(parent.getLocalName() + " should not have child element"); 182 } 183 184 185 } else if (elementLevel > 5) { 186 if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) { 187 if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) { 188 if (subcodeValuePresent) { 189 throw new OMBuilderException("multiple subCode value encountered"); 190 } else { 191 element = factory.createSOAPFaultValue((SOAPFaultSubCode) parent, builder); 192 subcodeValuePresent = true; 193 subSubcodePresent = false; 194 subCodeProcessing = false; 195 } 196 } else if (parser.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) { 197 if (subcodeValuePresent) { 198 if (!subSubcodePresent) { 199 element = factory.createSOAPFaultSubCode((SOAPFaultSubCode) parent, builder); 200 subcodeValuePresent = false; 201 subSubcodePresent = true; 202 subCodeProcessing = true; 203 } else { 204 throw new OMBuilderException("multiple subcode encountered"); 205 } 206 } else { 207 throw new OMBuilderException("Value should present before the subcode"); 208 } 209 } else { 210 throw new OMBuilderException(parser.getLocalName() + " is not supported inside the subCode element"); 211 } 212 } else if (builder.isProcessingDetailElements()) { 213 int detailElementLevel = 0; 214 boolean localNameExist = false; 215 for (int i = 0; i < detailElementNames.size(); i++) { 216 if (parent.getLocalName().equals((String ) detailElementNames.get(i))) { 217 localNameExist = true; 218 detailElementLevel = i + 1; 219 } 220 } 221 if (localNameExist) { 222 detailElementNames.setSize(detailElementLevel); 223 element = OMAbstractFactory.getOMFactory().createOMElement(parser.getLocalName(), null, parent, builder); 224 detailElementNames.add(parser.getLocalName()); 225 } 226 227 } else { 228 throw new OMBuilderException(parent.getLocalName() + " should not have child at element level " + elementLevel); 229 } 230 } 231 232 processNamespaceData(element, false); 233 processAttributes(element); 234 return element; 235 } 236 } | Popular Tags |