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 di...@apache.org on 2004/11/04 14:23:35 UTC

cvs commit: ws-axis/java/src/org/apache/axis/encoding SerializationContext.java

dims        2004/11/04 05:23:35

  Modified:    java/src/org/apache/axis/encoding/ser ArraySerializer.java
                        BeanSerializer.java
               java/src/org/apache/axis/message MessageElement.java
                        RPCParam.java
               java/src/org/apache/axis/encoding SerializationContext.java
  Log:
  Fix for:
  AXIS-1589 - SerializationContext.serialize(*,*,*,*,Boolean.FALSE) adds types
  
  from:
  toby cabot (toby@caboteria.org)
  
  Revision  Changes    Path
  1.59      +4 -9      ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java
  
  Index: ArraySerializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- ArraySerializer.java	11 Oct 2004 19:23:13 -0000	1.58
  +++ ArraySerializer.java	4 Nov 2004 13:23:34 -0000	1.59
  @@ -79,10 +79,9 @@
           MessageContext msgContext = context.getMessageContext();
           SchemaVersion schema = SchemaVersion.SCHEMA_2001;
           SOAPConstants soap = SOAPConstants.SOAP11_CONSTANTS;
  -        boolean encoded = true;
  +        boolean encoded = context.isEncoded();
           
           if (msgContext != null) {
  -            encoded = msgContext.isEncoded();
               schema = msgContext.getSchemaVersion();
               soap = msgContext.getSOAPConstants();
           }
  @@ -346,9 +345,7 @@
   
                       // Serialize the element.
                       context.serialize(elementName, serializeAttr, aValue,
  -                                      componentQName, // prefered type QName
  -                                      true,   // Send null values
  -                                      null);  // Respect default type config
  +                                      componentQName); // prefered type QName
                   }
               } else {
                   for (Iterator iterator = list.iterator(); iterator.hasNext();) {
  @@ -356,9 +353,7 @@
   
                       // Serialize the element.
                       context.serialize(elementName, serializeAttr, aValue,
  -                                      componentQName, // prefered type QName
  -                                      true,   // Send null values
  -                                      null);  // Respect default type config
  +                                      componentQName); // prefered type QName
   
                   }
               }
  @@ -367,7 +362,7 @@
               for (int index = 0; index < len; index++) {
                   for (int index2 = 0; index2 < dim2Len; index2++) {
                       Object aValue = Array.get(Array.get(value, index), index2);
  -                    context.serialize(elementName, null, aValue, componentQName, true, null);
  +                    context.serialize(elementName, null, aValue, componentQName);
                   }
               }
           }
  
  
  
  1.78      +4 -8      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.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- BeanSerializer.java	14 Oct 2004 20:28:47 -0000	1.77
  +++ BeanSerializer.java	4 Nov 2004 13:23:34 -0000	1.78
  @@ -103,11 +103,10 @@
           Attributes beanAttrs = getObjectAttributes(value, attributes, context);
   
           // Get the encoding style
  -        String encodingStyle = context.getEncodingStyle();
  -        boolean isEncoded = Constants.isSOAP_ENC(encodingStyle);
  +        boolean isEncoded = context.isEncoded();
   
           // check whether we have and xsd:any namespace="##any" type
  -        boolean suppressElement = !context.isEncoded() &&
  +        boolean suppressElement = !isEncoded &&
                                     name.getNamespaceURI().equals("") &&
                                     name.getLocalPart().equals("any");
   
  @@ -176,9 +175,7 @@
                           context.serialize(qname,
                                             null,
                                             propValue,
  -                                          xmlType,
  -                                          true,
  -                                          null);
  +                                          xmlType);
                       } else {
                           // Collection of properties: serialize each one
                           int j=0;
  @@ -193,8 +190,7 @@
                               }
                               if (j >= 0) {
                                   context.serialize(qname, null,
  -                                                  propValue, xmlType,
  -                                                  true, null);
  +                                                  propValue, xmlType);
                               }
                           }
                       }
  
  
  
  1.186     +1 -1      ws-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.185
  retrieving revision 1.186
  diff -u -r1.185 -r1.186
  --- MessageElement.java	14 Oct 2004 23:37:03 -0000	1.185
  +++ MessageElement.java	4 Nov 2004 13:23:35 -0000	1.186
  @@ -1243,7 +1243,7 @@
           if (objectValue != null) {
               outputContext.serialize(new QName(namespaceURI, name),
                                 attributes,
  -                              objectValue, null, false, null);
  +                              objectValue);
               return;
           }
   
  
  
  
  1.61      +1 -1      ws-axis/java/src/org/apache/axis/message/RPCParam.java
  
  Index: RPCParam.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/RPCParam.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- RPCParam.java	8 Jul 2004 08:51:57 -0000	1.60
  +++ RPCParam.java	4 Nov 2004 13:23:35 -0000	1.61
  @@ -178,7 +178,7 @@
                             null,   // no extra attrs
                             value,  // value
                             xmlType, // java/xml type
  -                          true, wantXSIType); 
  +                          Boolean.TRUE, wantXSIType); 
       }
   
       private void writeObject(ObjectOutputStream out)
  
  
  
  1.94      +96 -15    ws-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- SerializationContext.java	27 Oct 2004 03:21:55 -0000	1.93
  +++ SerializationContext.java	4 Nov 2004 13:23:35 -0000	1.94
  @@ -129,11 +129,17 @@
       private boolean sendXMLDecl = true;
   
       /**
  -     * Should I send xsi:type attributes?
  +     * Should I send xsi:type attributes?  By default, yes.
        */
       private boolean sendXSIType = true;
   
       /**
  +     * Send an element with an xsi:nil="true" attribute for null
  +     * variables (if Boolean.TRUE), or nothing (if Boolean.FALSE).
  +     */
  +    private Boolean sendNull = Boolean.TRUE;
  +
  +    /**
        * A place to hold objects we cache for multi-ref serialization, and
        * remember the IDs we assigned them.
        */
  @@ -467,7 +473,7 @@
        * @return a <code>String</code> value
        */
       public String getEncodingStyle() {
  -        return msgContext == null ? Use.ENCODED.getEncoding() : msgContext.getEncodingStyle();
  +        return msgContext == null ? Use.DEFAULT.getEncoding() : msgContext.getEncodingStyle();
       }
   
       /**
  @@ -476,7 +482,7 @@
        * @return a <code>boolean</code> value
        */
       public boolean isEncoded() {
  -        return msgContext == null ? true : msgContext.isEncoded();
  +        return Constants.isSOAP_ENC(getEncodingStyle());
       }
   
       /**
  @@ -622,13 +628,10 @@
        * directly or serialized as an mult-ref'd item)
        * The value is an Object, which may be a wrapped primitive, the
        * javaType is the actual unwrapped object type.
  -     * The xmlType (if specified) is the QName of the type that is used to set
  -     * xsi:type.  If not specified, xsi:type is set by using the javaType to
  +     * xsi:type is set by using the javaType to
        * find an appopriate xmlType from the TypeMappingRegistry.
  -     * The sendNull flag indicates whether null values should be sent over the
  -     * wire (default is to send such values with xsi:nil="true").
  -     * The sendType flag indicates whether the xsi:type flag should be sent
  -     * (default is true).
  +     * Null values and the xsi:type flag will be sent or not depending 
  +     * on previous configuration of this SerializationContext.
        * @param elemQName is the QName of the element
        * @param attributes are additional attributes
        * @param value is the object to serialize
  @@ -637,7 +640,32 @@
                             Attributes attributes,
                             Object value)
           throws IOException {
  -        serialize(elemQName, attributes, value, null, true, null);
  +        serialize(elemQName, attributes, value, null, null, null);
  +    }
  +
  +    /**
  +     * Serialize the indicated value as an element with the name
  +     * indicated by elemQName.
  +     * The attributes are additional attribute to be serialized on the element.
  +     * The value is the object being serialized.  (It may be serialized
  +     * directly or serialized as an mult-ref'd item)
  +     * The value is an Object, which may be a wrapped primitive, the
  +     * javaType is the actual unwrapped object type.
  +     * The xmlType is the QName of the type that is used to set
  +     * xsi:type.  If not specified, xsi:type is set by using the javaType to
  +     * find an appopriate xmlType from the TypeMappingRegistry.
  +     * Null values and the xsi:type flag will be sent or not depending 
  +     * on previous configuration of this SerializationContext.
  +     * @param elemQName is the QName of the element
  +     * @param attributes are additional attributes
  +     * @param value is the object to serialize
  +     */
  +    public void serialize(QName elemQName,
  +                          Attributes attributes,
  +                          Object value,
  +                          QName xmlType)
  +        throws IOException {
  +        serialize(elemQName, attributes, value, xmlType, null, null);
       }
   
       /**
  @@ -659,6 +687,9 @@
        * @param xmlType is the qname of the type or null.
        * @param sendNull determines whether to send null values.
        * @param sendType determines whether to set xsi:type attribute.
  +     *
  +     * @deprecated use serialize(QName, Attributes, Object, QName,
  +     * Boolean, Boolean) instead.
        */
       public void serialize(QName elemQName,
                             Attributes attributes,
  @@ -668,13 +699,54 @@
                             Boolean sendType)
           throws IOException
       {
  -        boolean shouldSendType = (sendType == null) ? shouldSendXSIType() :
  -            sendType.booleanValue();
  +        serialize( elemQName, attributes, value, xmlType, Boolean.valueOf(sendNull), sendType);
  +    }
  +
  +    /**
  +     * Serialize the indicated value as an element with the name
  +     * indicated by elemQName.
  +     * The attributes are additional attribute to be serialized on the element.
  +     * The value is the object being serialized.  (It may be serialized
  +     * directly or serialized as an mult-ref'd item)
  +     * The value is an Object, which may be a wrapped primitive.
  +     * The xmlType (if specified) is the QName of the type that is used to set
  +     * xsi:type.
  +     * The sendNull flag indicates whether to end an element with an xsi:nil="true" attribute for null
  +     * variables (if Boolean.TRUE), or nothing (if Boolean.FALSE).
  +     * The sendType flag indicates whether the xsi:type flag should be sent
  +     * (default is true).
  +     * @param elemQName is the QName of the element
  +     * @param attributes are additional attributes
  +     * @param value is the object to serialize
  +     * @param xmlType is the qname of the type or null.
  +     * @param sendNull determines whether to send null values.
  +     * @param sendType determines whether to set xsi:type attribute.
  +     */
  +    public void serialize(QName elemQName,
  +                          Attributes attributes,
  +                          Object value,
  +                          QName xmlType,
  +                          Boolean sendNull,
  +                          Boolean sendType)
  +        throws IOException
  +    {
  +        boolean sendXSITypeCache = sendXSIType;
  +        if (sendType != null) {
  +            sendXSIType = sendType.booleanValue();
  +        }
  +        boolean shouldSendType = shouldSendXSIType();
  +
  +        Boolean sendNullCache = this.sendNull;
  +        if (sendNull != null) {
  +            this.sendNull = sendNull;
  +        } else {
  +            sendNull = this.sendNull;
  +        }
   
           if (value == null) {
               // If the value is null, the element is
               // passed with xsi:nil="true" to indicate that no object is present.
  -            if (sendNull) {
  +            if (this.sendNull.booleanValue()) {
                   AttributesImpl attrs = new AttributesImpl();
                   if (attributes != null && 0 < attributes.getLength())
                       attrs.setAttributes(attributes);
  @@ -686,6 +758,8 @@
                   startElement(elemQName, attrs);
                   endElement();
               }
  +            sendXSIType = sendXSITypeCache;
  +            this.sendNull = sendNullCache;
               return;
           }
   
  @@ -703,6 +777,8 @@
   
                   //No need to add to mulitRefs. Attachment data stream handled by
                   // the message;
  +                sendXSIType = sendXSITypeCache;
  +                this.sendNull = sendNullCache;
                   return;
               }
           }
  @@ -750,6 +826,8 @@
                       attrs.addAttribute("", Constants.ATTR_ID, "id", "CDATA",
                                          id);
                       serializeActual(elemQName, attrs, value, xmlType, sendType);
  +                    sendXSIType = sendXSITypeCache;
  +                    this.sendNull = sendNullCache;
                       return;
                   }
   
  @@ -786,6 +864,8 @@
   
               startElement(elemQName, attrs);
               endElement();
  +            sendXSIType = sendXSITypeCache;
  +            this.sendNull = sendNullCache;
               return;
           }
   
  @@ -799,6 +879,7 @@
   
           // Actually serialize the value.  (i.e. not an href like above)
           serializeActual(elemQName, attributes, value, xmlType, sendType);
  +        sendXSIType = sendXSITypeCache;
       }
   
       /**
  @@ -871,7 +952,7 @@
                   // ascertain the type in these circumstances (though Axis does).
                   serialize(multirefQName, attrs, mri.value,
                             mri.xmlType,
  -                          true,
  +                          this.sendNull,
                             Boolean.TRUE);   // mri.sendType
               }
   
  @@ -1280,7 +1361,7 @@
                   TypeDesc typedesc = TypeDesc.getTypeDescForClass(value.getClass());
                   if (typedesc != null) {
                       QName qname = typedesc.getXmlType();
  -                    if (qname != null) {
  +                    if (shouldSendType && qname != null) {
                           writeXMLType = qname;
                       }
                   }