Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Dynamic Moxy accessing enum values
Dynamic Moxy accessing enum values [message #657607] Thu, 03 March 2011 13:21 Go to next message
Micha  is currently offline Micha Friend
Messages: 2
Registered: March 2011
Junior Member
Hi there,
I'm using the xsd listed below and a corresponding xml. Everything works well with dynamic moxy
but I havent any idea how to access the enum type within java.
Any suggestions?
Thanks for help.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema ...>
<xs:element name="person">
<xs:element name="first-name" type="xs:string"/>
<xs:element name="last-name" type="xs:string"/>
<xs:element name="quadrant" type="myns:compass-direction"/>

<xs:simpleType name="compass-direction">
<xs:restriction base="xs:string">
<xs:enumeration value="NORTH"/>
<xs:enumeration value="SOUTH"/>
<xs:enumeration value="EAST"/>
<xs:enumeration value="WEST"/>


//JAVA code
DynamicEntity person = (DynamicEntity)dynamicJAXBContext.createUnmarshaller().unmar shal( "person1.xml");
String firstName = person.get("firstName");
String lastName = person.get("lastName");
//until here it works well

//but now: how to get and set the value of the "quadrant"?
// following lines do not work
String quadrant=person.get("quadrant);
Re: Dynamic Moxy accessing enum values [message #657939 is a reply to message #657607] Fri, 04 March 2011 16:57 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

I am posting the following on behalf of Rick Barkhouse, who originally answered this question on Stack Overflow ( ic-moxy-accessing-enum-values/5183847#5183847):


Hi Micha,

To use an enum value for a set() operation, you need to first look up the enum constant using DynamicJAXBContext.getEnumConstant(), and then use that for the set. For example:

Object NORTH = ctx.getEnumConstant("your.package.CompassDirection", "NORTH");
person.set("quadrant", NORTH);

To get the value, you are calling the correct code, but the value that comes back will not be a String, it will the actual enum value Object associated with that String. You should use:

Object quadrant = person.get("quadrant");

Hope this helps,

Previous Topic:Foreign Key Constraint Issue Involving One-To-Many and Many-To-One Relationship in EcliplseLink2.1.
Next Topic:java.lang.SecurityException: signer information does not match signer information of other classes i
Goto Forum:

Current Time: Thu Jun 21 01:13:39 GMT 2018

Powered by FUDForum. Page generated in 0.01826 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top