users@jaxb.java.net

Re: Plugin for JAXB Outline Traversal

From: Simon Chase <schase_at_bbn.com>
Date: Thu, 31 Jul 2014 20:34:22 -0400

Yes, xsd:choice - I meant union in the C sense.

On Jul 31, 2014, at 7:45 PM, Vojtěch Krása <vojta.krasa_at_gmail.com> wrote:

> Btw by that union type, you meant xsd:choice and not xsd:union right?
>
>
>
>
> 2014-08-01 1:10 GMT+02:00 Vojtěch Krása <vojta.krasa_at_gmail.com>:
> You can see how I load getters and setters in PrimitiveFixerPlugin, sadly I do not know anything better that brute force (but I have not tried to find anything better either).
> Those union types are real problem, I've tried to find which fields are part of xsd:choice, I even searched in xjc source, with no luck. I will probably ask on jaxb mailing list how to handle that...
> But if you really want to generate it as List (I would not do it), then it seems to me that you could easily look into @XmlElementRef, and load those types from there...
>
> @XmlElementRefs({
> @XmlElementRef(name = "Tea", namespace = "a", type = JAXBElement.class),
> @XmlElementRef(name = "Coffee", namespace = "a", type = JAXBElement.class)
> })
> protected List<JAXBElement<String>> teaOrCoffee;
>
>
> V.
>
>
> 2014-08-01 0:02 GMT+02:00 Simon Chase <schase_at_bbn.com>:
>
> Hi,
>
> I am programmatically trying to be able to anticipate the correspondence between a generated Field, and its contained type or get/set methods, but without trying to reverse-engineer the xic compiler.
>
> For example, most of the time, a field’s get/set methods can be found by capitalizing the first letter of the field’s simple name, and then prepending “get” or “set.” But if the field was built from an xml element named “static” (bad practice, but allowable), then the field will be “_static” and the get and set methods will be “getStatic” and “setStatic”. I have also run into trouble with Lists, because an Xml list element can have a union type, but this becomes List<Object> in Java. The field for this list will be named <type1>Or<Type2>Or…Or<TypeN>. I could break the string apart by splitting on “Or,” but that would quickly fall apart if anyone put “Or” in a field (I don’t know if xic will break this out).
>
> Is there a way to query xjc to get this information? It looks like I can readily go from a code model object from the outline to its pre-compilation schema model, and back again, but I guess I’m trying to query xjc for what it’s going to do in between the two.
>
> Thanks,
> Simon
>
> On Jul 31, 2014, at 2:44 PM, Vojtěch Krása <vojta.krasa_at_gmail.com> wrote:
>
>> Hi,
>>
>> basically everything I know about the xjc is contained in my plugin. It seems to me that traversing as I do should be enough. What exactly are you trying to achieve?
>>
>> V.
>>
>> S pozdravem
>> Vojtěch Krása
>>
>>
>>
>> 2014-07-31 19:14 GMT+02:00 Simon Chase <schase_at_bbn.com>:
>> Hi,
>>
>> I’m trying to write a plugin that will be able to walk through the Outline tree for java code generated by xjc. Any guidance on how to traverse the outline, so that the plugin will be able to:
>>
>> - link a reference class’s field to its corresponding get/set methods
>> - link a field to its reference class
>> - link a List to its member class (or to a list of its member classes if it holds a union of types)
>>
>> would be helpful. I’ve looked through the outline and navigator classes packages, and the overarching architecture is not clear to me.
>>
>> Thanks,
>> Simon Chase
>> Software Engineer
>> Raytheon BBN Technologies
>>
>
>
>