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.constants.Style; 27 import org.apache.axis.components.logger.LogFactory; 28 import org.apache.axis.description.OperationDesc; 29 import org.apache.axis.description.ParameterDesc; 30 import org.apache.axis.encoding.DeserializationContext; 31 import org.apache.axis.encoding.Deserializer; 32 import org.apache.axis.encoding.DeserializerImpl; 33 import org.apache.axis.encoding.XMLType; 34 import org.apache.axis.soap.SOAPConstants; 35 import org.apache.axis.utils.JavaUtils; 36 import org.apache.axis.utils.Messages; 37 import org.apache.commons.logging.Log; 38 import org.w3c.dom.Element ; 39 import org.xml.sax.Attributes ; 40 import org.xml.sax.SAXException ; 41 42 import javax.xml.namespace.QName ; 43 44 58 public class RPCHandler extends SOAPHandler 59 { 60 protected static Log log = 61 LogFactory.getLog(RPCHandler.class.getName()); 62 63 private RPCElement rpcElem; 64 private RPCParam currentParam = null; 65 private boolean isResponse; 66 private OperationDesc operation; 67 private boolean isHeaderElement; 68 69 public RPCHandler(RPCElement rpcElem, boolean isResponse) 70 throws SAXException 71 { 72 this.rpcElem = rpcElem; 73 this.isResponse = isResponse; 74 } 75 76 public void setOperation(OperationDesc myOperation) { 77 this.operation = myOperation; 78 } 79 80 85 public void setHeaderElement(boolean value) { 86 isHeaderElement = true; 87 } 88 89 99 public void startElement(String namespace, String localName, 100 String prefix, Attributes attributes, 101 DeserializationContext context) 102 throws SAXException 103 { 104 super.startElement(namespace, localName, prefix, attributes, context); 105 currentParam = null; 106 } 107 108 117 public SOAPHandler onStartChild(String namespace, 118 String localName, 119 String prefix, 120 Attributes attributes, 121 DeserializationContext context) 122 throws SAXException 123 { 124 if (log.isDebugEnabled()) { 125 log.debug("Enter: RPCHandler.onStartChild()"); 126 } 127 128 if (!context.isDoneParsing()) { 129 try { 130 context.pushNewElement(new MessageElement(namespace, localName, 131 prefix, attributes, 132 context)); 133 } catch (AxisFault axisFault) { 134 throw new SAXException (axisFault); 135 } 136 } 137 138 MessageElement curEl = context.getCurElement(); 139 QName type = null; 140 QName qname = new QName (namespace, localName); 141 ParameterDesc paramDesc = null; 142 143 SOAPConstants soapConstants = context.getSOAPConstants(); 144 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && 145 Constants.QNAME_RPC_RESULT.equals(qname)) { 146 return new DeserializerImpl(); 148 } 149 150 if (currentParam == null || 152 !currentParam.getQName().getNamespaceURI().equals(namespace) || 153 !currentParam.getQName().getLocalPart().equals(localName)) { 154 currentParam = new RPCParam(namespace, localName, null); 155 rpcElem.addParam(currentParam); 156 } 157 158 type = curEl.getType(); 162 if (type == null) { 163 type = context.getTypeFromAttributes(namespace, 164 localName, 165 attributes); 166 } 167 168 if (log.isDebugEnabled()) { 169 log.debug(Messages.getMessage("typeFromAttr00", "" + type)); 170 } 171 172 173 Class destClass = null; 174 175 if (operation != null) { 178 179 if (isResponse) { 181 paramDesc = operation.getOutputParamByQName(qname); 182 } else { 183 paramDesc = operation.getInputParamByQName(qname); 184 } 185 186 187 if (paramDesc == null) { 193 if (isResponse) { 194 paramDesc = operation.getReturnParamDesc(); 195 } 196 else { 197 paramDesc = operation.getParameter(rpcElem.getParams().size() - 1); 198 } 199 } 200 201 if (paramDesc == null) { 202 throw new SAXException (Messages.getMessage("noParmDesc")); 203 } 204 if (!isHeaderElement && 207 ((isResponse && paramDesc.isOutHeader()) || 208 (!isResponse && paramDesc.isInHeader()))) { 209 throw new SAXException ( 210 Messages.getMessage("expectedHeaderParam", 211 paramDesc.getQName().toString())); 212 } 213 214 destClass = paramDesc.getJavaType(); 215 if ((destClass != null) && (destClass.isArray())) { 216 context.setDestinationClass(destClass); 217 } 218 219 currentParam.setParamDesc(paramDesc); 222 223 if (type == null) { 224 type = paramDesc.getTypeQName(); 225 } 226 } 227 228 if (type != null && type.equals(XMLType.AXIS_VOID)) { 229 Deserializer nilDSer = new DeserializerImpl(); 230 return (SOAPHandler) nilDSer; 231 } 232 233 if (context.isNil(attributes)) { 246 Deserializer nilDSer = new DeserializerImpl(); 247 nilDSer.registerValueTarget(new RPCParamTarget(currentParam)); 248 return (SOAPHandler) nilDSer; 249 } 250 251 Deserializer dser = null; 252 if ((type == null) && (namespace != null) && (!namespace.equals(""))) { 253 dser = context.getDeserializerForType(qname); 254 } else { 255 dser = context.getDeserializer(destClass, type); 256 if (dser == null && destClass != null && destClass.isArray() && 258 operation.getStyle() == Style.DOCUMENT) { 259 dser = context.getDeserializerForClass(destClass); 260 } 261 } 263 264 if (dser == null) { 265 if (type != null) { 266 dser = context.getDeserializerForType(type); 267 if(null != destClass && dser == null && Element .class.isAssignableFrom(destClass)){ 268 dser = context.getDeserializerForType(Constants.SOAP_ELEMENT); 271 272 } 273 if (dser == null) { 274 dser = context.getDeserializerForClass(destClass); 275 } 276 if (dser == null) { 277 throw new SAXException (Messages.getMessage( 278 "noDeser01", localName,"" + type)); 279 } 280 if (paramDesc != null && paramDesc.getJavaType() != null) { 281 Class xsiClass = 284 context.getTypeMapping().getClassForQName(type); 285 if (null != xsiClass && !JavaUtils.isConvertable(xsiClass, destClass)) { 286 throw new SAXException ("Bad types (" + 287 xsiClass + " -> " + destClass + ")"); } 289 } 290 } else { 291 dser = context.getDeserializerForClass(destClass); 292 if (dser == null) { 293 dser = new DeserializerImpl(); 294 } 295 } 296 } 297 298 dser.setDefaultType(type); 299 300 dser.registerValueTarget(new RPCParamTarget(currentParam)); 301 302 if (log.isDebugEnabled()) { 303 log.debug("Exit: RPCHandler.onStartChild()"); 304 } 305 return (SOAPHandler)dser; 306 } 307 308 public void endElement(String namespace, String localName, 309 DeserializationContext context) 310 throws SAXException 311 { 312 if (log.isDebugEnabled()) { 317 log.debug(Messages.getMessage("setProp00", 318 "MessageContext", "RPCHandler.endElement().")); 319 } 320 context.getMessageContext().setProperty("RPC", rpcElem); 321 } 322 } 323 | Popular Tags |