jaxb2-basics icon indicating copy to clipboard operation
jaxb2-basics copied to clipboard

Simplified Java property name customization

Open mkotelba opened this issue 9 years ago • 6 comments

Unless I'm mistaken, there is currently no mechanism to customize the name of the Java properties outputted by the Simply plugin, aside from the pluralization option; I half-remember seeing a statement somewhere in the docs (perhaps the old ones on highsource.org?) to this effect.

If this is indeed the case, should I be aware of anything in particular if I were to fork and (attempt to) implement the functionality?

mkotelba avatar Apr 21 '15 20:04 mkotelba

You're right, property name creation is hardcoded at the moment:

https://github.com/highsource/jaxb2-basics/blob/master/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/simplify/SimplifyPlugin.java#L350-L369

highsource avatar Apr 22 '15 06:04 highsource

After taking a stab at it, I must admit that the guts of XJC are tricky as hell; I have a new-found appreciation for the Simplify plugin :)

I tried to approach the functionality by adding a new Simplify-specific customization element, generated-property, that can be used multiple times in the same context as the relevant Simplify as-*-property, each time providing an association of a property local name that naturally gets spit out by Simplify -> what you actually want it to be called.

Once you get down to the correct CPropertyInfo, its easy (2x calls to setName for the public/private variants). Dealing with the crazy complexity of all possible combinations to get there (CReferencePropertyInfo, CElementPropertyInfo, etc combos) + possible Java keyword conflicts that result in forced renames and even more abstraction = I gave up and wrote a terrible Groovy GMaven build script that just iterates through the ClassOutlines' properties.

mkotelba avatar May 14 '15 07:05 mkotelba

@mkotelba Sorry to hear about this. I actually did not thought it was so complex. I'd personally add a configuration sub-element like

<simplify:as-element-property>
<simplify:property element="foo:bar" name="bar"/>
</simplify:as-element-property>

The XML element names should be quite easy to get from items of CElementPropertyInfo or CReferencePropertyInfo. So find out the QName of the element and look up the customized property name for it in the customization.

  • For the element property info it is here (CTypeRef.getTagName() provides the QName).
  • For the element reference property info it is here (CElement.getElementName() provides the QName).

So I think this must be doable.

What were you trying to do, exactly? Would you give an example of your desired customization?

highsource avatar May 14 '15 22:05 highsource

See also http://jira.highsource.org/browse/JIIB-54.

highsource avatar Dec 29 '15 10:12 highsource

@highsource there are news about property name customization?

Cavva79 avatar Jul 21 '16 09:07 Cavva79

No, not yet. PRs welcome - as always.

highsource avatar Jul 21 '16 14:07 highsource