KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > SimpleListDeserializerFactory


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 import org.apache.axis.utils.JavaUtils;
19
20 import javax.xml.namespace.QName JavaDoc;
21 import javax.xml.rpc.JAXRPCException JavaDoc;
22
23 import java.io.ObjectStreamException JavaDoc;
24 import java.lang.reflect.Constructor JavaDoc;
25
26 /**
27  * DeserializerFactory for
28  * <xsd:simpleType ...>
29  * <xsd:list itemType="...">
30  * </xsd:simpleType>
31  * based on SimpleDeserializerFactory
32  *
33  * @author Ias (iasandcb@tmax.co.kr)
34  */

35 public class SimpleListDeserializerFactory extends BaseDeserializerFactory {
36
37     private static final Class JavaDoc[] STRING_CLASS =
38         new Class JavaDoc [] {String JavaDoc.class};
39
40     private final Class JavaDoc clazzType;
41     private transient Constructor JavaDoc constructor = null;
42     /**
43      * Note that the factory is constructed with the QName and xmlType. This is important
44      * to allow distinction between primitive values and java.lang wrappers.
45      **/

46     public SimpleListDeserializerFactory(Class JavaDoc javaType, QName JavaDoc xmlType) {
47         super(SimpleListDeserializer.class, xmlType, javaType.getComponentType());
48         clazzType = javaType;
49         Class JavaDoc componentType = javaType.getComponentType();
50         try {
51             if (!componentType.isPrimitive()) {
52                 constructor =
53                 componentType.getDeclaredConstructor(STRING_CLASS);
54             }
55             else {
56                 Class JavaDoc wrapper = JavaUtils.getWrapperClass(componentType);
57                 if (wrapper != null)
58                     constructor =
59                         wrapper.getDeclaredConstructor(STRING_CLASS);
60             }
61         } catch (java.lang.NoSuchMethodException JavaDoc e) {
62             throw new IllegalArgumentException JavaDoc(e.toString());
63         }
64     }
65     
66     /**
67      * Get the Deserializer and the set the Constructor so the
68      * deserializer does not have to do introspection.
69      */

70     public javax.xml.rpc.encoding.Deserializer JavaDoc getDeserializerAs(String JavaDoc mechanismType)
71         throws JAXRPCException JavaDoc {
72         if (javaType == java.lang.Object JavaDoc.class) {
73             return null;
74         }
75         SimpleListDeserializer deser = (SimpleListDeserializer) super.getDeserializerAs(mechanismType);
76         if (deser != null)
77             deser.setConstructor(constructor);
78         return deser;
79     }
80     
81     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
82         return new SimpleListDeserializerFactory(clazzType, xmlType);
83     }
84 }
85
Popular Tags