1 55 56 package org.jboss.axis.encoding.ser; 57 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.encoding.Base64; 60 import org.jboss.axis.encoding.SerializationContext; 61 import org.jboss.axis.encoding.SimpleValueSerializer; 62 import org.jboss.axis.wsdl.fromJava.Types; 63 import org.w3c.dom.Element ; 64 import org.xml.sax.Attributes ; 65 66 import javax.xml.namespace.QName ; 67 import java.io.IOException ; 68 69 76 public class Base64Serializer implements SimpleValueSerializer 77 { 78 79 public QName xmlType; 80 public Class javaType; 81 82 public Base64Serializer(Class javaType, QName xmlType) 83 { 84 this.xmlType = xmlType; 85 this.javaType = javaType; 86 } 87 88 91 public void serialize(QName name, Attributes attributes, 92 Object value, SerializationContext context) 93 throws IOException 94 { 95 context.startElement(name, attributes); 96 context.writeString(getValueAsString(value, context)); 97 context.endElement(); 98 } 99 100 public String getValueAsString(Object value, SerializationContext context) 101 { 102 byte[] data = null; 103 if (javaType == byte[].class) 104 { 105 data = (byte[])value; 106 } 107 else 108 { 109 data = new byte[((Byte [])value).length]; 110 for (int i = 0; i < data.length; i++) 111 { 112 Byte b = ((Byte [])value)[i]; 113 if (b != null) 114 data[i] = b.byteValue(); 115 } 116 } 117 118 return Base64.encode(data, 0, data.length); 119 } 120 121 public String getMechanismType() 122 { 123 return Constants.AXIS_SAX; 124 } 125 126 137 public Element writeSchema(Class javaType, Types types) throws Exception 138 { 139 return null; 140 } 141 } 142 | Popular Tags |