<div dir="ltr"><br><div class="gmail_extra">Hey <font face="Arial">Vojtech,<br><br></font></div><div class="gmail_extra"><font face="Arial">How are you?, please see my reply inline.<br></font></div><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div><span></span></div><div><br><br></div> <div style="display:block"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div dir="ltr"> <font face="Arial"> On Friday, November 28, 2014 5:26 PM, Vojtech Szocs <<a href="mailto:vszocs@redhat.com" target="_blank">vszocs@redhat.com</a>> wrote:<br> </font> </div> <br><br> <div>Hi guys,<br><br>since the initial (small, working & well-tested) version of oVirtJS<br>JavaScript SDK is finished [*], I've started working on GWT wrapper<br>for oVirtJS.<br><br>While analyzing/reverse-engineering oVirt Java SDK, some thoughts<br>came to my mind, and I wanted to share them with you.<br><br>[*] TODO(vszocs) upload new patchset with all recent changes<br><br>First, the way XJC (JAXB binding compiler that generates Java beans<br>out of REST XSD schema) is invoked looks a bit weird to me, as Java<br>SDK's XsdCodegen does this:<br><br> Runtime.getRuntime().exec(command)<br><br>Why not simply use existing Maven plugins to invoke XJC?<br>- either: <a href="https://github.com/highsource/maven-jaxb2-plugin" target="_blank">https://github.com/highsource/maven-jaxb2-plugin</a><br></div></div></div></div></div></blockquote><div><br></div><div><font size="4">it was using jaxb to begin with, but Juan has replaced it with XJC,<br></font></div><div><font size="4">btw Juan, what was the motivation behind this? <br>(REST api uses jaxb as well so we used to have 1x1 mappings)</font><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="display:block"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div>- or: <a href="http://mojo.codehaus.org/jaxb2-maven-plugin/" target="_blank">http://mojo.codehaus.org/jaxb2-maven-plugin/</a><br></div></div></div></div></div></blockquote><div><br></div><div><font size="4">same.</font><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="display:block"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div><br>Second, and most importantly, what's the point of having "group"<br>entities? I'll give an example - api.xsd contains this:<br><br> <xs:complexType name="DataCenters"><br> <xs:complexContent><br> <xs:extension base="BaseResources"><br> <xs:sequence><br> <xs:annotation><br> <xs:appinfo><br> <jaxb:property name="DataCenters"/><br> </xs:appinfo><br> </xs:annotation><br> <xs:element ref="data_center" minOccurs="0" maxOccurs="unbounded"/><br> </xs:sequence><br> </xs:extension><br> </xs:complexContent><br> </xs:complexType><br><br>(Same as above for Hosts, Clusters, VMs, etc.)<br><br>This results in following (IMHO rather meaningless) Java class<br>being generated by XJC:<br><br>public class DataCenters extends BaseResources {<br><br> @XmlElement(name = "data_center")<br> protected List<DataCenter> dataCenters;<br><br> public List<DataCenter> getDataCenters() {<br> if (dataCenters == null) {<br> dataCenters = new ArrayList<DataCenter>();<br> }<br> return this.dataCenters;<br> }<br><br> public boolean isSetDataCenters() {<br> return ((this.dataCenters!= null)&&(!this.dataCenters.isEmpty()));<br> }<br><br> public void unsetDataCenters() {<br> this.dataCenters = null;<br> }<br><br>}<br><br>Instead, we could use @XmlElementWrapper as described in [1]<br>to avoid generating "group" entities altogether.<br><br>[1] <a href="https://github.com/dmak/jaxb-xew-plugin" target="_blank">https://github.com/dmak/jaxb-xew-plugin</a><br><br>The fact that Java SDK provides decorator for each specific<br>resource collection (like DataCenters), instead of having ONE<br>resource collection type, greatly complicates overall design<br>and code-gen aspect.<br></div></div></div></div></div></blockquote><div><br></div><div><font size="4">well, i guess now is speaking JS constraints ghost, am i right?</font>,<br></div><div><font size="4">at any case, the reasons for having decorator per collection are:<br><br></font></div><div><font size="4">1. compliance with REST API (all SDKs and REST api sharing same well know architecture)<br></font></div><div><font size="4">2. "decorator" is a well known and commonly used java design pattern<br></font></div><div><font size="4">3. having one resource type serving all collections would create a bottleneck<br></font></div><div><font size="4">(well it might depend on how you implementing it, but still in my view it's less convenient/readable<br>than dedicated collection with own context, verbs and behaviour)<br></font></div><div><font size="4"><br></font></div><div><font size="4">after all the purpose of sdk is being java client serving java application in "Java" way<br>while JS use-case & paradigms are totally different</font>.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="display:block"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div><br>In oVirtJS GWT wrapper, we'll avoid above complication through<br>single resource collection type (having common methods like<br>get(id), list() etc) for all resources.<br></div></div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="display:block"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div><br>Regards,<br>Vojtech<br>_______________________________________________<br>Devel mailing list<br><a href="mailto:Devel@ovirt.org" target="_blank">Devel@ovirt.org</a><br><a href="http://lists.ovirt.org/mailman/listinfo/devel" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a><br><br><br></div> </div> </div> </div> </div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><br></div>Michael Pasternak<br></div></div>
</div></div>