Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/axis/encoding/ser/SimpleListDeserializerFactory.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  import org.apache.axis.utils.JavaUtils;
19  
20  import javax.xml.namespace.QName;
21  import javax.xml.rpc.JAXRPCException;
22  
23  import java.io.ObjectStreamException;
24  import java.lang.reflect.Constructor;
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[] STRING_CLASS = 
38          new Class [] {String.class};
39  
40      private final Class clazzType;
41      private transient Constructor 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 javaType, QName xmlType) {
47          super(SimpleListDeserializer.class, xmlType, javaType.getComponentType());
48          clazzType = javaType;
49          Class componentType = javaType.getComponentType();
50          try {
51              if (!componentType.isPrimitive()) {
52                  constructor = 
53                  componentType.getDeclaredConstructor(STRING_CLASS);
54              }
55              else {
56                  Class wrapper = JavaUtils.getWrapperClass(componentType);
57                  if (wrapper != null)
58                      constructor = 
59                          wrapper.getDeclaredConstructor(STRING_CLASS);
60              }
61          } catch (java.lang.NoSuchMethodException e) {
62              throw new IllegalArgumentException(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 getDeserializerAs(String mechanismType)
71          throws JAXRPCException {
72          if (javaType == java.lang.Object.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 readResolve() throws ObjectStreamException {
82          return new SimpleListDeserializerFactory(clazzType, xmlType);
83      }
84  }