आप अपनी संपत्ति के नाम को अनुकूलित करने के लिए बाहरी बाइंडिंग फ़ाइल का उपयोग कर सकते हैं। JAXB को संपत्ति के रूप में विधि को पहचानने के लिए इसे get
या is
के साथ बूलियन प्रकारों के लिए शुरू करने के सम्मेलन का पालन करना होगा।
schema.xsd
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="root">
<xs:attribute name="is-buy-now" type="xs:boolean"/>
</xs:complexType>
</xs:schema>
बाइंडिंग।एक्सएमएल
बाइंडिंग में दाखिल नीचे हम XML विशेषता के लिए एक संपत्ति नाम निर्दिष्ट किया है is-buy-now
कहा जाता है:
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="is.xsd">
<jxb:bindings node="//xs:complexType[@name='root']/xs:attribute[@name='is-buy-now']">
<jxb:property name="buyNow"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
XJC कॉल
-b
विकल्प के लिए एक बाइंडिंग फ़ाइल निर्दिष्ट करने के लिए प्रयोग किया जाता है:
xjc -d out -b bindings.xml schema.xsd
रूट
नतीजतन निम्नलिखित वर्ग के साथ उत्पन्न हो जाएगा: isBuyNow
और setBuyNow
तरीके:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.02.03 at 05:18:59 AM EST
//
package generated;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for root complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="root">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <attribute name="is-buy-now" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "root")
public class Root {
@XmlAttribute(name = "is-buy-now")
protected Boolean buyNow;
/**
* Gets the value of the buyNow property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isBuyNow() {
return buyNow;
}
/**
* Sets the value of the buyNow property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setBuyNow(Boolean value) {
this.buyNow = value;
}
}
अद्यतन
आप जावा वर्गों से शुरू करते हैं तो आप @XmlAccessorType(XmlAccessType.FIELD)
निर्दिष्ट कर सकते हैं फ़ील्ड को मैप करने के लिए और अपनी विधियों का नाम चुनने के लिए:
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {
@XmlAttribute(name="has-buy-now")
private boolean buyNow;
public boolean hasBuyNow() {
return buyNow;
}
}
स्रोत
2012-02-03 10:33:39
आप एक मानक (जेएसआर -222) बाहरी बाध्यकारी फ़ाइल का उपयोग कर संपत्ति नाम को कस्टमाइज़ कर सकते हैं, और बाहरी प्लग-इन की आवश्यकता नहीं है: http://stackoverflow.com/a/9127208/383861 –