1 55 56 package org.jboss.axis.encoding.ser; 57 58 import org.jboss.axis.encoding.Base64; 59 import org.jboss.axis.encoding.DeserializationContext; 60 import org.jboss.axis.encoding.DeserializerImpl; 61 import org.xml.sax.Attributes ; 62 import org.xml.sax.SAXException ; 63 64 import javax.xml.namespace.QName ; 65 66 73 public class Base64Deserializer extends DeserializerImpl 74 { 75 76 public QName xmlType; 77 public Class javaType; 78 79 StringBuffer buf = null; 80 81 public Base64Deserializer(Class javaType, QName xmlType) 82 { 83 this.xmlType = xmlType; 84 this.javaType = javaType; 85 } 86 87 90 public void characters(char[] chars, int start, int end) 91 throws SAXException 92 { 93 if (buf == null) 96 { 97 buf = new StringBuffer (); 98 } 99 buf.append(chars, start, end); 100 } 101 102 public void onStartElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException 103 { 104 super.onStartElement(namespace, localName, prefix, attributes, context); 105 } 106 107 110 public void onEndElement(String namespace, String localName, 111 DeserializationContext context) 112 throws SAXException 113 { 114 if (buf != null) 116 { 117 value = Base64.decode(buf.toString()); 118 if (javaType == Byte [].class) 119 { 120 Byte [] data = new Byte [((byte[])value).length]; 121 for (int i = 0; i < data.length; i++) 122 { 123 byte b = ((byte[])value)[i]; 124 data[i] = new Byte (b); 125 } 126 value = data; 127 } 128 } 129 130 super.onEndElement(namespace, localName, context); 131 if (!isNil && value == null) 133 { 134 if (javaType == byte[].class) 135 { 136 value = new byte[0]; 137 } 138 else 139 { 140 value = new Byte [0]; 141 } 142 } 143 } 144 } 145 | Popular Tags |