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.description.OperationDesc; 66 import org.jboss.axis.description.ParameterDesc; 67 import org.jboss.axis.encoding.DeserializationContext; 68 import org.jboss.axis.encoding.Deserializer; 69 import org.jboss.axis.encoding.DeserializerImpl; 70 import org.jboss.axis.encoding.MethodTarget; 71 import org.jboss.axis.soap.SOAPConstants; 72 import org.jboss.axis.utils.JavaUtils; 73 import org.jboss.axis.utils.Messages; 74 import org.jboss.logging.Logger; 75 import org.xml.sax.Attributes ; 76 import org.xml.sax.SAXException ; 77 78 import javax.xml.namespace.QName ; 79 import javax.xml.soap.SOAPElement ; 80 import java.util.Vector ; 81 82 96 public class RPCHandler extends SOAPHandler 97 { 98 private static Logger log = Logger.getLogger(RPCHandler.class.getName()); 99 100 private RPCElement rpcElem; 101 private RPCParam currentParam = null; 102 private boolean isResponse; 103 private OperationDesc operation; 104 private boolean isHeaderElement; 105 106 public RPCHandler(RPCElement rpcElem, boolean isResponse) 107 { 108 this.rpcElem = rpcElem; 109 this.isResponse = isResponse; 110 } 111 112 public void setOperation(OperationDesc myOperation) 113 { 114 this.operation = myOperation; 115 } 116 117 123 public void setHeaderElement(boolean value) 124 { 125 isHeaderElement = true; 126 } 127 128 139 public void startElement(String namespace, String localName, 140 String prefix, Attributes attributes, 141 DeserializationContext context) 142 throws SAXException 143 { 144 super.startElement(namespace, localName, prefix, attributes, context); 145 currentParam = null; 146 } 147 148 157 public SOAPHandler onStartChild(String namespace, 158 String localName, 159 String prefix, 160 Attributes attributes, 161 DeserializationContext context) 162 throws SAXException 163 { 164 if (log.isDebugEnabled()) 165 { 166 log.debug("Enter: RPCHandler.onStartChild()"); 167 } 168 169 if (!context.isDoneParsing()) 170 { 171 try 172 { 173 context.pushNewElement(new SOAPElementAxisImpl(namespace, localName, 174 prefix, attributes, 175 context)); 176 } 177 catch (AxisFault axisFault) 178 { 179 throw new SAXException (axisFault); 180 } 181 } 182 183 SOAPElementAxisImpl curEl = context.getCurElement(); 184 QName type = null; 185 QName qname = new QName (namespace, localName); 186 ParameterDesc paramDesc = null; 187 188 SOAPConstants soapConstants = context.getMessageContext().getSOAPConstants(); 189 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && 190 Constants.QNAME_RPC_RESULT.equals(qname)) 191 { 192 return new DeserializerImpl(); 194 } 195 196 Vector params = rpcElem.getParams(); 197 198 if (currentParam == null || 200 !currentParam.getQName().getNamespaceURI().equals(namespace) || 201 !currentParam.getQName().getLocalPart().equals(localName)) 202 { 203 currentParam = new RPCParam(namespace, localName, null); 204 rpcElem.addParam(currentParam); 205 } 206 207 type = curEl.getType(); 211 if (type == null) 212 { 213 type = context.getTypeFromAttributes(namespace, localName, attributes); 214 } 215 216 if (log.isDebugEnabled()) 217 { 218 log.debug(Messages.getMessage("typeFromAttr00", "" + type)); 219 } 220 221 222 Class destClass = null; 223 224 if (operation != null) 227 { 228 229 if (isResponse) 231 { 232 paramDesc = operation.getOutputParamByQName(qname); 233 } 234 else 235 { 236 paramDesc = operation.getInputParamByQName(qname); 237 } 238 239 240 if (paramDesc == null) 246 { 247 if (isResponse) 248 { 249 paramDesc = operation.getReturnParamDesc(); 250 } 251 else 252 { 253 paramDesc = operation.getParameter(params.size() - 1); 254 } 255 } 256 257 if (paramDesc == null) 258 { 259 throw new SAXException (Messages.getMessage("noParmDesc")); 260 } 261 if (!isHeaderElement && 264 ((isResponse && paramDesc.isOutHeader()) || 265 (!isResponse && paramDesc.isInHeader()))) 266 { 267 throw new SAXException (Messages.getMessage("expectedHeaderParam", 268 paramDesc.getQName().toString())); 269 } 270 271 destClass = paramDesc.getJavaType(); 272 273 currentParam.setParamDesc(paramDesc); 276 277 if (type == null) 278 { 279 type = paramDesc.getTypeQName(); 280 } 281 } 282 283 if (context.isNil(attributes)) 296 { 297 Deserializer nilDSer = new DeserializerImpl(); 298 nilDSer.registerValueTarget(new MethodTarget(currentParam, RPCParam.getValueSetMethod())); 299 return (SOAPHandler)nilDSer; 300 } 301 302 Deserializer dser = null; 303 if ((type == null) && (namespace != null) && (!namespace.equals(""))) 304 { 305 dser = context.getDeserializerForType(qname); 306 } 307 else 308 { 309 dser = context.getDeserializer(destClass, type); 310 } 311 312 if (dser == null) 313 { 314 if (type != null) 315 { 316 dser = context.getDeserializerForType(type); 317 if (null != destClass && dser == null && destClass.isAssignableFrom(SOAPElement .class)) 318 { 319 dser = context.getDeserializerForType(Constants.SOAP_ELEMENT); 322 323 } 324 if (dser == null) 325 { 326 throw new SAXException (Messages.getMessage("noDeser01", localName, "" + type)); 327 } 328 if (paramDesc != null && paramDesc.getJavaType() != null && !Constants.XSD_ANYTYPE.equals(type)) 329 { 330 Class xsiClass = context.getTypeMapping().getClassForQName(type); 332 if (xsiClass != null && !JavaUtils.isConvertable(xsiClass, destClass)) 333 { 334 throw new SAXException ("Bad types (" + xsiClass + " -> " + destClass + ")"); 335 } 336 } 337 } 338 else 339 { 340 dser = new DeserializerImpl(); 341 if (dser == null) 342 { 343 throw new SAXException (Messages.getMessage("noDeser01", localName, "" + type)); 344 } 345 } 346 } 347 348 dser.setDefaultType(type); 349 350 dser.registerValueTarget(new MethodTarget(currentParam, RPCParam.getValueSetMethod())); 351 352 if (log.isDebugEnabled()) 353 { 354 log.debug("Exit: RPCHandler.onStartChild()"); 355 } 356 return (SOAPHandler)dser; 357 } 358 359 public void endElement(String namespace, String localName, DeserializationContext context) 360 throws SAXException 361 { 362 if (log.isDebugEnabled()) 367 { 368 log.debug(Messages.getMessage("setProp00", 369 "MessageContext", "RPCHandler.endElement().")); 370 } 371 context.getMessageContext().setProperty("RPC", rpcElem); 372 } 373 } 374 | Popular Tags |