OXM is nearing completion

This commit is contained in:
Arjen Poutsma
2009-01-09 12:48:19 +00:00
parent f2329cf426
commit fc06f9ba72
99 changed files with 6343 additions and 5359 deletions

View File

@@ -22,109 +22,120 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stream.StreamResult;
import org.custommonkey.xmlunit.XMLTestCase;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.springframework.xml.transform.StaxResult;
import org.springframework.util.xml.StaxUtils;
public abstract class AbstractMarshallerTestCase extends XMLTestCase {
public abstract class AbstractMarshallerTestCase {
protected Marshaller marshaller;
protected Marshaller marshaller;
protected Object flights;
protected Object flights;
protected static final String EXPECTED_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
protected static final String EXPECTED_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
protected final void setUp() throws Exception {
marshaller = createMarshaller();
flights = createFlights();
XMLUnit.setIgnoreWhitespace(true);
}
@Before
public final void setUp() throws Exception {
marshaller = createMarshaller();
flights = createFlights();
XMLUnit.setIgnoreWhitespace(true);
}
protected abstract Marshaller createMarshaller() throws Exception;
protected abstract Marshaller createMarshaller() throws Exception;
protected abstract Object createFlights();
protected abstract Object createFlights();
public void testMarshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document result = builder.newDocument();
DOMResult domResult = new DOMResult(result);
marshaller.marshal(flights, domResult);
Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
namespace.setNodeValue("http://samples.springframework.org/flight");
flightsElement.setAttributeNode(namespace);
expected.appendChild(flightsElement);
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, result);
}
@Test
public void marshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document result = builder.newDocument();
DOMResult domResult = new DOMResult(result);
marshaller.marshal(flights, domResult);
Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
namespace.setNodeValue("http://samples.springframework.org/flight");
flightsElement.setAttributeNode(namespace);
expected.appendChild(flightsElement);
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, result);
}
public void testMarshalStreamResultWriter() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStreamResultWriter() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStreamResultOutputStream() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING,
new String(os.toByteArray(), "UTF-8"));
}
@Test
public void marshalStreamResultOutputStream() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING,
new String(os.toByteArray(), "UTF-8"));
}
public void testMarshalStaxResultStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
StaxResult result = new StaxResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
Result result = StaxUtils.createStaxResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStaxResultEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StaxResult result = new StaxResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
Result result = StaxUtils.createStaxResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalJaxp14StaxResultStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
StAXResult result = new StAXResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalJaxp14StaxResultStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
StAXResult result = new StAXResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalJaxp14StaxResultEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StAXResult result = new StAXResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalJaxp14StaxResultEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StAXResult result = new StAXResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
}

View File

@@ -23,12 +23,15 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
@@ -36,104 +39,114 @@ import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.springframework.xml.transform.StaxSource;
import org.springframework.util.xml.StaxUtils;
public abstract class AbstractUnmarshallerTestCase extends TestCase {
public abstract class AbstractUnmarshallerTestCase {
protected Unmarshaller unmarshaller;
protected Unmarshaller unmarshaller;
protected static final String INPUT_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
protected static final String INPUT_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
protected final void setUp() throws Exception {
unmarshaller = createUnmarshaller();
}
@Before
public final void setUp() throws Exception {
unmarshaller = createUnmarshaller();
}
protected abstract Unmarshaller createUnmarshaller() throws Exception;
protected abstract Unmarshaller createUnmarshaller() throws Exception;
protected abstract void testFlights(Object o);
protected abstract void testFlights(Object o);
protected abstract void testFlight(Object o);
protected abstract void testFlight(Object o);
public void testUnmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
document.appendChild(flightsElement);
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = document.createTextNode("42");
numberElement.appendChild(text);
DOMSource source = new DOMSource(document);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
document.appendChild(flightsElement);
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = document.createTextNode("42");
numberElement.appendChild(text);
DOMSource source = new DOMSource(document);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStreamSourceReader() throws Exception {
StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStreamSourceReader() throws Exception {
StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStreamSourceInputStream() throws Exception {
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStreamSourceInputStream() throws Exception {
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalSAXSource() throws Exception {
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXSource source = new SAXSource(reader, new InputSource(new StringReader(INPUT_STRING)));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalSAXSource() throws Exception {
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXSource source = new SAXSource(reader, new InputSource(new StringReader(INPUT_STRING)));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
StaxSource source = new StaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StaxSource source = new StaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalJaxp14StaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalJaxp14StaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalJaxp14StaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalJaxp14StaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
StaxSource source = new StaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
@Test
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
Source source = StaxUtils.createStaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
}

View File

@@ -17,61 +17,65 @@ package org.springframework.oxm.castor;
import javax.xml.transform.sax.SAXResult;
import org.easymock.MockControl;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.springframework.core.io.ClassPathResource;
import org.springframework.oxm.AbstractMarshallerTestCase;
import org.springframework.oxm.Marshaller;
import org.xml.sax.ContentHandler;
public class CastorMarshallerTest extends AbstractMarshallerTestCase {
@Override
@Override
protected Marshaller createMarshaller() throws Exception {
CastorMarshaller marshaller = new CastorMarshaller();
ClassPathResource mappingLocation = new ClassPathResource("mapping.xml", CastorMarshaller.class);
marshaller.setMappingLocation(mappingLocation);
marshaller.afterPropertiesSet();
return marshaller;
}
CastorMarshaller marshaller = new CastorMarshaller();
ClassPathResource mappingLocation = new ClassPathResource("mapping.xml", CastorMarshaller.class);
marshaller.setMappingLocation(mappingLocation);
marshaller.afterPropertiesSet();
return marshaller;
}
@Override
@Override
protected Object createFlights() {
Flight flight = new Flight();
flight.setNumber(42L);
Flights flights = new Flights();
flights.addFlight(flight);
return flights;
}
Flight flight = new Flight();
flight.setNumber(42L);
Flights flights = new Flights();
flights.addFlight(flight);
return flights;
}
public void testMarshalSaxResult() throws Exception {
MockControl handlerControl = MockControl.createControl(ContentHandler.class);
ContentHandler handlerMock = (ContentHandler) handlerControl.getMock();
handlerMock.startDocument();
handlerMock.startPrefixMapping("tns", "http://samples.springframework.org/flight");
handlerMock.startElement("http://samples.springframework.org/flight", "flights", "tns:flights", null);
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
handlerMock.startElement("http://samples.springframework.org/flight", "flight", "tns:flight", null);
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
handlerMock.startElement("http://samples.springframework.org/flight", "number", "tns:number", null);
handlerControl.setMatcher(MockControl.ALWAYS_MATCHER);
handlerMock.characters(new char[]{'4', '2'}, 0, 2);
handlerControl.setMatcher(MockControl.ARRAY_MATCHER);
handlerMock.endElement("http://samples.springframework.org/flight", "number", "tns:number");
handlerMock.endElement("http://samples.springframework.org/flight", "flight", "tns:flight");
handlerMock.endElement("http://samples.springframework.org/flight", "flights", "tns:flights");
handlerMock.endPrefixMapping("tns");
handlerMock.endDocument();
@Test
public void marshalSaxResult() throws Exception {
ContentHandler handlerMock = createMock(ContentHandler.class);
handlerMock.startDocument();
handlerMock.startPrefixMapping("tns", "http://samples.springframework.org/flight");
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("tns:flights"),
isA(Attributes.class));
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("tns:flight"),
isA(Attributes.class));
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("tns:number"),
isA(Attributes.class));
handlerMock.characters(aryEq(new char[]{'4', '2'}), eq(0), eq(2));
handlerMock.endElement("http://samples.springframework.org/flight", "number", "tns:number");
handlerMock.endElement("http://samples.springframework.org/flight", "flight", "tns:flight");
handlerMock.endElement("http://samples.springframework.org/flight", "flights", "tns:flights");
handlerMock.endPrefixMapping("tns");
handlerMock.endDocument();
handlerControl.replay();
SAXResult result = new SAXResult(handlerMock);
marshaller.marshal(flights, result);
handlerControl.verify();
}
replay(handlerMock);
SAXResult result = new SAXResult(handlerMock);
marshaller.marshal(flights, result);
verify(handlerMock);
}
public void testSupports() throws Exception {
assertTrue("CastorMarshaller does not support Flights", marshaller.supports(Flights.class));
assertTrue("CastorMarshaller does not support Flight", marshaller.supports(Flight.class));
}
@Test
public void supports() throws Exception {
assertTrue("CastorMarshaller does not support Flights", marshaller.supports(Flights.class));
assertTrue("CastorMarshaller does not support Flight", marshaller.supports(Flight.class));
}
}

View File

@@ -19,56 +19,56 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.transform.stream.StreamSource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.oxm.AbstractUnmarshallerTestCase;
import org.springframework.oxm.Unmarshaller;
public class CastorUnmarshallerTest extends AbstractUnmarshallerTestCase {
@Override
@Override
protected void testFlights(Object o) {
Flights flights = (Flights) o;
assertNotNull("Flights is null", flights);
assertEquals("Invalid amount of flight elements", 1, flights.getFlightCount());
testFlight(flights.getFlight()[0]);
}
Flights flights = (Flights) o;
assertNotNull("Flights is null", flights);
assertEquals("Invalid amount of flight elements", 1, flights.getFlightCount());
testFlight(flights.getFlight()[0]);
}
@Override
@Override
protected void testFlight(Object o) {
Flight flight = (Flight) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
Flight flight = (Flight) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
@Override
@Override
protected Unmarshaller createUnmarshaller() throws Exception {
CastorMarshaller marshaller = new CastorMarshaller();
ClassPathResource mappingLocation = new ClassPathResource("mapping.xml", CastorMarshaller.class);
marshaller.setMappingLocation(mappingLocation);
marshaller.afterPropertiesSet();
return marshaller;
}
CastorMarshaller marshaller = new CastorMarshaller();
ClassPathResource mappingLocation = new ClassPathResource("mapping.xml", CastorMarshaller.class);
marshaller.setMappingLocation(mappingLocation);
marshaller.afterPropertiesSet();
return marshaller;
}
public void testUnmarshalTargetClass() throws Exception {
CastorMarshaller unmarshaller = new CastorMarshaller();
unmarshaller.setTargetClass(Flights.class);
unmarshaller.afterPropertiesSet();
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalTargetClass() throws Exception {
CastorMarshaller unmarshaller = new CastorMarshaller();
unmarshaller.setTargetClass(Flights.class);
unmarshaller.afterPropertiesSet();
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testSetBothTargetClassAndMapping() throws IOException {
try {
CastorMarshaller marshaller = new CastorMarshaller();
marshaller.setMappingLocation(new ClassPathResource("mapping.xml", CastorMarshaller.class));
marshaller.setTargetClass(getClass());
marshaller.afterPropertiesSet();
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException ex) {
// expected
}
}
@Test(expected = IllegalArgumentException.class)
public void testSetBothTargetClassAndMapping() throws IOException {
CastorMarshaller marshaller = new CastorMarshaller();
marshaller.setMappingLocation(new ClassPathResource("mapping.xml", CastorMarshaller.class));
marshaller.setTargetClass(getClass());
marshaller.afterPropertiesSet();
}
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.oxm.config;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import junit.framework.TestCase;
public class Jaxb2OxmNamespaceHandlerTest extends TestCase {
private ApplicationContext applicationContext;
protected void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("jaxb2OxmNamespaceHandlerTest.xml", getClass());
}
public void testContextPathMarshaller() throws Exception {
applicationContext.getBean("contextPathMarshaller", Jaxb2Marshaller.class);
}
public void testClassesToBeBoundMarshaller() throws Exception {
applicationContext.getBean("classesMarshaller", Jaxb2Marshaller.class);
}
}

View File

@@ -16,37 +16,50 @@
package org.springframework.oxm.config;
import org.apache.xmlbeans.XmlOptions;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.oxm.jaxb.Jaxb1Marshaller;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.oxm.jibx.JibxMarshaller;
import org.springframework.oxm.xmlbeans.XmlBeansMarshaller;
import junit.framework.TestCase;
import org.apache.xmlbeans.XmlOptions;
public class OxmNamespaceHandlerTest {
public class OxmNamespaceHandlerTest extends TestCase {
private ApplicationContext applicationContext;
private ApplicationContext applicationContext;
@Before
public void createAppContext() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("oxmNamespaceHandlerTest.xml", getClass());
}
protected void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("oxmNamespaceHandlerTest.xml", getClass());
}
@Test
@Ignore
public void jibxMarshaller() throws Exception {
applicationContext.getBean("jibxMarshaller", JibxMarshaller.class);
}
public void testJaxb1Marshaller() throws Exception {
applicationContext.getBean("jaxb1Marshaller", Jaxb1Marshaller.class);
}
@Test
public void xmlBeansMarshaller() throws Exception {
XmlBeansMarshaller marshaller = applicationContext.getBean("xmlBeansMarshaller", XmlBeansMarshaller.class);
XmlOptions options = marshaller.getXmlOptions();
assertNotNull("Options not set", options);
assertTrue("option not set", options.hasOption("SAVE_PRETTY_PRINT"));
assertEquals("option not set", "true", options.get("SAVE_PRETTY_PRINT"));
}
public void testJibxMarshaller() throws Exception {
applicationContext.getBean("jibxMarshaller", JibxMarshaller.class);
}
@Test
public void jaxb2ContextPathMarshaller() throws Exception {
applicationContext.getBean("contextPathMarshaller", Jaxb2Marshaller.class);
}
@Test
public void jaxb2ClassesToBeBoundMarshaller() throws Exception {
applicationContext.getBean("classesMarshaller", Jaxb2Marshaller.class);
}
public void testXmlBeansMarshaller() throws Exception {
XmlBeansMarshaller marshaller =
(XmlBeansMarshaller) applicationContext.getBean("xmlBeansMarshaller", XmlBeansMarshaller.class);
XmlOptions options = marshaller.getXmlOptions();
assertNotNull("Options not set", options);
assertTrue("option not set", options.hasOption("SAVE_PRETTY_PRINT"));
assertEquals("option not set", "true", options.get("SAVE_PRETTY_PRINT"));
}
}

View File

@@ -0,0 +1,47 @@
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.3-b01-fcs
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.01.08 at 12:41:36 PM CET
//
package org.springframework.oxm.jaxb;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for flightType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="flightType">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="number" type="{http://www.w3.org/2001/XMLSchema}long"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "flightType", propOrder = {"number"})
public class FlightType {
protected long number;
/** Gets the value of the number property. */
public long getNumber() {
return number;
}
/** Sets the value of the number property. */
public void setNumber(long value) {
this.number = value;
}
}

View File

@@ -0,0 +1,66 @@
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.3-b01-fcs
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.01.08 at 12:41:36 PM CET
//
package org.springframework.oxm.jaxb;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="flight" type="{http://samples.springframework.org/flight}flightType"
* maxOccurs="unbounded"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"flight"})
@XmlRootElement(name = "flights")
public class Flights {
@XmlElement(required = true)
protected List<FlightType> flight;
/**
* Gets the value of the flight property.
*
* <p> This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
* to the returned list will be present inside the JAXB object. This is why there is not a <CODE>set</CODE> method for
* the flight property.
*
* <p> For example, to add a new item, do as follows:
* <pre>
* getFlight().add(newItem);
* </pre>
*
*
* <p> Objects of the following type(s) are allowed in the list {@link FlightType }
*/
public List<FlightType> getFlight() {
if (flight == null) {
flight = new ArrayList<FlightType>();
}
return this.flight;
}
}

