KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > wfxml > util > AltBeanSerializerFactory


1 /*
2  */

3
4 package org.enhydra.shark.wfxml.util;
5
6 import javax.xml.namespace.QName JavaDoc;
7 import javax.xml.rpc.JAXRPCException JavaDoc;
8
9 import org.apache.axis.description.TypeDesc;
10 import org.apache.axis.encoding.Serializer;
11 import org.apache.axis.encoding.ser.*;
12 import org.apache.axis.utils.*;
13
14 /**
15  * SerializerFactory for Bean
16  *
17  * @author V.Puskas
18  * @version 0.1
19  */

20 public class AltBeanSerializerFactory extends BaseSerializerFactory {
21
22    protected TypeDesc typeDesc = null;
23    protected BeanPropertyDescriptor[] propertyDescriptor = null;
24
25    public AltBeanSerializerFactory(Class JavaDoc javaType, QName JavaDoc xmlType) {
26        super(BeanSerializerShark.class, xmlType, javaType);
27        // Sometimes an Enumeration class is registered as a Bean.
28
// If this is the case, silently switch to the EnumSerializer
29
if (JavaUtils.isEnumClass(javaType)) {
30            serClass = EnumSerializer.class;
31        }
32
33        typeDesc = TypeDesc.getTypeDescForClass(javaType);
34
35        if (typeDesc != null) {
36            propertyDescriptor = typeDesc.getPropertyDescriptors();
37        } else {
38            propertyDescriptor = BeanUtils.getPd(javaType, null);
39        }
40    }
41
42    public javax.xml.rpc.encoding.Serializer JavaDoc getSerializerAs(String JavaDoc mechanismType)
43        throws JAXRPCException JavaDoc {
44        return (Serializer) super.getSerializerAs(mechanismType);
45    }
46
47    /**
48     * Optimize construction of a BeanSerializer by caching the
49     * type and property descriptors.
50     */

51    protected Serializer getGeneralPurpose(String JavaDoc mechanismType) {
52        if (javaType == null || xmlType == null) {
53           return super.getGeneralPurpose(mechanismType);
54        }
55
56        if (serClass == EnumSerializer.class) {
57           return super.getGeneralPurpose(mechanismType);
58        }
59
60        return new BeanSerializerShark(javaType, xmlType, typeDesc,
61                                  propertyDescriptor);
62    }
63 }
64
Popular Tags