A very usefull feature in JAXB/JAXWS in code first approach is to use
Enumeration to define some specific set in XML-SCHEMA ie :
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AchatVente", namespace = "
http://myapp/services/v1/")
public enum BuySell {
B("B"), S("S");
private String value;
BuySell (String v) {
value = v;
}
public String value() {
return value;
}
public static BuySell fromValue(String value) {
for( BuySell av : BuySell .values() ) {
if ( av.value().equals(value) )
return av;
}
return A;
}
}
==>
<xs:simpleType name="BuySell ">
<xs:restriction base="xs:string">
<xs:enumeration value="B"/>
<xs:enumeration value="S"/>
</xs:restriction>
</xs:simpleType>
Did there is a way to do the same dynamically
(xs:restriction/xs:enumeration), not using Enumeration but using
standard Java classes (these one grabbing their possible values at
runtime, ie from SQL backend).
Regards