1 16 package org.apache.axis2.soap.impl.llom; 17 18 import org.apache.axis2.om.OMConstants; 19 import org.apache.axis2.om.OMElement; 20 import org.apache.axis2.om.OMException; 21 import org.apache.axis2.om.OMXMLParserWrapper; 22 import org.apache.axis2.soap.SOAPBody; 23 import org.apache.axis2.soap.SOAPEnvelope; 24 import org.apache.axis2.soap.SOAPFault; 25 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants; 26 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants; 27 28 31 public abstract class SOAPBodyImpl extends SOAPElement 32 implements SOAPBody, OMConstants { 33 36 private boolean hasSOAPFault = false; 37 38 41 public SOAPBodyImpl(SOAPEnvelope envelope) throws SOAPProcessingException { 42 super(envelope, SOAPConstants.BODY_LOCAL_NAME, true); 43 44 } 45 46 52 public SOAPBodyImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) { 53 super(envelope, SOAPConstants.BODY_LOCAL_NAME, builder); 54 } 55 56 65 public abstract SOAPFault addFault(Exception e) throws OMException; 66 67 75 public boolean hasFault() { 76 if (hasSOAPFault) { 77 return true; 78 } else { 79 OMElement element = getFirstElement(); 80 if (element != null 81 && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName()) 82 && (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName()) 83 || SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName()))) { hasSOAPFault = true; 85 return true; 86 } else { 87 return false; 88 } 89 } 90 } 91 92 99 public SOAPFault getFault() { 100 OMElement element = getFirstElement(); 101 if (hasSOAPFault) { 102 return (SOAPFault) element; 103 } else if (element != null 104 && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName()) 105 && (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName()) 106 || SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName()))) { hasSOAPFault = true; 108 return (SOAPFault) element; 109 } else { 110 return null; 111 } 112 113 } 114 115 120 public void addFault(SOAPFault soapFault) throws OMException { 121 if (hasSOAPFault) { 122 throw new OMException("SOAP Body already has a SOAP Fault and there can not be more than one SOAP fault"); 123 } 124 addChild(soapFault); 125 hasSOAPFault = true; 126 } 127 128 protected void checkParent(OMElement parent) throws SOAPProcessingException { 129 if (!(parent instanceof SOAPEnvelopeImpl)) { 130 throw new SOAPProcessingException("Expecting an implementation of SOAP Envelope as the parent. But received some other implementation"); 131 } 132 } 133 } 134 | Popular Tags |