users@jaxb.java.net

Re: Some codemodel questions

From: Hanson Char <hanson.char_at_gmail.com>
Date: Mon, 14 May 2007 10:02:49 -0700

>how to add a constructor invocation for a class that I don't have a JClass
for.

You can easily get the respective JClass of any plain old class via the
JCodeModel.

    JCodeModel codeModel = ... // such as implClass.owner() where
implClass is a JDefinedClass instance
    JClass myJClass = codeModel.ref(MyClass.class)

Hope this helps.

Hanson Char

On 5/14/07, Colin Fleming <colin.mailinglist_at_gmail.com> wrote:
>
> Hi all,
>
> 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.
>
> Also, I don't fully understand when an element factory method will be
> added to the ObjectFactory. The following schema seems to create one:
>
> <xs:element name="isomsg" type="IsoMessage"/>
>
> but the following doesn't:
>
> <xs:element name="Users">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="cardUser" type="User" minOccurs="0"
> maxOccurs="unbounded"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> 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. 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?
>
> Thanks for any help,
> Colin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>