You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by gd...@apache.org on 2005/02/07 08:54:04 UTC

cvs commit: ws-axis/java/src/org/apache/axis/encoding/ser BeanSerializer.java SimpleDeserializer.java SimpleSerializer.java

gdaniels    2005/02/06 23:54:04

  Modified:    java/src/org/apache/axis/description JavaServiceDesc.java
               java/src/org/apache/axis/encoding
                        DefaultTypeMappingImpl.java TypeMapping.java
                        TypeMappingDelegate.java TypeMappingImpl.java
                        TypeMappingRegistryImpl.java
               java/src/org/apache/axis/encoding/ser BeanSerializer.java
                        SimpleDeserializer.java SimpleSerializer.java
  Log:
  * When the BeanSerializer is serializing null values for
    elements with minOccurs > 0 and nillable == false, check
    to see if the desired class is a Number and if so try
    to turn it into a zero instead (a little friendlier than
    an exception).
  
  * Introduce TypeMapping.getQNameForClass(xmlType, javaType),
    which acts like getQNameForClass(xmlType) but will search
    up the TypeMapping hierarchy first for an EXACT match
    for the given type before falling back to the default
    (whatever the last mapping for xmlType was).
  
  * Use the above when syncing methods for greater accuracy.
  
  * Register LANGUAGE and NAME in the default type mapping
    (why not?)
  
  * Remove "HACK" from TypeMappingRegistry
  
  There are likely still a couple of broken things, but we're better off
  than we were this morning.  More tomorrow.
  
  Revision  Changes    Path
  1.21      +2 -1      ws-axis/java/src/org/apache/axis/description/JavaServiceDesc.java
  
  Index: JavaServiceDesc.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/description/JavaServiceDesc.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- JavaServiceDesc.java	28 Jan 2005 20:11:11 -0000	1.20
  +++ JavaServiceDesc.java	7 Feb 2005 07:54:03 -0000	1.21
  @@ -686,7 +686,8 @@
                               paramClass = JavaUtils.getHolderValueType(paramClass);
                           }
                           if (paramClass == null) {
  -                            paramClass = getTypeMapping().getClassForQName(param.getTypeQName());
  +                            paramClass = getTypeMapping().getClassForQName(param.getTypeQName(),
  +                                                                           type);
                           }
   
                           if (paramClass != null) {
  
  
  
  1.87      +2 -0      ws-axis/java/src/org/apache/axis/encoding/DefaultTypeMappingImpl.java
  
  Index: DefaultTypeMappingImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/DefaultTypeMappingImpl.java,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- DefaultTypeMappingImpl.java	20 Jan 2005 14:18:05 -0000	1.86
  +++ DefaultTypeMappingImpl.java	7 Feb 2005 07:54:03 -0000	1.87
  @@ -184,6 +184,8 @@
           */
           // anySimpleType is mapped to java.lang.String according to JAX-RPC 1.1 spec.
           myRegisterSimple(Constants.XSD_ANYSIMPLETYPE, java.lang.String.class);
  +        myRegisterSimple(Constants.XSD_LANGUAGE, java.lang.String.class);
  +        myRegisterSimple(Constants.XSD_NAME, java.lang.String.class);
           
           // If SOAP 1.1 over the wire, map wrapper classes to XSD primitives.
           myRegisterSimple(Constants.XSD_STRING, java.lang.String.class);
  
  
  
  1.14      +2 -0      ws-axis/java/src/org/apache/axis/encoding/TypeMapping.java
  
  Index: TypeMapping.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/TypeMapping.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TypeMapping.java	25 Feb 2004 14:02:36 -0000	1.13
  +++ TypeMapping.java	7 Feb 2005 07:54:04 -0000	1.14
  @@ -95,6 +95,8 @@
        */
       public Class getClassForQName(QName xmlType);
   
  +    public Class getClassForQName(QName xmlType, Class javaType);
  +
       /**
        * Returns an array of all the classes contained within this mapping
        */
  
  
  
  1.16      +13 -0     ws-axis/java/src/org/apache/axis/encoding/TypeMappingDelegate.java
  
  Index: TypeMappingDelegate.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/TypeMappingDelegate.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TypeMappingDelegate.java	25 Feb 2004 14:02:36 -0000	1.15
  +++ TypeMappingDelegate.java	7 Feb 2005 07:54:04 -0000	1.16
  @@ -167,6 +167,19 @@
       }
   
       /**
  +     * Gets the Class mapped to QName, preferring the passed Class if possible
  +     * @param xmlType qname or null
  +     * @param javaType a Java class
  +     * @return javaType class for type or null for no mappingor delegate
  +     */
  +    public Class getClassForQName(QName xmlType, Class javaType) {
  +        if (delegate != null) {
  +            return delegate.getClassForQName(xmlType, javaType);
  +        }
  +        return null;
  +    }
  +
  +    /**
        * Get the QName for this Java class, but only return a specific
        * mapping if there is one.  In other words, don't do special array
        * processing, etc.
  
  
  
  1.55      +24 -8     ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java
  
  Index: TypeMappingImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- TypeMappingImpl.java	17 Dec 2004 17:00:46 -0000	1.54
  +++ TypeMappingImpl.java	7 Feb 2005 07:54:04 -0000	1.55
  @@ -645,21 +645,37 @@
        * @return javaType class for type or null for no mapping
        */
       public Class getClassForQName(QName xmlType) {
  +        return getClassForQName(xmlType, null);
  +    }
  +
  +    public Class getClassForQName(QName xmlType, Class javaType) {
           if (xmlType == null) {
               return null;
           }
   
           //log.debug("getClassForQName xmlType =" + xmlType);
  -        Class javaType = null;
  -        //look for it in our map
  -        Pair pair = (Pair) qName2Pair.get(xmlType);
  -        if (pair == null && delegate != null) {
  -            //on no match, delegate
  -            javaType = delegate.getClassForQName(xmlType);
  -        } else if (pair != null) {
  -            javaType = pair.javaType;
  +
  +        if (javaType != null) {
  +            // Looking for an exact match first
  +            Pair pair = new Pair(javaType, xmlType);
  +            if (pair2DF.get(pair) == null) {
  +                if (delegate != null) {
  +                    javaType = delegate.getClassForQName(xmlType, javaType);
  +                }
  +            }
           }
   
  +        if (javaType == null) {
  +            //look for it in our map
  +            Pair pair = (Pair) qName2Pair.get(xmlType);
  +            if (pair == null && delegate != null) {
  +                //on no match, delegate
  +                javaType = delegate.getClassForQName(xmlType);
  +            } else if (pair != null) {
  +                javaType = pair.javaType;
  +            }
  +        }
  +        
           //log.debug("getClassForQName javaType =" + javaType);
           if(javaType == null && shouldDoAutoTypes()) {
               String pkg = Namespaces.getPackage(xmlType.getNamespaceURI());
  
  
  
  1.30      +1 -6      ws-axis/java/src/org/apache/axis/encoding/TypeMappingRegistryImpl.java
  
  Index: TypeMappingRegistryImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/TypeMappingRegistryImpl.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- TypeMappingRegistryImpl.java	23 Jan 2005 23:11:00 -0000	1.29
  +++ TypeMappingRegistryImpl.java	7 Feb 2005 07:54:04 -0000	1.30
  @@ -136,12 +136,7 @@
        */ 
       public TypeMappingRegistryImpl(TypeMapping tm) {
           mapTM = new HashMap();
  -        // TODO: HACK ALERT!!!! need this to get test/wsdl/schema2 working  
  -        if(tm instanceof DefaultJAXRPC11TypeMappingImpl){
  -            defaultDelTM = tm;
  -        } else {
  -            defaultDelTM = new TypeMappingDelegate(tm);
  -        }
  +        defaultDelTM = new TypeMappingDelegate(tm);
           register(Constants.URI_SOAP11_ENC, new DefaultSOAPEncodingTypeMappingImpl());
       }
   
  
  
  
  1.83      +30 -5     ws-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
  
  Index: BeanSerializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- BeanSerializer.java	7 Feb 2005 02:18:36 -0000	1.82
  +++ BeanSerializer.java	7 Feb 2005 07:54:04 -0000	1.83
  @@ -41,6 +41,7 @@
   import java.io.Serializable;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Modifier;
  +import java.lang.reflect.Constructor;
   import java.util.List;
   
   /**
  @@ -57,6 +58,8 @@
   
       private static final QName MUST_UNDERSTAND_QNAME = 
           new QName(Constants.URI_SOAP11_ENV, Constants.ATTR_MUST_UNDERSTAND);
  +    private static final Object[] ZERO_ARGS =
  +        new Object [] { "0" };
   
       QName xmlType;
       Class javaType;
  @@ -124,9 +127,11 @@
                       continue;
                   QName qname = null;
                   QName xmlType = null;
  +                Class javaType = propertyDescriptor[i].getType();
  +
                   boolean isOmittable = false;
                   // isNillable default value depends on the field type
  -                boolean isNillable = Types.isNullable(propertyDescriptor[i].getType());
  +                boolean isNillable = Types.isNullable(javaType);
   
                   // If we have type metadata, check to see what we're doing
                   // with this field.  If it's an attribute, skip it.  If it's
  @@ -162,7 +167,7 @@
   
                   if (xmlType == null) {
                       // look up the type QName using the class
  -                    xmlType = context.getQNameForClass(propertyDescriptor[i].getType());
  +                    xmlType = context.getQNameForClass(javaType);
                   }
   
                   // Read the value from the property
  @@ -172,13 +177,33 @@
                           Object propValue =
                               propertyDescriptor[i].get(value);
   
  +
                           if (propValue == null) {
  -                            // an element cannot be null if nillable property is set to 
  +                            // an element cannot be null if nillable property is set to
                               // "false" and the element cannot be omitted
                               if (!isNillable && !isOmittable) {
  -                                throw new IOException(Messages.getMessage("nullNonNillableElement", propName));
  +                                if (Number.class.isAssignableFrom(javaType)) {
  +                                    // If we have a null and it's a number, though,
  +                                    // we might turn it into the appropriate kind of 0.
  +                                    // TODO : Should be caching these constructors?
  +                                    try {
  +                                        Constructor constructor =
  +                                                javaType.getConstructor(
  +                                                        SimpleDeserializer.STRING_CLASS);
  +                                        propValue = constructor.newInstance(ZERO_ARGS);
  +                                    } catch (Exception e) {
  +                                        // If anything goes wrong here, oh well we tried.
  +                                    }
  +                                }
  +
  +                                if (propValue == null) {
  +                                    throw new IOException(
  +                                            Messages.getMessage(
  +                                                    "nullNonNillableElement",
  +                                                    propName));
  +                                }
                               }
  -                            
  +
                               // if meta data says minOccurs=0, then we can skip
                               // it if its value is null and we aren't doing SOAP
                               // encoding.
  
  
  
  1.45      +7 -4      ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java
  
  Index: SimpleDeserializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- SimpleDeserializer.java	6 Feb 2005 19:31:13 -0000	1.44
  +++ SimpleDeserializer.java	7 Feb 2005 07:54:04 -0000	1.45
  @@ -52,7 +52,7 @@
       private static final Class[] STRING_STRING_CLASS = 
           new Class [] {String.class, String.class};
   
  -    private static final Class[] STRING_CLASS = 
  +    public static final Class[] STRING_CLASS = 
           new Class [] {String.class};
   
       private final CharArrayWriter val = new CharArrayWriter();
  @@ -98,8 +98,7 @@
               if (typeDesc == null) {
                   typeDesc = TypeDesc.getTypeDescForClass(javaType);
               }
  -        }
  -        // Get the cached propertyDescriptor from the type or 
  +        // Get the cached propertyDescriptor from the type or
           // generate a fresh one.
           if (typeDesc != null) {
               propertyMap = typeDesc.getPropertyDescriptorMap();
  @@ -111,6 +110,7 @@
                   propertyMap.put(descriptor.getName(), descriptor);
               }
           }
  +        }
       }
       
       /**
  @@ -357,7 +357,10 @@
                   typeDesc.getFieldNameForAttribute(attrQName);
                   if (fieldName == null)
                       continue;
  -            } 
  +            }
  +
  +            if (propertyMap == null)
  +                continue;
               
               // look for the attribute property
               BeanPropertyDescriptor bpd =
  
  
  
  1.38      +2 -3      ws-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java
  
  Index: SimpleSerializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- SimpleSerializer.java	6 Feb 2005 23:57:27 -0000	1.37
  +++ SimpleSerializer.java	7 Feb 2005 07:54:04 -0000	1.38
  @@ -22,6 +22,7 @@
   import org.apache.axis.description.TypeDesc;
   import org.apache.axis.encoding.SerializationContext;
   import org.apache.axis.encoding.SimpleValueSerializer;
  +import org.apache.axis.encoding.SimpleType;
   import org.apache.axis.utils.BeanPropertyDescriptor;
   import org.apache.axis.utils.BeanUtils;
   import org.apache.axis.utils.Messages;
  @@ -32,8 +33,6 @@
   
   import javax.xml.namespace.QName;
   import java.io.IOException;
  -import java.beans.PropertyDescriptor;
  -import java.lang.reflect.InvocationTargetException;
   
   /**
    * Serializer for primitives and anything simple whose value is obtained with toString()
  @@ -129,7 +128,7 @@
               return context.qName2String((QName)value);
           }
   
  -        if(propertyDescriptor != null) {
  +        if (propertyDescriptor != null && !(value instanceof SimpleType)) {
               BeanPropertyDescriptor pd = BeanUtils.getSpecificPD(propertyDescriptor, "_value");
               if(pd != null) {
                   try {