Source code: org/apache/axis/encoding/ser/Base64Deserializer.java
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.apache.axis.encoding.ser;
18
19 import org.apache.axis.encoding.Base64;
20
21 import javax.xml.namespace.QName;
22
23 /**
24 * Deserializer for Base64
25 *
26 * @author Sam Ruby <rubys@us.ibm.com>
27 * Modified by @author Rich scheuerle <scheu@us.ibm.com>
28 * @see <a href="http://www.w3.org/TR/xmlschema-2/#base64Binary">XML Schema 3.2.16</a>
29 */
30 public class Base64Deserializer extends SimpleDeserializer {
31
32 public Base64Deserializer(Class javaType, QName xmlType) {
33 super(javaType, xmlType);
34 }
35
36 /**
37 * Convert the string that has been accumulated into an Object. Subclasses
38 * may override this. Note that if the javaType is a primitive, the returned
39 * object is a wrapper class.
40 * @param source the serialized value to be deserialized
41 * @throws Exception any exception thrown by this method will be wrapped
42 */
43 public Object makeValue(String source) throws Exception {
44 byte [] value = Base64.decode(source);
45
46 if (value == null) {
47 if (javaType == Byte[].class) {
48 return new Byte[0];
49 } else {
50 return new byte[0];
51 }
52 }
53
54 if (javaType == Byte[].class) {
55 Byte[] data = new Byte[ value.length ];
56 for (int i=0; i<data.length; i++) {
57 byte b = value[i];
58 data[i] = new Byte(b);
59 }
60 return data;
61 }
62 return value;
63 }
64 }