1 16 17 package org.apache.axis.message; 18 19 23 24 import org.apache.axis.AxisFault; 25 import org.apache.axis.Constants; 26 import org.apache.axis.MessageContext; 27 import org.apache.axis.Message; 28 import org.apache.axis.components.logger.LogFactory; 29 import org.apache.axis.description.OperationDesc; 30 import org.apache.axis.encoding.DeserializationContext; 31 import org.apache.axis.constants.Style; 32 import org.apache.axis.soap.SOAPConstants; 33 import org.apache.axis.utils.Messages; 34 import org.apache.commons.logging.Log; 35 import org.xml.sax.Attributes ; 36 import org.xml.sax.SAXException ; 37 38 import javax.xml.namespace.QName ; 39 40 public class BodyBuilder extends SOAPHandler 41 { 42 protected static Log log = 43 LogFactory.getLog(BodyBuilder.class.getName()); 44 45 boolean gotRPCElement = false; 46 47 private SOAPEnvelope envelope; 48 49 BodyBuilder(SOAPEnvelope envelope) 50 { 51 this.envelope = envelope; 52 } 53 54 public void startElement(String namespace, String localName, 55 String prefix, Attributes attributes, 56 DeserializationContext context) 57 throws SAXException 58 { 59 SOAPConstants soapConstants = context.getSOAPConstants(); 60 61 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && 62 attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { 63 64 AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, 65 null, Messages.getMessage("noEncodingStyleAttrAppear", "Body"), null, null, null); 66 67 throw new SAXException (fault); 68 } 69 70 if (!context.isDoneParsing()) { 72 if (!context.isProcessingRef()) { 73 if (myElement == null) { 74 try { 75 myElement = new SOAPBody(namespace, localName, prefix, 76 attributes, context, envelope.getSOAPConstants()); 77 } catch (AxisFault axisFault) { 78 throw new SAXException (axisFault); 79 } 80 } 81 context.pushNewElement(myElement); 82 } 83 envelope.setBody((SOAPBody)myElement); 84 } 85 } 86 87 public MessageElement makeNewElement(String namespace, String localName, 89 String prefix, Attributes attributes, 90 DeserializationContext context) 91 throws AxisFault { 92 return new SOAPBody(namespace, 93 localName, 94 prefix, 95 attributes, 96 context, 97 context.getSOAPConstants()); 98 } 99 100 public SOAPHandler onStartChild(String namespace, 101 String localName, 102 String prefix, 103 Attributes attributes, 104 DeserializationContext context) 105 throws SAXException 106 { 107 SOAPBodyElement element = null; 108 if (log.isDebugEnabled()) { 109 log.debug("Enter: BodyBuilder::onStartChild()"); 110 } 111 112 QName qname = new QName (namespace, localName); 113 SOAPHandler handler = null; 114 115 123 boolean isRoot = true; 124 String root = attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC, 125 Constants.ATTR_ROOT); 126 if ((root != null) && root.equals("0")) isRoot = false; 127 128 MessageContext msgContext = context.getMessageContext(); 129 OperationDesc [] operations = null; 130 try { 131 if(msgContext != null) { 132 operations = msgContext.getPossibleOperationsByQName(qname); 133 } 134 135 if ((operations != null) && (operations.length == 1)) 137 msgContext.setOperation(operations[0]); 138 } catch (org.apache.axis.AxisFault e) { 139 throw new SAXException (e); 142 } 143 144 Style style = operations == null ? Style.RPC : operations[0].getStyle(); 145 SOAPConstants soapConstants = context.getSOAPConstants(); 146 147 151 if (localName.equals(Constants.ELEM_FAULT) && 152 namespace.equals(soapConstants.getEnvelopeURI())) { 153 try { 154 element = new SOAPFault(namespace, localName, prefix, 155 attributes, context); 156 } catch (AxisFault axisFault) { 157 throw new SAXException (axisFault); 158 } 159 element.setEnvelope(context.getEnvelope()); 160 handler = new SOAPFaultBuilder((SOAPFault)element, 161 context); 162 } else if (!gotRPCElement) { 163 if (isRoot && (style != Style.MESSAGE)) { 164 gotRPCElement = true; 165 166 try { 167 168 element = new RPCElement(namespace, localName, prefix, 169 attributes, context, operations); 170 171 } catch (org.apache.axis.AxisFault e) { 172 throw new SAXException (e); 176 } 177 178 if (msgContext != null && !msgContext.isHighFidelity() && 183 (operations == null || operations.length == 1)) { 184 ((RPCElement)element).setNeedDeser(false); 185 boolean isResponse = false; 186 if (msgContext.getCurrentMessage() != null && 187 Message.RESPONSE.equals(msgContext.getCurrentMessage().getMessageType())) 188 isResponse = true; 189 handler = new RPCHandler((RPCElement)element, 190 isResponse); 191 if (operations != null) { 192 ((RPCHandler)handler).setOperation(operations[0]); 193 msgContext.setOperation(operations[0]); 194 } 195 } 196 } 197 } 198 199 if (element == null) { 200 if ((style == Style.RPC) && 201 soapConstants == SOAPConstants.SOAP12_CONSTANTS) { 202 throw new SAXException (Messages.getMessage("onlyOneBodyFor12")); 203 } 204 try { 205 element = new SOAPBodyElement(namespace, localName, prefix, 206 attributes, context); 207 } catch (AxisFault axisFault) { 208 throw new SAXException (axisFault); 209 } 210 if (element.getFixupDeserializer() != null) 211 handler = (SOAPHandler)element.getFixupDeserializer(); 212 } 213 214 if (handler == null) 215 handler = new SOAPHandler(); 216 217 handler.myElement = element; 218 219 221 if (log.isDebugEnabled()) { 222 log.debug("Exit: BodyBuilder::onStartChild()"); 223 } 224 return handler; 225 } 226 227 public void onEndChild(String namespace, String localName, 228 DeserializationContext context) 229 { 230 } 231 } 232 | Popular Tags |