• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unmarshalling and binding XML to a Java object  RSS feed

 
bel Canto
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any patterns or successful techniques employed when your MDB retrieves an XML message from a queue and you need to bind it to an object for further manipulation by various session beans... ?

Any good resources will be highly appreciated.

Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on what you have defined already.

There is the XMLEncoder and XMLDecoder classes already in Java 1.4, for simple cases. There is JAXB, which you can generate Java files or XML Schema when you have one or the other. In the case where both are already defined, you can use XPath, DOM, JDOM, Axis, to hard code it, or you can try Castor XML to map you object to the XML Schema.

Mark
 
bel Canto
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Mark for your prompt suggestions.

The XML schema for the message is defined. Currently, I am using JDOM to parse the message (onMessage is using instanceof TextMessage) and am binding it to an Object definition that basically has getters defined.

The setup seems to work but is not very "efficient" - in that I have to write custom validation to validate the message. And the object definiton is not very dynamic and has to be updated manually to generate more getters if the message schema changes.

I'm looking for something like:
Parser.parse(message) which first invokes something like validator(message, schema) and after it validates the message document against the supplied schema it binds the xml to a loosely defined object that stuffs all the various attributes and its values into an array or some similar data structure. Other code can then work with the object and get data by traversing through the array. This will also allow me to do something like onMessage(msg instanceof ObjectMessage) instead of what I am doing right now.

Thanks again and hope to hear back...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!