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 2002/08/16 18:41:35 UTC

cvs commit: xml-axis/java/test/encoding TestAttributes.java

gdaniels    2002/08/16 09:41:35

  Modified:    java/src/org/apache/axis/encoding
                        SerializationContextImpl.java TypeMappingImpl.java
               java/src/org/apache/axis/encoding/ser SimpleSerializer.java
               java/src/org/apache/axis/utils axisNLS.properties
               java/test/encoding TestAttributes.java
  Log:
  Cleanup, remove unneeded info structure, add recursive getTypeQName
  which walks up the inheritance tree.
  
  More cleanup on the way...
  
  Revision  Changes    Path
  1.55      +16 -21    xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java
  
  Index: SerializationContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- SerializationContextImpl.java	16 Aug 2002 11:07:09 -0000	1.54
  +++ SerializationContextImpl.java	16 Aug 2002 16:41:34 -0000	1.55
  @@ -1137,7 +1137,6 @@
                                                "" + this));
               }
   
  -            SerializerInfo info = null;
               // if we're looking for xsd:anyType, accept anything...
               if (Constants.XSD_ANYTYPE.equals(xmlType)) {
                   xmlType = null;
  @@ -1145,12 +1144,13 @@
               }
   
               // Try getting a serializer for the prefered xmlType
  -            info = getSerializer(javaType, xmlType);
  +            Serializer ser = getSerializer(javaType, xmlType);
   
  -            if ( info != null ) {
  +            if ( ser != null ) {
                   // Send the xmlType if indicated.
                   if (shouldSendType) {
  -                    xmlType = ((TypeMappingImpl)tm).getXMLType(info.javaType, xmlType);
  +                    xmlType = ((TypeMappingImpl)tm).getXMLType(javaType,
  +                                                               xmlType);
                       attributes = setTypeAttribute(attributes, xmlType);
                   }
                   // The multiref QName is our own fake name.
  @@ -1159,7 +1159,7 @@
                   // in the interop tests.
                   //if (name.equals(multirefQName) && type != null)
                   //    name = type;
  -                info.ser.serialize(elemQName, attributes, value, this);
  +                ser.serialize(elemQName, attributes, value, this);
                   return;
               }
   
  @@ -1169,11 +1169,6 @@
           // !!! Write out a generic null, or get type info from somewhere else?
       }
   
  -    class SerializerInfo {
  -        Serializer ser;
  -        Class javaType;
  -    }
  -
       /**
        * getSerializer
        * Attempts to get a serializer for the indicated javaType and xmlType.
  @@ -1181,8 +1176,7 @@
        * @param xmlType is the preferred qname type.
        * @return found class/serializer or null
        **/
  -    private SerializerInfo getSerializer(Class javaType, QName xmlType) {
  -        SerializerInfo info = null;
  +    private Serializer getSerializer(Class javaType, QName xmlType) {
           SerializerFactory  serFactory  = null ;
           TypeMapping tm = getTypeMapping();
   
  @@ -1215,17 +1209,18 @@
           if ( serFactory != null ) {
               ser = (Serializer) serFactory.getSerializerAs(Constants.AXIS_SAX);
           }
  -        if (ser != null) {
  -            info = new SerializerInfo();
  -            info.ser = ser;
  -            info.javaType = javaType;
  -        }
  -        return info;
  +
  +        return ser;
       }
   
       public String getValueAsString(Object value, QName xmlType) throws IOException {
  -        SerializerInfo info = getSerializer(value.getClass(), xmlType);
  -        SimpleValueSerializer ser = (SimpleValueSerializer)info.ser;
  -        return ser.getValueAsString(value, this);
  +        Serializer ser = getSerializer(value.getClass(), xmlType);
  +        if (!(ser instanceof SimpleValueSerializer)) {
  +            throw new IOException(
  +                    JavaUtils.getMessage("needSimpleValueSer",
  +                                         ser.getClass().getName()));
  +        }
  +        SimpleValueSerializer simpleSer = (SimpleValueSerializer)ser;
  +        return simpleSer.getValueAsString(value, this);
       }
   }
  
  
  
  1.25      +30 -8     xml-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java
  
  Index: TypeMappingImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TypeMappingImpl.java	16 Aug 2002 11:07:09 -0000	1.24
  +++ TypeMappingImpl.java	16 Aug 2002 16:41:35 -0000	1.25
  @@ -366,7 +366,7 @@
   
           // If the xmlType was not provided, get one
           if (xmlType == null) {
  -            xmlType = getTypeQName(javaType);
  +            xmlType = getTypeQNameRecursive(javaType);
   
               // If we couldn't find one, we're hosed, since getTypeQName()
               // already asked all of our delegates.
  @@ -512,6 +512,29 @@
        * @param javaType class or type
        * @return xmlType qname or null
        */
  +    public QName getTypeQNameRecursive(Class javaType) {
  +        QName ret = null;
  +        while (javaType != null) {
  +            ret = getTypeQName(javaType);
  +            if (ret != null)
  +                return ret;
  +
  +            // Walk my interfaces...
  +            Class [] interfaces = javaType.getInterfaces();
  +            if (interfaces != null) {
  +                for (int i = 0; i < interfaces.length; i++) {
  +                    Class iface = interfaces[i];
  +                    ret = getTypeQName(iface);
  +                    if (ret != null)
  +                        return ret;
  +                }
  +            }
  +
  +            javaType = javaType.getSuperclass();
  +        }
  +        return null;
  +    }
  +
       public QName getTypeQName(Class javaType) {
           //log.debug("getTypeQName javaType =" + javaType);
           if (javaType == null)
  @@ -525,17 +548,16 @@
               xmlType = pair.xmlType;
           }
   
  +        if (xmlType == null && doAutoTypes) {
  +            xmlType = new QName(Constants.NS_URI_JAVA,
  +                                javaType.getName());
  +        }
  +
           // Can only detect arrays via code
  -        if (xmlType == null &&
  -            (javaType.isArray() ||
  +        if (xmlType == null && (javaType.isArray() ||
                javaType == List.class ||
                List.class.isAssignableFrom(javaType))) {
               xmlType = Constants.SOAP_ARRAY;
  -        }
  -
  -        if (xmlType == null && doAutoTypes) {
  -            xmlType = new QName(Constants.NS_URI_JAVA,
  -                                javaType.getName());
           }
   
           //log.debug("getTypeQName xmlType =" + xmlType);
  
  
  
  1.24      +0 -10     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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- SimpleSerializer.java	16 Aug 2002 11:07:09 -0000	1.23
  +++ SimpleSerializer.java	16 Aug 2002 16:41:35 -0000	1.24
  @@ -74,8 +74,6 @@
   import javax.xml.namespace.QName;
   
   import java.io.IOException;
  -import java.text.SimpleDateFormat;
  -import java.util.TimeZone;
   
   /**
    * Serializer for primitives and anything simple whose value is obtained with toString()
  @@ -83,14 +81,6 @@
    * @author Rich Scheuerle <di...@yahoo.com>
    */
   public class SimpleSerializer implements SimpleValueSerializer {
  -    private static SimpleDateFormat zulu =
  -       new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  -                         //  0123456789 0 123456789
  -
  -    static {
  -        zulu.setTimeZone(TimeZone.getTimeZone("GMT"));
  -    }
  -
       public QName xmlType;
       public Class javaType;
   
  
  
  
  1.44      +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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- axisNLS.properties	16 Aug 2002 15:19:56 -0000	1.43
  +++ axisNLS.properties	16 Aug 2002 16:41:35 -0000	1.44
  @@ -984,6 +984,7 @@
   
   # NOTE:  in noDataHandler, do not translate DataHandler.
   noDataHandler=Could not create a DataHandler for {0}, returning {1} instead.
  +needSimpleValueSer=Serializer class {0} does not implement SimpleValueSerializer, which is necessary for attributes.
   
   # NOTE:  in needJIMI, do not translate "JIMI", "java.awt.Image", "http://java.sun.com/products/jimi/"
   needJIMI=JIMI is necessary to use java.awt.Image attachments (http://java.sun.com/products/jimi/).
  
  
  
  1.16      +0 -7      xml-axis/java/test/encoding/TestAttributes.java
  
  Index: TestAttributes.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/encoding/TestAttributes.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestAttributes.java	3 Jul 2002 18:47:08 -0000	1.15
  +++ TestAttributes.java	16 Aug 2002 16:41:35 -0000	1.16
  @@ -39,13 +39,6 @@
   
       public static final String myNS = "urn:myNS";
   
  -    public static void main(String [] args) throws Exception
  -    {
  -        TestAttributes tester = new TestAttributes("TestAttributes");
  -        tester.testBean();
  -        tester.testSimpleType();
  -    }
  -
       public TestAttributes(String name) {
           super(name);
       }