View File

@@ -1,84 +0,0 @@
/*
* Copyright 2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.oxm.jaxb;
import java.util.Collections;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.XmlMappingException;
import org.springframework.oxm.jaxb1.FlightType;
import org.springframework.oxm.jaxb1.Flights;
import org.springframework.oxm.jaxb1.FlightsType;
import org.springframework.oxm.jaxb1.impl.FlightTypeImpl;
import org.springframework.oxm.jaxb1.impl.FlightsImpl;
public class Jaxb1MarshallerTest extends AbstractJaxbMarshallerTestCase {
private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb1";
@Override
protected final Marshaller createMarshaller() throws Exception {
Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
marshaller.setContextPaths(new String[]{CONTEXT_PATH});
marshaller.afterPropertiesSet();
return marshaller;
}
@Override
protected Object createFlights() {
FlightType flight = new FlightTypeImpl();
flight.setNumber(42L);
Flights flights = new FlightsImpl();
flights.getFlight().add(flight);
return flights;
}
public void testProperties() throws Exception {
Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.setMarshallerProperties(
Collections.singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE));
marshaller.afterPropertiesSet();
}
public void testNoContextPath() throws Exception {
try {
Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
marshaller.afterPropertiesSet();
fail("Should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException e) {
}
}
public void testInvalidContextPath() throws Exception {
try {
Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
marshaller.setContextPath("ab");
marshaller.afterPropertiesSet();
fail("Should have thrown an XmlMappingException");
}
catch (XmlMappingException ex) {
}
}
public void testSupports() throws Exception {
assertTrue("Jaxb1Marshaller does not support Flights", marshaller.supports(Flights.class));
assertFalse("Jaxb1Marshaller supports FlightsType", marshaller.supports(FlightsType.class));
}
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.oxm.jaxb;
import org.springframework.oxm.AbstractUnmarshallerTestCase;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.jaxb1.FlightType;
import org.springframework.oxm.jaxb1.Flights;
public class Jaxb1UnmarshallerTest extends AbstractUnmarshallerTestCase {
@Override
protected Unmarshaller createUnmarshaller() throws Exception {
Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
marshaller.setContextPath("org.springframework.oxm.jaxb1");
marshaller.setValidating(true);
marshaller.afterPropertiesSet();
return marshaller;
}
@Override
protected void testFlights(Object o) {
Flights flights = (Flights) o;
assertNotNull("Flights is null", flights);
assertEquals("Invalid amount of flight elements", 1, flights.getFlight().size());
testFlight(flights.getFlight().get(0));
}
@Override
protected void testFlight(Object o) {
FlightType flight = (FlightType) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
}

View File

@@ -20,7 +20,6 @@ import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -47,8 +46,12 @@ import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stream.StreamResult;
import org.custommonkey.xmlunit.XMLTestCase;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
@@ -59,271 +62,268 @@ import org.xml.sax.Locator;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.oxm.XmlMappingException;
import org.springframework.oxm.jaxb2.FlightType;
import org.springframework.oxm.jaxb2.Flights;
import org.springframework.oxm.jaxb2.ObjectFactory;
import org.springframework.oxm.mime.MimeContainer;
import org.springframework.util.FileCopyUtils;
import org.springframework.xml.transform.StaxResult;
import org.springframework.xml.transform.StringResult;
import org.springframework.util.xml.StaxUtils;
public class Jaxb2MarshallerTest extends XMLTestCase {
public class Jaxb2MarshallerTest {
private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb2";
private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb";
private static final String EXPECTED_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
private static final String EXPECTED_STRING =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
private Jaxb2Marshaller marshaller;
private Jaxb2Marshaller marshaller;
private Flights flights;
private Flights flights;
protected void setUp() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.afterPropertiesSet();
FlightType flight = new FlightType();
flight.setNumber(42L);
flights = new Flights();
flights.getFlight().add(flight);
}
@Before
public void createMarshaller() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.afterPropertiesSet();
FlightType flight = new FlightType();
flight.setNumber(42L);
flights = new Flights();
flights.getFlight().add(flight);
}
public void testMarshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.newDocument();
DOMResult domResult = new DOMResult(document);
marshaller.marshal(flights, domResult);
Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
expected.appendChild(flightsElement);
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
}
@Test
public void marshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.newDocument();
DOMResult domResult = new DOMResult(document);
marshaller.marshal(flights, domResult);
Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
expected.appendChild(flightsElement);
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
}
public void testMarshalStreamResultWriter() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStreamResultWriter() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStreamResultOutputStream() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING,
new String(os.toByteArray(), "UTF-8"));
}
@Test
public void marshalStreamResultOutputStream() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING,
new String(os.toByteArray(), "UTF-8"));
}
public void testMarshalStaxResultXMLStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
StaxResult result = new StaxResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultXMLStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
Result result = StaxUtils.createStaxResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStaxResultXMLEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StaxResult result = new StaxResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultXMLEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
Result result = StaxUtils.createStaxResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStaxResultXMLStreamWriterJaxp14() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
StAXResult result = new StAXResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultXMLStreamWriterJaxp14() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
StAXResult result = new StAXResult(streamWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStaxResultXMLEventWriterJaxp14() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StAXResult result = new StAXResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultXMLEventWriterJaxp14() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StAXResult result = new StAXResult(eventWriter);
marshaller.marshal(flights, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testProperties() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.setMarshallerProperties(
Collections.singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE));
marshaller.afterPropertiesSet();
}
@Test
public void properties() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.setMarshallerProperties(
Collections.singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE));
marshaller.afterPropertiesSet();
}
public void testNoContextPathOrClassesToBeBound() throws Exception {
try {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.afterPropertiesSet();
fail("Should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException e) {
}
}
@Test(expected = IllegalArgumentException.class)
public void noContextPathOrClassesToBeBound() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.afterPropertiesSet();
}
public void testInvalidContextPath() throws Exception {
try {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("ab");
marshaller.afterPropertiesSet();
fail("Should have thrown an XmlMappingException");
}
catch (XmlMappingException ex) {
}
}
@Test(expected = XmlMappingException.class)
public void testInvalidContextPath() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("ab");
marshaller.afterPropertiesSet();
}
public void testMarshalInvalidClass() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{FlightType.class});
marshaller.afterPropertiesSet();
Result result = new StreamResult(new StringWriter());
Flights flights = new Flights();
try {
marshaller.marshal(flights, result);
fail("Should have thrown an MarshallingFailureException");
}
catch (XmlMappingException ex) {
// expected
}
}
@Test(expected = XmlMappingException.class)
public void marshalInvalidClass() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{FlightType.class});
marshaller.afterPropertiesSet();
Result result = new StreamResult(new StringWriter());
Flights flights = new Flights();
marshaller.marshal(flights, result);
}
public void testMarshalSaxResult() throws Exception {
ContentHandler handlerMock = createStrictMock(ContentHandler.class);
handlerMock.setDocumentLocator(isA(Locator.class));
handlerMock.startDocument();
handlerMock.startPrefixMapping("", "http://samples.springframework.org/flight");
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("flights"),
isA(Attributes.class));
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("flight"),
isA(Attributes.class));
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("number"),
isA(Attributes.class));
handlerMock.characters(isA(char[].class), eq(0), eq(2));
handlerMock.endElement("http://samples.springframework.org/flight", "number", "number");
handlerMock.endElement("http://samples.springframework.org/flight", "flight", "flight");
handlerMock.endElement("http://samples.springframework.org/flight", "flights", "flights");
handlerMock.endPrefixMapping("");
handlerMock.endDocument();
replay(handlerMock);
@Test
public void marshalSaxResult() throws Exception {
ContentHandler handlerMock = createStrictMock(ContentHandler.class);
handlerMock.setDocumentLocator(isA(Locator.class));
handlerMock.startDocument();
handlerMock.startPrefixMapping("", "http://samples.springframework.org/flight");
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("flights"),
isA(Attributes.class));
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("flight"),
isA(Attributes.class));
handlerMock.startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("number"),
isA(Attributes.class));
handlerMock.characters(isA(char[].class), eq(0), eq(2));
handlerMock.endElement("http://samples.springframework.org/flight", "number", "number");
handlerMock.endElement("http://samples.springframework.org/flight", "flight", "flight");
handlerMock.endElement("http://samples.springframework.org/flight", "flights", "flights");
handlerMock.endPrefixMapping("");
handlerMock.endDocument();
replay(handlerMock);
SAXResult result = new SAXResult(handlerMock);
marshaller.marshal(flights, result);
verify(handlerMock);
}
SAXResult result = new SAXResult(handlerMock);
marshaller.marshal(flights, result);
verify(handlerMock);
}
public void testSupportsContextPath() throws Exception {
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
assertTrue("Jaxb2Marshaller does not support Flights",
marshaller.supports(createFlights.getGenericReturnType()));
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
marshaller.supports(createFlight.getGenericReturnType()));
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
JAXBElement<Jaxb2MarshallerTest> testElement =
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
}
@Test
public void supportsContextPath() throws Exception {
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
assertTrue("Jaxb2Marshaller does not support Flights",
marshaller.supports(createFlights.getGenericReturnType()));
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
marshaller.supports(createFlight.getGenericReturnType()));
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
JAXBElement<Jaxb2MarshallerTest> testElement =
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
}
public void testSupportsClassesToBeBound() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{Flights.class, FlightType.class});
marshaller.afterPropertiesSet();
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
assertTrue("Jaxb2Marshaller does not support Flights",
marshaller.supports(createFlights.getGenericReturnType()));
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
marshaller.supports(createFlight.getGenericReturnType()));
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
JAXBElement<Jaxb2MarshallerTest> testElement =
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
}
@Test
public void supportsClassesToBeBound() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{Flights.class, FlightType.class});
marshaller.afterPropertiesSet();
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
assertTrue("Jaxb2Marshaller does not support Flights",
marshaller.supports(createFlights.getGenericReturnType()));
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
marshaller.supports(createFlight.getGenericReturnType()));
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
JAXBElement<Jaxb2MarshallerTest> testElement =
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
}
public void testSupportsPrimitives() throws Exception {
Method primitives = getClass().getDeclaredMethod("primitives", JAXBElement.class, JAXBElement.class,
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class,
JAXBElement.class);
Type[] types = primitives.getGenericParameterTypes();
for (int i = 0; i < types.length; i++) {
ParameterizedType type = (ParameterizedType) types[i];
assertTrue("Jaxb2Marshaller does not support " + type, marshaller.supports(types[i]));
}
}
@Test
public void supportsPrimitives() throws Exception {
Method primitives = getClass()
.getDeclaredMethod("primitives", JAXBElement.class, JAXBElement.class, JAXBElement.class,
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class);
Type[] types = primitives.getGenericParameterTypes();
for (Type type : types) {
assertTrue("Jaxb2Marshaller does not support " + type, marshaller.supports(type));
}
}
public void testSupportsStandards() throws Exception {
Method standards = getClass().getDeclaredMethod("standards", JAXBElement.class, JAXBElement.class,
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class,
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class,
JAXBElement.class, JAXBElement.class);
Type[] types = standards.getGenericParameterTypes();
for (int i = 0; i < types.length; i++) {
ParameterizedType type = (ParameterizedType) types[i];
assertTrue("Jaxb2Marshaller does not support " + type, marshaller.supports(types[i]));
}
}
@Test
public void supportsStandards() throws Exception {
Method standards = getClass()
.getDeclaredMethod("standards", JAXBElement.class, JAXBElement.class, JAXBElement.class,
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class,
JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class, JAXBElement.class,
JAXBElement.class);
Type[] types = standards.getGenericParameterTypes();
for (Type type : types) {
assertTrue("Jaxb2Marshaller does not support " + type, marshaller.supports(type));
}
}
public void testMarshalAttachments() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{BinaryObject.class});
marshaller.setMtomEnabled(true);
marshaller.afterPropertiesSet();
MimeContainer mimeContainer = createMock(MimeContainer.class);
@Test
public void marshalAttachments() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{BinaryObject.class});
marshaller.setMtomEnabled(true);
marshaller.afterPropertiesSet();
MimeContainer mimeContainer = createMock(MimeContainer.class);
Resource logo = new ClassPathResource("spring-ws.png", getClass());
DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));
Resource logo = new ClassPathResource("spring-ws.png", getClass());
DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));
expect(mimeContainer.convertToXopPackage()).andReturn(true);
mimeContainer.addAttachment(isA(String.class), isA(DataHandler.class));
expectLastCall().times(3);
expect(mimeContainer.convertToXopPackage()).andReturn(true);
mimeContainer.addAttachment(isA(String.class), isA(DataHandler.class));
expectLastCall().times(3);
replay(mimeContainer);
byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream());
BinaryObject object = new BinaryObject(bytes, dataHandler);
Result result = new StringResult();
marshaller.marshal(object, result, mimeContainer);
verify(mimeContainer);
assertTrue("No XML written", result.toString().length() > 0);
}
replay(mimeContainer);
byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream());
BinaryObject object = new BinaryObject(bytes, dataHandler);
StringWriter writer = new StringWriter();
marshaller.marshal(object, new StreamResult(writer), mimeContainer);
verify(mimeContainer);
assertTrue("No XML written", writer.toString().length() > 0);
}
private void primitives(JAXBElement<Boolean> bool,
JAXBElement<Byte> aByte,
JAXBElement<Short> aShort,
JAXBElement<Integer> anInteger,
JAXBElement<Long> aLong,
JAXBElement<Float> aFloat,
JAXBElement<Double> aDouble,
JAXBElement<byte[]> byteArray) {
}
private void primitives(JAXBElement<Boolean> bool,
JAXBElement<Byte> aByte,
JAXBElement<Short> aShort,
JAXBElement<Integer> anInteger,
JAXBElement<Long> aLong,
JAXBElement<Float> aFloat,
JAXBElement<Double> aDouble,
JAXBElement<byte[]> byteArray) {
}
private void standards(JAXBElement<String> string,
JAXBElement<BigInteger> integer,
JAXBElement<BigDecimal> decimal,
JAXBElement<Calendar> calendar,
JAXBElement<Date> date,
JAXBElement<QName> qName,
JAXBElement<URI> uri,
JAXBElement<XMLGregorianCalendar> xmlGregorianCalendar,
JAXBElement<Duration> duration,
JAXBElement<Object> object,
JAXBElement<Image> image,
JAXBElement<DataHandler> dataHandler,
JAXBElement<Source> source,
JAXBElement<UUID> uuid) {
}
private void standards(JAXBElement<String> string,
JAXBElement<BigInteger> integer,
JAXBElement<BigDecimal> decimal,
JAXBElement<Calendar> calendar,
JAXBElement<Date> date,
JAXBElement<QName> qName,
JAXBElement<URI> uri,
JAXBElement<XMLGregorianCalendar> xmlGregorianCalendar,
JAXBElement<Duration> duration,
JAXBElement<Object> object,
JAXBElement<Image> image,
JAXBElement<DataHandler> dataHandler,
JAXBElement<Source> source,
JAXBElement<UUID> uuid) {
}
}

View File

@@ -32,8 +32,10 @@ import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
@@ -43,154 +45,160 @@ import org.xml.sax.helpers.XMLReaderFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.oxm.jaxb2.FlightType;
import org.springframework.oxm.jaxb2.Flights;
import org.springframework.oxm.mime.MimeContainer;
import org.springframework.xml.transform.StaxSource;
import org.springframework.xml.transform.StringSource;
import org.springframework.util.xml.StaxUtils;
public class Jaxb2UnmarshallerTest extends TestCase {
public class Jaxb2UnmarshallerTest {
private static final String INPUT_STRING = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
private static final String INPUT_STRING = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
private Jaxb2Marshaller unmarshaller;
private Jaxb2Marshaller unmarshaller;
protected void setUp() throws Exception {
unmarshaller = new Jaxb2Marshaller();
unmarshaller.setContextPath("org.springframework.oxm.jaxb2");
unmarshaller.setSchema(new ClassPathResource("org/springframework/oxm/flight.xsd"));
unmarshaller.afterPropertiesSet();
}
@Before
public void createMarshaller() throws Exception {
unmarshaller = new Jaxb2Marshaller();
unmarshaller.setContextPath("org.springframework.oxm.jaxb");
unmarshaller.setSchema(new ClassPathResource("org/springframework/oxm/flight.xsd"));
unmarshaller.afterPropertiesSet();
}
public void testUnmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
document.appendChild(flightsElement);
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = document.createTextNode("42");
numberElement.appendChild(text);
DOMSource source = new DOMSource(document);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
document.appendChild(flightsElement);
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = document.createTextNode("42");
numberElement.appendChild(text);
DOMSource source = new DOMSource(document);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStreamSourceReader() throws Exception {
StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStreamSourceReader() throws Exception {
StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStreamSourceInputStream() throws Exception {
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void testUnmarshalStreamSourceInputStream() throws Exception {
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalSAXSource() throws Exception {
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXSource source = new SAXSource(reader, new InputSource(new StringReader(INPUT_STRING)));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalSAXSource() throws Exception {
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXSource source = new SAXSource(reader, new InputSource(new StringReader(INPUT_STRING)));
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
StaxSource source = new StaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StaxSource source = new StaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStaxSourceXmlStreamReaderJaxp14() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlStreamReaderJaxp14() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testUnmarshalStaxSourceXmlEventReaderJaxp14() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlEventReaderJaxp14() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
public void testMarshalAttachments() throws Exception {
unmarshaller = new Jaxb2Marshaller();
unmarshaller.setClassesToBeBound(new Class[]{BinaryObject.class});
unmarshaller.setMtomEnabled(true);
unmarshaller.afterPropertiesSet();
MimeContainer mimeContainer = createMock(MimeContainer.class);
@Test
public void marshalAttachments() throws Exception {
unmarshaller = new Jaxb2Marshaller();
unmarshaller.setClassesToBeBound(new Class[]{BinaryObject.class});
unmarshaller.setMtomEnabled(true);
unmarshaller.afterPropertiesSet();
MimeContainer mimeContainer = createMock(MimeContainer.class);
Resource logo = new ClassPathResource("spring-ws.png", getClass());
DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));
Resource logo = new ClassPathResource("spring-ws.png", getClass());
DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile()));
expect(mimeContainer.isXopPackage()).andReturn(true);
expect(mimeContainer.getAttachment(
"<6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws>"))
.andReturn(dataHandler);
expect(mimeContainer.getAttachment(
"<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>"))
.andReturn(dataHandler);
expect(mimeContainer.getAttachment("696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png"))
.andReturn(dataHandler);
replay(mimeContainer);
String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" +
"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
"</bytes>" + "<dataHandler>" +
"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
"</dataHandler>" +
"<swaDataHandler>696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png</swaDataHandler>" +
"</binaryObject>";
expect(mimeContainer.isXopPackage()).andReturn(true);
expect(mimeContainer.getAttachment(
"<6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws>")).andReturn(dataHandler);
expect(mimeContainer.getAttachment(
"<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).andReturn(dataHandler);
expect(mimeContainer.getAttachment("696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png"))
.andReturn(dataHandler);
replay(mimeContainer);
String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" +
"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
"</bytes>" + "<dataHandler>" +
"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
"</dataHandler>" +
"<swaDataHandler>696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png</swaDataHandler>" +
"</binaryObject>";
Source source = new StringSource(content);
Object result = unmarshaller.unmarshal(source, mimeContainer);
assertTrue("Result is not a BinaryObject", result instanceof BinaryObject);
verify(mimeContainer);
BinaryObject object = (BinaryObject) result;
assertNotNull("bytes property not set", object.getBytes());
assertTrue("bytes property not set", object.getBytes().length > 0);
assertNotNull("datahandler property not set", object.getSwaDataHandler());
}
StringReader reader = new StringReader(content);
Object result = unmarshaller.unmarshal(new StreamSource(reader), mimeContainer);
assertTrue("Result is not a BinaryObject", result instanceof BinaryObject);
verify(mimeContainer);
BinaryObject object = (BinaryObject) result;
assertNotNull("bytes property not set", object.getBytes());
assertTrue("bytes property not set", object.getBytes().length > 0);
assertNotNull("datahandler property not set", object.getSwaDataHandler());
}
private void testFlights(Object o) {
Flights flights = (Flights) o;
assertNotNull("Flights is null", flights);
assertEquals("Invalid amount of flight elements", 1, flights.getFlight().size());
testFlight(flights.getFlight().get(0));
}
private void testFlights(Object o) {
Flights flights = (Flights) o;
assertNotNull("Flights is null", flights);
assertEquals("Invalid amount of flight elements", 1, flights.getFlight().size());
testFlight(flights.getFlight().get(0));
}
private void testFlight(Object o) {
FlightType flight = (FlightType) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
private void testFlight(Object o) {
FlightType flight = (FlightType) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
public void testUnmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
streamReader.nextTag(); // skip to flight
StaxSource source = new StaxSource(streamReader);
JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source);
FlightType flight = element.getValue();
testFlight(flight);
}
@Test
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
streamReader.nextTag(); // skip to flight
Source source = StaxUtils.createStaxSource(streamReader);
JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source);
FlightType flight = element.getValue();
testFlight(flight);
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.3-b01-fcs
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.01.08 at 12:41:36 PM CET
//
package org.springframework.oxm.jaxb;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each Java content interface and Java element interface generated in the
* org.springframework.oxm.jaxb package. <p>An ObjectFactory allows you to programatically construct new instances of
* the Java representation for XML content. The Java representation of XML content can consist of schema derived
* interfaces and classes representing the binding of schema type definitions, element declarations and model groups.
* Factory methods for each of these are provided in this class.
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _Flight_QNAME = new QName("http://samples.springframework.org/flight", "flight");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package:
* org.springframework.oxm.jaxb
*/
public ObjectFactory() {
}
/** Create an instance of {@link FlightType } */
public FlightType createFlightType() {
return new FlightType();
}
/** Create an instance of {@link Flights } */
public Flights createFlights() {
return new Flights();
}
/** Create an instance of {@link JAXBElement }{@code <}{@link FlightType }{@code >}} */
@XmlElementDecl(namespace = "http://samples.springframework.org/flight", name = "flight")
public JAXBElement<FlightType> createFlight(FlightType value) {
return new JAXBElement<FlightType>(_Flight_QNAME, FlightType.class, null, value);
}
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.3-b01-fcs
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.01.08 at 12:41:36 PM CET
//
@javax.xml.bind.annotation.XmlSchema(namespace = "http://samples.springframework.org/flight",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package org.springframework.oxm.jaxb;

View File

@@ -16,66 +16,73 @@
package org.springframework.oxm.jibx;
import java.io.StringWriter;
import javax.xml.transform.stream.StreamResult;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import org.custommonkey.xmlunit.XMLUnit;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.oxm.AbstractMarshallerTestCase;
import org.springframework.oxm.Marshaller;
import org.springframework.xml.transform.StringResult;
@Ignore
public class JibxMarshallerTest extends AbstractMarshallerTestCase {
@Override
@Override
protected Marshaller createMarshaller() throws Exception {
JibxMarshaller marshaller = new JibxMarshaller();
marshaller.setTargetClass(Flights.class);
marshaller.afterPropertiesSet();
return marshaller;
}
JibxMarshaller marshaller = new JibxMarshaller();
marshaller.setTargetClass(Flights.class);
marshaller.afterPropertiesSet();
return marshaller;
}
@Override
@Override
protected Object createFlights() {
Flights flights = new Flights();
FlightType flight = new FlightType();
flight.setNumber(42L);
flights.addFlight(flight);
return flights;
}
Flights flights = new Flights();
FlightType flight = new FlightType();
flight.setNumber(42L);
flights.addFlight(flight);
return flights;
}
public void testAfterPropertiesSetNoContextPath() throws Exception {
try {
JibxMarshaller marshaller = new JibxMarshaller();
marshaller.afterPropertiesSet();
fail("Should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException e) {
}
}
@Test(expected = IllegalArgumentException.class)
public void afterPropertiesSetNoContextPath() throws Exception {
JibxMarshaller marshaller = new JibxMarshaller();
marshaller.afterPropertiesSet();
}
public void testIndentation() throws Exception {
((JibxMarshaller) marshaller).setIndent(4);
StringResult result = new StringResult();
marshaller.marshal(flights, result);
XMLUnit.setIgnoreWhitespace(false);
String expected = "<?xml version=\"1.0\"?>\n" +
"<flights xmlns=\"http://samples.springframework.org/flight\">\n" + " <flight>\n" +
" <number>42</number>\n" + " </flight>\n" + "</flights>";
assertXMLEqual(expected, result.toString());
}
@Test
public void indentation() throws Exception {
((JibxMarshaller) marshaller).setIndent(4);
StringWriter writer = new StringWriter();
marshaller.marshal(flights, new StreamResult(writer));
XMLUnit.setIgnoreWhitespace(false);
String expected =
"<?xml version=\"1.0\"?>\n" + "<flights xmlns=\"http://samples.springframework.org/flight\">\n" +
" <flight>\n" + " <number>42</number>\n" + " </flight>\n" + "</flights>";
assertXMLEqual(expected, writer.toString());
}
public void testEncodingAndStandalone() throws Exception {
((JibxMarshaller) marshaller).setEncoding("ISO-8859-1");
((JibxMarshaller) marshaller).setStandalone(Boolean.TRUE);
StringResult result = new StringResult();
marshaller.marshal(flights, result);
assertTrue("Encoding and standalone not set",
result.toString().startsWith("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>"));
}
@Test
public void encodingAndStandalone() throws Exception {
((JibxMarshaller) marshaller).setEncoding("ISO-8859-1");
((JibxMarshaller) marshaller).setStandalone(Boolean.TRUE);
StringWriter writer = new StringWriter();
marshaller.marshal(flights, new StreamResult(writer));
assertTrue("Encoding and standalone not set",
writer.toString().startsWith("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>"));
}
public void testSupports() throws Exception {
assertTrue("JibxMarshaller does not support Flights", marshaller.supports(Flights.class));
assertTrue("JibxMarshaller does not support FlightType", marshaller.supports(FlightType.class));
assertFalse("JibxMarshaller supports illegal type", marshaller.supports(getClass()));
}
@Test
public void testSupports() throws Exception {
assertTrue("JibxMarshaller does not support Flights", marshaller.supports(Flights.class));
assertTrue("JibxMarshaller does not support FlightType", marshaller.supports(FlightType.class));
assertFalse("JibxMarshaller supports illegal type", marshaller.supports(getClass()));
}
}

