1 57 58 package org.apache.soap.encoding.soapenc; 59 60 import java.beans.*; 61 import java.io.*; 62 import java.util.*; 63 import java.lang.reflect.*; 64 import org.w3c.dom.*; 65 import org.apache.soap.util.*; 66 import org.apache.soap.util.xml.*; 67 import org.apache.soap.*; 68 import org.apache.soap.rpc.*; 69 70 79 public class VectorSerializer implements Serializer, Deserializer 80 { 81 public void marshall(String inScopeEncStyle, Class javaType, Object src, 82 Object context, Writer sink, NSStack nsStack, 83 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 84 throws IllegalArgumentException, IOException 85 { 86 nsStack.pushScope(); 87 88 if ((src != null) && 89 !(src instanceof Vector) && 90 !(src instanceof Enumeration)) 91 throw new IllegalArgumentException("Tried to pass a '" + 92 src.getClass().toString() + "' to VectorSerializer"); 93 94 String lengthStr; 95 Enumeration enum; 96 97 if (src instanceof Enumeration) { 98 103 enum = (Enumeration)src; 104 lengthStr = ""; 105 } else { 106 Vector v = (Vector)src; 107 enum = v.elements(); 108 109 lengthStr = src != null 110 ? v.size() + "" 111 : ""; 112 } 113 114 115 if (src == null) 116 { 117 SoapEncUtils.generateNullStructure(inScopeEncStyle, 118 javaType, 119 context, 120 sink, 121 nsStack, 122 xjmr); 123 } 124 else 125 { 126 SoapEncUtils.generateStructureHeader(inScopeEncStyle, 127 javaType, 128 context, 129 sink, 130 nsStack, 131 xjmr); 132 133 sink.write(StringUtils.lineSeparator); 134 135 for (Enumeration e = enum; e.hasMoreElements(); ) 136 { 137 nsStack.pushScope(); 138 139 Object value = e.nextElement(); 140 141 if (value == null) 142 { 143 SoapEncUtils.generateNullStructure(Constants.NS_URI_SOAP_ENC, 144 Object.class, "item", sink, 145 nsStack, xjmr); 146 } 147 else 148 { 149 Class actualComponentType = value.getClass(); 150 151 xjmr.marshall(Constants.NS_URI_SOAP_ENC, actualComponentType, value, 152 "item", sink, nsStack, ctx); 153 } 154 155 sink.write(StringUtils.lineSeparator); 156 nsStack.popScope(); 157 } 158 159 sink.write("</" + context + '>'); 160 } 161 162 nsStack.popScope(); 163 } 164 165 public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src, 166 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 167 throws IllegalArgumentException 168 { 169 Element root = (Element)src; 170 if (SoapEncUtils.isNull(root)) { 171 return new Bean(Vector.class, null); 172 } 173 174 Vector v = new Vector(); 175 176 Element tempEl = DOMUtils.getFirstChildElement(root); 177 while (tempEl != null) { 178 String declEncStyle = DOMUtils.getAttributeNS(tempEl, 179 Constants.NS_URI_SOAP_ENV, Constants.ATTR_ENCODING_STYLE); 180 String actualEncStyle = declEncStyle != null 181 ? declEncStyle 182 : inScopeEncStyle; 183 184 String href = tempEl.getAttribute(Constants.ATTR_REFERENCE); 186 Element actualEl = tempEl; 187 if(href != null && !href.equals("") && (href.charAt(0) == '#')) 188 { 189 href = href.substring(1); 190 actualEl = DOMUtils.getElementByID(src.getOwnerDocument().getDocumentElement(),href); 191 if (actualEl == null) { 192 throw new IllegalArgumentException("No such ID '" + href + "'"); 193 } 194 } 195 196 QName declItemType = SoapEncUtils.getTypeQName(actualEl); 197 QName actualItemType = declItemType; 198 199 Bean itemBean = xjmr.unmarshall(actualEncStyle, actualItemType, 200 actualEl, ctx); 201 202 v.addElement(itemBean.value); 203 204 tempEl = DOMUtils.getNextSiblingElement(tempEl); 205 } 206 207 return new Bean(Vector.class, v); 208 } 209 210 } 211 | Popular Tags |