Java JAXB生成的方法不使用泛型
我有一个JAXB模式,其中一个类包含另一个类的列表。模式如下所示 但是,每当我从这个模式创建java类时,该方法都不使用泛型,所以我必须像java 5之前的方法一样使用强制转换Java JAXB生成的方法不使用泛型,java,xsd,jaxb,Java,Xsd,Jaxb,我有一个JAXB模式,其中一个类包含另一个类的列表。模式如下所示 但是,每当我从这个模式创建java类时,该方法都不使用泛型,所以我必须像java 5之前的方法一样使用强制转换 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:common="glodas.research"> <xs:import n
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:common="glodas.research">
<xs:import namespace="glodas.research" schemaLocation="../common.xsd" />
<!-- Dashboard Level -->
<xs:complexType name="DashboardStatType">
<xs:complexContent>
<xs:extension base="common:IndustryRegionType">
<xs:sequence>
<xs:element name="ModuleStat" type="ModuleStatType"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ModuleViolation" type="ModuleViolation"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="BrCode" type="xs:string" />
<xs:attribute name="RegionDescription" type="xs:string" />
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="ChapterCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="UnpublishedCount" type="xs:int" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Module Level -->
<xs:complexType name="ModuleStatType">
<xs:sequence>
<xs:element name="ChapterStat" type="ChapterStatType"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="ChapterCountViolation" type="ChapterCountViolation"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="ModuleDescription" type="xs:string" />
<xs:attribute name="ModuleNumber" type="xs:int" use="required" />
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="UnpublishedCount" type="xs:int" use="required"/>
</xs:complexType>
<!-- Chapter Level -->
<xs:complexType name="ChapterStatType">
<xs:sequence>
<xs:element name="BitStat" type="BitStatType" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="ChapterId" type="xs:int" use="required"/>
<xs:attribute name="ChapterTitle" type="xs:string" use="required"/>
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
</xs:complexType>
<!-- Bit Level -->
<xs:complexType name="BitStatType">
<xs:sequence>
<xs:element name="BitStat" type="BitStatType" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="BitAge" type="BitAge" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="WiId" type="xs:int" use="required"/>
<xs:attribute name="Title" type="xs:string" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="LastPublishedDate" type="xs:date" use="required"/>
</xs:complexType>
<xs:complexType name="ValidationMessage">
<xs:attribute name="Text" type="xs:string" use="required"/>
<xs:attribute name="Severity" type="xs:int" use="optional"/>
</xs:complexType>
<xs:complexType name="BitAge">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Age" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="BitsCount">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="AgeLimitViolation">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="ChapterCountViolation">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="ModuleViolation">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:element name="GetDashboardMonitorResponse">
<xs:annotation>
<xs:documentation>Response for DashboardMonitor.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element type="DashboardStatType" name="DashboardStat" minOccurs="1"
maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我希望java方法像这样生成
java.util.List<BitAge> getBitAge();
java.util.List getBitAge();
能否提供有关XML模式的更多详细信息?我试图用以下内容重现您的问题
nov30.xsd
由于我没有common.xsd的源代码,因此我对您提供的XML架构进行了一个小改动:
<!--xs:import namespace="glodas.research" schemaLocation="../common.xsd" / -->
<!-- Dashboard Level -->
<xs:complexType name="DashboardStatType">
<!--xs:complexContent>
<xs:extension base="common:IndustryRegionType"-->
<xs:sequence>
<xs:element name="ModuleStat" type="ModuleStatType"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ModuleViolation" type="ModuleViolation"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="BrCode" type="xs:string" />
<xs:attribute name="RegionDescription" type="xs:string" />
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="ChapterCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="UnpublishedCount" type="xs:int" use="required"/>
<!-- /xs:extension>
</xs:complexContent -->
</xs:complexType>
BitStatType
结果列表属性仍按预期使用泛型:
//
// 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: 2011.11.30 at 11:38:04 AM EST
//
package generated;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
/**
* <p>Java class for BitStatType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="BitStatType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="BitStat" type="{}BitStatType" maxOccurs="unbounded" minOccurs="0"/>
* <element name="BitAge" type="{}BitAge" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* <attribute name="WiId" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="Title" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="TriggerRulesCount" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="TriggerEventsCount" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="LastPublishedDate" use="required" type="{http://www.w3.org/2001/XMLSchema}date" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BitStatType", propOrder = {
"bitStat",
"bitAge"
})
public class BitStatType {
@XmlElement(name = "BitStat")
protected List<BitStatType> bitStat;
@XmlElement(name = "BitAge")
protected List<BitAge> bitAge;
@XmlAttribute(name = "WiId", required = true)
protected int wiId;
@XmlAttribute(name = "Title", required = true)
protected String title;
@XmlAttribute(name = "TriggerRulesCount", required = true)
protected int triggerRulesCount;
@XmlAttribute(name = "TriggerEventsCount", required = true)
protected int triggerEventsCount;
@XmlAttribute(name = "LastPublishedDate", required = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar lastPublishedDate;
/**
* Gets the value of the bitStat property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the bitStat property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getBitStat().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link BitStatType }
*
*
*/
public List<BitStatType> getBitStat() {
if (bitStat == null) {
bitStat = new ArrayList<BitStatType>();
}
return this.bitStat;
}
/**
* Gets the value of the bitAge property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the bitAge property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getBitAge().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link BitAge }
*
*
*/
public List<BitAge> getBitAge() {
if (bitAge == null) {
bitAge = new ArrayList<BitAge>();
}
return this.bitAge;
}
/**
* Gets the value of the wiId property.
*
*/
public int getWiId() {
return wiId;
}
/**
* Sets the value of the wiId property.
*
*/
public void setWiId(int value) {
this.wiId = value;
}
/**
* Gets the value of the title property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTitle() {
return title;
}
/**
* Sets the value of the title property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTitle(String value) {
this.title = value;
}
/**
* Gets the value of the triggerRulesCount property.
*
*/
public int getTriggerRulesCount() {
return triggerRulesCount;
}
/**
* Sets the value of the triggerRulesCount property.
*
*/
public void setTriggerRulesCount(int value) {
this.triggerRulesCount = value;
}
/**
* Gets the value of the triggerEventsCount property.
*
*/
public int getTriggerEventsCount() {
return triggerEventsCount;
}
/**
* Sets the value of the triggerEventsCount property.
*
*/
public void setTriggerEventsCount(int value) {
this.triggerEventsCount = value;
}
/**
* Gets the value of the lastPublishedDate property.
*
* @return
* possible object is
* {@link XMLGregorianCalendar }
*
*/
public XMLGregorianCalendar getLastPublishedDate() {
return lastPublishedDate;
}
/**
* Sets the value of the lastPublishedDate property.
*
* @param value
* allowed object is
* {@link XMLGregorianCalendar }
*
*/
public void setLastPublishedDate(XMLGregorianCalendar value) {
this.lastPublishedDate = value;
}
}
*
*
*
*列表中允许以下类型的对象
*{@link BitStatType}
*
*
*/
公共列表getBitStat(){
if(bitStat==null){
bitStat=newarraylist();
}
返回这个.bitStat;
}
/**
*获取bitAge属性的值。
*
*
*此访问器方法返回对活动列表的引用,
*不是快照。因此,您对
*返回的列表将出现在JAXB对象中。
*这就是为什么bitAge属性没有set
方法的原因。
*
*
*例如,要添加新项目,请执行以下操作:
*
*getBitAge().add(newItem);
*
*
*
*
*列表中允许以下类型的对象
*{@link BitAge}
*
*
*/
公共列表getBitAge(){
if(位==null){
bitAge=newarraylist();
}
返回此.bitAge;
}
/**
*获取wiId属性的值。
*
*/
public int getWiId(){
返回wiId;
}
/**
*设置wiId属性的值。
*
*/
公共void setWiId(int值){
this.wiId=值;
}
/**
*获取title属性的值。
*
*@返回
*可能的对象是
*{@link String}
*
*/
公共字符串getTitle(){
返回标题;
}
/**
*设置标题属性的值。
*
*@param值
*允许的对象是
*{@link String}
*
*/
公共void setTitle(字符串值){
this.title=值;
}
/**
*获取TriggerRuleScont属性的值。
*
*/
public int getTriggerRuleScont(){
返回触发规则;
}
/**
*设置TriggerRuleScont属性的值。
*
*/
public void setTriggerRuleScont(int值){
this.triggerRuleScont=值;
}
/**
*获取TriggerEventCount属性的值。
*
*/
public int getTriggerEventCount(){
返回触发事件计数;
}
/**
*设置TriggerEventCount属性的值。
*
*/
公共无效SetTriggerEventCount(int值){
this.TriggerEventCount=值;
}
/**
*获取lastPublishedDate属性的值。
*
*@返回
*可能的对象是
*{@link XmlGregorianalendar}
*
*/
公共XMLGregorianCalendar getLastPublishedDate(){
返回最新数据;
}
/**
*设置lastPublishedDate属性的值。
*
*@param值
*允许的对象是
*{@link XmlGregorianalendar}
*
*/
public void setLastPublishedDate(XMLGregorianCalendar值){
this.lastPublishedDate=值;
}
}
@java_mouse-我已经更新了我的答案,但仍然没有看到相同的问题。>xjc-版本xjc版本“JDK 6中的JAXB 2.1.10”JavaTM XML绑定体系结构(JAXB)参考实现,(在JDK 6中构建JAXB 2.1.10)Blaise,您可以发布您使用的XJC版本和XJC jars的哪个版本吗?@java_mouse-我使用的是
OracleJDK1.6.0_20-b02
中包含的XJC。看起来我使用的是旧版本的JAXBM可能是您在执行jaxb时使用的是Java1.4?>XJC-versionXJCversionJDK6中的JAXB2.1.10“JavaTM XML绑定体系结构(jaxb)参考实现(在JDK 6中构建JAXB 2.1.10)
xjc -d out nov30.xsd
//
// 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: 2011.11.30 at 11:38:04 AM EST
//
package generated;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
/**
* <p>Java class for BitStatType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="BitStatType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="BitStat" type="{}BitStatType" maxOccurs="unbounded" minOccurs="0"/>
* <element name="BitAge" type="{}BitAge" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* <attribute name="WiId" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="Title" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="TriggerRulesCount" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="TriggerEventsCount" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="LastPublishedDate" use="required" type="{http://www.w3.org/2001/XMLSchema}date" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BitStatType", propOrder = {
"bitStat",
"bitAge"
})
public class BitStatType {
@XmlElement(name = "BitStat")
protected List<BitStatType> bitStat;
@XmlElement(name = "BitAge")
protected List<BitAge> bitAge;
@XmlAttribute(name = "WiId", required = true)
protected int wiId;
@XmlAttribute(name = "Title", required = true)
protected String title;
@XmlAttribute(name = "TriggerRulesCount", required = true)
protected int triggerRulesCount;
@XmlAttribute(name = "TriggerEventsCount", required = true)
protected int triggerEventsCount;
@XmlAttribute(name = "LastPublishedDate", required = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar lastPublishedDate;
/**
* Gets the value of the bitStat property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the bitStat property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getBitStat().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link BitStatType }
*
*
*/
public List<BitStatType> getBitStat() {
if (bitStat == null) {
bitStat = new ArrayList<BitStatType>();
}
return this.bitStat;
}
/**
* Gets the value of the bitAge property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the bitAge property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getBitAge().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link BitAge }
*
*
*/
public List<BitAge> getBitAge() {
if (bitAge == null) {
bitAge = new ArrayList<BitAge>();
}
return this.bitAge;
}
/**
* Gets the value of the wiId property.
*
*/
public int getWiId() {
return wiId;
}
/**
* Sets the value of the wiId property.
*
*/
public void setWiId(int value) {
this.wiId = value;
}
/**
* Gets the value of the title property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTitle() {
return title;
}
/**
* Sets the value of the title property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTitle(String value) {
this.title = value;
}
/**
* Gets the value of the triggerRulesCount property.
*
*/
public int getTriggerRulesCount() {
return triggerRulesCount;
}
/**
* Sets the value of the triggerRulesCount property.
*
*/
public void setTriggerRulesCount(int value) {
this.triggerRulesCount = value;
}
/**
* Gets the value of the triggerEventsCount property.
*
*/
public int getTriggerEventsCount() {
return triggerEventsCount;
}
/**
* Sets the value of the triggerEventsCount property.
*
*/
public void setTriggerEventsCount(int value) {
this.triggerEventsCount = value;
}
/**
* Gets the value of the lastPublishedDate property.
*
* @return
* possible object is
* {@link XMLGregorianCalendar }
*
*/
public XMLGregorianCalendar getLastPublishedDate() {
return lastPublishedDate;
}
/**
* Sets the value of the lastPublishedDate property.
*
* @param value
* allowed object is
* {@link XMLGregorianCalendar }
*
*/
public void setLastPublishedDate(XMLGregorianCalendar value) {
this.lastPublishedDate = value;
}
}