Hi,
I want to unmarshall XML data for a class SimpleMessage that has two
constructors with one and two parameters, respectively.
The type of the second parameter is an enum-like class Severity (without
a valueOf() method).
Now, there seems to be a problem, when unmarshalling data where the
second parameter is missing (or null):
<SimpleMessage text="cannot delete temporary file"/>
<SimpleMessage severity="Warning" text="marked object as obsolete"/>
<SimpleMessage severity="Error" text="must shut down system">
The following mapping was used:
<mapping>
<class name="SimpleMessage" verify-constructable="false">
<map-to xml="SimpleMessage" />
<field name="severity" type="Severity" get-method="severity"
set-method="%2" handler="SeverityHandler">
<bind-xml name="severity" node="attribute"/>
</field>
<field name="formattedText" type="java.lang.String"
get-method="formattedText" set-method="%1" >
<bind-xml name="text" node="attribute"/>
</field>
</class>
</mapping>
where a SeverityHandler was implemented. The class code is attached, a
test case can be provided.
Do you think there is a problem or am I just missing something?
Best regards,
Uwe
public final class SimpleMessage {
private Severity severity;
private String text;
public SimpleMessage(String text) {
this(text, Severity.WARNING);
}
public SimpleMessage(String text, Severity severity) {
this.text = text;
this.severity = severity;
}
public Severity severity() {
return severity;
}
public String formattedText() {
return text;
}
}
public final class Severity {
public static final Severity ERROR = new Severity("Error");
public static final Severity WARNING = new Severity("Warning");
public static final Severity OK = new Severity("OK");
private final transient String name;
private Severity(String name) {
this.name = name;
}
public String toString() {
return name;
}
}
This e-mail and any attachment thereto may contain confidential information
and/or information protected by intellectual property rights for the exclusive
attention of the intended addressees named above. Any access of third parties
to this e-mail is unauthorised. Any use of this e-mail by unintended recipients
such as total or partial copying, distribution, disclosure etc. is prohibited
and may be unlawful. When addressed to our clients the content of this e-mail
is subject to the General Terms and Conditions of GL's Group of Companies
applicable at the date of this e-mail.
If you have received this e-mail in error, please notify the sender either by
telephone or by e-mail and delete the material from any computer.
GL's Group of Companies does not warrant and/or guarantee that this message at
the moment of receipt is authentic, correct and its communication free of
errors, interruption etc.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email