1 55 56 package org.jboss.axis.message; 57 58 62 63 import org.jboss.axis.AxisFault; 64 import org.jboss.axis.Constants; 65 import org.jboss.axis.MessageContext; 66 import org.jboss.axis.description.OperationDesc; 67 import org.jboss.axis.encoding.DeserializationContext; 68 import org.jboss.axis.enums.Style; 69 import org.jboss.axis.soap.SOAPConstants; 70 import org.jboss.axis.utils.Messages; 71 import org.jboss.logging.Logger; 72 import org.xml.sax.Attributes ; 73 import org.xml.sax.SAXException ; 74 75 import javax.xml.namespace.QName ; 76 77 public class BodyBuilder extends SOAPHandler 78 { 79 private static Logger log = Logger.getLogger(BodyBuilder.class.getName()); 80 81 boolean gotRPCElement = false; 82 83 private SOAPEnvelopeAxisImpl envelope; 84 85 BodyBuilder(SOAPEnvelopeAxisImpl envelope) 86 { 87 this.envelope = envelope; 88 } 89 90 public void startElement(String namespace, String localName, 91 String prefix, Attributes attributes, 92 DeserializationContext context) 93 throws SAXException 94 { 95 SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; 96 if (context.getMessageContext() != null) 97 soapConstants = context.getMessageContext().getSOAPConstants(); 98 99 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && 100 attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) 101 { 102 103 AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, 104 null, Messages.getMessage("noEncodingStyleAttrAppear", "Body"), null, null, null); 105 106 throw new SAXException (fault); 107 } 108 109 if (!context.isDoneParsing()) 111 { 112 if (!context.isProcessingRef()) 113 { 114 if (myElement == null) 115 { 116 try 117 { 118 myElement = new SOAPBodyAxisImpl(namespace, localName, prefix, 119 attributes, context, envelope.getSOAPConstants()); 120 } 121 catch (AxisFault axisFault) 122 { 123 throw new SAXException (axisFault); 124 } 125 } 126 context.pushNewElement(myElement); 127 } 128 envelope.setBody((SOAPBodyAxisImpl)myElement); 129 } 130 } 131 132 public SOAPElementAxisImpl makeNewElement(String namespace, String localName, 134 String prefix, Attributes attributes, 135 DeserializationContext context) 136 throws AxisFault 137 { 138 SOAPConstants soapConstants = context.getMessageContext() == null ? 139 SOAPConstants.SOAP11_CONSTANTS : 140 context.getMessageContext().getSOAPConstants(); 141 return new SOAPBodyAxisImpl(namespace, 142 localName, 143 prefix, 144 attributes, 145 context, 146 soapConstants); 147 } 148 149 public SOAPHandler onStartChild(String namespace, 150 String localName, 151 String prefix, 152 Attributes attributes, 153 DeserializationContext context) 154 throws SAXException 155 { 156 SOAPBodyElementAxisImpl element = null; 157 if (log.isDebugEnabled()) 158 { 159 log.debug("Enter: BodyBuilder::onStartChild()"); 160 } 161 162 QName qname = new QName (namespace, localName); 163 SOAPHandler handler = null; 164 165 173 boolean isRoot = true; 174 String root = attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC, 175 Constants.ATTR_ROOT); 176 if ((root != null) && root.equals("0")) isRoot = false; 177 178 MessageContext msgContext = context.getMessageContext(); 179 OperationDesc[] operations = null; 180 try 181 { 182 if (msgContext != null) 183 { 184 operations = msgContext.getPossibleOperationsByQName(qname); 185 } 186 187 if ((operations != null) && (operations.length == 1)) 189 msgContext.setOperation(operations[0]); 190 } 191 catch (org.jboss.axis.AxisFault e) 192 { 193 throw new SAXException (e); 196 } 197 198 Style style = operations == null ? Style.RPC : operations[0].getStyle(); 199 MessageContext messageContext = context.getMessageContext(); 200 SOAPConstants soapConstants = messageContext == null ? SOAPConstants.SOAP11_CONSTANTS : messageContext.getSOAPConstants(); 201 202 206 if (Constants.ELEM_FAULT.equals(localName) && namespace.equals(soapConstants.getEnvelopeURI())) 207 { 208 try 209 { 210 element = new SOAPFaultImpl(namespace, localName, prefix, 211 attributes, context); 212 } 213 catch (AxisFault axisFault) 214 { 215 throw new SAXException (axisFault); 216 } 217 element.setEnvelope(context.getEnvelope()); 218 handler = new SOAPFaultBuilder((SOAPFaultImpl)element, 219 context); 220 } 221 else if (!gotRPCElement) 222 { 223 if (isRoot && (style != Style.MESSAGE)) 224 { 225 gotRPCElement = true; 226 227 try 228 { 229 230 element = new RPCElement(namespace, localName, prefix, 231 attributes, context, operations); 232 233 } 234 catch (org.jboss.axis.AxisFault e) 235 { 236 throw new SAXException (e); 240 } 241 242 if (operations == null && 245 (msgContext != null && !msgContext.isClient() && 246 (msgContext.getProperty(Constants.MC_NO_OPERATION_OK) == null)) && 247 soapConstants == SOAPConstants.SOAP12_CONSTANTS) 248 { 249 AxisFault fault = 250 new AxisFault(Constants.FAULT_SOAP12_SENDER, 251 "No such procedure", null, null); 252 fault.addFaultSubCode(Constants.FAULT_SUBCODE_PROC_NOT_PRESENT); 253 throw new SAXException (fault); 254 } 255 256 if (msgContext != null && !msgContext.isHighFidelity()) 261 { 262 if (operations == null || operations.length == 1) 263 { 264 ((RPCElement)element).setNeedDeser(false); 265 handler = new RPCHandler((RPCElement)element, false); 266 if (operations != null) 267 { 268 ((RPCHandler)handler).setOperation(operations[0]); 269 msgContext.setOperation(operations[0]); 270 } 271 } 272 } 273 274 if (handler == null) 275 handler = new RPCElementHandler(); 276 } 277 } 278 279 if (element == null) 280 { 281 if ((style == Style.RPC) && 282 soapConstants == SOAPConstants.SOAP12_CONSTANTS) 283 { 284 throw new SAXException (Messages.getMessage("onlyOneBodyFor12")); 285 } 286 try 287 { 288 element = new SOAPBodyElementAxisImpl(namespace, localName, prefix, 289 attributes, context); 290 } 291 catch (AxisFault axisFault) 292 { 293 throw new SAXException (axisFault); 294 } 295 if (element.getFixupDeserializer() != null) 296 handler = (SOAPHandler)element.getFixupDeserializer(); 297 } 298 299 if (handler == null) 300 handler = new SOAPHandler(); 301 302 handler.myElement = element; 303 304 306 if (log.isDebugEnabled()) 307 { 308 log.debug("Exit: BodyBuilder::onStartChild()"); 309 } 310 return handler; 311 } 312 313 public void onEndChild(String namespace, String localName, 314 DeserializationContext context) 315 { 316 } 317 } 318 | Popular Tags |