Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshalling BoundingBoxType was resulting in a ClassCastException #113

Merged
merged 1 commit into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ows/1.0.0/src/main/resources/ows-v_1_0_0.xjb
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="xjc annox">

<jaxb:bindings schemaLocation="http://schemas.opengis.net/ows/1.0.0/owsAll.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.ows.v_1_0_0"/>
</jaxb:schemaBindings>
</jaxb:bindings>

<!-- https://java.net/jira/browse/JAXB-986 -->
<jaxb:bindings schemaLocation="http://schemas.opengis.net/ows/1.0.0/owsCommon.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='BoundingBoxType']//xs:element[@name='LowerCorner']">
<annox:annotate target="field">@javax.xml.bind.annotation.XmlSchemaType(name="double")</annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='BoundingBoxType']//xs:element[@name='UpperCorner']">
<annox:annotate target="field">@javax.xml.bind.annotation.XmlSchemaType(name="double")</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.opengis.ows.v_1_0_0.tests;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import net.opengis.ows.v_1_0_0.BoundingBoxType;
import net.opengis.ows.v_1_0_0.ObjectFactory;

import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;

/**
* BoundingBox Tests
*/
public class BoundingBox_Test {

/**
* Holder of the context
*/
private JAXBContext context;

@Before
public void initializeContext() throws JAXBException {
this.context = JAXBContext.newInstance(BoundingBoxType.class.getPackage()
.getName()
+ ":"
+ BoundingBoxType.class.getPackage().getName());
}

/**
* Test that a bounding box element can be marshalled.
*
* @throws JAXBException
* Thrown if there is a problem marshalling the model.
* @throws SAXException
* Thrown if there is a problem validating against the schema.
*/
@Test
public void testMarshallBoundingBox() throws JAXBException, SAXException {
BoundingBoxType boundingBox = new BoundingBoxType();
boundingBox.getLowerCorner().add(0.0);
boundingBox.getLowerCorner().add(0.0);
boundingBox.getUpperCorner().add(4.0);
boundingBox.getUpperCorner().add(4.0);

ObjectFactory factory = new ObjectFactory();
JAXBElement<BoundingBoxType> objectToMarshal = factory
.createBoundingBox(boundingBox);

// Marshall.
Marshaller marshaller = this.context.createMarshaller();
marshaller.marshal(objectToMarshal, System.out);
}
}
14 changes: 12 additions & 2 deletions ows/1.1.0/src/main/resources/ows-v_1_1_0.xjb
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="xjc annox">

<jaxb:bindings schemaLocation="http://schemas.opengis.net/ows/1.1.0/owsAll.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.ows.v_1_1_0"/>
</jaxb:schemaBindings>
</jaxb:bindings>


<!-- https://java.net/jira/browse/JAXB-986 -->
<jaxb:bindings schemaLocation="http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='BoundingBoxType']//xs:element[@name='LowerCorner']">
<annox:annotate target="field">@javax.xml.bind.annotation.XmlSchemaType(name="double")</annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='BoundingBoxType']//xs:element[@name='UpperCorner']">
<annox:annotate target="field">@javax.xml.bind.annotation.XmlSchemaType(name="double")</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.opengis.ows.v_1_1_0.tests;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import net.opengis.ows.v_1_1_0.BoundingBoxType;
import net.opengis.ows.v_1_1_0.ObjectFactory;

import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;

/**
* BoundingBox Tests
*/
public class BoundingBox_Test {

/**
* Holder of the context
*/
private JAXBContext context;

@Before
public void initializeContext() throws JAXBException {
this.context = JAXBContext.newInstance(BoundingBoxType.class.getPackage()
.getName()
+ ":"
+ BoundingBoxType.class.getPackage().getName());
}

/**
* Test that a bounding box element can be marshalled.
*
* @throws JAXBException
* Thrown if there is a problem marshalling the model.
* @throws SAXException
* Thrown if there is a problem validating against the schema.
*/
@Test
public void testMarshallBoundingBox() throws JAXBException, SAXException {
BoundingBoxType boundingBox = new BoundingBoxType();
boundingBox.getLowerCorner().add(0.0);
boundingBox.getLowerCorner().add(0.0);
boundingBox.getUpperCorner().add(4.0);
boundingBox.getUpperCorner().add(4.0);

ObjectFactory factory = new ObjectFactory();
JAXBElement<BoundingBoxType> objectToMarshal = factory
.createBoundingBox(boundingBox);

// Marshall.
Marshaller marshaller = this.context.createMarshaller();
marshaller.marshal(objectToMarshal, System.out);
}
}