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/wsdl/toJava JavaBeanHelperWriter.java
Date Sat, 25 May 2002 00:03:16 GMT
scheu       02/05/24 17:03:16

  Modified:    java/src/org/apache/axis/encoding/ser BeanDeserializer.java
                        BeanSerializer.java SimpleDeserializer.java
                        SimpleSerializer.java
               java/src/org/apache/axis/utils BeanUtils.java
               java/src/org/apache/axis/wsdl/toJava
                        JavaBeanHelperWriter.java
  Log:
  Changes to fix defect 9060 (respect sequences).
  
  The following changes are made:
  
    1) The BeanUtils class is updated to order
       the BeanPropertyDescriptors using the order
       of the element FieldDesc of the TypeDesc
       (if meta data is present).
  
    2) Changed the serializers (BeanSerializer etc.)
       to pass TypeDesc to BeanUtils to construct
       the BeanPropertyDescriptors.
  
    3) Changed the JavaBeanHelperWriter to
       ALWAYS write the element meta data.  Since
       the FieldDesc's are ordered according
       to the wsdl file, the sequence information
       is always respected.  Note that I changed
       the elementMappings HashMap to an
       elementMetaData Vector so that the order would
       be preserved.
  
  Bingo
  
  Revision  Changes    Path
  1.28      +1 -1      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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- BeanDeserializer.java	24 May 2002 18:20:42 -0000	1.27
  +++ BeanDeserializer.java	25 May 2002 00:03:16 -0000	1.28
  @@ -112,7 +112,7 @@
           this.javaType = javaType;
           this.typeDesc = typeDesc;
           // Get a list of the bean properties
  -        BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType);
  +        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];
  
  
  
  1.33      +1 -1      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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- BeanSerializer.java	24 May 2002 21:34:21 -0000	1.32
  +++ BeanSerializer.java	25 May 2002 00:03:16 -0000	1.33
  @@ -109,7 +109,7 @@
           this.xmlType = xmlType;
           this.javaType = javaType;
           this.typeDesc = typeDesc;
  -        propertyDescriptor = BeanUtils.getPd(javaType);
  +        propertyDescriptor = BeanUtils.getPd(javaType, typeDesc);
       }
   
       /**
  
  
  
  1.15      +3 -4      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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SimpleDeserializer.java	24 May 2002 18:20:42 -0000	1.14
  +++ SimpleDeserializer.java	25 May 2002 00:03:16 -0000	1.15
  @@ -108,14 +108,13 @@
           
           // if this type is a SimpleType bean, get bean properties
           if (SimpleType.class.isAssignableFrom(javaType)) {
  -            this.pd = BeanUtils.getPd(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);
               }
  -
  -            typeDesc = TypeDesc.getTypeDescForClass(javaType);
           }        
       }
       public SimpleDeserializer(Class javaType, QName xmlType, TypeDesc typeDesc) {
  @@ -125,7 +124,7 @@
           
           // if this type is a SimpleType bean, get bean properties
           if (SimpleType.class.isAssignableFrom(javaType)) {
  -            this.pd = BeanUtils.getPd(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];
  
  
  
  1.15      +2 -2      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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SimpleSerializer.java	24 May 2002 21:34:21 -0000	1.14
  +++ SimpleSerializer.java	25 May 2002 00:03:16 -0000	1.15
  @@ -92,8 +92,8 @@
           
           if (SimpleType.class.isAssignableFrom(javaType)) {
               // get the bean properties and the list of attributes from the bean
  -            propertyDescriptor = BeanUtils.getPd(javaType);
               typeDesc = TypeDesc.getTypeDescForClass(javaType);
  +            propertyDescriptor = BeanUtils.getPd(javaType, typeDesc);
           }
       }
       public SimpleSerializer(Class javaType, QName xmlType, TypeDesc typeDesc) {
  @@ -103,7 +103,7 @@
           
           if (SimpleType.class.isAssignableFrom(javaType)) {
               // get the bean properties and the list of attributes from the bean
  -            propertyDescriptor = BeanUtils.getPd(javaType);
  +            propertyDescriptor = BeanUtils.getPd(javaType,typeDesc);
           }
       }
       /**
  
  
  
  1.6       +50 -7     xml-axis/java/src/org/apache/axis/utils/BeanUtils.java
  
  Index: BeanUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/BeanUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BeanUtils.java	24 May 2002 21:34:21 -0000	1.5
  +++ BeanUtils.java	25 May 2002 00:03:16 -0000	1.6
  @@ -75,8 +75,14 @@
   
       /**
        * Create a BeanPropertyDescriptor array for the indicated class.
  +     * @param Class javaType 
  +     * @param TypeDesc meta-data or null
  +     * @return array of properties in order
        */
       public static BeanPropertyDescriptor[] getPd(Class javaType) {
  +        return getPd(javaType, null);
  +    }
  +    public static BeanPropertyDescriptor[] getPd(Class javaType, TypeDesc typeDesc) {
           BeanPropertyDescriptor[] pd;
           try {
               final Class secJavaType = javaType;
  @@ -98,7 +104,7 @@
                               return result;
                           }
                       });
  -            pd = processPropertyDescriptors(rawPd,javaType);
  +            pd = processPropertyDescriptors(rawPd,javaType,typeDesc);
           } catch (Exception e) {
               // this should never happen
               throw new InternalException(e);
  @@ -147,12 +153,8 @@
           return ret;
       }
       /**
  -     * This method attempts to sort the property descriptors to match the
  -     * order defined in the class.  This is necessary to support
  -     * xsd:sequence processing, which means that the serialized order of
  -     * properties must match the xml element order.  (This method assumes that the
  -     * order of the set methods matches the xml element order...the emitter
  -     * will always order the set methods according to the xml order.)
  +     * This method attempts to sort the property descriptors using
  +     * the typeDesc and order defined in the class.
        *
        * This routine also looks for set(i, type) and get(i) methods and adjusts the
        * property to use these methods instead.  These methods are generated by the
  @@ -162,6 +164,12 @@
        */
       public static BeanPropertyDescriptor[] processPropertyDescriptors(
                     PropertyDescriptor[] rawPd, Class cls) {
  +        return processPropertyDescriptors(rawPd, cls, null);
  +    }
  +    public static BeanPropertyDescriptor[] processPropertyDescriptors(
  +                  PropertyDescriptor[] rawPd, Class cls, TypeDesc typeDesc) {
  +
  +        // Create a copy of the rawPd called myPd
           BeanPropertyDescriptor[] myPd = new BeanPropertyDescriptor[rawPd.length];
   
           int index1 = 0;
  @@ -180,6 +188,10 @@
   
               // Build a new pd array
               // defined by the order of the set methods.
  +            // *Note that this is not guaranteed since the getMethods
  +            // is not required to return the methods in the declared order;
  +            // however it seems to be the case most of the time.  The only way
  +            // to guarantee the correct ordering is if TypeDesc meta-data is available.
               BeanPropertyDescriptor[] newPd = new BeanPropertyDescriptor[rawPd.length];
               Method[] methods = cls.getMethods();
               for (int i=0; i < methods.length; i++) {
  @@ -277,6 +289,37 @@
                       }
                   }
               }
  +            
  +            // If typeDesc meta data exists, re-order according to the fields
  +            if (typeDesc != null && 
  +                typeDesc.getFields() != null) {
  +                ArrayList ordered = new ArrayList();
  +                // Add the TypeDesc elements first
  +                FieldDesc[] fds = typeDesc.getFields();
  +                for (int i=0; i<fds.length; i++) {
  +                    FieldDesc field = fds[i];
  +                    if (field.isElement()) {
  +                        boolean found = false;
  +                        for (int j=0; 
  +                             j<pd.size() && !found; 
  +                             j++) {
  +                            if (field.getFieldName().equals(
  +                               ((BeanPropertyDescriptor)pd.get(j)).getName())) {
  +                                ordered.add(pd.remove(j));
  +                                found = true;
  +                            }
  +                        }
  +                    }
  +                }
  +                // Add the remaining elements
  +                while (pd.size() > 0) {
  +                    ordered.add(pd.remove(0));
  +                }
  +                // Use the ordered list
  +                pd = ordered;
  +            }
  +
  +
               myPd = new BeanPropertyDescriptor[pd.size()];
               for (int i=0; i <pd.size(); i++) {
                   myPd[i] = (BeanPropertyDescriptor) pd.get(i);
  
  
  
  1.9       +23 -18    xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java
  
  Index: JavaBeanHelperWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JavaBeanHelperWriter.java	17 May 2002 19:09:32 -0000	1.8
  +++ JavaBeanHelperWriter.java	25 May 2002 00:03:16 -0000	1.9
  @@ -78,7 +78,7 @@
       protected Vector elements;
       protected Vector attributes;
       protected TypeEntry extendType;
  -    protected HashMap elementMappings = null;
  +    protected Vector elementMetaData = null;
   
       /**
        * Constructor.
  @@ -128,13 +128,18 @@
        * write MetaData code
        */
       protected void writeMetaData() throws IOException {
  -        // Collect elementMappings
  +        // Collect elementMetaData
           if (elements != null) {
               for (int i = 0; i < elements.size(); i++) {
                   ElementDecl elem = (ElementDecl)elements.get(i);
                   String elemName = elem.getName().getLocalPart();
                   String javaName = Utils.xmlNameToJava(elemName);
   
  +                // Changed the code to write meta data 
  +                // for all of the elements in order to
  +                // support sequences. Defect 9060
  +
  +
                   // Meta data is needed if the default serializer
                   // action cannot map the javaName back to the
                   // element's qname.  This occurs if:
  @@ -143,22 +148,22 @@
                   //    case and we have several problems with the mapping rules.
                   //    Seems best to gen meta data in this case.)
                   //  - the element name is qualified (has a namespace uri)
  -                if (!javaName.equals(elemName) || 
  -                    Character.isUpperCase(javaName.charAt(0)) ||
  -                    !elem.getName().getNamespaceURI().equals("")) {
  +                //if (!javaName.equals(elemName) || 
  +                //    Character.isUpperCase(javaName.charAt(0)) ||
  +                //    !elem.getName().getNamespaceURI().equals("")) {
                       // If we did some mangling, make sure we'll write out the XML
                       // the correct way.
  -                    if (elementMappings == null)
  -                        elementMappings = new HashMap();
  +                    if (elementMetaData == null)
  +                        elementMetaData = new Vector();
   
  -                    elementMappings.put(javaName, elem.getName());
  -                }
  +                    elementMetaData.add(elem);
  +                //}
               }
           }
           // if we have attributes, create metadata function which returns the
           // list of properties that are attributes instead of elements
   
  -        if (attributes != null || elementMappings != null) {
  +        if (attributes != null || elementMetaData != null) {
               boolean wroteFieldType = false;
               pw.println("    // " + JavaUtils.getMessage("typeMeta"));
               pw.println("    private static org.apache.axis.description.TypeDesc typeDesc
=");
  @@ -187,12 +192,12 @@
                   }
               }
   
  -            if (elementMappings != null) {
  -                Iterator i = elementMappings.entrySet().iterator();
  -                while (i.hasNext()) {
  -                    Map.Entry entry = (Map.Entry) i.next();
  -                    String fieldName = (String)entry.getKey();
  -                    QName xmlName = (QName) entry.getValue();
  +            if (elementMetaData != null) {
  +                for (int i=0; i<elementMetaData.size(); i++) {
  +                    ElementDecl elem = (ElementDecl) elementMetaData.elementAt(i);
  +                    String elemLocalName = elem.getName().getLocalPart();
  +                    String fieldName = Utils.xmlNameToJava(elemLocalName);
  +                    QName xmlName = elem.getName();
                       pw.print("        ");
                       if (!wroteFieldType) {
                           pw.print("org.apache.axis.description.FieldDesc ");
  @@ -226,7 +231,7 @@
        */
       protected void writeSerializer() throws IOException {
           String typeDesc = null;
  -        if (attributes != null || elementMappings != null) {
  +        if (attributes != null || elementMetaData != null) {
               typeDesc = "typeDesc";
           }
           String ser = " org.apache.axis.encoding.ser.BeanSerializer";
  @@ -253,7 +258,7 @@
        */
       protected void writeDeserializer()  throws IOException {
           String typeDesc = null;
  -        if (attributes != null || elementMappings != null) {
  +        if (attributes != null || elementMetaData != null) {
               typeDesc = "typeDesc";
           }
           String dser = " org.apache.axis.encoding.ser.BeanDeserializer";
  
  
  

Mime
View raw message