View File

@@ -15,36 +15,42 @@
*/
package org.springframework.oxm.jibx;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Ignore;
import org.springframework.oxm.AbstractUnmarshallerTestCase;
import org.springframework.oxm.Unmarshaller;
@Ignore
public class JibxUnmarshallerTest extends AbstractUnmarshallerTestCase {
@Override
@Override
protected Unmarshaller createUnmarshaller() throws Exception {
JibxMarshaller unmarshaller = new JibxMarshaller();
unmarshaller.setTargetClass(Flights.class);
unmarshaller.afterPropertiesSet();
return unmarshaller;
}
JibxMarshaller unmarshaller = new JibxMarshaller();
unmarshaller.setTargetClass(Flights.class);
unmarshaller.afterPropertiesSet();
return unmarshaller;
}
@Override
@Override
protected void testFlights(Object o) {
Flights flights = (Flights) o;
assertNotNull("Flights is null", flights);
assertEquals("Invalid amount of flight elements", 1, flights.sizeFlightList());
testFlight(flights.getFlight(0));
}
Flights flights = (Flights) o;
assertNotNull("Flights is null", flights);
assertEquals("Invalid amount of flight elements", 1, flights.sizeFlightList());
testFlight(flights.getFlight(0));
}
@Override
@Override
protected void testFlight(Object o) {
FlightType flight = (FlightType) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
FlightType flight = (FlightType) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
@Override
public void testUnmarshalPartialStaxSourceXmlStreamReader() throws Exception {
// JiBX does not support reading XML fragments, hence the override here
}
@Override
@Ignore
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
// JiBX does not support reading XML fragments, hence the override here
}
}

