1 16 package org.apache.axis.message; 17 18 import org.apache.axis.components.logger.LogFactory; 19 import org.apache.axis.description.ParameterDesc; 20 import org.apache.axis.encoding.SerializationContext; 21 import org.apache.axis.utils.JavaUtils; 22 import org.apache.axis.utils.Messages; 23 import org.apache.axis.constants.Style; 24 import org.apache.axis.Constants; 25 import org.apache.axis.MessageContext; 26 import org.apache.commons.logging.Log; 27 28 import javax.xml.namespace.QName ; 29 import javax.xml.soap.SOAPElement ; 30 import javax.xml.soap.SOAPException ; 31 32 import java.io.IOException ; 33 import java.io.ObjectInputStream ; 34 import java.io.ObjectOutputStream ; 35 import java.io.Serializable ; 36 import java.lang.reflect.Method ; 37 import java.util.ArrayList ; 38 39 43 public class RPCParam extends MessageElement implements Serializable 44 { 45 protected static Log log = 46 LogFactory.getLog(RPCParam.class.getName()); 47 48 private Object value = null; 49 private int countSetCalls = 0; 51 private ParameterDesc paramDesc; 52 53 59 private Boolean wantXSIType = null; 60 61 private static Method valueSetMethod; 62 static { 63 Class cls = RPCParam.class; 64 try { 65 valueSetMethod = cls.getMethod("set", new Class [] {Object .class}); 66 } catch (NoSuchMethodException e) { 67 log.error(Messages.getMessage("noValue00", "" + e)); 68 throw new RuntimeException (e.getMessage()); 69 } 70 } 71 72 74 public RPCParam(String name, Object value) 75 { 76 this(new QName ("", name), value); 77 } 78 79 public RPCParam(QName qname, Object value) 80 { 81 super(qname); 82 if (value instanceof java.lang.String ) { 83 try { 84 this.addTextNode((String ) value); 85 } catch (SOAPException e) { 86 throw new RuntimeException (Messages.getMessage("cannotCreateTextNode00")); 87 } 88 } else { 89 this.value = value; 90 } 91 } 92 93 public RPCParam(String namespace, String name, Object value) 94 { 95 this(new QName (namespace, name), value); 96 } 97 98 public void setRPCCall(RPCElement call) 99 { 100 parent = call; 101 } 102 103 public Object getObjectValue() 104 { 105 return value; 106 } 107 108 public void setObjectValue(Object value) 109 { 110 this.value = value; 111 } 112 113 121 public void set(Object newValue) { 122 countSetCalls++; 123 if (countSetCalls==1) { 126 this.value = newValue; 127 return; 128 } 129 else if (countSetCalls==2) { 132 ArrayList list = new ArrayList (); 133 list.add(this.value); 134 this.value = list; 135 } 136 ((ArrayList ) this.value).add(newValue); 138 } 139 140 public static Method getValueSetMethod() 141 { 142 return valueSetMethod; 143 } 144 145 public ParameterDesc getParamDesc() { 146 return paramDesc; 147 } 148 149 public void setParamDesc(ParameterDesc paramDesc) { 150 this.paramDesc = paramDesc; 151 } 152 153 public void setXSITypeGeneration(Boolean value) { 154 this.wantXSIType = value; 155 } 156 157 public Boolean getXSITypeGeneration() { 158 return this.wantXSIType; 159 } 160 161 public void serialize(SerializationContext context) 162 throws IOException 163 { 164 Class javaType = value == null ? null: value.getClass(); 170 QName xmlType = null; 171 if (paramDesc != null) { 172 if (javaType == null) { 173 javaType = paramDesc.getJavaType() != null ? 174 paramDesc.getJavaType(): javaType; 175 } else if (!(javaType.equals(paramDesc.getJavaType()))) { 176 Class clazz = JavaUtils.getPrimitiveClass(javaType); 177 if(clazz == null || !clazz.equals(paramDesc.getJavaType())) { 178 if (!(javaType.equals( 179 JavaUtils.getHolderValueType(paramDesc.getJavaType())))) { 180 181 wantXSIType = Boolean.TRUE; 184 } 185 } 186 } 187 xmlType = paramDesc.getTypeQName(); 188 QName itemQName = paramDesc.getItemQName(); 189 if (itemQName == null) { 190 MessageContext mc = context.getMessageContext(); 191 if (mc != null && mc.getOperation() != null && mc.getOperation().getStyle() == Style.DOCUMENT) { 192 itemQName = Constants.QNAME_LITERAL_ITEM; 193 } 194 } 195 context.setItemQName(itemQName); 196 197 QName itemType = paramDesc.getItemType(); 198 context.setItemType(itemType); 199 } 200 context.serialize(getQName(), null, value, xmlType, Boolean.TRUE, wantXSIType); 205 } 206 207 private void writeObject(ObjectOutputStream out) 208 throws IOException { 209 if (getQName() == null) { 210 out.writeBoolean(false); 211 } else { 212 out.writeBoolean(true); 213 out.writeObject(getQName().getNamespaceURI()); 214 out.writeObject(getQName().getLocalPart()); 215 } 216 out.defaultWriteObject(); 217 } 218 219 private void readObject(ObjectInputStream in) 220 throws IOException , ClassNotFoundException { 221 if (in.readBoolean()) { 222 setQName(new QName ((String )in.readObject(), 223 (String )in.readObject())); 224 } 225 in.defaultReadObject(); 226 } 227 228 protected void outputImpl(SerializationContext context) throws Exception { 229 serialize(context); 230 } 231 232 public String getValue() { 233 return getValueDOM(); 234 } 235 236 239 public SOAPElement addTextNode(String s) throws SOAPException { 240 value = s; 241 return super.addTextNode(s); 242 } 243 246 public void setValue(String value) { 247 this.value = value; 248 super.setValue(value); 249 } 250 } 251 | Popular Tags |