Wednesday, 4 February 2015

JaxB only creating one getting and setter for multiple elements



I am new to JaxB and XML schemas. I have been looking through google and here to figure out why when I generate my JaxB classes it only creates one getter and one setter for multiple elements.


For example,


public class PolicyType {



@XmlElements({
@XmlElement(name = "description", type = String.class),
@XmlElement(name = "threshold", type = ThresholdType.class),
@XmlElement(name = "boolean", type = BooleanType.class),
@XmlElement(name = "whitelist", type = WhitelistType.class),
@XmlElement(name = "policy", type = PolicyType.class),
@XmlElement(name = "dirtylist", type = PolicyType.Dirtylist.class),
@XmlElement(name = "cleanlist", type = PolicyType.Cleanlist.class),
@XmlElement(name = "whiteImageList", type = PolicyType.WhiteImageList.class)
})
protected List<Object> descriptionOrThresholdOrBoolean;
@XmlAttribute(name = "name", required = true)
protected String name;

/**
* Gets the value of the descriptionOrThresholdOrBoolean 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 descriptionOrThresholdOrBoolean property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getDescriptionOrThresholdOrBoolean().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link String }
* {@link ThresholdType }
* {@link BooleanType }
* {@link WhitelistType }
* {@link PolicyType }
* {@link PolicyType.Dirtylist }
* {@link PolicyType.Cleanlist }
* {@link PolicyType.WhiteImageList }
*
*
*/
public List<Object> getDescriptionOrThresholdOrBoolean() {
if (descriptionOrThresholdOrBoolean == null) {
descriptionOrThresholdOrBoolean = new ArrayList<Object>();
}
return this.descriptionOrThresholdOrBoolean;
}


Each element is it's own class and own type defined in my xml...Here's a snippet



<xs:complexType name="policy.type">
<xs:sequence maxOccurs="unbounded" minOccurs="0">
<xs:element name="description" type="description.type" />
<xs:element name="threshold" type="threshold.type" />
<xs:element name="boolean" type="boolean.type" />
<xs:element name="whitelist" type="whitelist.type" />
<!--<xs:element name="policy" type="policy.type" />-->
<xs:element name="dirtylist">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="cleanlist">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="whiteImageList">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attributeGroup ref="policy.attlist" />
</xs:complexType>

<xs:complexType name="policies.type">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="policy" type="policy.type" />
<xs:element name="dirtylist" type="dirtylist.type" />
<xs:element name="cleanlist" type="cleanlist.type" />
<xs:element name="whiteImageList" type="whiteImageList.type" />
</xs:sequence>
</xs:complexType>

<xs:element name="policies" type="policies.type" />


I am trying to have JaxB generate a list for each defined type instead of a list of Objects that contains all of my types. (Makes it a pain to retrieve all of my information and such after unmarshalling)


Thoughts?


Let me know if you need more snippets....


Thanks in advance.


No comments:

Post a Comment