XMLでInteger.MAX_VALUEのようなJava定数を定義する方法を教えてください。enum の使い方は知っていますが、サードパーティのライブラリがあり、定数を操作する必要があります。たとえば、xml ファイルには何らかの値が存在し、生成された Java クラスでは定数として宣言する必要があります。
XML:
<person>
<firstname>Joe</firstname>
<lastname>Walnes</lastname>
<phone>
<code>123</code>
<number>1234-456</number>
</phone>
<fax>
<code>123</code>
<number>9999-999</number>
</fax>
</person>
ジャワ:
public class Person {
private String firstname;
private String lastname;
private PhoneNumber phone;
private PhoneNumber fax;
// ... constructors and methods
}
public class PhoneNumber {
private int code;
private String number;
// ... constructors and methods
}
これは機能します。しかし、次のようにする必要があります:
XML:
<person>
<firstname>Joe</firstname>
<lastname>Walnes</lastname>
<phone>
**<const>**PnoneNumber.LOCAL**</const>**
</phone>
<fax>
<code>123</code>
<number>9999-999</number>
</fax>
</person>
Java は次のようにする必要があります。
public class Person {
private String firstname;
private String lastname;
private PhoneNumber phone;
private PhoneNumber fax;
// ... constructors and methods
}
public class PhoneNumber {
public static final PnoneNumber LOCAL=new PhoneNumber(123,"1234-456");
private int code;
private String number;
// ... constructors and methods
}
カスタムコンバーターなしで簡単な方法でそれを行うことはできますか?
どうもありがとう。