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/test/wsdl/roundtrip InvalidCompanyId.java InvalidTickerSymbol.java
Date Fri, 12 Jul 2002 22:38:55 GMT
scheu       2002/07/12 15:38:55

  Modified:    java/src/org/apache/axis/utils BeanPropertyDescriptor.java
                        BeanUtils.java axisNLS.properties
               java/test/wsdl/roundtrip InvalidCompanyId.java
                        InvalidTickerSymbol.java
  Log:
  Problem:
  Java2WSDL uses the BeanSerializer writeSchema to write out the schema for an Exception class.
  This is done because Exception classes share a lot of processing with Beans...including
  the presences of meta data.
  
  The problem is that the BeanPropertyDescriptors that are built only contain the
  editable properties.  For Exceptions, the BeanPropertyDescriptor needs to contain
  the read-only properties as well.  The JSR 101 specification indicates that
  the elements within a complexType for a Fault are mapped to read-only properties in an Exception;
  thus Java2WSDL needs to consider the read-only properties when generating the wsdl.
  
  Solution:
  Code is added BeanUtils to add the read-only properties if the indicated class
  is Throwable.
  
  I also cleaned up the code a little...probably could use more cleanup.  Added
  some additional exception handling.
  I made a small change to the Roundtrip testcase to verify the problem and the fix.
  
  NOTE: THIS FIX IS REQUIRED TO PASS A TCK TEST.
  
  Revision  Changes    Path
  1.10      +22 -1     xml-axis/java/src/org/apache/axis/utils/BeanPropertyDescriptor.java
  
  Index: BeanPropertyDescriptor.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/BeanPropertyDescriptor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BeanPropertyDescriptor.java	10 Jul 2002 01:37:01 -0000	1.9
  +++ BeanPropertyDescriptor.java	12 Jul 2002 22:38:55 -0000	1.10
  @@ -60,6 +60,7 @@
   import java.lang.reflect.Method;
   
   import org.apache.axis.components.logger.LogFactory;
  +import org.apache.axis.AxisFault;
   import org.apache.commons.logging.Log;
   
   
  @@ -129,6 +130,24 @@
       }
   
       /** 
  +     * Construct a BPD with only a getter method
  +     * @param _name is the name of the property
  +     * @param _getter is the accessor method
  +     */
  +    public BeanPropertyDescriptor(String _name,
  +                                  Method _getter) {
  +        name = _name;
  +        getter = _getter;
  +        setter = null;
  +        if (_getter == null || _name == null) {
  +            throw new IllegalArgumentException(
  +                    JavaUtils.getMessage(getter == null ?
  +                                         "badGetter00" :
  +                                         "badProp03"));
  +        }
  +    }
  +
  +    /** 
        * Construct a BPD with a field
        * Both must be set
        * @param _name is the name of the property
  @@ -183,7 +202,7 @@
           } else if (field != null) {
               return field.get(obj);
           }
  -        return null;
  +        throw new IllegalAccessException(JavaUtils.getMessage("badGetter00"));
       }
       /**
        * Set the property value
  @@ -196,6 +215,8 @@
               setter.invoke(obj, new Object[] {newValue});
           } else if (field != null) {
               field.set(obj, newValue);
  +        } else {
  +            throw new IllegalAccessException(JavaUtils.getMessage("badSetter00"));
           }
       }    
       /** 
  
  
  
  1.10      +98 -37    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BeanUtils.java	17 Jun 2002 19:25:40 -0000	1.9
  +++ BeanUtils.java	12 Jul 2002 22:38:55 -0000	1.10
  @@ -69,9 +69,14 @@
   import java.lang.reflect.Modifier;
   import java.util.ArrayList;
   
  +import org.apache.axis.components.logger.LogFactory;
  +import org.apache.commons.logging.Log;
  +
   public class BeanUtils {
   
       public static final Object[] noArgs = new Object[] {}; 
  +    protected static Log log =
  +        LogFactory.getLog(BeanUtils.class.getName());
   
       /**
        * Create a BeanPropertyDescriptor array for the indicated class.
  @@ -191,8 +196,14 @@
           }
   
           try {
  -            // Create a new pd array and index into the array
  -            int index = 0;
  +
  +            // Create an Array List
  +            ArrayList pd = new ArrayList();
  +            for (int i=0; i < myPd.length; i++) {
  +                if (myPd[i] != null) {
  +                    pd.add(myPd[i]);
  +                }
  +            }
   
               // Build a new pd array
               // defined by the order of the set methods.
  @@ -200,41 +211,75 @@
               // 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];
  +            int index = 0;            
  +            ArrayList newPd = new ArrayList();
  +            for (int i=0; i <pd.size(); i++) {
  +                newPd.add(null);
  +            }
               Method[] methods = cls.getMethods();
               for (int i=0; i < methods.length; i++) {
                   Method method = methods[i];
                   if (method.getName().startsWith("set")) {
                       boolean found = false;
  -                    for (int j=0; j < myPd.length && !found; j++) {
  -                        if (myPd[j] != null &&
  -                            myPd[j].getWriteMethod() != null &&
  -                            myPd[j].getWriteMethod().equals(method)) {
  +                    for (int j=0; j < pd.size() && !found; j++) {
  +                        if (pd.get(j) != null &&
  +                            ((BeanPropertyDescriptor)pd.get(j)).getWriteMethod() != null
&&
  +                            ((BeanPropertyDescriptor)pd.get(j)).getWriteMethod().equals(method))
{
                               found = true;
  -                            newPd[index] = myPd[j];
  +                            newPd.set(index,pd.get(j));
                               index++;
                           }
                       }
                   }
               }
               // Now if there are any additional property descriptors, add them to the end.
  -            if (index < myPd.length) {
  -                for (int m=0; m < myPd.length && index < myPd.length; m++)
{
  +            if (index < pd.size()) {
  +                for (int m=0; m < pd.size() && index < pd.size(); m++) {
                       boolean found = false;
                       for (int n=0; n < index && !found; n++) {
  -                        found = (myPd[m]==newPd[n]);
  +                        found = (pd.get(m)==newPd.get(n));
                       }
                       if (!found) {
  -                        newPd[index] = myPd[m];
  +                        newPd.set(index,  pd.get(m));
                           index++;
                       }
                   }
               }
  -            // If newPd has same number of elements as myPd, use newPd.
  -            if (index == myPd.length) {
  -                myPd = newPd;
  +            // If newPd has same number of elements as pd, use newPd.
  +            if (index == pd.size()) {
  +                pd = newPd;
  +            }
  +            myPd = new BeanPropertyDescriptor[pd.size()];
  +            for (int i=0; i <pd.size(); i++) {
  +                myPd[i] = (BeanPropertyDescriptor) pd.get(i);
  +            }
  +            // If the javaType is Throwable, add the getter methods to the list.
  +            if (Throwable.class.isAssignableFrom(cls)) {
  +                for (int i=0; i < methods.length; i++) {
  +                    Method method = methods[i];
  +                    if (method.getParameterTypes().length == 0 &&
  +                        method.getReturnType() != void.class &&
  +                        (method.getName().startsWith("get") ||
  +                         ((method.getName().startsWith("is") &&
  +                           method.getReturnType() == boolean.class))) &&
  +                        // Specifically prevent the Throwable get methods
  +                        !(method.getName().equals("getMessage") ||
  +                          method.getName().equals("getLocalizedMessage"))) {
  +                        boolean found = false;
  +                        for (int j=0; j < pd.size() && !found; j++) {
  +                            BeanPropertyDescriptor bpd = (BeanPropertyDescriptor) pd.get(j);
  +                            found = method.equals(bpd.getReadMethod());
  +                        }
  +                        if (!found) {
  +                            pd.add(new BeanPropertyDescriptor(
  +                               getPropNameFromReadMethod(method),
  +                               method));
  +                        }
  +                    }
  +                }
               }
   
  +
               // Get the methods of the class and look for the special set and
               // get methods for property "collections"
               for (int i=0; i < methods.length; i++) {
  @@ -247,29 +292,26 @@
                               methods[j].getReturnType() == methods[i].getParameterTypes()[1]
&&
                               methods[j].getParameterTypes()[0] == int.class &&
                               methods[i].getParameterTypes()[0] == int.class) {
  -                            for (int k=0; k < myPd.length; k++) {
  -                                if (myPd[k] != null &&
  -                                    myPd[k].getReadMethod() != null &&
  -                                    myPd[k].getWriteMethod() != null &&
  -                                    myPd[k].getReadMethod().getName().equals(methods[j].getName())
&&
  -                                    myPd[k].getWriteMethod().getName().equals(methods[i].getName()))
{
  -                                    myPd[k] = new BeanPropertyDescriptor(myPd[k].getName(),
  -                                                                         myPd[k].getReadMethod(),
  -                                                                         myPd[k].getWriteMethod(),
  +                            for (int k=0; k < pd.size(); k++) {
  +                                BeanPropertyDescriptor bpd = 
  +                                    (BeanPropertyDescriptor) pd.get(k);
  +                                if (bpd != null &&
  +                                    bpd.getReadMethod() != null &&
  +                                    bpd.getWriteMethod() != null &&
  +                                    bpd.getReadMethod().getName().equals(methods[j].getName())
&&
  +                                    bpd.getWriteMethod().getName().equals(methods[i].getName()))
{
  +                                    pd.set(k, new BeanPropertyDescriptor(bpd.getName(),
  +                                                                         bpd.getReadMethod(),
  +                                                                         bpd.getWriteMethod(),
                                                                            methods[j],
  -                                                                         methods[i]);
  +                                                                         methods[i]));
                                   }
                               }
                           }
                       }
                   }
               }
  -            ArrayList pd = new ArrayList();
  -            for (int i=0; i < myPd.length; i++) {
  -                if (myPd[i] != null) {
  -                    pd.add(myPd[i]);
  -                }
  -            }
  +
               // Now look for public fields
               Field fields[] = cls.getFields();
               if (fields != null && fields.length > 0) {    
  @@ -300,7 +342,7 @@
                       }
                   }
               }
  -            
  +
               // If typeDesc meta data exists, re-order according to the fields
               if (typeDesc != null && 
                   typeDesc.getFields() != null) {
  @@ -330,16 +372,35 @@
                   pd = ordered;
               }
   
  -
               myPd = new BeanPropertyDescriptor[pd.size()];
               for (int i=0; i <pd.size(); i++) {
                   myPd[i] = (BeanPropertyDescriptor) pd.get(i);
               }
  -
           } catch (Exception e) {
  -            // Don't process Property Descriptors if problems occur
  -            return myPd;
  +            log.error(JavaUtils.getMessage("badPropertyDesc00", cls.getName()), e);
  +            throw new InternalException(e);
  +        }
  +        return myPd; 
  +    }
  +
  +    /**
  +     * Given a read Method (i.e. is or get Method) 
  +     * returns the name of the property.
  +     */
  +    private static String getPropNameFromReadMethod(Method method) {
  +        String name = method.getName();
  +        if (name.startsWith("is")) {
  +            name = name.substring(2);
  +        } else {
  +            name = name.substring(3);
           }
  -        return myPd;
  +        if (name.length() == 0) {
  +            return null;
  +        } else if (name.length() == 1) {
  +            return Character.toLowerCase(name.charAt(0)) + "";
  +        } else {
  +            return Character.toLowerCase(name.charAt(0)) + name.substring(1);
  +        } 
  +        
       }
   }
  
  
  
  1.26      +1 -0      xml-axis/java/src/org/apache/axis/utils/axisNLS.properties
  
  Index: axisNLS.properties
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/axisNLS.properties,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- axisNLS.properties	10 Jul 2002 17:33:03 -0000	1.25
  +++ axisNLS.properties	12 Jul 2002 22:38:55 -0000	1.26
  @@ -942,3 +942,4 @@
   setJavaTypeErr00=Illegal argument passed to ParameterDesc.setJavaType.  The java type {0}
