2016-05-10 1 views
0

生成されたクラスのメンバ変数名は、スキーマ上で同じ文字の大文字と小文字の区別に従うように指定する方法はありますかレベル(つまり、グローバルバインディングではない)?xjcが要素の名前と要素の名前が全く同じクラスを生成するようにする

私はxyzPropertyXYZProperty自体ではなくという名前のメンバ変数に対応している必要があり、スキーマでXYZPropertyという名前の要素を備えています。私はバインディングファイルに次のように追加してみましたが、それはうまくいきませんでした:

<jxb:bindings node="//xsd:complexType[@name='SomeType']/xsd:sequence/xsd:element[@name='XYZProperty']"> 
    <jxb:property name="XYZProperty"/> 
</jxb:bindings> 
// XSD

:complexTypeの[@名= 'SomeType']/XSD:シーケンス/のxsd:要素[@name = 'XYZProperty']は、スキーマ内の要素へのxpathです。

答えて

1

xjcのOpenJDK実装では、com.sun.xml.internal.bind.api.impl.NameConverter#toVariableNameを使用して、プロパティ名をメンバ変数名に変換します。変数名を「そのまま」残すことができる実装は存在しないようです。該当する場合は、own xjc pluginと書くことができます。これにより、プライベートプロパティ名が公開名に設定されます。プラグインは次のようなものです:

import org.xml.sax.ErrorHandler; 
import org.xml.sax.SAXException; 

import com.sun.tools.xjc.Options; 
import com.sun.tools.xjc.Plugin; 
import com.sun.tools.xjc.model.CClassInfo; 
import com.sun.tools.xjc.model.CPropertyInfo; 
import com.sun.tools.xjc.model.Model; 
import com.sun.tools.xjc.outline.Outline; 

public class XJCPlugin extends Plugin { 
    @Override 
    public String getOptionName() { 
     return "XsameElementNames"; 
    } 

    @Override 
    public int parseArgument(Options opt, String[] args, int i) { 
     return 1; 
    } 

    @Override 
    public String getUsage() { 
     return " -XsameElementNames : set property private name as its public name"; 
    } 

    @Override 
    public void postProcessModel(Model model, ErrorHandler errorHandler) { 
     for (CClassInfo c : model.beans().values()) { 
      for (CPropertyInfo prop : c.getProperties()) { 
       prop.setName(false, prop.getName(true)); 
      } 
     } 
    } 

    @Override 
    public boolean run(Outline arg0, Options arg1, ErrorHandler arg2) throws SAXException { 
     return true; 
    } 
} 
+0

ありがとうございました。しかし、私は自分の実装を既存のプロジェクトで使うことはできないと思います。今では、jaxbバインディング要素**のプロパティ**が実際に何をしているのかを理解しただけで、名前付け規則に従って名前を使用しています。 –

関連する問題