Author: cmueller Date: Mon Apr 1 17:10:08 2013 New Revision: 1463208 URL: http://svn.apache.org/r1463208 Log: CAMEL-5278: Allow JaxbDataFormat to (un)marshall with strict schema validation
Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatSchemaValidationTest.java camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/Address.java camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/ObjectFactory.java camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/package-info.java camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/ObjectFactory.java camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/Person.java camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/package-info.java camel/trunk/components/camel-jaxb/src/test/resources/address.xsd camel/trunk/components/camel-jaxb/src/test/resources/person.xsd Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java?rev=1463208&r1=1463207&r2=1463208&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java Mon Apr 1 17:10:08 2013 @@ -37,6 +37,8 @@ public class JaxbDataFormat extends Data @XmlAttribute(required = true) private String contextPath; @XmlAttribute + private String schema; + @XmlAttribute private Boolean prettyPrint; @XmlAttribute private Boolean ignoreJAXBElement; @@ -71,6 +73,14 @@ public class JaxbDataFormat extends Data this.contextPath = contextPath; } + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + public Boolean getPrettyPrint() { return prettyPrint; } @@ -174,6 +184,8 @@ public class JaxbDataFormat extends Data setProperty(dataFormat, "namespacePrefixRef", namespacePrefixRef); } setProperty(dataFormat, "contextPath", contextPath); + if (schema != null) { + setProperty(dataFormat, "schema", schema); + } } - } \ No newline at end of file Modified: camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java?rev=1463208&r1=1463207&r2=1463208&view=diff ============================================================================== --- camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java (original) +++ camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java Mon Apr 1 17:10:08 2013 @@ -16,22 +16,35 @@ */ package org.apache.camel.converter.jaxb; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Map; + +import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.bind.ValidationEvent; +import javax.xml.bind.ValidationEventHandler; import javax.xml.namespace.QName; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.xml.sax.SAXException; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; @@ -42,6 +55,7 @@ import org.apache.camel.support.ServiceS import org.apache.camel.util.CamelContextHelper; import org.apache.camel.util.IOHelper; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.ResourceHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,9 +68,11 @@ import org.slf4j.LoggerFactory; public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelContextAware { private static final transient Logger LOG = LoggerFactory.getLogger(JaxbDataFormat.class); + private static final transient SchemaFactory SCHEMA_FACTORY = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); private CamelContext camelContext; private JAXBContext context; private String contextPath; + private String schema; private boolean prettyPrint = true; private boolean ignoreJAXBElement = true; private boolean filterNonXmlChars; @@ -83,10 +99,11 @@ public class JaxbDataFormat extends Serv this.contextPath = contextPath; } - public void marshal(Exchange exchange, Object graph, OutputStream stream) throws IOException { + public void marshal(Exchange exchange, Object graph, OutputStream stream) throws IOException, SAXException { try { // must create a new instance of marshaller as its not thread safe - Marshaller marshaller = getContext().createMarshaller(); + Marshaller marshaller = createMarshaller(); + if (isPrettyPrint()) { marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); } @@ -136,7 +153,7 @@ public class JaxbDataFormat extends Serv return filteringWriter; } - public Object unmarshal(Exchange exchange, InputStream stream) throws IOException { + public Object unmarshal(Exchange exchange, InputStream stream) throws IOException, SAXException { try { Object answer; @@ -197,6 +214,14 @@ public class JaxbDataFormat extends Serv this.contextPath = contextPath; } + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + public boolean isPrettyPrint() { return prettyPrint; } @@ -315,8 +340,44 @@ public class JaxbDataFormat extends Serv } } - protected Unmarshaller createUnmarshaller() throws JAXBException { - return getContext().createUnmarshaller(); + protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException { + Unmarshaller unmarshaller = getContext().createUnmarshaller(); + if (schema != null) { + Schema newSchema = SCHEMA_FACTORY.newSchema(getSources()); + unmarshaller.setSchema(newSchema); + unmarshaller.setEventHandler(new ValidationEventHandler() { + public boolean handleEvent(ValidationEvent event) { + // stop unmarshalling if the event is an ERROR or FATAL ERROR + return event.getSeverity() == 0; + } + }); + } + return unmarshaller; + } + + protected Marshaller createMarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException { + Marshaller marshaller = getContext().createMarshaller(); + if (schema != null) { + Schema newSchema = SCHEMA_FACTORY.newSchema(getSources()); + marshaller.setSchema(newSchema); + marshaller.setEventHandler(new ValidationEventHandler() { + public boolean handleEvent(ValidationEvent event) { + // stop marshalling if the event is an ERROR or FATAL ERROR + return event.getSeverity() == 0; + } + }); + } + return marshaller; } + private Source[] getSources() throws FileNotFoundException, MalformedURLException { + // we support multiple schema by delimiting they by ',' + String[] schemas = schema.split(","); + Source[] sources = new Source[schemas.length]; + for (int i = 0; i < schemas.length; i++) { + URL schemaUrl = ResourceHelper.resolveMandatoryResourceAsUrl(camelContext.getClassResolver(), schemas[i]); + sources[i] = new StreamSource(schemaUrl.toExternalForm()); + } + return sources; + } } Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatSchemaValidationTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatSchemaValidationTest.java?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatSchemaValidationTest.java (added) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatSchemaValidationTest.java Mon Apr 1 17:10:08 2013 @@ -0,0 +1,144 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.converter.jaxb; + +import java.io.IOException; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.converter.jaxb.address.Address; +import org.apache.camel.converter.jaxb.person.Person; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JaxbDataFormatSchemaValidationTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:marshall") + private MockEndpoint mockMarshall; + + @EndpointInject(uri = "mock:unmarshall") + private MockEndpoint mockUnmarshall; + + @Test + public void testMarshallSuccess() throws Exception { + mockMarshall.expectedMessageCount(1); + + Address address = new Address(); + address.setAddressLine1("Hauptstr. 1; 01129 Entenhausen"); + Person person = new Person(); + person.setFirstName("Christian"); + person.setLastName("Mueller"); + person.setAge(Integer.valueOf(36)); + person.setAddress(address); + + template.sendBody("direct:marshall", person); + + assertMockEndpointsSatisfied(); + + String payload = mockMarshall.getExchanges().get(0).getIn().getBody(String.class); + log.info(payload); + + assertTrue(payload.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")); + assertTrue(payload.contains("<person xmlns=\"person.jaxb.converter.camel.apache.org\" xmlns:ns2=\"address.jaxb.converter.camel.apache.org\">")); + assertTrue(payload.contains("<firstName>Christian</firstName>")); + assertTrue(payload.contains("<lastName>Mueller</lastName>")); + assertTrue(payload.contains("<age>36</age>")); + assertTrue(payload.contains("<address>")); + assertTrue(payload.contains("<ns2:addressLine1>Hauptstr. 1; 01129 Entenhausen</ns2:addressLine1>")); + assertTrue(payload.contains("</address>")); + assertTrue(payload.contains("</person>")); + } + + @Test + public void testMarshallWithValidationException() throws Exception { + try { + template.sendBody("direct:marshall", new Person()); + fail("CamelExecutionException expected"); + } catch (CamelExecutionException e) { + Throwable cause = e.getCause(); + assertIsInstanceOf(IOException.class, cause); + assertTrue(cause.getMessage().contains("javax.xml.bind.MarshalException")); + assertTrue(cause.getMessage().contains("org.xml.sax.SAXParseException")); + assertTrue(cause.getMessage().contains("Invalid content was found")); + } + } + + @Test + public void testUnmarshallSuccess() throws Exception { + mockUnmarshall.expectedMessageCount(1); + + String xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>") + .append("<person xmlns=\"person.jaxb.converter.camel.apache.org\" xmlns:ns2=\"address.jaxb.converter.camel.apache.org\">") + .append("<firstName>Christian</firstName>") + .append("<lastName>Mueller</lastName>") + .append("<age>36</age>") + .append("<address>") + .append("<ns2:addressLine1>Hauptstr. 1; 01129 Entenhausen</ns2:addressLine1>") + .append("</address>") + .append("</person>") + .toString(); + template.sendBody("direct:unmarshall", xml); + + assertMockEndpointsSatisfied(); + + Person person = mockUnmarshall.getExchanges().get(0).getIn().getBody(Person.class); + + assertEquals("Christian", person.getFirstName()); + assertEquals("Mueller", person.getLastName()); + assertEquals(Integer.valueOf(36), person.getAge()); + } + + @Test + public void testUnmarshallWithValidationException() throws Exception { + String xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>") + .append("<person xmlns=\"person.jaxb.converter.camel.apache.org\" />") + .toString(); + + try { + template.sendBody("direct:unmarshall", xml); + fail("CamelExecutionException expected"); + } catch (CamelExecutionException e) { + Throwable cause = e.getCause(); + assertIsInstanceOf(IOException.class, cause); + assertTrue(cause.getMessage().contains("javax.xml.bind.UnmarshalException")); + assertTrue(cause.getMessage().contains("org.xml.sax.SAXParseException")); + assertTrue(cause.getMessage().contains("The content of element 'person' is not complete")); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(); + jaxbDataFormat.setContextPath(Person.class.getPackage().getName()); + jaxbDataFormat.setSchema("classpath:person.xsd,classpath:address.xsd"); + + from("direct:marshall") + .marshal(jaxbDataFormat) + .to("mock:marshall"); + + from("direct:unmarshall") + .unmarshal(jaxbDataFormat) + .to("mock:unmarshall"); + } + }; + } +} \ No newline at end of file Modified: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatTest.java?rev=1463208&r1=1463207&r2=1463208&view=diff ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatTest.java (original) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatTest.java Mon Apr 1 17:10:08 2013 @@ -71,5 +71,4 @@ public class JaxbDataFormatTest { assertFalse(jaxbDataFormat.needFiltering(exchange)); } - } Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/Address.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/Address.java?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/Address.java (added) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/Address.java Mon Apr 1 17:10:08 2013 @@ -0,0 +1,110 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.converter.jaxb.address; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +/** + * <p>Java class for address complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * <complexType name="address"> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="addressLine1" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="addressLine2" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "address", propOrder = {"addressLine1", "addressLine2"}) +public class Address { + + @XmlElement(required = true) + protected String addressLine1; + protected String addressLine2; + + /** + * Gets the value of the addressLine1 property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAddressLine1() { + return addressLine1; + } + + /** + * Sets the value of the addressLine1 property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAddressLine1(String value) { + this.addressLine1 = value; + } + + /** + * Gets the value of the addressLine2 property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAddressLine2() { + return addressLine2; + } + + /** + * Sets the value of the addressLine2 property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAddressLine2(String value) { + this.addressLine2 = value; + } + + public Address withAddressLine1(String value) { + setAddressLine1(value); + return this; + } + + public Address withAddressLine2(String value) { + setAddressLine2(value); + return this; + } + +} Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/ObjectFactory.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/ObjectFactory.java?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/ObjectFactory.java (added) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/ObjectFactory.java Mon Apr 1 17:10:08 2013 @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.converter.jaxb.address; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the org.apache.camel.converter.jaxb.address 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 { + + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.apache.camel.converter.jaxb.address + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Address } + * + */ + public Address createAddress() { + return new Address(); + } + +} Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/package-info.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/package-info.java?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/package-info.java (added) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/address/package-info.java Mon Apr 1 17:10:08 2013 @@ -0,0 +1,18 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +@javax.xml.bind.annotation.XmlSchema(namespace = "address.jaxb.converter.camel.apache.org", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +package org.apache.camel.converter.jaxb.address; Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/ObjectFactory.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/ObjectFactory.java?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/ObjectFactory.java (added) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/ObjectFactory.java Mon Apr 1 17:10:08 2013 @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.converter.jaxb.person; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the org.apache.camel.converter.jaxb.person 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 { + + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.apache.camel.converter.jaxb.person + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Person } + * + */ + public Person createPerson() { + return new Person(); + } + +} Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/Person.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/Person.java?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/Person.java (added) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/Person.java Mon Apr 1 17:10:08 2013 @@ -0,0 +1,179 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.converter.jaxb.person; + +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; +import org.apache.camel.converter.jaxb.address.Address; + + +/** + * <p>Java class for anonymous complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="firstName" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="lastName" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="age" type="{http://www.w3.org/2001/XMLSchema}int"/> + * <element name="address" type="{address.jaxb.converter.camel.apache.org}address"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"firstName", "lastName", "age", "address"}) +@XmlRootElement(name = "person") +public class Person { + + @XmlElement(required = true) + protected String firstName; + @XmlElement(required = true) + protected String lastName; + @XmlElement(required = true, type = Integer.class, nillable = true) + protected Integer age; + @XmlElement(required = true) + protected Address address; + + /** + * Gets the value of the firstName property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getFirstName() { + return firstName; + } + + /** + * Sets the value of the firstName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setFirstName(String value) { + this.firstName = value; + } + + /** + * Gets the value of the lastName property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLastName() { + return lastName; + } + + /** + * Sets the value of the lastName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLastName(String value) { + this.lastName = value; + } + + /** + * Gets the value of the age property. + * + * @return + * possible object is + * {@link Integer } + * + */ + public Integer getAge() { + return age; + } + + /** + * Sets the value of the age property. + * + * @param value + * allowed object is + * {@link Integer } + * + */ + public void setAge(Integer value) { + this.age = value; + } + + /** + * Gets the value of the address property. + * + * @return + * possible object is + * {@link Address } + * + */ + public Address getAddress() { + return address; + } + + /** + * Sets the value of the address property. + * + * @param value + * allowed object is + * {@link Address } + * + */ + public void setAddress(Address value) { + this.address = value; + } + + public Person withFirstName(String value) { + setFirstName(value); + return this; + } + + public Person withLastName(String value) { + setLastName(value); + return this; + } + + public Person withAge(Integer value) { + setAge(value); + return this; + } + + public Person withAddress(Address value) { + setAddress(value); + return this; + } + +} Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/package-info.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/package-info.java?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/package-info.java (added) +++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/person/package-info.java Mon Apr 1 17:10:08 2013 @@ -0,0 +1,18 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +@javax.xml.bind.annotation.XmlSchema(namespace = "person.jaxb.converter.camel.apache.org", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +package org.apache.camel.converter.jaxb.person; Added: camel/trunk/components/camel-jaxb/src/test/resources/address.xsd URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/resources/address.xsd?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/resources/address.xsd (added) +++ camel/trunk/components/camel-jaxb/src/test/resources/address.xsd Mon Apr 1 17:10:08 2013 @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<xs:schema attributeFormDefault="unqualified" + elementFormDefault="qualified" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:p="org.person" + targetNamespace="address.jaxb.converter.camel.apache.org"> + + <xs:complexType name="address"> + <xs:sequence> + <xs:element name="addressLine1" type="xs:string" minOccurs="1" /> + <xs:element name="addressLine2" type="xs:string" minOccurs="0"/> + </xs:sequence> + </xs:complexType> +</xs:schema> \ No newline at end of file Added: camel/trunk/components/camel-jaxb/src/test/resources/person.xsd URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/resources/person.xsd?rev=1463208&view=auto ============================================================================== --- camel/trunk/components/camel-jaxb/src/test/resources/person.xsd (added) +++ camel/trunk/components/camel-jaxb/src/test/resources/person.xsd Mon Apr 1 17:10:08 2013 @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<xs:schema attributeFormDefault="unqualified" + elementFormDefault="qualified" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:a="address.jaxb.converter.camel.apache.org" + targetNamespace="person.jaxb.converter.camel.apache.org"> + + <xs:import schemaLocation="address.xsd" namespace="address.jaxb.converter.camel.apache.org" /> + + <xs:element name="person"> + <xs:complexType> + <xs:sequence> + <xs:element name="firstName" type="xs:string" minOccurs="1" /> + <xs:element name="lastName" type="xs:string" minOccurs="1"/> + <xs:element name="age" type="xs:int" nillable="true" minOccurs="1"/> + <xs:element name="address" type="a:address" minOccurs="1" /> + </xs:sequence> + </xs:complexType> + </xs:element> +</xs:schema> \ No newline at end of file