axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yu, Joel, Contractor" <Joel.Yu....@asamra.hoffman.army.mil>
Subject RE: xsd:dateTime parse
Date Thu, 13 May 2004 16:21:40 GMT
<xsd:complexType name="DateTimeType">
  <xsd:simpleContent>
    <xsd:extension base="xsd:dateTime"/>
  </xsd:simpleContent>
</xsd:complexType>


this is the class wsdl2java generated:

/**
 * DateTimeType.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis WSDL2Java emitter.
 */

package com.monster.schemas.Monster;

public class DateTimeType  implements java.io.Serializable,
org.apache.axis.encoding.SimpleType {
    private java.util.Calendar value;

    public DateTimeType() {
    }

    public DateTimeType(java.util.Calendar value) {
        this.value = value;
    }

    // Simple Types must have a String constructor
    public DateTimeType(java.lang.String value) {
        java.util.Calendar cal = java.util.Calendar.getInstance();
        try {
          java.util.Date dt =
(java.text.DateFormat.getDateTimeInstance()).parse(value);
          cal.setTime(dt);
          this.value = cal;
        }
        catch (java.text.ParseException e){
            throw new java.lang.RuntimeException(e.toString());
        }
    }

    // Simple Types must have a toString for serializing the value
    public java.lang.String toString() {
        return value == null ? null : value.toString();
    }

    public java.util.Calendar getValue() {
        return value;
    }

    public void setValue(java.util.Calendar value) {
        this.value = value;
    }

    private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof DateTimeType)) return false;
        DateTimeType other = (DateTimeType) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true &&
            ((this.value==null && other.getValue()==null) ||
             (this.value!=null &&
              this.value.equals(other.getValue())));
        __equalsCalc = null;
        return _equals;
    }

    private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getValue() != null) {
            _hashCode += getValue().hashCode();
        }
        __hashCodeCalc = false;
        return _hashCode;
    }

    // Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(DateTimeType.class);

    static {
        typeDesc.setXmlType(new
javax.xml.namespace.QName("http://schemas.monster.com/Monster",
"DateTimeType"));
        org.apache.axis.description.ElementDesc elemField = new
org.apache.axis.description.ElementDesc();
        elemField.setFieldName("value");
        elemField.setXmlName(new javax.xml.namespace.QName("", "value"));
        elemField.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "dateTime"));
        typeDesc.addFieldDesc(elemField);
    }

    /**
     * Return type metadata object
     */
    public static org.apache.axis.description.TypeDesc getTypeDesc() {
        return typeDesc;
    }

    /**
     * Get Custom Serializer
     */
    public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType,
           java.lang.Class _javaType,
           javax.xml.namespace.QName _xmlType) {
        return
          new  org.apache.axis.encoding.ser.SimpleSerializer(
            _javaType, _xmlType, typeDesc);
    }

    /**
     * Get Custom Deserializer
     */
    public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType,
           java.lang.Class _javaType,
           javax.xml.namespace.QName _xmlType) {
        return
          new  org.apache.axis.encoding.ser.SimpleDeserializer(
            _javaType, _xmlType, typeDesc);
    }

}

-----Original Message-----
From: Steve Loughran [mailto:steve_l@iseran.com]
Sent: Thursday, May 13, 2004 12:06 PM
To: axis-dev@ws.apache.org
Subject: Re: xsd:dateTime parse


I think Joel's point was that this was the WSDL generated code for 
wsdl2java, which is bad news. The CalendarDeserializer should be 
converting xsd:dateTime into Calendar types for you.

Looking at wsdl.tojava.JavaBeanWriter#writeSimpleTypeGetter, it does 
look just like the code that wsdl2java will generate if it thinks it is 
creating a Date from something coming in over the wire.

Two thoughts occur to me

1. -why is it generating a Date mapping, and not calendar, which is the 
correct representation for dateTime as it includes timezone

2. -if we really are supporting dateTime to date mappings, the generated 
code is looks broken.

But point #1 is key. Joel, can you post the relevant bits of your WSDL 
so that we can see what is causing the confusion?


David D. Lucas wrote:
> You are probably using the default DateFormat format.
> Try using something like this:
> 
>   SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'hh:mm:ssZ"); 
> //check the format in the JavaDoc for this
>   Date date = sdf.parse(value);
> 
> Keep in mind sdf can be expensive and you might want to cache these.
> 
> Best wishes,
> Dave
> 
> 
> 
> Yu, Joel, Contractor wrote:
> 
>> The exception message is:
>>
>> java.text.ParseException: Unparseable date: "2004-05-12T00:00:00-05:00"
>>
>> -----Original Message-----
>> From: Steve Loughran [mailto:steve_l@iseran.com]
>> Sent: Thursday, May 13, 2004 6:44 AM
>> To: axis-dev@ws.apache.org
>> Subject: Re: xsd:dateTime parse
>>
>>
>> Yu, Joel, Contractor wrote:
>>
>>> The following is code generated by wsdl2java for xsd:dateTime type.  
>>> It is
>>> unalbe to parse date of xsd:dateTime format.  I am getting a
>>> java.text.ParseException.  I am using axis 1.1 and jdk 1.4.  How can I
>>> change the following code so it will parse xsd:dateTime format.
>>>
>>> thanks
>>>
>>>
>>>    public DateTimeType(java.lang.String value) {
>>>        java.util.Calendar cal = java.util.Calendar.getInstance();
>>>        try {
>>>          java.util.Date dt =
>>> (java.text.DateFormat.getDateTimeInstance()).parse(value);  <-- throws
>>> exception
>>>          cal.setTime(dt);
>>>          this.value = cal;
>>>        }
>>>        catch (java.text.ParseException e){
>>>            throw new java.lang.RuntimeException(e.toString());
>>>        }
>>>    }
>>
>>
>>
>> What do the values coming in look like? It may really be a legit 
>> failure handled ungracefully.
>>
>> -steve
>>
> 

Mime
View raw message