does not match the mode {1}
   badNormalizedString00=Invalid normalizedString value
   badToken00=Invalid token value
  +badPropertyDesc00=Internal Error occurred while build the property descriptors for {0}
  
  
  
  1.3       +1 -1      xml-axis/java/test/wsdl/roundtrip/InvalidCompanyId.java
  
  Index: InvalidCompanyId.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/roundtrip/InvalidCompanyId.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InvalidCompanyId.java	19 Apr 2002 14:03:14 -0000	1.2
  +++ InvalidCompanyId.java	12 Jul 2002 22:38:55 -0000	1.3
  @@ -64,7 +64,7 @@
    */
   public class InvalidCompanyId extends Exception {
   
  -    public int companyId;
  +    private int companyId;
       private InvalidCompanyId e;  // This should not be put in the wsdl
   
       public InvalidCompanyId(int companyId) {
  
  
  
  1.3       +1 -1      xml-axis/java/test/wsdl/roundtrip/InvalidTickerSymbol.java
  
  Index: InvalidTickerSymbol.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/roundtrip/InvalidTickerSymbol.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InvalidTickerSymbol.java	19 Apr 2002 14:03:14 -0000	1.2
  +++ InvalidTickerSymbol.java	12 Jul 2002 22:38:55 -0000	1.3
  @@ -64,7 +64,7 @@
    */
   public class InvalidTickerSymbol extends Exception {
   
  -    public String tickerSymbol;
  +    private String tickerSymbol;
   
       public InvalidTickerSymbol(String tickerSymbol) {
           this.tickerSymbol = tickerSymbol;
  
  
  

Mime
View raw message