xsd:choice elements get parsed to either List<JAXBElement<?>> or List<Serializable>. For example the network elements become:
public List<Serializable> getNodeOrLinkOrCentroid() {
if (nodeOrLinkOrCentroid == null) {
nodeOrLinkOrCentroid = new ArrayList<Serializable>();
}
return this.nodeOrLinkOrCentroid;
}
In case of List<Serializable> we can use ParseUtil.getObjectsOfType(...) to return all the elements of a certain type. In case of List<JAXBElement<?>> it is not possible to use ParseUtil.getObjectsOfType(...). This limits the possibilities of what we can specify in XSD, without burdening ourselves with elaborate parsing code to deal with the low-level JAXBElement<?> objects.
For example we have the voluntary incentives below. The outer xsd:sequence results in a List<Incentive> (Incentive being a generated type).
But, now we have a list of elements, inside of which there is a choice. This is an unnecessary layer, and it obscures and convolutes the tree in the editor. What we want is the following, with the set of chosen incentives directly under the VoluntaryIncentives element.
This is much better than the List<Serializable> of before. In case of List<JAXBElement<?>> the XPath string needs to point to one of the elements. For example:
We can scan usage of ParseUtil.getObjectsOfType(...) and replace these with appropriate bindings. Moreover various XSD types may be simplified and also get a binding.
xsd:choice
elements get parsed to eitherList<JAXBElement<?>>
orList<Serializable>
. For example the network elements become:In case of
List<Serializable>
we can useParseUtil.getObjectsOfType(...)
to return all the elements of a certain type. In case ofList<JAXBElement<?>>
it is not possible to useParseUtil.getObjectsOfType(...)
. This limits the possibilities of what we can specify in XSD, without burdening ourselves with elaborate parsing code to deal with the low-levelJAXBElement<?>
objects.For example we have the voluntary incentives below. The outer
xsd:sequence
results in aList<Incentive>
(Incentive
being a generated type).But, now we have a list of elements, inside of which there is a choice. This is an unnecessary layer, and it obscures and convolutes the tree in the editor. What we want is the following, with the set of chosen incentives directly under the
VoluntaryIncentives
element.This however results in a
List<JAXBElement<?>>
. To solve this we can use jax2 simplify plugin, see https://github.com/highsource/jaxb2-basics/wiki/JAXB2-Simplify-Plugin.Within the jaxb configuration in the pom file of ots-parser-xml we add (with
maven-jaxb2-basics.version
defined elsewhere):In bindings.xml we add in the main tag:
And the following bindings:
This results in the following generated code in
Network
:This is much better than the
List<Serializable>
of before. In case ofList<JAXBElement<?>>
the XPath string needs to point to one of the elements. For example:We can scan usage of
ParseUtil.getObjectsOfType(...)
and replace these with appropriate bindings. Moreover various XSD types may be simplified and also get a binding.