1 57 58 package org.apache.soap.encoding.soapenc; 59 60 import java.io.*; 61 import org.w3c.dom.*; 62 import org.apache.soap.util.*; 63 import org.apache.soap.util.xml.*; 64 import org.apache.soap.*; 65 import org.apache.soap.rpc.*; 66 67 75 public class ParameterSerializer implements Serializer, Deserializer 76 { 77 public void marshall(String inScopeEncStyle, Class javaType, Object src, 78 Object context, Writer sink, NSStack nsStack, 79 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 80 throws IllegalArgumentException , IOException 81 { 82 nsStack.pushScope(); 83 84 Parameter param = (Parameter)src; 85 Class type = param.getType(); 86 String name = param.getName(); 87 Object value = param.getValue(); 88 89 if (!(context instanceof PrefixedName)) 90 { 91 context = name; 92 } 93 94 if (value == null && !type.isArray()) 95 { 96 SoapEncUtils.generateNullStructure(inScopeEncStyle, type, context, 97 sink, nsStack, xjmr); 98 } 99 else 100 { 101 String declEncStyle = param.getEncodingStyleURI(); 102 String actualEncStyle = declEncStyle != null 103 ? declEncStyle 104 : inScopeEncStyle; 105 Serializer s = xjmr.querySerializer(type, actualEncStyle); 106 107 s.marshall(inScopeEncStyle, type, value, context, 108 sink, nsStack, xjmr, ctx); 109 } 110 111 nsStack.popScope(); 112 } 113 114 public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src, 115 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 116 throws IllegalArgumentException 117 { 118 Element paramEl = (Element)src; 119 String name = paramEl.getTagName(); 120 Bean bean = null; 121 122 126 String href = DOMUtils.getAttribute(paramEl, Constants.ATTR_REFERENCE); 127 128 if (href != null) 129 { 130 if (href.length() > 0 && href.charAt(0) == '#') 132 { 133 href = href.substring(1); 134 135 Element el = 136 DOMUtils.getElementByID(src.getOwnerDocument().getDocumentElement(), 137 href); 138 139 if (el == null) 140 { 141 throw new IllegalArgumentException ("No such ID '" + href + "'."); 142 } 143 144 QName soapType = SoapEncUtils.getTypeQName(el); 145 146 if (soapType == null) 147 { 148 155 String paramNamespaceURI = paramEl.getNamespaceURI(); 156 157 if (paramNamespaceURI != null) 158 { 159 soapType = new QName(paramNamespaceURI, name); 160 } 161 else 162 { 163 soapType = new QName("", name); 164 } 165 } 166 167 bean = xjmr.unmarshall(inScopeEncStyle, soapType, el, ctx); 168 } 169 else 170 { 171 bean = (new MimePartSerializer()).unmarshall(inScopeEncStyle, 172 elementType, src, 173 xjmr, ctx); 174 } 175 } 176 else 177 { 178 QName soapType = SoapEncUtils.getTypeQName(paramEl); 179 180 if (soapType == null) 181 { 182 189 String paramNamespaceURI = paramEl.getNamespaceURI(); 190 191 if (paramNamespaceURI != null) 192 { 193 soapType = new QName(paramNamespaceURI, name); 194 } 195 else 196 { 197 soapType = new QName("", name); 198 } 199 } 200 201 bean = (SoapEncUtils.isNull(paramEl) 202 && !new QName(Constants.NS_URI_SOAP_ENC, 203 "Array").equals(soapType) 204 ? new Bean(xjmr.queryJavaType(soapType, inScopeEncStyle), 205 null) 206 : xjmr.unmarshall(inScopeEncStyle, soapType, paramEl, ctx)); 207 } 208 209 Parameter parameter = new Parameter(name, bean.type, 210 bean.value, null); 211 212 return new Bean(Parameter.class, parameter); 213 } 214 } 215 | Popular Tags |