1 16 17 package org.apache.axis.encoding.ser; 18 19 import org.apache.axis.Constants; 20 import org.apache.axis.components.logger.LogFactory; 21 import org.apache.axis.encoding.SerializationContext; 22 import org.apache.axis.encoding.Serializer; 23 import org.apache.axis.utils.IdentityHashMap; 24 import org.apache.axis.utils.Messages; 25 import org.apache.axis.wsdl.fromJava.Types; 26 import org.apache.commons.logging.Log; 27 import org.w3c.dom.Element ; 28 import org.xml.sax.Attributes ; 29 30 import javax.xml.namespace.QName ; 31 import java.io.IOException ; 32 import java.util.Iterator ; 33 import java.util.Vector ; 34 35 42 43 public class VectorSerializer implements Serializer 44 { 45 protected static Log log = 46 LogFactory.getLog(VectorSerializer.class.getName()); 47 48 59 public void serialize(QName name, Attributes attributes, 60 Object value, SerializationContext context) 61 throws IOException 62 { 63 if (!(value instanceof Vector )) 64 throw new IOException ( 65 Messages.getMessage("noVector00", "VectorSerializer", 66 value.getClass().getName())); 67 68 Vector vector = (Vector )value; 69 70 if(isRecursive(new IdentityHashMap(), vector)){ 72 throw new IOException (Messages.getMessage("badVector00")); 73 } 74 75 context.startElement(name, attributes); 76 for (Iterator i = vector.iterator(); i.hasNext(); ) 77 { 78 Object item = i.next(); 79 context.serialize(Constants.QNAME_LITERAL_ITEM, null, item); 80 } 81 context.endElement(); 82 } 83 84 public boolean isRecursive(IdentityHashMap map, Vector vector) 85 { 86 map.add(vector); 87 boolean recursive = false; 88 for(int i=0;i<vector.size() && !recursive;i++) 89 { 90 Object o = vector.get(i); 91 if(o instanceof Vector ) { 92 if(map.containsKey(o)) { 93 return true; 94 } else { 95 recursive = isRecursive(map, (Vector )o); 96 } 97 } 98 } 99 return recursive; 100 } 101 102 public String getMechanismType() { return Constants.AXIS_SAX; } 103 104 115 public Element writeSchema(Class javaType, Types types) throws Exception { 116 Element complexType = types.createElement("complexType"); 117 complexType.setAttribute("name", "Vector"); 118 types.writeSchemaTypeDecl(Constants.SOAP_VECTOR, complexType); 119 Element seq = types.createElement("sequence"); 120 complexType.appendChild(seq); 121 122 Element element = types.createElement("element"); 123 element.setAttribute("name", "item"); 124 element.setAttribute("minOccurs", "0"); 125 element.setAttribute("maxOccurs", "unbounded"); 126 element.setAttribute("type", "xsd:anyType"); 127 seq.appendChild(element); 128 129 return complexType; 130 } 131 } 132 | Popular Tags |