View File

@@ -1,156 +0,0 @@
/*
* Copyright 2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.oxm.support;
import javax.jms.BytesMessage;
import javax.jms.Session;
import javax.jms.TextMessage;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
public class MarshallingMessageConverterTest extends TestCase {
private MarshallingMessageConverter converter;
private MockControl marshallerControl;
private Marshaller marshallerMock;
private MockControl unmarshallerControl;
private Unmarshaller unmarshallerMock;
private MockControl sessionControl;
private Session sessionMock;
protected void setUp() throws Exception {
marshallerControl = MockControl.createControl(Marshaller.class);
marshallerMock = (Marshaller) marshallerControl.getMock();
unmarshallerControl = MockControl.createControl(Unmarshaller.class);
unmarshallerMock = (Unmarshaller) unmarshallerControl.getMock();
converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock);
sessionControl = MockControl.createControl(Session.class);
sessionMock = (Session) sessionControl.getMock();
}
public void testToBytesMessage() throws Exception {
MockControl bytesMessageControl = MockControl.createControl(BytesMessage.class);
BytesMessage bytesMessageMock = (BytesMessage) bytesMessageControl.getMock();
Object toBeMarshalled = new Object();
sessionControl.expectAndReturn(sessionMock.createBytesMessage(), bytesMessageMock);
marshallerMock.marshal(toBeMarshalled, new StringResult());
marshallerControl.setMatcher(MockControl.ALWAYS_MATCHER);
bytesMessageMock.writeBytes(new byte[0]);
bytesMessageControl.setMatcher(MockControl.ALWAYS_MATCHER);
marshallerControl.replay();
unmarshallerControl.replay();
sessionControl.replay();
bytesMessageControl.replay();
converter.toMessage(toBeMarshalled, sessionMock);
marshallerControl.verify();
unmarshallerControl.verify();
sessionControl.verify();
bytesMessageControl.verify();
}
public void testFromBytesMessage() throws Exception {
MockControl bytesMessageControl = MockControl.createControl(BytesMessage.class);
BytesMessage bytesMessageMock = (BytesMessage) bytesMessageControl.getMock();
Object unmarshalled = new Object();
bytesMessageControl.expectAndReturn(bytesMessageMock.getBodyLength(), 10);
bytesMessageMock.readBytes(new byte[0]);
bytesMessageControl.setMatcher(MockControl.ALWAYS_MATCHER);
bytesMessageControl.setReturnValue(0);
unmarshallerMock.unmarshal(new StringSource(""));
unmarshallerControl.setMatcher(MockControl.ALWAYS_MATCHER);
unmarshallerControl.setReturnValue(unmarshalled);
marshallerControl.replay();
unmarshallerControl.replay();
sessionControl.replay();
bytesMessageControl.replay();
Object result = converter.fromMessage(bytesMessageMock);
assertEquals("Invalid result", result, unmarshalled);
marshallerControl.verify();
unmarshallerControl.verify();
sessionControl.verify();
bytesMessageControl.verify();
}
public void testToTextMessage() throws Exception {
converter.setMarshalTo(MarshallingMessageConverter.MARSHAL_TO_TEXT_MESSAGE);
MockControl textMessageControl = MockControl.createControl(TextMessage.class);
TextMessage textMessageMock = (TextMessage) textMessageControl.getMock();
Object toBeMarshalled = new Object();
sessionControl.expectAndReturn(sessionMock.createTextMessage(""), textMessageMock);
marshallerMock.marshal(toBeMarshalled, new StringResult());
marshallerControl.setMatcher(MockControl.ALWAYS_MATCHER);
marshallerControl.replay();
unmarshallerControl.replay();
sessionControl.replay();
textMessageControl.replay();
converter.toMessage(toBeMarshalled, sessionMock);
marshallerControl.verify();
unmarshallerControl.verify();
sessionControl.verify();
textMessageControl.verify();
}
public void testFromTextMessage() throws Exception {
MockControl textMessageControl = MockControl.createControl(TextMessage.class);
TextMessage textMessageMock = (TextMessage) textMessageControl.getMock();
Object unmarshalled = new Object();
unmarshallerMock.unmarshal(new StringSource(""));
unmarshallerControl.setMatcher(MockControl.ALWAYS_MATCHER);
unmarshallerControl.setReturnValue(unmarshalled);
textMessageControl.expectAndReturn(textMessageMock.getText(), "");
marshallerControl.replay();
unmarshallerControl.replay();
sessionControl.replay();
textMessageControl.replay();
Object result = converter.fromMessage(textMessageMock);
assertEquals("Invalid result", result, unmarshalled);
marshallerControl.verify();
unmarshallerControl.verify();
sessionControl.verify();
textMessageControl.verify();
}
}

View File

@@ -1,135 +0,0 @@
/*
* Copyright 2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.oxm.support;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.xml.transform.stream.StreamResult;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.oxm.Marshaller;
public class MarshallingViewTest extends TestCase {
private MarshallingView view;
private MockControl control;
private Marshaller marshallerMock;
protected void setUp() throws Exception {
control = MockControl.createControl(Marshaller.class);
marshallerMock = (Marshaller) control.getMock();
view = new MarshallingView(marshallerMock);
}
public void testGetContentType() {
Assert.assertEquals("Invalid content type", "application/xml", view.getContentType());
}
public void testRenderModelKey() throws Exception {
Object toBeMarshalled = new Object();
String modelKey = "key";
view.setModelKey(modelKey);
Map model = new HashMap();
model.put(modelKey, toBeMarshalled);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
control.expectAndReturn(marshallerMock.supports(Object.class), true);
marshallerMock.marshal(toBeMarshalled, new StreamResult(response.getOutputStream()));
control.setMatcher(MockControl.ALWAYS_MATCHER);
control.replay();
view.render(model, request, response);
Assert.assertEquals("Invalid content type", "application/xml", response.getContentType());
Assert.assertEquals("Invalid content length", 0, response.getContentLength());
control.verify();
}
public void testRenderModelKeyUnsupported() throws Exception {
Object toBeMarshalled = new Object();
String modelKey = "key";
view.setModelKey(modelKey);
Map model = new HashMap();
model.put(modelKey, toBeMarshalled);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
control.expectAndReturn(marshallerMock.supports(Object.class), false);
control.replay();
try {
view.render(model, request, response);
fail("ServletException expected");
}
catch (ServletException ex) {
// expected
}
control.verify();
}
public void testRenderNoModelKey() throws Exception {
Object toBeMarshalled = new Object();
String modelKey = "key";
Map model = new HashMap();
model.put(modelKey, toBeMarshalled);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
control.expectAndReturn(marshallerMock.supports(Object.class), true);
marshallerMock.marshal(toBeMarshalled, new StreamResult(response.getOutputStream()));
control.setMatcher(MockControl.ALWAYS_MATCHER);
control.replay();
view.render(model, request, response);
Assert.assertEquals("Invalid content type", "application/xml", response.getContentType());
Assert.assertEquals("Invalid content length", 0, response.getContentLength());
control.verify();
}
public void testRenderUnsupportedModel() throws Exception {
Object toBeMarshalled = new Object();
String modelKey = "key";
Map model = new HashMap();
model.put(modelKey, toBeMarshalled);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
control.expectAndReturn(marshallerMock.supports(Object.class), false);
control.replay();
try {
view.render(model, request, response);
fail("ServletException expected");
}
catch (ServletException ex) {
// expected
}
control.verify();
}
}

View File

@@ -0,0 +1,180 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* An XML document type.
* Localname: flight
* Namespace: http://samples.springframework.org/flight
* Java type: org.springframework.samples.flight.FlightDocument
*
* Automatically generated - do not modify.
*/
package org.springframework.oxm.xmlbeans;
/**
* A document containing one flight(@http://samples.springframework.org/flight) element.
*
* This is a complex type.
*/
public interface FlightDocument extends org.apache.xmlbeans.XmlObject {
public static final org.apache.xmlbeans.SchemaType type =
(org.apache.xmlbeans.SchemaType) org.apache.xmlbeans.XmlBeans
.typeSystemForClassLoader(FlightDocument.class.getClassLoader(),
"schemaorg_apache_xmlbeans.system.s5EF858A5E57B2761C3670716FC0A909C")
.resolveHandle("flightc6b8doctype");
/** Gets the "flight" element */
org.springframework.oxm.xmlbeans.FlightType getFlight();
/** Sets the "flight" element */
void setFlight(org.springframework.oxm.xmlbeans.FlightType flight);
/** Appends and returns a new empty "flight" element */
org.springframework.oxm.xmlbeans.FlightType addNewFlight();
/** A factory class with static methods for creating instances of this type. */
public static final class Factory {
public static org.springframework.oxm.xmlbeans.FlightDocument newInstance() {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.newInstance(type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.newInstance(type, options);
}
/** @param xmlAsString the string value to parse */
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.lang.String xmlAsString)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xmlAsString, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.lang.String xmlAsString,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xmlAsString, type, options);
}
/** @param file the file from which to load an xml document */
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.io.File file)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(file, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.io.File file,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(file, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.net.URL u)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(u, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.net.URL u,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(u, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.io.InputStream is)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(is, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.io.InputStream is,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(is, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.io.Reader r)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(r, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(java.io.Reader r,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(r, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(javax.xml.stream.XMLStreamReader sr)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(sr, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(javax.xml.stream.XMLStreamReader sr,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(sr, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(org.w3c.dom.Node node)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(node, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightDocument parse(org.w3c.dom.Node node,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(node, type, options);
}
/** @deprecated {@link XMLInputStream} */
public static org.springframework.oxm.xmlbeans.FlightDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xis, type, null);
}
/** @deprecated {@link XMLInputStream} */
public static org.springframework.oxm.xmlbeans.FlightDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis,
org.apache.xmlbeans.XmlOptions options)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.springframework.oxm.xmlbeans.FlightDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xis, type, options);
}
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, null);
}
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis,
org.apache.xmlbeans.XmlOptions options)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, options);
}
private Factory() {
} // No instance of this class allowed
}
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* XML Type: flightType
* Namespace: http://samples.springframework.org/flight
* Java type: org.springframework.samples.flight.FlightType
*
* Automatically generated - do not modify.
*/
package org.springframework.oxm.xmlbeans;
/**
* An XML flightType(@http://samples.springframework.org/flight).
*
* This is a complex type.
*/
public interface FlightType extends org.apache.xmlbeans.XmlObject {
public static final org.apache.xmlbeans.SchemaType type =
(org.apache.xmlbeans.SchemaType) org.apache.xmlbeans.XmlBeans
.typeSystemForClassLoader(FlightType.class.getClassLoader(),
"schemaorg_apache_xmlbeans.system.s5EF858A5E57B2761C3670716FC0A909C")
.resolveHandle("flighttype4702type");
/** Gets the "number" element */
long getNumber();
/** Gets (as xml) the "number" element */
org.apache.xmlbeans.XmlLong xgetNumber();
/** Sets the "number" element */
void setNumber(long number);
/** Sets (as xml) the "number" element */
void xsetNumber(org.apache.xmlbeans.XmlLong number);
/** A factory class with static methods for creating instances of this type. */
public static final class Factory {
public static org.springframework.oxm.xmlbeans.FlightType newInstance() {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.newInstance(type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.newInstance(type, options);
}
/** @param xmlAsString the string value to parse */
public static org.springframework.oxm.xmlbeans.FlightType parse(java.lang.String xmlAsString)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xmlAsString, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.lang.String xmlAsString,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xmlAsString, type, options);
}
/** @param file the file from which to load an xml document */
public static org.springframework.oxm.xmlbeans.FlightType parse(java.io.File file)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(file, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.io.File file,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(file, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.net.URL u)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(u, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.net.URL u,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(u, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.io.InputStream is)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(is, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.io.InputStream is,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(is, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.io.Reader r)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(r, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(java.io.Reader r,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(r, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(javax.xml.stream.XMLStreamReader sr)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(sr, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(javax.xml.stream.XMLStreamReader sr,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(sr, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(org.w3c.dom.Node node)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(node, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightType parse(org.w3c.dom.Node node,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(node, type, options);
}
/** @deprecated {@link XMLInputStream} */
public static org.springframework.oxm.xmlbeans.FlightType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xis, type, null);
}
/** @deprecated {@link XMLInputStream} */
public static org.springframework.oxm.xmlbeans.FlightType parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis,
org.apache.xmlbeans.XmlOptions options)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.springframework.oxm.xmlbeans.FlightType) org.apache.xmlbeans.XmlBeans.getContextTypeLoader()
.parse(xis, type, options);
}
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, null);
}
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis,
org.apache.xmlbeans.XmlOptions options)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, options);
}
private Factory() {
} // No instance of this class allowed
}
}

