1 16 17 package org.jboss.axis.message; 18 19 import org.jboss.axis.AxisFault; 20 import org.jboss.axis.NotImplementedException; 21 import org.jboss.axis.encoding.DeserializationContext; 22 import org.jboss.logging.Logger; 23 import org.w3c.dom.DOMException ; 24 import org.xml.sax.Attributes ; 25 import org.xml.sax.SAXException ; 26 27 import javax.xml.namespace.QName ; 28 import javax.xml.soap.Name ; 29 import javax.xml.soap.SOAPElement ; 30 import javax.xml.soap.SOAPException ; 31 import java.math.BigDecimal ; 32 import java.math.BigInteger ; 33 import java.util.ArrayList ; 34 import java.util.Arrays ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 import java.util.Vector ; 38 39 51 public class RPCParamElementImpl extends SOAPElementAxisImpl 52 { 53 54 private static Logger log = Logger.getLogger(RPCParamElementImpl.class.getName()); 55 56 private RPCElement rpcElement; 58 private DeserializationContext context; 59 60 public RPCParamElementImpl(String namespace, String localPart, String prefix, Attributes attributes, DeserializationContext context) throws AxisFault 61 { 62 super(namespace, localPart, prefix, attributes, context); 63 64 SOAPElement curEl = context.getCurElement(); 65 if (curEl instanceof RPCParamElementImpl) 66 rpcElement = ((RPCParamElementImpl)curEl).rpcElement; 67 68 if (curEl instanceof RPCElement) 69 rpcElement = (RPCElement)curEl; 70 71 if (rpcElement == null) 72 { 73 IllegalArgumentException ex = new IllegalArgumentException ("Unexpected element type: " + curEl.getClass().getName()); 74 log.error(ex.getMessage(), ex); 75 throw ex; 76 } 77 78 this.context = context; 79 } 80 81 public RPCParamElementImpl(RPCParam rpcParam) 82 { 83 super(rpcParam.getQName(), rpcParam.getValue()); 84 rpcElement = rpcParam.myCall; 85 86 if (rpcElement == null) 87 { 88 IllegalArgumentException ex = new IllegalArgumentException ("RPCParam has no parent element"); 89 log.error(ex.getMessage(), ex); 90 throw ex; 91 } 92 93 97 List supported = Arrays.asList(new Class []{ 98 String .class, Integer .class, Float .class, Double .class, Long .class, Boolean .class, 99 Short .class, Byte .class, BigInteger .class, BigDecimal .class 100 }); 101 102 Object value = rpcParam.getValue(); 103 if (value != null) 104 { 105 try 106 { 107 if (supported.contains(value.getClass())) 108 { 109 super.addTextNode(value.toString()); 110 } 111 else 112 { 113 log.debug("Cannot add text node for rpc parameter type: " + value.getClass().getName()); 114 } 115 } 116 catch (SOAPException e) 117 { 118 log.error("Cannot addTextNode: " + value, e); 119 } 120 } 121 } 122 123 public Iterator getChildElements() 124 { 125 if (!hasChildNodes() && objectValue != null) 126 { 127 throw new NotImplementedException("SOAPElement view of RPCParam not implemented"); 128 } 129 else 130 { 131 return super.getChildElements(); 132 } 133 } 134 135 public Iterator getChildElements(Name name) 136 { 137 if (!hasChildNodes() && objectValue != null) 138 { 139 throw new NotImplementedException("SOAPElement view of RPCParam not implemented"); 140 } 141 else 142 { 143 return super.getChildElements(name); 144 } 145 } 146 147 150 public SOAPElement addTextNode(String value) throws SOAPException 151 { 152 SOAPElement txtNode = super.addTextNode(value); 153 setRPCParamValue(value); 154 return txtNode; 155 } 156 157 160 public void setValue(String value) 161 { 162 super.setValue(value); 163 setRPCParamValue(value); 164 } 165 166 169 public void setNodeValue(String value) throws DOMException 170 { 171 super.setNodeValue(value); 172 setRPCParamValue(value); 173 } 174 175 178 private void setRPCParamValue(String newValue) 179 { 180 if (context == null || context.isDoneParsing()) 183 { 184 RPCParam rpcParam = getRPCParam(); 185 Object paramValue = rpcParam.getValue(); 186 187 if (paramValue != null && !paramValue.getClass().isAssignableFrom(newValue.getClass())) 188 log.warn("Trying to change the value type from " + paramValue.getClass().getName() + " to " + newValue.getClass().getName()); 189 190 rpcParam.setValue(newValue); 191 } 192 } 193 194 198 private RPCParam getRPCParam() 199 { 200 201 RPCParam rpcParam = null; 202 203 QName rpcParamElementName = getQName(); 204 ArrayList weHave = new ArrayList (); 205 try 206 { 207 Vector params = rpcElement.getParams(); 208 for (int i = 0; i < params.size(); i++) 209 { 210 211 RPCParam aux = (RPCParam)params.elementAt(i); 212 QName rpcParamName = aux.getQName(); 213 weHave.add(rpcParamName); 214 215 if (rpcParamName.equals(rpcParamElementName)) 216 { 217 if (rpcParam != null) 218 log.error("Duplicate parameter: " + rpcParamName); 219 else 220 rpcParam = aux; 221 } 222 } 223 } 224 catch (SAXException e) 225 { 226 log.error("Cannot get RPCParam " + rpcParamElementName, e); 227 } 228 229 if (rpcParam == null) 230 log.warn("Cannot find parameter: " + getQName() + " we have " + weHave); 231 232 return rpcParam; 233 } 234 } 235 | Popular Tags |