1 16 17 package org.apache.axis.encoding.ser; 18 19 import org.apache.axis.Constants; 20 import org.apache.axis.encoding.SerializationContext; 21 import org.apache.axis.encoding.SimpleValueSerializer; 22 import org.apache.axis.types.HexBinary; 23 import org.apache.axis.utils.JavaUtils; 24 import org.apache.axis.wsdl.fromJava.Types; 25 import org.w3c.dom.Element ; 26 import org.xml.sax.Attributes ; 27 28 import javax.xml.namespace.QName ; 29 import java.io.IOException ; 30 37 public class HexSerializer implements SimpleValueSerializer { 38 39 public QName xmlType; 40 public Class javaType; 41 public HexSerializer(Class javaType, QName xmlType) { 42 this.xmlType = xmlType; 43 this.javaType = javaType; 44 } 45 46 49 public void serialize(QName name, Attributes attributes, 50 Object value, SerializationContext context) 51 throws IOException 52 { 53 context.startElement(name, attributes); 54 context.writeString(getValueAsString(value, context)); 55 context.endElement(); 56 } 57 58 public String getValueAsString(Object value, SerializationContext context) { 59 value = JavaUtils.convert(value, javaType); 60 if (javaType == HexBinary.class) { 61 return value.toString(); 62 } else { 63 return HexBinary.encode((byte[]) value); 64 } 65 } 66 67 public String getMechanismType() { return Constants.AXIS_SAX; } 68 69 80 public Element writeSchema(Class javaType, Types types) throws Exception { 81 return null; 82 } 83 } 84 | Popular Tags |