users@jaxb.java.net

RE: How to tell element from attribute in plugin code

From: Joel Sacks <sacks_at_btmmr.com>
Date: Wed, 22 Oct 2008 09:48:46 -0700

Aleksei-

Thanks so much for this information, it was exactly what I was looking for.
And, I probably will want to ask some follow-up questions in a week or so
when I get to the next roadblock.

-Joel

-----Original Message-----
From: aleksei.valikov_at_gmail.com [mailto:aleksei.valikov_at_gmail.com] On Behalf
Of Aleksei Valikov
Sent: Monday, October 20, 2008 12:34 PM
To: users_at_jaxb.dev.java.net
Subject: Re: How to tell element from attribute in plugin code

Hi.

> I'm trying to write a plugin that will generate some basic ActionScript
> based on a schema, and I'm hooking in at "run" time, so I have access to
the
> Outline data structure. I've been tracing through various bits of code in
> the debugger, and I can't figure out how to distinguish between a property
> that will be emitted as an attribute in the Java code, and a property that
> will be emitted as an element. Attributes get marked in the Java source
> code with @attribute, but I haven't been able to figure out how the
> formatter figures that out. Any suggestions? Thanks.

Okay, I'll sketch it out really very briefly. You have two levels,
model and outline. Model is the structure, outline is how the model is
represented in classes and properties. Generally there's a parallel
Outline -> Model, ClassOutline -> CClassInfo, FieldOutline ->
CPropertyInfo. CClassInfo and CPropertyInfo corresponds to XML Schema
types and elements/attributes.
ClassOutline and FieldOutline corresponse to the generated Java class
and properties/fields. These outlines first appear when CClassInfo and
CProperyInfo are "rendered" into their Java representation (which are
logically ClassOutline and FieldOutline).

So, to answer you question, if you have Outline, you can iterate over
ClassOutline it contains (see getClasses() method). Once you have a
ClassOutline, you can iterate over fields it contains (see
getDeclaredFields()). A field is something which is seen in the
generated Java code, typically as an annotated field with
getter/setter. If you have a FieldOutline, you can get property info
which generated it via the getPropertyInfo() method. This will get you
an instance of CPropertyInfo. Check the subclasses of CPropertyInfo
for different types of properties. There's "element", "attribute",
"value" and "reference" subclasses of CPropertyInfo. This lets you
know what you're dealing with. The "reference" type is the most tricky
of all.

Hope this helps.

Bye.
/lexi

ps. I wish I had this info when I was starting HJ3. Could have saved
me few weeks to figure it out. Ask me if you're stuck further on, I've
eaten few pounds of salt with XJC internals.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net