View File

@@ -0,0 +1,243 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* An XML document type.
* Localname: flights
* Namespace: http://samples.springframework.org/flight
* Java type: org.springframework.samples.flight.FlightsDocument
*
* Automatically generated - do not modify.
*/
package org.springframework.oxm.xmlbeans;
/**
* A document containing one flights(@http://samples.springframework.org/flight) element.
*
* This is a complex type.
*/
public interface FlightsDocument extends org.apache.xmlbeans.XmlObject {
public static final org.apache.xmlbeans.SchemaType type =
(org.apache.xmlbeans.SchemaType) org.apache.xmlbeans.XmlBeans
.typeSystemForClassLoader(FlightsDocument.class.getClassLoader(),
"schemaorg_apache_xmlbeans.system.s5EF858A5E57B2761C3670716FC0A909C")
.resolveHandle("flights4eb9doctype");
/** Gets the "flights" element */
org.springframework.oxm.xmlbeans.FlightsDocument.Flights getFlights();
/** Sets the "flights" element */
void setFlights(org.springframework.oxm.xmlbeans.FlightsDocument.Flights flights);
/** Appends and returns a new empty "flights" element */
org.springframework.oxm.xmlbeans.FlightsDocument.Flights addNewFlights();
/**
* An XML flights(@http://samples.springframework.org/flight).
*
* This is a complex type.
*/
public interface Flights extends org.apache.xmlbeans.XmlObject {
public static final org.apache.xmlbeans.SchemaType type =
(org.apache.xmlbeans.SchemaType) org.apache.xmlbeans.XmlBeans
.typeSystemForClassLoader(Flights.class.getClassLoader(),
"schemaorg_apache_xmlbeans.system.s5EF858A5E57B2761C3670716FC0A909C")
.resolveHandle("flightseba8elemtype");
/** Gets a List of "flight" elements */
java.util.List<org.springframework.oxm.xmlbeans.FlightType> getFlightList();
/**
* Gets array of all "flight" elements
*
* @deprecated
*/
org.springframework.oxm.xmlbeans.FlightType[] getFlightArray();
/** Gets ith "flight" element */
org.springframework.oxm.xmlbeans.FlightType getFlightArray(int i);
/** Returns number of "flight" element */
int sizeOfFlightArray();
/** Sets array of all "flight" element */
void setFlightArray(org.springframework.oxm.xmlbeans.FlightType[] flightArray);
/** Sets ith "flight" element */
void setFlightArray(int i, org.springframework.oxm.xmlbeans.FlightType flight);
/** Inserts and returns a new empty value (as xml) as the ith "flight" element */
org.springframework.oxm.xmlbeans.FlightType insertNewFlight(int i);
/** Appends and returns a new empty value (as xml) as the last "flight" element */
org.springframework.oxm.xmlbeans.FlightType addNewFlight();
/** Removes the ith "flight" element */
void removeFlight(int i);
/** A factory class with static methods for creating instances of this type. */
public static final class Factory {
public static org.springframework.oxm.xmlbeans.FlightsDocument.Flights newInstance() {
return (org.springframework.oxm.xmlbeans.FlightsDocument.Flights) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().newInstance(type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument.Flights newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.springframework.oxm.xmlbeans.FlightsDocument.Flights) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().newInstance(type, options);
}
private Factory() {
} // No instance of this class allowed
}
}
/** A factory class with static methods for creating instances of this type. */
public static final class Factory {
public static org.springframework.oxm.xmlbeans.FlightsDocument newInstance() {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().newInstance(type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument newInstance(org.apache.xmlbeans.XmlOptions options) {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().newInstance(type, options);
}
/** @param xmlAsString the string value to parse */
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.lang.String xmlAsString)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(xmlAsString, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.lang.String xmlAsString,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(xmlAsString, type, options);
}
/** @param file the file from which to load an xml document */
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.io.File file)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(file, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.io.File file,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(file, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.net.URL u)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(u, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.net.URL u,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(u, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.io.InputStream is)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(is, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.io.InputStream is,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(is, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.io.Reader r)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(r, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(java.io.Reader r,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(r, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(javax.xml.stream.XMLStreamReader sr)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(sr, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(javax.xml.stream.XMLStreamReader sr,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(sr, type, options);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(org.w3c.dom.Node node)
throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(node, type, null);
}
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(org.w3c.dom.Node node,
org.apache.xmlbeans.XmlOptions options) throws org.apache.xmlbeans.XmlException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(node, type, options);
}
/** @deprecated {@link XMLInputStream} */
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(xis, type, null);
}
/** @deprecated {@link XMLInputStream} */
public static org.springframework.oxm.xmlbeans.FlightsDocument parse(org.apache.xmlbeans.xml.stream.XMLInputStream xis,
org.apache.xmlbeans.XmlOptions options)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return (org.springframework.oxm.xmlbeans.FlightsDocument) org.apache.xmlbeans.XmlBeans
.getContextTypeLoader().parse(xis, type, options);
}
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, null);
}
/** @deprecated {@link XMLInputStream} */
public static org.apache.xmlbeans.xml.stream.XMLInputStream newValidatingXMLInputStream(org.apache.xmlbeans.xml.stream.XMLInputStream xis,
org.apache.xmlbeans.XmlOptions options)
throws org.apache.xmlbeans.XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException {
return org.apache.xmlbeans.XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, options);
}
private Factory() {
} // No instance of this class allowed
}
}

View File

@@ -19,43 +19,42 @@ import java.io.ByteArrayOutputStream;
import javax.xml.transform.stream.StreamResult;
import org.apache.xmlbeans.XmlObject;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.oxm.AbstractMarshallerTestCase;
import org.springframework.oxm.Marshaller;
import org.springframework.samples.flight.FlightType;
import org.springframework.samples.flight.FlightsDocument;
import org.springframework.samples.flight.FlightsDocument.Flights;
@Ignore
public class XmlBeansMarshallerTest extends AbstractMarshallerTestCase {
@Override
@Override
protected Marshaller createMarshaller() throws Exception {
return new XmlBeansMarshaller();
}
return new XmlBeansMarshaller();
}
public void testMarshalNonXmlObject() throws Exception {
try {
marshaller.marshal(new Object(), new StreamResult(new ByteArrayOutputStream()));
fail("XmlBeansMarshaller did not throw ClassCastException for non-XmlObject");
}
catch (ClassCastException e) {
// Expected behavior
}
}
@Override
@Override
protected Object createFlights() {
FlightsDocument flightsDocument = FlightsDocument.Factory.newInstance();
Flights flights = flightsDocument.addNewFlights();
FlightType flightType = flights.addNewFlight();
flightType.setNumber(42L);
return flightsDocument;
}
FlightsDocument flightsDocument = FlightsDocument.Factory.newInstance();
FlightsDocument.Flights flights = flightsDocument.addNewFlights();
FlightType flightType = flights.addNewFlight();
flightType.setNumber(42L);
return flightsDocument;
}
public void testSupports() throws Exception {
assertTrue("XmlBeansMarshaller does not support XmlObject", marshaller.supports(XmlObject.class));
assertFalse("XmlBeansMarshaller supports other objects", marshaller.supports(Object.class));
assertTrue("XmlBeansMarshaller does not support FlightsDocument", marshaller.supports(FlightsDocument.class));
assertTrue("XmlBeansMarshaller does not support Flights", marshaller.supports(Flights.class));
assertTrue("XmlBeansMarshaller does not support FlightType", marshaller.supports(FlightType.class));
}
@Test(expected = ClassCastException.class)
public void testMarshalNonXmlObject() throws Exception {
marshaller.marshal(new Object(), new StreamResult(new ByteArrayOutputStream()));
}
@Test
public void supports() throws Exception {
assertTrue("XmlBeansMarshaller does not support XmlObject", marshaller.supports(XmlObject.class));
assertFalse("XmlBeansMarshaller supports other objects", marshaller.supports(Object.class));
assertTrue("XmlBeansMarshaller does not support FlightsDocument", marshaller.supports(FlightsDocument.class));
assertTrue("XmlBeansMarshaller does not support Flights", marshaller.supports(FlightsDocument.Flights.class));
assertTrue("XmlBeansMarshaller does not support FlightType", marshaller.supports(FlightType.class));
}
}

