• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Unmarshalling and binding XML to a Java object

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
What are you doing in my house? Get 'em tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic