users@jaxb.java.net

XJC. How to preserve case?

From: Pechinsky Anton <anth_at_tut.by>
Date: Wed, 25 May 2011 10:58:47 +0300

Hi all,

I can't instruct XJC to preserve character case.
I'm integrating with .NET web service and case is important for my project.

For example if element is declared as Account in schema then I'd like
to see exactly the same property in target class:
xsd:
<element name="Account" type="xs:string"/>
java:
String Account;

I need to preserve case globally (for every identifier) so I can't
manually specify each property in customization file.


The problem is that reference implementation uses concrete name
converter class after applying user provided name converter:
com.sun.tools.xjc.model.CPropertyInfo#CPropertyInfo(String name,
boolean collection, XSComponent source,
                            CCustomizations customizations, Locator locator) {
...
// next line causes the problem
String n = NameConverter.standard.toVariableName(name);
...

I've tried:
- Custom plugin with custom name converter. Unfortunately name
converter doesn't help because I can change everything except first
char. This is because of above problem (concrete class usage)

- Custom plugin which modifies generated mode. No idea how to obtain
original field name

    public boolean run(Outline model, Options opt, ErrorHandler
errorHandler) throws SAXException {

        for (ClassOutline classOutline : model.getClasses()) {
            Map<String, JFieldVar> generatedFields =
classOutline.implClass.fields();
            for (JFieldVar field : generatedFields.values()) {
                // at this moment field's public name has first char
in upper case while private name in lower case despite how it was
declared in schema :(
                // so I need to get original field name
                Sting originalFieldName = ???????
                field.name(originalFieldName);
            }

Help me please.

Thanks