View File

@@ -19,75 +19,70 @@ import java.io.StringReader;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.oxm.AbstractUnmarshallerTestCase;
import org.springframework.oxm.Unmarshaller;
import org.springframework.samples.flight.FlightDocument;
import org.springframework.samples.flight.FlightType;
import org.springframework.samples.flight.FlightsDocument;
import org.springframework.samples.flight.FlightsDocument.Flights;
import org.springframework.xml.transform.StaxSource;
import org.springframework.xml.transform.StringSource;
import org.springframework.util.xml.StaxUtils;
@Ignore
public class XmlBeansUnmarshallerTest extends AbstractUnmarshallerTestCase {
@Override
@Override
protected Unmarshaller createUnmarshaller() throws Exception {
return new XmlBeansMarshaller();
}
return new XmlBeansMarshaller();
}
@Override
@Override
protected void testFlights(Object o) {
FlightsDocument flightsDocument = (FlightsDocument) o;
assertNotNull("FlightsDocument is null", flightsDocument);
Flights flights = flightsDocument.getFlights();
assertEquals("Invalid amount of flight elements", 1, flights.sizeOfFlightArray());
testFlight(flights.getFlightArray(0));
}
FlightsDocument flightsDocument = (FlightsDocument) o;
assertNotNull("FlightsDocument is null", flightsDocument);
FlightsDocument.Flights flights = flightsDocument.getFlights();
assertEquals("Invalid amount of flight elements", 1, flights.sizeOfFlightArray());
testFlight(flights.getFlightArray(0));
}
@Override
@Override
protected void testFlight(Object o) {
FlightType flight = null;
if (o instanceof FlightType) {
flight = (FlightType) o;
}
else if (o instanceof FlightDocument) {
FlightDocument flightDocument = (FlightDocument) o;
flight = flightDocument.getFlight();
}
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
FlightType flight = null;
if (o instanceof FlightType) {
flight = (FlightType) o;
}
else if (o instanceof FlightDocument) {
FlightDocument flightDocument = (FlightDocument) o;
flight = flightDocument.getFlight();
}
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
@Override
public void testUnmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
StaxSource source = new StaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
@Override
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
Source source = StaxUtils.createStaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
public void testValidate() throws Exception {
((XmlBeansMarshaller) unmarshaller).setValidating(true);
try {
String invalidInput = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>abc</tns:number></tns:flight></tns:flights>";
unmarshaller.unmarshal(new StringSource(invalidInput));
fail("Expected a XmlBeansValidationFailureException");
}
catch (XmlBeansValidationFailureException ex) {
// expected
}
}
@Test(expected = XmlBeansValidationFailureException.class)
public void testValidate() throws Exception {
((XmlBeansMarshaller) unmarshaller).setValidating(true);
String invalidInput = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>abc</tns:number></tns:flight></tns:flights>";
unmarshaller.unmarshal(new StreamSource(new StringReader(invalidInput)));
}
}

View File

@@ -0,0 +1,61 @@
/*
* An XML document type.
* Localname: flight
* Namespace: http://samples.springframework.org/flight
* Java type: org.springframework.oxm.xmlbeans.FlightDocument
*
* Automatically generated - do not modify.
*/
package org.springframework.oxm.xmlbeans.impl;
/**
* A document containing one flight(@http://samples.springframework.org/flight) element.
*
* This is a complex type.
*/
public class FlightDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl
implements org.springframework.oxm.xmlbeans.FlightDocument {
public FlightDocumentImpl(org.apache.xmlbeans.SchemaType sType) {
super(sType);
}
private static final javax.xml.namespace.QName FLIGHT$0 =
new javax.xml.namespace.QName("http://samples.springframework.org/flight", "flight");
/** Gets the "flight" element */
public org.springframework.oxm.xmlbeans.FlightType getFlight() {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightType target = null;
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().find_element_user(FLIGHT$0, 0);
if (target == null) {
return null;
}
return target;
}
}
/** Sets the "flight" element */
public void setFlight(org.springframework.oxm.xmlbeans.FlightType flight) {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightType target = null;
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().find_element_user(FLIGHT$0, 0);
if (target == null) {
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().add_element_user(FLIGHT$0);
}
target.set(flight);
}
}
/** Appends and returns a new empty "flight" element */
public org.springframework.oxm.xmlbeans.FlightType addNewFlight() {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightType target = null;
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().add_element_user(FLIGHT$0);
return target;
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* XML Type: flightType
* Namespace: http://samples.springframework.org/flight
* Java type: org.springframework.samples.flight.FlightType
*
* Automatically generated - do not modify.
*/
package org.springframework.oxm.xmlbeans.impl;
/**
* An XML flightType(@http://samples.springframework.org/flight).
*
* This is a complex type.
*/
public class FlightTypeImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl
implements org.springframework.oxm.xmlbeans.FlightType {
public FlightTypeImpl(org.apache.xmlbeans.SchemaType sType) {
super(sType);
}
private static final javax.xml.namespace.QName NUMBER$0 =
new javax.xml.namespace.QName("http://samples.springframework.org/flight", "number");
/** Gets the "number" element */
public long getNumber() {
synchronized (monitor()) {
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue) get_store().find_element_user(NUMBER$0, 0);
if (target == null) {
return 0L;
}
return target.getLongValue();
}
}
/** Gets (as xml) the "number" element */
public org.apache.xmlbeans.XmlLong xgetNumber() {
synchronized (monitor()) {
check_orphaned();
org.apache.xmlbeans.XmlLong target = null;
target = (org.apache.xmlbeans.XmlLong) get_store().find_element_user(NUMBER$0, 0);
return target;
}
}
/** Sets the "number" element */
public void setNumber(long number) {
synchronized (monitor()) {
check_orphaned();
org.apache.xmlbeans.SimpleValue target = null;
target = (org.apache.xmlbeans.SimpleValue) get_store().find_element_user(NUMBER$0, 0);
if (target == null) {
target = (org.apache.xmlbeans.SimpleValue) get_store().add_element_user(NUMBER$0);
}
target.setLongValue(number);
}
}
/** Sets (as xml) the "number" element */
public void xsetNumber(org.apache.xmlbeans.XmlLong number) {
synchronized (monitor()) {
check_orphaned();
org.apache.xmlbeans.XmlLong target = null;
target = (org.apache.xmlbeans.XmlLong) get_store().find_element_user(NUMBER$0, 0);
if (target == null) {
target = (org.apache.xmlbeans.XmlLong) get_store().add_element_user(NUMBER$0);
}
target.set(number);
}
}
}

