1 55 56 package org.jboss.axis.encoding.ser; 57 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.encoding.SerializationContext; 60 import org.jboss.axis.encoding.Serializer; 61 import org.jboss.axis.utils.IdentityHashMap; 62 import org.jboss.axis.utils.Messages; 63 import org.jboss.axis.wsdl.fromJava.Types; 64 import org.jboss.logging.Logger; 65 import org.w3c.dom.Element ; 66 import org.xml.sax.Attributes ; 67 68 import javax.xml.namespace.QName ; 69 import java.io.IOException ; 70 import java.util.Iterator ; 71 import java.util.Vector ; 72 73 80 81 public class VectorSerializer implements Serializer 82 { 83 private static Logger log = Logger.getLogger(VectorSerializer.class.getName()); 84 85 97 public void serialize(QName name, Attributes attributes, 98 Object value, SerializationContext context) 99 throws IOException 100 { 101 if (!(value instanceof Vector )) 102 throw new IOException (Messages.getMessage("noVector00", "VectorSerializer", 103 value.getClass().getName())); 104 105 Vector vector = (Vector )value; 106 107 if (isRecursive(new IdentityHashMap(), vector)) 109 { 110 throw new IOException (Messages.getMessage("badVector00")); 111 } 112 113 context.startElement(name, attributes); 114 for (Iterator i = vector.iterator(); i.hasNext();) 115 { 116 Object item = i.next(); 117 context.serialize(Constants.QNAME_LITERAL_ITEM, null, item); 118 } 119 context.endElement(); 120 } 121 122 public boolean isRecursive(IdentityHashMap map, Vector vector) 123 { 124 map.add(vector); 125 boolean recursive = false; 126 for (int i = 0; i < vector.size() && !recursive; i++) 127 { 128 Object o = vector.get(i); 129 if (o instanceof Vector ) 130 { 131 if (map.containsKey(o)) 132 { 133 return true; 134 } 135 else 136 { 137 recursive = isRecursive(map, (Vector )o); 138 } 139 } 140 } 141 return recursive; 142 } 143 144 public String getMechanismType() 145 { 146 return Constants.AXIS_SAX; 147 } 148 149 160 public Element writeSchema(Class javaType, Types types) throws Exception 161 { 162 Element complexType = types.createElement("complexType"); 163 complexType.setAttribute("name", "Vector"); 164 types.writeSchemaElement(Constants.SOAP_VECTOR, complexType); 165 Element seq = types.createElement("sequence"); 166 complexType.appendChild(seq); 167 168 Element element = types.createElement("element"); 169 element.setAttribute("name", "item"); 170 element.setAttribute("minOccurs", "0"); 171 element.setAttribute("maxOccurs", "unbounded"); 172 element.setAttribute("type", "xsd:anyType"); 173 seq.appendChild(element); 174 175 return complexType; 176 } 177 } 178 | Popular Tags |