highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
109 stars 54 forks source link

Simplified Java property name customization #27

Open mkotelba opened 9 years ago

mkotelba commented 9 years ago

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?

highsource commented 9 years ago

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

mkotelba commented 9 years ago

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.

highsource commented 9 years ago

@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.

So I think this must be doable.

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

highsource commented 8 years ago

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

Cavva79 commented 8 years ago

@highsource there are news about property name customization?

highsource commented 8 years ago

No, not yet. PRs welcome - as always.