Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Introspection/Reflection (via Javabeans?) to work with JAXB-Generated Classes?  RSS feed

 
Andrew Adamson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before I go into exactly what I'd like to do, I'll give you a quick rundown of the environment I'm working in. Also, I apologize if this is the wrong forum, but there's a lot of Java technologies around these days, and I'm not at all sure which would be the best classification for this question.

This question relates primarily to web services - I have an endpoint set up as a servlet in Glassfish V2 UR2. The WSDL stores the payload definitions in two different XSDs - one I created, and one I was provided. I have no control over either (not at this stage, anyway - too late in the process). I also call a web service belonging to another party, for which the WSDL and XSD files were provided. Again, I have no control over the provided XSD/WSDL files. EDIT: Doh, forgot Java Version stuff - Java 1.5 on Ubuntu 7.10. I use Eclipse for most of my development work.

One of the things that I need to do is, obviously, populate the data into the requests that I'm sending out from our application. There's a few ways I could do that - I could hard-code everything, one line of Java code per property being set (if not more). Makes things tricky if I need to change which property I'm getting/setting. What I would like to be able to do is just pass in a String, JavaBeans style, to get one property, and then do roughly the same thing to set the property in the outgoing message. That would be fairly simple, except that due to the construction of the XSD, the majority of the methods take JAXBElement<actualType> instead of a direct reference to the actual type.

What I would like to know is this: Is there a way (an existing Java API, or an open-source library for example) to work around that, so I don't have to deal with the JAXBElement class directly? It must be possible, as I can marshall/unmarshall the data without touching it, but I wouldn't be terribly surprised to learn that's all part of the JAXB implementation, and isn't able to do what I want.

Assuming I can use it to set properties, reading them should be a breeze (Need to do with one of the incoming requests...).

One of the problems with setting (and reading) them, though, is that there's a bunch of methods like



Which, given that Application is optional, could cause problems if it's not set. More importantly, when setting properties for the outbound request, is there a way to automatically generate an empty Application class if one isn't found?

The Javadoc for @XmlElementRef talks about Javabeans, but I've only used such functionality as is present in BeanUtils, so I'm not really sure how to make use of it.

Any advice that anyone could give on this would be greatly appreciated.
 
Andrew Adamson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No one got any ideas? I've had a look around on Google, but I can't find anything that provides a simple API for what I want to do. I could write some code myself, but I'm not terribly keen on that if there's already something that does the job for me.

Near as I can tell, the best bet would be to use the core JavaBeans API to get a list of properties, then handle conversion internally or something, and use the ObjectFactory class if I try to get a property for the first time and find it's null or something. The JAXB API seems pretty much entirely focused around converting to/from XML which isn't a huge amount of help here.

Anyway, if no one has any ideas I'll keep looking around...

Thanks all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!