users@jaxb.java.net

Re: XJC get the annotaion of an created field or as alternative the property order

From: Florian Bachmann <f.bachmann_at_micromata.de>
Date: Mon, 23 Nov 2009 16:44:36 +0100

Hey /lexi,
thank you, this should help me (:
regards Flori

On 23.11.2009, at 16:40, Aleksei Valikov wrote:

> Hi,
>
>> Hello XJC-Users,
>> is there a way to get to annotations of an generated class?
>> Assume ich have a ClassOutline classOutline.
>> Is there a method, like: classOutline.target.getAnnotations();
>>
>> The reason, I like to get these information is, that I like to access to XmlType propOrder-Annotation.
>>
>> For Example, JAXB generates
>> @XmlAccessorType(XmlAccessType.FIELD)
>> @XmlType(name = "MyClassType", propOrder = {
>> "firstField",
>> "secondField",
>> "thirdField",
>> "anOtherField"
>> })
>> public class MyClass {}
>>
>> Is it possible to access the annotation of the created prop-order annotation, to get the order of the created fields? To know, that the secondField is really the second field and anOtherField is the fourth field? Or is it possible to find out the property/field order?
>
> You can't get this information from the code model without hacks. And
> it's not the right way anyway.
>
> The right way would be to get this information from the CClassInfo.
> See how the propOrder field is generated:
>
> CClassInfo target = ...;
> ...
> if(target.isOrdered()) {
> for(CPropertyInfo p : target.getProperties() ) {
> if( ! (p instanceof CAttributePropertyInfo )) {
> if (!( (p instanceof CReferencePropertyInfo) &&
> ((CReferencePropertyInfo)p).isDummy())) {
> xtw.propOrder(p.getName(false));
> }
> }
> }
> } else {
> // produce empty array
> xtw.getAnnotationUse().paramArray("propOrder");
> }
>
> Bye.
> /lexi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>

--
Florian Bachmann, Softwareentwicklung
Micromata GmbH
Hauptsitz: Marie-Calm Str. 1-5, D-34131 Kassel
Niederlassung Bonn: Menuhinstr. 8, 53113 Bonn
Tel: +49 561 / 31 67 93 - 0
Fax: +49 561 / 31 67 93 - 11
mailto: f.bachmann_at_micromata.com
http://www.micromata.com
AG Kassel HRB 7370
Geschäftsführung:
Dipl.-Ing. Thomas Landgraf
Dipl.-Phys. Kai Reinhard