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:complexType>
<xs:sequence>
<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:sequence>
</xs:complexType>
</xs:element>

<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"/>
</xs:restriction>
</xs:simpleType>

</xs:schema>

//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);
person.set("quadrant","NORTH");
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 ( http://stackoverflow.com/questions/5181374/eclipselink-dynam 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,

Rick
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: Tue Apr 23 13:27:45 GMT 2024

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

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

Back to the top