axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/encoding/ser BeanDeserializer.java BeanSerializer.java SimpleDeserializer.java SimpleSerializer.java
Date Mon, 08 Jul 2002 14:37:45 GMT
scheu       2002/07/08 07:37:45

  Modified:    java/src/org/apache/axis/description TypeDesc.java
               java/src/org/apache/axis/encoding/ser BeanDeserializer.java
                        BeanSerializer.java SimpleDeserializer.java
                        SimpleSerializer.java
  Log:
  Problem:
  BeanPropertyDescriptors are constructed each time a bean/simple serializer/deserializer
  is constructed.
  
  Solution:
  Cache the BeanPropertDescriptor array (and map) in the TypeDesc (if present).  This
  makes it easily accessible from both the serializer and deserializer.  Caching in the
  TypeDesc also allows easy access from customized serializers/deserializers.
  
  Revision  Changes    Path
  1.17      +47 -0     xml-axis/java/src/org/apache/axis/description/TypeDesc.java
  
  Index: TypeDesc.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/description/TypeDesc.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TypeDesc.java	1 Jul 2002 09:29:43 -0000	1.16
  +++ TypeDesc.java	8 Jul 2002 14:37:44 -0000	1.17
  @@ -57,10 +57,13 @@
   
   import org.apache.axis.utils.ClassUtils;
   import org.apache.axis.utils.JavaUtils;
  +import org.apache.axis.utils.BeanUtils;
  +import org.apache.axis.utils.BeanPropertyDescriptor;
   
   import javax.xml.namespace.QName;
   import java.lang.reflect.Method;
   import java.util.HashMap;
  +import java.util.Map;
   
   /**
    * A TypeDesc represents a Java<->XML data binding.  It is essentially
  @@ -129,6 +132,11 @@
       /** Are there any fields which are serialized as attributes? */
       private boolean _hasAttributes = false;
   
  +    /** Introspected property descriptors */
  +    private BeanPropertyDescriptor[] propertyDescriptor = null; 
  +    /** Map with key = property descriptor name, value = descriptor */
  +    private Map propertyMap = null;
  +
       /**
        * Obtain the current array of FieldDescs
        */
  @@ -359,5 +367,44 @@
   
       public void setXmlType(QName xmlType) {
           this.xmlType = xmlType;
  +    }
  +
  +    /**
  +     * Get/Cache the property descriptors
  +     * @return PropertyDescriptor
  +     */
  +    public BeanPropertyDescriptor[] getPropertyDescriptors() {
  +        // Return the propertyDescriptor if already set.
  +        // If not set, use BeanUtils.getPd to get the property descriptions.
  +        //
  +        // Since javaClass is a generated class, there
  +        // may be a faster way to set the property descriptions than
  +        // using BeanUtils.getPd.  But for now calling getPd is sufficient.
  +        if (propertyDescriptor == null) {
  +            propertyDescriptor = BeanUtils.getPd(javaClass, this);
  +        }
  +        return propertyDescriptor;
  +    }
  +    /**
  +     * Get/Cache the property descriptor map
  +     * @return Map with key=propertyName, value=descriptor
  +     */
  +    public Map getPropertyDescriptorMap() {
  +        // Return map if already set.
  +        if (propertyMap != null) {
  +            return propertyMap;
  +        }
  +
  +        // Make sure properties exist
  +        if (propertyDescriptor == null) {
  +            getPropertyDescriptors();  
  +        }
  +        // Build the map
  +        propertyMap = new HashMap();
  +        for (int i = 0; i < propertyDescriptor.length; i++) {
  +            BeanPropertyDescriptor descriptor = propertyDescriptor[i];
  +            propertyMap.put(descriptor.getName(), descriptor);
  +        }
  +        return propertyMap;
       }
   }
  
  
  
  1.37      +15 -7     xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java
  
  Index: BeanDeserializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- BeanDeserializer.java	3 Jul 2002 17:50:22 -0000	1.36
  +++ BeanDeserializer.java	8 Jul 2002 14:37:44 -0000	1.37
  @@ -79,6 +79,7 @@
   import java.io.Serializable;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Map;
   
   /**
    * General purpose deserializer for an arbitrary java bean.
  @@ -94,7 +95,7 @@
   
       QName xmlType;
       Class javaType;
  -    protected HashMap propertyMap = new HashMap();
  +    protected Map propertyMap = null;
       protected QName prevQName;
   
       public static final String DESERIALIZE_ANY = "DeserializeAny";
  @@ -110,18 +111,25 @@
           this(javaType, xmlType, TypeDesc.getTypeDescForClass(javaType));
       }
   
  -    // Construct BeanSerializer for the indicated class/qname and meta Data
  +    // Construct BeanDeserializer for the indicated class/qname and meta Data
       public BeanDeserializer(Class javaType, QName xmlType, TypeDesc typeDesc ) {
           this.xmlType = xmlType;
           this.javaType = javaType;
           this.typeDesc = typeDesc;
           // Get a list of the bean properties
  -        BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType, typeDesc);
  -        // loop through properties and grab the names for later
  -        for (int i = 0; i < pd.length; i++) {
  -            BeanPropertyDescriptor descriptor = pd[i];
  -            propertyMap.put(descriptor.getName(), descriptor);
  +        BeanPropertyDescriptor[] pd = null;
  +        if (typeDesc != null) {
  +            propertyMap = typeDesc.getPropertyDescriptorMap();
  +        } else {
  +            pd = BeanUtils.getPd(javaType, null);
  +            propertyMap = new HashMap();
  +            // loop through properties and grab the names for later
  +            for (int i = 0; i < pd.length; i++) {
  +                BeanPropertyDescriptor descriptor = pd[i];
  +                propertyMap.put(descriptor.getName(), descriptor);
  +            }
           }
  +
           // create a value
           try {
               value=javaType.newInstance();
  
  
  
  1.41      +11 -4     xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
  
  Index: BeanSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- BeanSerializer.java	3 Jul 2002 17:50:22 -0000	1.40
  +++ BeanSerializer.java	8 Jul 2002 14:37:44 -0000	1.41
  @@ -113,7 +113,11 @@
           this.xmlType = xmlType;
           this.javaType = javaType;
           this.typeDesc = typeDesc;
  -        propertyDescriptor = BeanUtils.getPd(javaType, typeDesc);
  +        if (typeDesc != null) {
  +            propertyDescriptor = typeDesc.getPropertyDescriptors();
  +        } else {
  +            propertyDescriptor = BeanUtils.getPd(javaType, null);
  +        }
       }
   
       /**
  @@ -272,9 +276,12 @@
               extension.setAttribute("base", base);
               e = extension;
               // Get the property descriptors for the super class
  -            superPd =
  -                BeanUtils.getPd(superClass,
  -                                TypeDesc.getTypeDescForClass(superClass));
  +            TypeDesc superTypeDesc = TypeDesc.getTypeDescForClass(superClass);
  +            if (superTypeDesc != null) {
  +                superPd = typeDesc.getPropertyDescriptors();
  +            } else {
  +                superPd = BeanUtils.getPd(superClass, null);
  +            }
           } else {
               e = complexType;
           }
  
  
  
  1.20      +29 -21    xml-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java
  
  Index: SimpleDeserializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SimpleDeserializer.java	11 Jun 2002 14:53:56 -0000	1.19
  +++ SimpleDeserializer.java	8 Jul 2002 14:37:44 -0000	1.20
  @@ -90,8 +90,7 @@
   
       StringBuffer val = new StringBuffer();
       private Constructor constructor = null;
  -    private BeanPropertyDescriptor[] pd = null;
  -    private HashMap propertyMap = new HashMap();
  +    private Map propertyMap = null;
       private HashMap attributeMap = null;
   
       public QName xmlType;
  @@ -106,33 +105,42 @@
       public SimpleDeserializer(Class javaType, QName xmlType) {
           this.xmlType = xmlType;
           this.javaType = javaType;
  -        
  -        // if this type is a SimpleType bean, get bean properties
  -        if (SimpleType.class.isAssignableFrom(javaType)) {
  -            typeDesc = TypeDesc.getTypeDescForClass(javaType);
  -            this.pd = BeanUtils.getPd(javaType,typeDesc);
  -            // loop through properties and grab the names for later
  -            for (int i = 0; i < pd.length; i++) {
  -                BeanPropertyDescriptor descriptor = pd[i];
  -                propertyMap.put(descriptor.getName(), descriptor);
  -            }
  -        }        
  +
  +        init();
       }
       public SimpleDeserializer(Class javaType, QName xmlType, TypeDesc typeDesc) {
           this.xmlType = xmlType;
           this.javaType = javaType;
           this.typeDesc = typeDesc;
           
  -        // if this type is a SimpleType bean, get bean properties
  +        init();
  +    }    
  +
  +   /**
  +    * Initialize the typeDesc, property descriptors and propertyMap.
  +    */
  +    private void init() {
  +        // The typeDesc and map array are only necessary
  +        // if this class extends SimpleType.
           if (SimpleType.class.isAssignableFrom(javaType)) {
  -            this.pd = BeanUtils.getPd(javaType, typeDesc);
  -            // loop through properties and grab the names for later
  -            for (int i = 0; i < pd.length; i++) {
  -                BeanPropertyDescriptor descriptor = pd[i];
  -                propertyMap.put(descriptor.getName(), descriptor);
  +            // Set the typeDesc if not already set
  +            if (typeDesc == null) {
  +                typeDesc = TypeDesc.getTypeDescForClass(javaType);
               }
  -        }        
  -    }    
  +            // Get the cached propertyDescriptor from the type or 
  +            // generate a fresh one.
  +            if (typeDesc != null) {
  +                propertyMap = typeDesc.getPropertyDescriptorMap();
  +            } else {   
  +                BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType, null);
  +                propertyMap = new HashMap();
  +                for (int i = 0; i < pd.length; i++) {
  +                    BeanPropertyDescriptor descriptor = pd[i];
  +                    propertyMap.put(descriptor.getName(), descriptor);
  +                }
  +            }
  +        }
  +    }
         
       /** 
        * The Factory calls setConstructor.
  
  
  
  1.20      +22 -9     xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java
  
  Index: SimpleSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SimpleSerializer.java	20 Jun 2002 20:35:46 -0000	1.19
  +++ SimpleSerializer.java	8 Jul 2002 14:37:44 -0000	1.20
  @@ -90,23 +90,36 @@
       public SimpleSerializer(Class javaType, QName xmlType) {
           this.xmlType = xmlType;
           this.javaType = javaType;
  -        
  -        if (SimpleType.class.isAssignableFrom(javaType)) {
  -            // get the bean properties and the list of attributes from the bean
  -            typeDesc = TypeDesc.getTypeDescForClass(javaType);
  -            propertyDescriptor = BeanUtils.getPd(javaType, typeDesc);
  -        }
  +        init();
       }
       public SimpleSerializer(Class javaType, QName xmlType, TypeDesc typeDesc) {
           this.xmlType = xmlType;
           this.javaType = javaType;
           this.typeDesc = typeDesc;
  -        
  +        init();
  +    }
  +
  +   /**
  +    * Initialize the typeDesc and propertyDescriptor array.
  +    */
  +    private void init() {
  +        // The typeDesc and propertyDescriptor array are only necessary
  +        // if this class extends SimpleType.
           if (SimpleType.class.isAssignableFrom(javaType)) {
  -            // get the bean properties and the list of attributes from the bean
  -            propertyDescriptor = BeanUtils.getPd(javaType,typeDesc);
  +            // Set the typeDesc if not already set
  +            if (typeDesc == null) {
  +                typeDesc = TypeDesc.getTypeDescForClass(javaType);
  +            }
  +            // Get the cached propertyDescriptor from the type or 
  +            // generate a fresh one.
  +            if (typeDesc != null) {
  +                propertyDescriptor = typeDesc.getPropertyDescriptors();
  +            } else {   
  +                propertyDescriptor = BeanUtils.getPd(javaType, null);
  +            }
           }
       }
  +
       /**
        * Serialize a primitive or simple value.
        * If the object to serialize is a primitive, the Object value below
  
  
  

Mime
View raw message