Juni 23rd, 2006
Enum in Webservices
JBossWS 1.0 unterstützt noch nicht das direkte Nutzen von enums in Webservices. Dies ist erst bei der Unterstützung von JAXB-2.0 möglich. Bis dahin müssen Enums im J2EE 1.4 Enum-Stil implementiert werden.
Dabei ist folgende Struktur für eine Enumeration vorgesehen:
//Java public class <enumeration_name> { // … // Constructor protected <enumeration_name>(<base_type> value) { … } // One for each label in the enumeration public static final <base_type> _<label> = <value>; public static final <enumeration_name> <label> = new <enumeration_name>(_<label>); // Gets the value for a enumerated value public <base_type> getValue() {…} // Gets enumeration with a specific value // Required to throw java.lang.IllegalArgumentException if // any invalid value is specified public static <enumeration_name> fromValue(<base_type> value) { … } // Gets enumeration from a String // Required to throw java.lang.IllegalArgumentException if // any invalid value is specified public static <enumeration_name> fromString(String value){ … } // Returns String representation of the enumerated value public String toString() { … } public boolean equals(Object obj) { … } public int hashCode() { … } }
Jede Klasse, welche diese Struktur hat und über ein WebService verwendet wird, wird entsprechend als Enumeration exportiert.