1 16 17 package org.apache.axis.encoding.ser; 18 19 import org.apache.axis.Constants; 20 import org.apache.axis.encoding.Base64; 21 import org.apache.axis.encoding.SerializationContext; 22 import org.apache.axis.encoding.SimpleValueSerializer; 23 import org.apache.axis.wsdl.fromJava.Types; 24 import org.w3c.dom.Element ; 25 import org.xml.sax.Attributes ; 26 27 import javax.xml.namespace.QName ; 28 import java.io.IOException ; 29 30 37 public class Base64Serializer implements SimpleValueSerializer { 38 39 public QName xmlType; 40 public Class javaType; 41 public Base64Serializer(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 byte[] data = null; 60 if (javaType == byte[].class) { 61 data = (byte[]) value; 62 } else { 63 data = new byte[ ((Byte []) value).length ]; 64 for (int i=0; i<data.length; i++) { 65 Byte b = ((Byte []) value)[i]; 66 if (b != null) 67 data[i] = b.byteValue(); 68 } 69 } 70 71 return Base64.encode(data, 0, data.length); 72 } 73 74 public String getMechanismType() { return Constants.AXIS_SAX; } 75 76 87 public Element writeSchema(Class javaType, Types types) throws Exception { 88 return null; 89 } 90 } 91 | Popular Tags |