View Javadoc

1   package org.codehaus.ivory.serialize;
2   
3   import javax.xml.namespace.QName;
4   import javax.xml.rpc.JAXRPCException;
5   
6   import org.apache.axis.description.TypeDesc;
7   import org.apache.axis.encoding.Serializer;
8   import org.apache.axis.encoding.ser.BaseSerializerFactory;
9   import org.apache.axis.encoding.ser.EnumSerializer;
10  import org.apache.axis.utils.BeanPropertyDescriptor;
11  import org.apache.axis.utils.JavaUtils;
12  
13  /***
14   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
15   * @since May 21, 2003
16   */
17  public class MetadataSerializerFactory extends BaseSerializerFactory
18  {
19      protected TypeDesc typeDesc = null;
20      protected BeanPropertyDescriptor[] propertyDescriptor = null;
21  
22      public MetadataSerializerFactory(Class javaType, QName xmlType)
23      {
24          super(MetadataSerializer.class, xmlType, javaType);
25          // Sometimes an Enumeration class is registered as a Bean.
26          // If this is the case, silently switch to the EnumSerializer
27          if (JavaUtils.isEnumClass(javaType))
28          {
29              serClass = EnumSerializer.class;
30          }
31  
32          typeDesc = TypeDesc.getTypeDescForClass(javaType);
33  
34          if (typeDesc != null)
35          {
36              propertyDescriptor = typeDesc.getPropertyDescriptors();
37          }
38          else
39          {
40              propertyDescriptor = MetaBeanUtils.getPd(javaType, null);
41          }
42      }
43  
44      public javax.xml.rpc.encoding.Serializer getSerializerAs(
45          String mechanismType)
46          throws JAXRPCException
47      {
48          return (Serializer) super.getSerializerAs(mechanismType);
49      }
50      
51      /***
52       * Optimize construction of a BeanSerializer by caching the
53       * type and property descriptors.
54       */
55      protected Serializer getGeneralPurpose(String mechanismType)
56      {
57          if (javaType == null || xmlType == null)
58          {
59              return super.getGeneralPurpose(mechanismType);
60          }
61  
62          if (serClass == EnumSerializer.class)
63          {
64              return super.getGeneralPurpose(mechanismType);
65          }
66  
67          return new MetadataSerializer(
68              javaType,
69              xmlType,
70              typeDesc,
71              propertyDescriptor);
72      }
73  }