View File

@@ -0,0 +1,200 @@
/*
* An XML document type.
* Localname: flights
* Namespace: http://samples.springframework.org/flight
* Java type: org.springframework.samples.flight.FlightsDocument
*
* Automatically generated - do not modify.
*/
package org.springframework.oxm.xmlbeans.impl;
/**
* A document containing one flights(@http://samples.springframework.org/flight) element.
*
* This is a complex type.
*/
public class FlightsDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl
implements org.springframework.oxm.xmlbeans.FlightsDocument {
public FlightsDocumentImpl(org.apache.xmlbeans.SchemaType sType) {
super(sType);
}
private static final javax.xml.namespace.QName FLIGHTS$0 =
new javax.xml.namespace.QName("http://samples.springframework.org/flight", "flights");
/** Gets the "flights" element */
public org.springframework.oxm.xmlbeans.FlightsDocument.Flights getFlights() {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightsDocument.Flights target = null;
target = (org.springframework.oxm.xmlbeans.FlightsDocument.Flights) get_store()
.find_element_user(FLIGHTS$0, 0);
if (target == null) {
return null;
}
return target;
}
}
/** Sets the "flights" element */
public void setFlights(org.springframework.oxm.xmlbeans.FlightsDocument.Flights flights) {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightsDocument.Flights target = null;
target = (org.springframework.oxm.xmlbeans.FlightsDocument.Flights) get_store()
.find_element_user(FLIGHTS$0, 0);
if (target == null) {
target = (org.springframework.oxm.xmlbeans.FlightsDocument.Flights) get_store()
.add_element_user(FLIGHTS$0);
}
target.set(flights);
}
}
/** Appends and returns a new empty "flights" element */
public org.springframework.oxm.xmlbeans.FlightsDocument.Flights addNewFlights() {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightsDocument.Flights target = null;
target = (org.springframework.oxm.xmlbeans.FlightsDocument.Flights) get_store().add_element_user(FLIGHTS$0);
return target;
}
}
/**
* An XML flights(@http://samples.springframework.org/flight).
*
* This is a complex type.
*/
public static class FlightsImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl
implements org.springframework.oxm.xmlbeans.FlightsDocument.Flights {
public FlightsImpl(org.apache.xmlbeans.SchemaType sType) {
super(sType);
}
private static final javax.xml.namespace.QName FLIGHT$0 =
new javax.xml.namespace.QName("http://samples.springframework.org/flight", "flight");
/** Gets a List of "flight" elements */
public java.util.List<org.springframework.oxm.xmlbeans.FlightType> getFlightList() {
final class FlightList extends java.util.AbstractList<org.springframework.oxm.xmlbeans.FlightType> {
public org.springframework.oxm.xmlbeans.FlightType get(int i) {
return FlightsImpl.this.getFlightArray(i);
}
public org.springframework.oxm.xmlbeans.FlightType set(int i,
org.springframework.oxm.xmlbeans.FlightType o) {
org.springframework.oxm.xmlbeans.FlightType old = FlightsImpl.this.getFlightArray(i);
FlightsImpl.this.setFlightArray(i, o);
return old;
}
public void add(int i, org.springframework.oxm.xmlbeans.FlightType o) {
FlightsImpl.this.insertNewFlight(i).set(o);
}
public org.springframework.oxm.xmlbeans.FlightType remove(int i) {
org.springframework.oxm.xmlbeans.FlightType old = FlightsImpl.this.getFlightArray(i);
FlightsImpl.this.removeFlight(i);
return old;
}
public int size() {
return FlightsImpl.this.sizeOfFlightArray();
}
}
synchronized (monitor()) {
check_orphaned();
return new FlightList();
}
}
/** Gets array of all "flight" elements */
public org.springframework.oxm.xmlbeans.FlightType[] getFlightArray() {
synchronized (monitor()) {
check_orphaned();
java.util.List targetList = new java.util.ArrayList();
get_store().find_all_element_users(FLIGHT$0, targetList);
org.springframework.oxm.xmlbeans.FlightType[] result =
new org.springframework.oxm.xmlbeans.FlightType[targetList.size()];
targetList.toArray(result);
return result;
}
}
/** Gets ith "flight" element */
public org.springframework.oxm.xmlbeans.FlightType getFlightArray(int i) {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightType target = null;
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().find_element_user(FLIGHT$0, i);
if (target == null) {
throw new IndexOutOfBoundsException();
}
return target;
}
}
/** Returns number of "flight" element */
public int sizeOfFlightArray() {
synchronized (monitor()) {
check_orphaned();
return get_store().count_elements(FLIGHT$0);
}
}
/** Sets array of all "flight" element */
public void setFlightArray(org.springframework.oxm.xmlbeans.FlightType[] flightArray) {
synchronized (monitor()) {
check_orphaned();
arraySetterHelper(flightArray, FLIGHT$0);
}
}
/** Sets ith "flight" element */
public void setFlightArray(int i, org.springframework.oxm.xmlbeans.FlightType flight) {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightType target = null;
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().find_element_user(FLIGHT$0, i);
if (target == null) {
throw new IndexOutOfBoundsException();
}
target.set(flight);
}
}
/** Inserts and returns a new empty value (as xml) as the ith "flight" element */
public org.springframework.oxm.xmlbeans.FlightType insertNewFlight(int i) {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightType target = null;
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().insert_element_user(FLIGHT$0, i);
return target;
}
}
/** Appends and returns a new empty value (as xml) as the last "flight" element */
public org.springframework.oxm.xmlbeans.FlightType addNewFlight() {
synchronized (monitor()) {
check_orphaned();
org.springframework.oxm.xmlbeans.FlightType target = null;
target = (org.springframework.oxm.xmlbeans.FlightType) get_store().add_element_user(FLIGHT$0);
return target;
}
}
/** Removes the ith "flight" element */
public void removeFlight(int i) {
synchronized (monitor()) {
check_orphaned();
get_store().remove_element(FLIGHT$0, i);
}
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.oxm.xstream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("flight")
public class AnnotatedFlight {
@XStreamAlias("number")
private long flightNumber;
public long getFlightNumber() {
return flightNumber;
}
public void setFlightNumber(long number) {
this.flightNumber = number;
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.oxm.xstream;
import java.io.StringWriter;
import javax.xml.transform.stream.StreamResult;
import org.custommonkey.xmlunit.XMLTestCase;
public class AnnotationXStreamMarshallerTest extends XMLTestCase {
private AnnotationXStreamMarshaller marshaller;
private static final String EXPECTED_STRING = "<flight><number>42</number></flight>";
private Flight flight;
protected void setUp() throws Exception {
marshaller = new AnnotationXStreamMarshaller();
marshaller.setAnnotatedClass(Flight.class);
flight = new Flight();
flight.setFlightNumber(42L);
}
public void testMarshalStreamResultWriter() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
}

View File

@@ -17,7 +17,10 @@
package org.springframework.oxm.xstream;
import java.io.ByteArrayOutputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
@@ -27,196 +30,228 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import org.custommonkey.xmlunit.XMLTestCase;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
import org.easymock.MockControl;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.xml.sax.ContentHandler;
import org.springframework.xml.transform.StaxResult;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
import org.springframework.util.xml.StaxUtils;
public class XStreamMarshallerTest extends XMLTestCase {
public class XStreamMarshallerTest {
private static final String EXPECTED_STRING = "<flight><flightNumber>42</flightNumber></flight>";
private static final String EXPECTED_STRING = "<flight><flightNumber>42</flightNumber></flight>";
private XStreamMarshaller marshaller;
private XStreamMarshaller marshaller;
private Flight flight;
private AnnotatedFlight flight;
protected void setUp() throws Exception {
marshaller = new XStreamMarshaller();
Properties aliases = new Properties();
aliases.setProperty("flight", Flight.class.getName());
marshaller.setAliases(aliases);
flight = new Flight();
flight.setFlightNumber(42L);
}
@Before
public void createMarshaller() throws Exception {
marshaller = new XStreamMarshaller();
Properties aliases = new Properties();
aliases.setProperty("flight", AnnotatedFlight.class.getName());
marshaller.setAliases(aliases);
flight = new AnnotatedFlight();
flight.setFlightNumber(42L);
}
public void testMarshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.newDocument();
DOMResult domResult = new DOMResult(document);
marshaller.marshal(flight, domResult);
Document expected = builder.newDocument();
Element flightElement = expected.createElement("flight");
expected.appendChild(flightElement);
Element numberElement = expected.createElement("flightNumber");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
}
@Test
public void marshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.newDocument();
DOMResult domResult = new DOMResult(document);
marshaller.marshal(flight, domResult);
Document expected = builder.newDocument();
Element flightElement = expected.createElement("flight");
expected.appendChild(flightElement);
Element numberElement = expected.createElement("flightNumber");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
}
// see SWS-392
public void testMarshalDOMResultToExistentDocument() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document existent = builder.newDocument();
Element rootElement = existent.createElement("root");
Element flightsElement = existent.createElement("flights");
rootElement.appendChild(flightsElement);
existent.appendChild(rootElement);
// see SWS-392
@Test
public void marshalDOMResultToExistentDocument() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document existent = builder.newDocument();
Element rootElement = existent.createElement("root");
Element flightsElement = existent.createElement("flights");
rootElement.appendChild(flightsElement);
existent.appendChild(rootElement);
// marshall into the existent document
DOMResult domResult = new DOMResult(flightsElement);
marshaller.marshal(flight, domResult);
// marshall into the existent document
DOMResult domResult = new DOMResult(flightsElement);
marshaller.marshal(flight, domResult);
Document expected = builder.newDocument();
Element eRootElement = expected.createElement("root");
Element eFlightsElement = expected.createElement("flights");
Element eFlightElement = expected.createElement("flight");
eRootElement.appendChild(eFlightsElement);
eFlightsElement.appendChild(eFlightElement);
expected.appendChild(eRootElement);
Element eNumberElement = expected.createElement("flightNumber");
eFlightElement.appendChild(eNumberElement);
Text text = expected.createTextNode("42");
eNumberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, existent);
}
Document expected = builder.newDocument();
Element eRootElement = expected.createElement("root");
Element eFlightsElement = expected.createElement("flights");
Element eFlightElement = expected.createElement("flight");
eRootElement.appendChild(eFlightsElement);
eFlightsElement.appendChild(eFlightElement);
expected.appendChild(eRootElement);
Element eNumberElement = expected.createElement("flightNumber");
eFlightElement.appendChild(eNumberElement);
Text text = expected.createTextNode("42");
eNumberElement.appendChild(text);
assertXMLEqual("Marshaller writes invalid DOMResult", expected, existent);
}
public void testMarshalStreamResultWriter() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStreamResultWriter() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStreamResultOutputStream() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
marshaller.marshal(flight, result);
String s = new String(os.toByteArray(), "UTF-8");
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, s);
}
@Test
public void marshalStreamResultOutputStream() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
marshaller.marshal(flight, result);
String s = new String(os.toByteArray(), "UTF-8");
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, s);
}
public void testMarshalSaxResult() throws Exception {
MockControl handlerControl = MockControl.createStrictControl(ContentHandler.class);
handlerControl.setDefaultMatcher(MockControl.ALWAYS_MATCHER);
ContentHandler handlerMock = (ContentHandler) handlerControl.getMock();
handlerMock.startDocument();
handlerMock.startElement("", "flight", "flight", null);
handlerMock.startElement("", "number", "number", null);
handlerMock.characters(new char[]{'4', '2'}, 0, 2);
handlerMock.endElement("", "number", "number");
handlerMock.endElement("", "flight", "flight");
handlerMock.endDocument();
@Test
public void marshalSaxResult() throws Exception {
MockControl handlerControl = MockControl.createStrictControl(ContentHandler.class);
handlerControl.setDefaultMatcher(MockControl.ALWAYS_MATCHER);
ContentHandler handlerMock = (ContentHandler) handlerControl.getMock();
handlerMock.startDocument();
handlerMock.startElement("", "flight", "flight", null);
handlerMock.startElement("", "number", "number", null);
handlerMock.characters(new char[]{'4', '2'}, 0, 2);
handlerMock.endElement("", "number", "number");
handlerMock.endElement("", "flight", "flight");
handlerMock.endDocument();
handlerControl.replay();
SAXResult result = new SAXResult(handlerMock);
marshaller.marshal(flight, result);
handlerControl.verify();
}
handlerControl.replay();
SAXResult result = new SAXResult(handlerMock);
marshaller.marshal(flight, result);
handlerControl.verify();
}
public void testMarshalStaxResultXMLStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
StaxResult result = new StaxResult(streamWriter);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultXMLStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
Result result = StaxUtils.createStaxResult(streamWriter);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testMarshalStaxResultXMLEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StaxResult result = new StaxResult(eventWriter);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
@Test
public void marshalStaxResultXMLEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
Result result = StaxUtils.createStaxResult(eventWriter);
marshaller.marshal(flight, result);
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
}
public void testConverters() throws Exception {
marshaller.setConverters(new Converter[]{new EncodedByteArrayConverter()});
byte[] buf = new byte[]{0x1, 0x2};
StringResult result = new StringResult();
marshaller.marshal(buf, result);
assertXMLEqual("<byte-array>AQI=</byte-array>", result.toString());
StringSource source = new StringSource(result.toString());
byte[] bufResult = (byte[]) marshaller.unmarshal(source);
assertTrue("Invalid result", Arrays.equals(buf, bufResult));
}
@Test
public void converters() throws Exception {
marshaller.setConverters(new Converter[]{new EncodedByteArrayConverter()});
byte[] buf = new byte[]{0x1, 0x2};
Writer writer = new StringWriter();
marshaller.marshal(buf, new StreamResult(writer));
assertXMLEqual("<byte-array>AQI=</byte-array>", writer.toString());
Reader reader = new StringReader(writer.toString());
byte[] bufResult = (byte[]) marshaller.unmarshal(new StreamSource(reader));
assertTrue("Invalid result", Arrays.equals(buf, bufResult));
}
public void testUseAttributesFor() throws Exception {
marshaller.setUseAttributeForTypes(new Class[]{Long.TYPE});
StringResult result = new StringResult();
marshaller.marshal(flight, result);
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, result.toString());
}
@Test
public void useAttributesFor() throws Exception {
marshaller.setUseAttributeForTypes(new Class[]{Long.TYPE});
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
}
public void testUseAttributesForStringClassMap() throws Exception {
marshaller.setUseAttributeFor(Collections.singletonMap("flightNumber", Long.TYPE));
StringResult result = new StringResult();
marshaller.marshal(flight, result);
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, result.toString());
}
@Test
public void useAttributesForStringClassMap() throws Exception {
marshaller.setUseAttributeFor(Collections.singletonMap("flightNumber", Long.TYPE));
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
}
public void testUseAttributesForClassStringMap() throws Exception {
marshaller.setUseAttributeFor(Collections.singletonMap(Flight.class, "flightNumber"));
StringResult result = new StringResult();
marshaller.marshal(flight, result);
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, result.toString());
}
@Test
public void useAttributesForClassStringMap() throws Exception {
marshaller.setUseAttributeFor(Collections.singletonMap(AnnotatedFlight.class, "flightNumber"));
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight flightNumber=\"42\" />";
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
}
public void testOmitField() throws Exception {
marshaller.addOmittedField(Flight.class, "flightNumber");
StringResult result = new StringResult();
marshaller.marshal(flight, result);
assertXpathNotExists("/flight/flightNumber", result.toString());
}
@Test
public void omitField() throws Exception {
marshaller.addOmittedField(AnnotatedFlight.class, "flightNumber");
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
assertXpathNotExists("/flight/flightNumber", writer.toString());
}
public void testOmitFields() throws Exception {
Map omittedFieldsMap = Collections.singletonMap(Flight.class, "flightNumber");
marshaller.setOmittedFields(omittedFieldsMap);
StringResult result = new StringResult();
marshaller.marshal(flight, result);
assertXpathNotExists("/flight/flightNumber", result.toString());
}
@Test
public void omitFields() throws Exception {
Map omittedFieldsMap = Collections.singletonMap(AnnotatedFlight.class, "flightNumber");
marshaller.setOmittedFields(omittedFieldsMap);
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
assertXpathNotExists("/flight/flightNumber", writer.toString());
}
@Test
public void driver() throws Exception {
marshaller.setStreamDriver(new JettisonMappedXmlDriver());
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
assertEquals("Invalid result", "{\"flight\":{\"flightNumber\":42}}", writer.toString());
Object o = marshaller.unmarshal(new StreamSource(new StringReader(writer.toString())));
assertTrue("Unmarshalled object is not Flights", o instanceof AnnotatedFlight);
AnnotatedFlight unflight = (AnnotatedFlight) o;
assertNotNull("Flight is null", unflight);
assertEquals("Number is invalid", 42L, unflight.getFlightNumber());
}
@Test
public void testMarshalStreamResultWriter() throws Exception {
marshaller.setAnnotatedClass(AnnotatedFlight.class);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
AnnotatedFlight flight = new AnnotatedFlight();
flight.setFlightNumber(42);
marshaller.marshal(flight, result);
String expected = "<flight><number>42</number></flight>";
assertXMLEqual("Marshaller writes invalid StreamResult", expected, writer.toString());
}
public void testDriver() throws Exception {
marshaller.setStreamDriver(new JettisonMappedXmlDriver());
StringResult result = new StringResult();
marshaller.marshal(flight, result);
assertEquals("Invalid result", "{\"flight\":{\"flightNumber\":\"42\"}}", result.toString());
Object o = marshaller.unmarshal(new StringSource(result.toString()));
assertTrue("Unmarshalled object is not Flights", o instanceof Flight);
Flight unflight = (Flight) o;
assertNotNull("Flight is null", unflight);
assertEquals("Number is invalid", 42L, unflight.getFlightNumber());
}
}

