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 bu...@apache.org on 2002/07/10 16:47:46 UTC
DO NOT REPLY [Bug 10645] New: -
Problem with simple types restricted to xsd:date and xsd:dateTime
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10645>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10645
Problem with simple types restricted to xsd:date and xsd:dateTime
Summary: Problem with simple types restricted to xsd:date and
xsd:dateTime
Product: Axis
Version: future (enh)
Platform: Other
OS/Version: Other
Status: NEW
Severity: Normal
Priority: Other
Component: WSDL processing
AssignedTo: axis-dev@xml.apache.org
ReportedBy: msapozhnikov@axsone.com
For simple types with restriction to xsd:date or xsd:dateTime compiler produces
depricated warnings and compile errors.
Example 1.
For the type defined as:
<simpleType name="DateType">
<restriction base="xsd:date">
</restriction>
</simpleType>
code generated:
public class DateType implements java.io.Serializable,
org.apache.axis.encoding.SimpleType {
private java.util.Date value;
public DateType() {
}
public java.util.Date getValue() {
return value;
}
public void setValue(java.util.Date value) {
this.value = value;
}
public DateType(java.util.Date value) {
this.value = value;
}
// Simple Types must have a String constructor
public DateType(java.lang.String value) {
this.value = new java.util.Date(value);
}
... etc
}
String constructor Date(String) method is deprecated and compiler produces
deprecated warnings.
Suggestion: To change
this.value = new java.util.Date(value);
to something like this
try{
this.value =
(java.text.DateFormat.getDateTimeInstance()).parse(value);
}
catch (java.text.ParseException e){
this.value = new java.util.Date(); // current date or rethrow???
}
Example 2.
<simpleType name="DateTime">
<restriction base="xsd:dateTime">
</restriction>
</simpleType>
Here situation gets even worse, because it is mapped to java.util.Calendar
class and String constructor has code
this.value = new java.util.Calendar(value);
which does not compile, because Calendar class does not have public
constructor.
Suggestion: To generate for Calendar fields something like
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){
this.value = cal; // current or null??? or rethrow??
}
I think rethrowing exception is a better choice, because of bad data.
Suggested code changes:
The next method in JavaBeanWriter.java with proposed changes:
/**
* Writes the constructors for SimpleTypes.
* Writes a constructor accepting a string and
* a constructor accepting the simple java type.
*/
protected void writeSimpleConstructors() {
// If this is a simple type,need to emit a string
// constructor and a value construtor.
if (type.isSimpleType() && simpleValueType != null) {
if (!simpleValueType.equals("java.lang.String")) {
pw.println(" public " + className + "(" +
simpleValueType + " value) {");
pw.println(" this.value = value;");
pw.println(" }");
pw.println();
}
pw.println(" // " + JavaUtils.getMessage("needStringCtor"));
pw.println(" public " + className + "(java.lang.String value) {");
// Make sure we wrap base types with its Object type
String wrapper = JavaUtils.getWrapper(simpleValueType);
if (wrapper != null) {
pw.println(" this.value = new " + wrapper +
"(value)." + simpleValueType + "Value();");
} else {
//mys changes start
if (simpleValueType.equals("java.util.Date")) {
pw.println(" try{");
pw.println(" this.value =
(java.text.DateFormat.getDateTimeInstance()).parse(value);");
pw.println(" }");
pw.println(" catch (java.text.ParseException e){");
pw.println(" this.value = new java.util.Date(); //
current date or rethrow???");
pw.println(" }");
}
else if (simpleValueType.equals("java.util.Calendar")) {
pw.println(" java.util.Calendar cal =
java.util.Calendar.getInstance();");
pw.println(" try{");
pw.println(" java.util.Date dt =
(java.text.DateFormat.getDateTimeInstance()).parse(value);");
pw.println(" cal.setTime(dt);");
pw.println(" this.value = cal;");
pw.println(" }");
pw.println(" catch (java.text.ParseException e){");
pw.println(" this.value = cal; // current or
null??? or rethrow??");
pw.println(" }");
}
else
//mys changes end
pw.println(" this.value = new " +
simpleValueType + "(value);");
}
pw.println(" }");
pw.println();
}
}
I am not sure if this is the only place where these changes have to be made,
because I worked only with WSDL2Java tool.