users@jaxb.java.net

Re: Some codemodel questions

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 15 May 2007 10:37:10 +0200

Hi.

We need a plugin basically as described by malachid in the comments on
> Kohsuke's blog here:
> http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html.
> It seems as though it never got published, so I'm trying to write one
> myself. It's mostly been pretty straightforward, but the sticking
> point (as usual, it seems) is working out the codemodel. The API is
> generally pretty good, but sometimes seemingly simple things are
> difficult to work out.
>
> Anyway, I have two questions: I have a JBlock, and I'd like to add a
> 'return new JAXBElement(<params>), but I can't figure out how to add a
> constructor invocation for a class that I don't have a JClass for.


You can get a JClass with from code model with:

codeModel.ref(JAXBElement.class)

Can I test if a createXXX function is generated on the ObjectFactory
> using the codemodel? I couldn't find anything in either ClassOutline,
> CClassInfo or JDefinedClass that would tell me.


May JDefinedClass.getMethod(...) or JDefinedClass.methods() be what you want


I thought
> CClassInfo.isElement and getElementName might do the trick, but it
> seems not. Also, is there any way to get a reference to the create
> function generated on the ObjectFactory (or, even better, a reference
> to the ObjectFactory class) so I can invoke it?



There is an object factory generator per package context. It is populated
with CElementInfos from model.getAllElements() and CClassInfos (see
BeanGenerator code). There's also getObjectFactory() method in object
factory generator. There's objectFactoryGenerator() in PackageOutline.

I hope this helps.

Bye.
/lexi