code_junkie

JAXB - XJC - influencing generated typesafe enum class and members

Nov 11th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <xs:simpleType name="test">
  2. <xs:annotation>
  3. <xs:appinfo>
  4. <jaxb:typesafeEnumClass/>
  5. </xs:appinfo>
  6. </xs:annotation>
  7. <xs:restriction base="xs:string">
  8. <xs:enumeration value="4">
  9. <xs:annotation>
  10. <xs:appinfo>
  11. <jaxb:typesafeEnumMember name="FOUR"/>
  12. </xs:appinfo>
  13. </xs:annotation>
  14. </xs:enumeration>
  15. <xs:enumeration value="6">
  16. <xs:annotation>
  17. <xs:appinfo>
  18. <jaxb:typesafeEnumMember name="SIX"/>
  19. </xs:appinfo>
  20. </xs:annotation>
  21. </xs:enumeration>
  22. </xs:restriction>
  23. </xs:simpleType>
  24.  
  25. @XmlEnum
  26. public enum Test {
  27.  
  28. @XmlEnumValue("4")
  29. FOUR("4"),
  30. @XmlEnumValue("6")
  31. SIX("6");
  32. private final String value;
  33.  
  34. Test(String v) {
  35. value = v;
  36. }
  37.  
  38. public String value() {
  39. return value;
  40. }
  41.  
  42. public static Test fromValue(String v) {
  43. for (Test c: Test.values()) {
  44. if (c.value.equals(v)) {
  45. return c;
  46. }
  47. }
  48. throw new IllegalArgumentException(v.toString());
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment