KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  */

3
4 package org.enhydra.shark.wfxml.util;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import javax.xml.namespace.QName JavaDoc;
10
11 import org.apache.axis.description.TypeDesc;
12 import org.apache.axis.encoding.Deserializer;
13 import org.apache.axis.encoding.ser.BaseDeserializerFactory;
14 import org.apache.axis.encoding.ser.EnumDeserializer;
15 import org.apache.axis.utils.*;
16
17 /**
18  * DeserializerFactory for Bean
19  *
20  * @author V.Puskas
21  * @version 0.1
22  */

23 public class AltBeanDeserializerFactory extends BaseDeserializerFactory {
24
25    /** Type metadata about this class for XML deserialization */
26    protected TypeDesc typeDesc = null;
27    protected Map JavaDoc propertyMap = null;
28
29    public AltBeanDeserializerFactory(Class JavaDoc javaType, QName JavaDoc xmlType) {
30        super(BeanDeserializerShark.class, xmlType, javaType);
31
32        // Sometimes an Enumeration class is registered as a Bean.
33
// If this is the case, silently switch to the EnumDeserializer
34
if (JavaUtils.isEnumClass(javaType)) {
35            deserClass = EnumDeserializer.class;
36        }
37
38        typeDesc = TypeDesc.getTypeDescForClass(javaType);
39        propertyMap = getProperties(javaType, typeDesc);
40    }
41
42   /**
43     * Get a list of the bean properties
44     */

45    public static Map JavaDoc getProperties(Class JavaDoc javaType, TypeDesc typeDesc ) {
46        Map JavaDoc propertyMap = null;
47
48        if (typeDesc != null) {
49            propertyMap = typeDesc.getPropertyDescriptorMap();
50        } else {
51            BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType, null);
52            propertyMap = new HashMap JavaDoc();
53            // loop through properties and grab the names for later
54
for (int i = 0; i < pd.length; i++) {
55                BeanPropertyDescriptor descriptor = pd[i];
56                propertyMap.put(descriptor.getName(), descriptor);
57            }
58        }
59
60        return propertyMap;
61    }
62
63   /**
64     * Optimize construction of a BeanDeserializer by caching the
65     * type descriptor and property map.
66     */

67    protected Deserializer getGeneralPurpose(String JavaDoc mechanismType) {
68        if (javaType == null || xmlType == null) {
69           return super.getGeneralPurpose(mechanismType);
70        }
71
72        if (deserClass == EnumDeserializer.class) {
73           return super.getGeneralPurpose(mechanismType);
74        }
75
76        return new BeanDeserializerShark(javaType, xmlType, typeDesc, propertyMap);
77    }
78 }
79
Popular Tags