Skip to content

Commit

Permalink
make wrapped XML serialization configurable for compositions
Browse files Browse the repository at this point in the history
fixes #66
  • Loading branch information
pahjbo committed Dec 16, 2024
1 parent c37dc39 commit e13d8d1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
1 change: 1 addition & 0 deletions tools/binding_sample_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<python-package>org.ivoa.dm.samplemodel</python-package>
<xml-targetnamespace prefix="simp">http://ivoa.net/dm/sample/sample/v1</xml-targetnamespace>
<xmllegacy-targetnamespace prefix="simp" schemaFilename="Sample.xsd" schemaLocation="Sample.xsd">http://ivoa.net/dm/sample/sample</xmllegacy-targetnamespace>
<xml compositionStyle="unwrapped"/>
<rdb inheritance-strategy="single-table"
discriminatorColumnLength="64"/>
<type-detail vodml-id="catalog.SkyCoordinateFrame.name">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ void externalXMLSchemaTest() throws JAXBException, IOException {
System.err.println("File " + fout.getAbsolutePath());
result.printValidationErrors(System.err);
}
else {
System.out.println("File " + fout.getAbsolutePath());
}
assertTrue(result.isOk, "validation with external schema");
}

Expand Down
13 changes: 10 additions & 3 deletions tools/xslt/jaxb.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,16 @@

<xsl:template match="composition[multiplicity/maxOccurs != 1]" mode="JAXBAnnotation">
<xsl:variable name="type" select="vf:JavaType(datatype/vodml-ref)"/>
@jakarta.xml.bind.annotation.XmlElementWrapper( name = "<xsl:value-of select="name"/>")
@jakarta.xml.bind.annotation.XmlElement( name = "<xsl:value-of select="$models/key('ellookup',current()/datatype/vodml-ref)/name"/>", required = <xsl:apply-templates select="." mode="required"/>, type = <xsl:value-of select="$type"/>.class)
<xsl:if test="$models/key('ellookup',current()/datatype/vodml-ref)/@abstract or vf:hasSubTypes(current()/datatype/vodml-ref)">
<xsl:choose>
<xsl:when test="$mapping/bnd:mappedModels/model[name=current()/ancestor-or-self::vo-dml:model/name]/xml/@compositionStyle='unwrapped'">
@jakarta.xml.bind.annotation.XmlElement( name = "<xsl:value-of select="name"/>", required = <xsl:apply-templates select="." mode="required"/>, type = <xsl:value-of select="$type"/>.class)
</xsl:when>
<xsl:otherwise>
@jakarta.xml.bind.annotation.XmlElementWrapper( name = "<xsl:value-of select="name"/>")
@jakarta.xml.bind.annotation.XmlElement( name = "<xsl:value-of select="$models/key('ellookup',current()/datatype/vodml-ref)/name"/>", required = <xsl:apply-templates select="." mode="required"/>, type = <xsl:value-of select="$type"/>.class)
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$models/key('ellookup',current()/datatype/vodml-ref)/@abstract or vf:hasSubTypes(current()/datatype/vodml-ref)">
<xsl:value-of select="$jsontypinfo"/>
</xsl:if>
</xsl:template>
Expand Down
7 changes: 2 additions & 5 deletions tools/xslt/vo-dml2xsdNew.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ note that this schema is substantially different from the era when this code was

<xsl:variable name="xsd-ns">http://www.w3.org/2001/XMLSchema</xsl:variable>


<xsl:variable name="modelname" select="/vo-dml:model/name"/>

<!-- main pattern : processes for root node model -->
<xsl:template match="/">
Expand All @@ -46,9 +46,6 @@ note that this schema is substantially different from the era when this code was

<xsl:template match="vo-dml:model">

<xsl:variable name="modelname" select="name"/>


<xsl:variable name="targetNamespace">
<xsl:value-of select="vf:xsdNs($modelname)"/>
</xsl:variable>
Expand Down Expand Up @@ -363,7 +360,7 @@ note that this schema is substantially different from the era when this code was
</xsl:if>
</xsl:template>

<xsl:template match="composition[multiplicity/maxOccurs != 1]" >
<xsl:template match="composition[multiplicity/maxOccurs != 1 and not($mapping/bnd:mappedModels/model[name=$modelname]/xml/@compositionStyle='unwrapped')]" >
<xsd:element>
<xsl:attribute name="name" >
<xsl:value-of select="name"/>
Expand Down
39 changes: 30 additions & 9 deletions xsd/vo-dml-binding.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ targetNamespace="http://www.ivoa.net/xml/vodml-binding/v0.9.1" attributeFormDefa
</xsd:element>
<xsd:element name="java-package" type="JavaName" minOccurs="0" maxOccurs="1" />
<xsd:element name="python-package" type="PythonName" minOccurs="0" maxOccurs="1" />
<!-- TODO put all the XML mapping into own element -->
<xsd:element name="xml-targetnamespace" type="xmlnsMapping" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Expand All @@ -40,6 +41,21 @@ targetNamespace="http://www.ivoa.net/xml/vodml-binding/v0.9.1" attributeFormDefa
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="xml" maxOccurs="1" minOccurs="0">
<xsd:complexType>
<xsd:attribute name="compositionStyle" default="wrapped">
<xsd:annotation>
<xsd:documentation>whether compositions with multiplicities greater than 1 should have a wrapper element</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="wrapped"></xsd:enumeration>
<xsd:enumeration value="unwrapped"></xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="json-baseURI" type="xsd:string" maxOccurs="1" minOccurs="0"></xsd:element>
<xsd:element name="rdb" minOccurs="0" maxOccurs="1">
<xsd:complexType>
Expand All @@ -60,13 +76,15 @@ targetNamespace="http://www.ivoa.net/xml/vodml-binding/v0.9.1" attributeFormDefa
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="fetching" use="optional" default="lazy">
<xsd:annotation>
<xsd:documentation>whether child objects from the database are fetched at initial query time or only on use</xsd:documentation>
</xsd:annotation>
<xsd:annotation>
<xsd:documentation>
whether child objects from the database are fetched at initial query time or only on use
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="lazy"></xsd:enumeration>
<xsd:enumeration value="eager"></xsd:enumeration>
<xsd:enumeration value="lazy"></xsd:enumeration>
<xsd:enumeration value="eager"></xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
Expand All @@ -78,10 +96,9 @@ targetNamespace="http://www.ivoa.net/xml/vodml-binding/v0.9.1" attributeFormDefa
</xsd:annotation>
</xsd:element>
<xsd:element name="type-detail" type="TypeDetail" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>the list of type detail the model.</xsd:documentation>
</xsd:annotation>

<xsd:annotation>
<xsd:documentation>the list of type detail the model.</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Expand Down Expand Up @@ -244,4 +261,8 @@ IMPL - this could be put into the code - especially as the number of JSON built-
</xsd:complexType>



<xsd:simpleType name="NewSimpleType">
<xsd:restriction base="xsd:string"></xsd:restriction>
</xsd:simpleType>
</xsd:schema>

0 comments on commit e13d8d1

Please sign in to comment.