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 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 String namespaceURI = parser.getNamespaceURI(); 49 String prefix = parser.getPrefix(); 50 OMNamespace namespace = null; 51 if (!"".equals(namespaceURI)) { 52 if (prefix == null) { 53 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 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 uri = parser.getAttributeNamespace(i); 86 if (uri.hashCode() != 0) { 87 ns = node.findNamespace(uri, 88 parser.getAttributePrefix(i)); 89 } 90 91 node.addAttribute(parser.getAttributeLocalName(i), 94 parser.getAttributeValue(i), ns); 95 } 96 } 97 } 98 | Popular Tags |