File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes XMLBeans versus JAXB schema compilation differences Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "XMLBeans versus JAXB schema compilation differences" Watch "XMLBeans versus JAXB schema compilation differences" New topic

XMLBeans versus JAXB schema compilation differences

John Zimmermann

Joined: Jun 27, 2012
Posts: 1

I have an XML fragment that I am trying to compile using JAXB. The compilation executes successfully but there are some differences between the java files generated by JAXB when compared to XMLBeans. Here is the XML fragment:

<simpleType name="MyDataType">
<restriction base="xsd:string">
<enumeration value="Text"/><!-- enum const = 0 -->
<enumeration value="Integer"/><!-- enum const = 1 -->
<enumeration value="Float"/><!-- enum const = 2 -->
<enumeration value="Boolean"/><!-- enum const = 3 -->
<enumeration value="TimeStamp"/><!-- enum const = 4 -->
<enumeration value="Code"/><!-- enum const = 5 -->
<enumeration value="MultiLanguageText"/><!-- enum const = 6 -->

JAXB will generate the following class:

@XmlType(name = "MyDataType", namespace = "")
public enum MyDataType{

private final String value;

MyDataType(String v) {
value = v;

public String value() {
return value;

public static MyDataType fromValue(String v) {
for (MyDataType c: MyDataType.values()) {
if (c.value.equals(v)) {
return c;
throw new IllegalArgumentException(v);

XMLBeans would apply an ordinal to the elements like so:

public interface FlexFieldDataType extends org.apache.xmlbeans.XmlString
public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)
org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(FlexFieldDataType.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s463C563221D006C73594BDAF6D050EA7").resolveHandle("flexfielddatatypeb902type");

org.apache.xmlbeans.StringEnumAbstractBase enumValue();
void set(org.apache.xmlbeans.StringEnumAbstractBase e);

static final Enum TEXT = Enum.forString("Text");
static final Enum INTEGER = Enum.forString("Integer");
static final Enum FLOAT = Enum.forString("Float");
static final Enum BOOLEAN = Enum.forString("Boolean");
static final Enum TIME_STAMP = Enum.forString("TimeStamp");
static final Enum CODE = Enum.forString("Code");
static final Enum MULTI_LANGUAGE_TEXT = Enum.forString("MultiLanguageText");

static final int INT_TEXT = Enum.INT_TEXT;
static final int INT_INTEGER = Enum.INT_INTEGER;
static final int INT_FLOAT = Enum.INT_FLOAT;
static final int INT_BOOLEAN = Enum.INT_BOOLEAN;
static final int INT_TIME_STAMP = Enum.INT_TIME_STAMP;
static final int INT_CODE = Enum.INT_CODE;

* Enumeration value class for com.sumtotalsystems.sumtotal7.sumtotalbo.FlexFieldDataType.
* These enum values can be used as follows:
* <pre>
* enum.toString(); // returns the string value of the enum
* enum.intValue(); // returns an int value, useful for switches
* // e.g., case Enum.INT_TEXT
* Enum.forString(s); // returns the enum value for a string
* Enum.forInt(i); // returns the enum value for an int
* </pre>
* Enumeration objects are immutable singleton objects that
* can be compared using == object equality. They have no
* public constructor. See the constants defined within this
* class for all the valid values.
static final class Enum extends org.apache.xmlbeans.StringEnumAbstractBase
* Returns the enum value for a string, or null if none.
public static Enum forString(java.lang.String s)
{ return (Enum)table.forString(s); }
* Returns the enum value corresponding to an int, or null if none.
public static Enum forInt(int i)
{ return (Enum)table.forInt(i); }

private Enum(java.lang.String s, int i)
{ super(s, i); }

static final int INT_TEXT = 1;
static final int INT_INTEGER = 2;
static final int INT_FLOAT = 3;
static final int INT_BOOLEAN = 4;
static final int INT_TIME_STAMP = 5;
static final int INT_CODE = 6;
static final int INT_MULTI_LANGUAGE_TEXT = 7;

Is there anyway I can achieve this behavior using JAXB? The ordinals are references throughout the client code and it would be nice to preserve this behavior ...
I agree. Here's the link:
subject: XMLBeans versus JAXB schema compilation differences
It's not a secret anymore!