[ovirt-devel] Some ideas on oVirt Java SDK

Vojtech Szocs vszocs at redhat.com
Fri Nov 28 15:26:39 UTC 2014


Hi guys,

since the initial (small, working & well-tested) version of oVirtJS
JavaScript SDK is finished [*], I've started working on GWT wrapper
for oVirtJS.

While analyzing/reverse-engineering oVirt Java SDK, some thoughts
came to my mind, and I wanted to share them with you.

[*] TODO(vszocs) upload new patchset with all recent changes

First, the way XJC (JAXB binding compiler that generates Java beans
out of REST XSD schema) is invoked looks a bit weird to me, as Java
SDK's XsdCodegen does this:

  Runtime.getRuntime().exec(command)

Why not simply use existing Maven plugins to invoke XJC?
- either: https://github.com/highsource/maven-jaxb2-plugin
- or: http://mojo.codehaus.org/jaxb2-maven-plugin/

Second, and most importantly, what's the point of having "group"
entities? I'll give an example - api.xsd contains this:

  <xs:complexType name="DataCenters">
    <xs:complexContent>
      <xs:extension base="BaseResources">
        <xs:sequence>
          <xs:annotation>
            <xs:appinfo>
                <jaxb:property name="DataCenters"/>
            </xs:appinfo>
          </xs:annotation>
          <xs:element ref="data_center" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

(Same as above for Hosts, Clusters, VMs, etc.)

This results in following (IMHO rather meaningless) Java class
being generated by XJC:

public class DataCenters extends BaseResources {

    @XmlElement(name = "data_center")
    protected List<DataCenter> dataCenters;

    public List<DataCenter> getDataCenters() {
        if (dataCenters == null) {
            dataCenters = new ArrayList<DataCenter>();
        }
        return this.dataCenters;
    }

    public boolean isSetDataCenters() {
        return ((this.dataCenters!= null)&&(!this.dataCenters.isEmpty()));
    }

    public void unsetDataCenters() {
        this.dataCenters = null;
    }

}

Instead, we could use @XmlElementWrapper as described in [1]
to avoid generating "group" entities altogether.

[1] https://github.com/dmak/jaxb-xew-plugin

The fact that Java SDK provides decorator for each specific
resource collection (like DataCenters), instead of having ONE
resource collection type, greatly complicates overall design
and code-gen aspect.

In oVirtJS GWT wrapper, we'll avoid above complication through
single resource collection type (having common methods like
get(id), list() etc) for all resources.

Regards,
Vojtech



More information about the Devel mailing list