View File

@@ -19,66 +19,73 @@ package org.springframework.oxm.xstream;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.springframework.xml.transform.StaxSource;
import org.springframework.util.xml.StaxUtils;
public class XStreamUnmarshallerTest extends TestCase {
public class XStreamUnmarshallerTest {
protected static final String INPUT_STRING = "<flight><flightNumber>42</flightNumber></flight>";
protected static final String INPUT_STRING = "<flight><flightNumber>42</flightNumber></flight>";
private XStreamMarshaller unmarshaller;
private XStreamMarshaller unmarshaller;
protected void setUp() throws Exception {
unmarshaller = new XStreamMarshaller();
Properties aliases = new Properties();
aliases.setProperty("flight", Flight.class.getName());
unmarshaller.setAliases(aliases);
}
@Before
public void creteUnmarshaller() throws Exception {
unmarshaller = new XStreamMarshaller();
Properties aliases = new Properties();
aliases.setProperty("flight", AnnotatedFlight.class.getName());
unmarshaller.setAliases(aliases);
}
private void testFlight(Object o) {
assertTrue("Unmarshalled object is not Flights", o instanceof Flight);
Flight flight = (Flight) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getFlightNumber());
}
private void testFlight(Object o) {
assertTrue("Unmarshalled object is not Flights", o instanceof AnnotatedFlight);
AnnotatedFlight flight = (AnnotatedFlight) o;
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getFlightNumber());
}
public void testUnmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(INPUT_STRING)));
DOMSource source = new DOMSource(document);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
@Test
public void unmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(INPUT_STRING)));
DOMSource source = new DOMSource(document);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
public void testUnmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
StaxSource source = new StaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
public void testUnmarshalStreamSourceInputStream() throws Exception {
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
@Test
public void unmarshalStreamSourceInputStream() throws Exception {
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
public void testUnmarshalStreamSourceReader() throws Exception {
StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
@Test
public void unmarshalStreamSourceReader() throws Exception {
StreamSource source = new StreamSource(new StringReader(INPUT_STRING));
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
}

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oxm="http://www.springframework.org/schema/oxm" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
<oxm:jaxb2-marshaller id="contextPathMarshaller" contextPath="org.springframework.oxm.jaxb2"/>
<oxm:jaxb2-marshaller id="classesMarshaller">
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb2.Flights"/>
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb2.FlightType"/>
</oxm:jaxb2-marshaller>
</beans>

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oxm="http://www.springframework.org/schema/oxm" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
<oxm:jaxb1-marshaller id="jaxb1Marshaller" contextPath="org.springframework.oxm.jaxb1"/>
<oxm:jibx-marshaller id="jibxMarshaller" target-class="org.springframework.oxm.jibx.Flights"/>
<oxm:xmlbeans-marshaller id="xmlBeansMarshaller" options="xmlBeansOptions"/>
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<!--<oxm:jibx-marshaller id="jibxMarshaller" target-class="org.springframework.oxm.jibx.Flights"/>-->
<oxm:xmlbeans-marshaller id="xmlBeansMarshaller" options="xmlBeansOptions"/>
<bean id="xmlBeansOptions" class="org.springframework.oxm.xmlbeans.XmlOptionsFactoryBean">
<property name="options">
@@ -14,4 +13,11 @@
</props>
</property>
</bean>
<oxm:jaxb2-marshaller id="contextPathMarshaller" contextPath="org.springframework.oxm.jaxb"/>
<oxm:jaxb2-marshaller id="classesMarshaller">
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb.Flights"/>
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb.FlightType"/>
</oxm:jaxb2-marshaller>
</beans>