This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

XMLBeans versus JAXB schema compilation differences

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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 -->
</restriction>
</simpleType>

JAXB will generate the following class:

@XmlType(name = "MyDataType", namespace = "http://www.example.com/aSampleNamespace")
@XmlEnum
public enum MyDataType{

@XmlEnumValue("Text")
TEXT("Text"),
@XmlEnumValue("Integer")
INTEGER("Integer"),
@XmlEnumValue("Float")
FLOAT("Float"),
@XmlEnumValue("Boolean")
BOOLEAN("Boolean"),
@XmlEnumValue("TimeStamp")
TIME_STAMP("TimeStamp"),
@XmlEnumValue("Code")
CODE("Code"),
@XmlEnumValue("MultiLanguageText")
MULTI_LANGUAGE_TEXT("MultiLanguageText");
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;
static final int INT_MULTI_LANGUAGE_TEXT = Enum.INT_MULTI_LANGUAGE_TEXT;

/**
* 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 ...
 
It's just a flesh wound! Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic