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.SimpleValueSerializer; 61 import org.jboss.axis.types.HexBinary; 62 import org.jboss.axis.utils.JavaUtils; 63 import org.jboss.axis.wsdl.fromJava.Types; 64 import org.w3c.dom.Element ; 65 import org.xml.sax.Attributes ; 66 67 import javax.xml.namespace.QName ; 68 import java.io.IOException ; 69 70 77 public class HexSerializer implements SimpleValueSerializer 78 { 79 80 public QName xmlType; 81 public Class javaType; 82 83 public HexSerializer(Class javaType, QName xmlType) 84 { 85 this.xmlType = xmlType; 86 this.javaType = javaType; 87 } 88 89 92 public void serialize(QName name, Attributes attributes, 93 Object value, SerializationContext context) 94 throws IOException 95 { 96 context.startElement(name, attributes); 97 context.writeString(getValueAsString(value, context)); 98 context.endElement(); 99 } 100 101 public String getValueAsString(Object value, SerializationContext context) 102 { 103 value = JavaUtils.convert(value, javaType); 104 if (javaType == HexBinary.class) 105 { 106 return value.toString(); 107 } 108 else if (javaType.getComponentType() == Byte .class) 109 { 110 return HexBinary.encode((Byte [])value); 111 } 112 else if (javaType.getComponentType() == byte.class) 113 { 114 return HexBinary.encode((byte[])value); 115 } 116 else 117 { 118 throw new IllegalArgumentException ("Invalid Type: " + javaType); 119 } 120 } 121 122 public String getMechanismType() 123 { 124 return Constants.AXIS_SAX; 125 } 126 127 138 public Element writeSchema(Class javaType, Types types) throws Exception 139 { 140 return null; 141 } 142 } 143 | Popular Tags |