SPR-8309 - Spring OXM schema improvement for CastorMarshaller
This commit is contained in:
parent
ac7d48e5a8
commit
9765fefeac
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -176,7 +176,14 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the package names of packages with the Castor descriptor classes.
|
* Set the names of package with the Castor descriptor classes.
|
||||||
|
*/
|
||||||
|
public void setTargetPackage(String targetPackage) {
|
||||||
|
this.targetPackages = new String[] {targetPackage};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the names of packages with the Castor descriptor classes.
|
||||||
*/
|
*/
|
||||||
public void setTargetPackages(String[] targetPackages) {
|
public void setTargetPackages(String[] targetPackages) {
|
||||||
this.targetPackages = targetPackages;
|
this.targetPackages = targetPackages;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2011 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.w3c.dom.Element;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parser for the <code><oxm:castor-marshaller/></code> element.
|
||||||
|
*
|
||||||
|
* @author Jakub Narloch
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
public class CastorMarshallerBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
|
||||||
|
|
||||||
|
private static final String CASTOR_MARSHALLER_CLASS_NAME = "org.springframework.oxm.castor.CastorMarshaller";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getBeanClassName(Element element) {
|
||||||
|
return CASTOR_MARSHALLER_CLASS_NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,6 +31,7 @@ public class OxmNamespaceHandler extends NamespaceHandlerSupport {
|
||||||
registerBeanDefinitionParser("jaxb2-marshaller", new Jaxb2MarshallerBeanDefinitionParser());
|
registerBeanDefinitionParser("jaxb2-marshaller", new Jaxb2MarshallerBeanDefinitionParser());
|
||||||
registerBeanDefinitionParser("jibx-marshaller", new JibxMarshallerBeanDefinitionParser());
|
registerBeanDefinitionParser("jibx-marshaller", new JibxMarshallerBeanDefinitionParser());
|
||||||
registerBeanDefinitionParser("xmlbeans-marshaller", new XmlBeansMarshallerBeanDefinitionParser());
|
registerBeanDefinitionParser("xmlbeans-marshaller", new XmlBeansMarshallerBeanDefinitionParser());
|
||||||
|
registerBeanDefinitionParser("castor-marshaller", new CastorMarshallerBeanDefinitionParser());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,46 @@
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
|
|
||||||
|
<xsd:element name="castor-marshaller">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:annotation>
|
||||||
|
<xsd:documentation
|
||||||
|
source="java:org.springframework.oxm.castor.CastorMarshaller">
|
||||||
|
Defines a Castor Marshaller.
|
||||||
|
</xsd:documentation>
|
||||||
|
<xsd:appinfo>
|
||||||
|
<tool:annotation>
|
||||||
|
<tool:exports type="org.springframework.oxm.castor.CastorMarshaller" />
|
||||||
|
</tool:annotation>
|
||||||
|
</xsd:appinfo>
|
||||||
|
</xsd:annotation>
|
||||||
|
<xsd:complexContent>
|
||||||
|
<xsd:extension base="beans:identifiedType">
|
||||||
|
<xsd:attribute name="encoding" type="xsd:string">
|
||||||
|
<xsd:annotation>
|
||||||
|
<xsd:documentation>The encoding to use for stream reading.</xsd:documentation>
|
||||||
|
</xsd:annotation>
|
||||||
|
</xsd:attribute>
|
||||||
|
<xsd:attribute name="target-class" type="classType">
|
||||||
|
<xsd:annotation>
|
||||||
|
<xsd:documentation>The target class to be bound with Castor marshaller.</xsd:documentation>
|
||||||
|
</xsd:annotation>
|
||||||
|
</xsd:attribute>
|
||||||
|
<xsd:attribute name="target-package" type="xsd:string">
|
||||||
|
<xsd:annotation>
|
||||||
|
<xsd:documentation>The target package that contains Castor descriptor classes.</xsd:documentation>
|
||||||
|
</xsd:annotation>
|
||||||
|
</xsd:attribute>
|
||||||
|
<xsd:attribute name="mapping-location" type="xsd:string">
|
||||||
|
<xsd:annotation>
|
||||||
|
<xsd:documentation>The path to Castor mapping file.</xsd:documentation>
|
||||||
|
</xsd:annotation>
|
||||||
|
</xsd:attribute>
|
||||||
|
</xsd:extension>
|
||||||
|
</xsd:complexContent>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
|
||||||
<xsd:simpleType name="classType">
|
<xsd:simpleType name="classType">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation source="java:java.lang.Class">A class supported by a marshaller.</xsd:documentation>
|
<xsd:documentation source="java:java.lang.Class">A class supported by a marshaller.</xsd:documentation>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright ${YEAR} the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,18 +17,24 @@
|
||||||
package org.springframework.oxm.config;
|
package org.springframework.oxm.config;
|
||||||
|
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
import org.springframework.oxm.castor.CastorMarshaller;
|
||||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||||
import org.springframework.oxm.jibx.JibxMarshaller;
|
|
||||||
import org.springframework.oxm.xmlbeans.XmlBeansMarshaller;
|
import org.springframework.oxm.xmlbeans.XmlBeansMarshaller;
|
||||||
|
|
||||||
public class OxmNamespaceHandlerTest {
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the {@link OxmNamespaceHandler} class.
|
||||||
|
*
|
||||||
|
* @author Arjen Poustma
|
||||||
|
* @author Jakub Narloch
|
||||||
|
*/
|
||||||
|
public class OxmNamespaceHandlerTests {
|
||||||
|
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
|
@ -37,12 +43,6 @@ public class OxmNamespaceHandlerTest {
|
||||||
applicationContext = new ClassPathXmlApplicationContext("oxmNamespaceHandlerTest.xml", getClass());
|
applicationContext = new ClassPathXmlApplicationContext("oxmNamespaceHandlerTest.xml", getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore
|
|
||||||
public void jibxMarshaller() throws Exception {
|
|
||||||
applicationContext.getBean("jibxMarshaller", JibxMarshaller.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xmlBeansMarshaller() throws Exception {
|
public void xmlBeansMarshaller() throws Exception {
|
||||||
XmlBeansMarshaller marshaller = applicationContext.getBean("xmlBeansMarshaller", XmlBeansMarshaller.class);
|
XmlBeansMarshaller marshaller = applicationContext.getBean("xmlBeansMarshaller", XmlBeansMarshaller.class);
|
||||||
|
|
@ -54,12 +54,37 @@ public class OxmNamespaceHandlerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jaxb2ContextPathMarshaller() throws Exception {
|
public void jaxb2ContextPathMarshaller() throws Exception {
|
||||||
applicationContext.getBean("contextPathMarshaller", Jaxb2Marshaller.class);
|
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ContextPathMarshaller", Jaxb2Marshaller.class);
|
||||||
|
assertNotNull(jaxb2Marshaller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jaxb2ClassesToBeBoundMarshaller() throws Exception {
|
public void jaxb2ClassesToBeBoundMarshaller() throws Exception {
|
||||||
applicationContext.getBean("classesMarshaller", Jaxb2Marshaller.class);
|
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ClassesMarshaller", Jaxb2Marshaller.class);
|
||||||
|
assertNotNull(jaxb2Marshaller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void castorEncodingMarshaller() throws Exception {
|
||||||
|
CastorMarshaller castorMarshaller = applicationContext.getBean("castorEncodingMarshaller", CastorMarshaller.class);
|
||||||
|
assertNotNull(castorMarshaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void castorTargetClassMarshaller() throws Exception {
|
||||||
|
CastorMarshaller castorMarshaller = applicationContext.getBean("castorTargetClassMarshaller", CastorMarshaller.class);
|
||||||
|
assertNotNull(castorMarshaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void castorTargetPackageMarshaller() throws Exception {
|
||||||
|
CastorMarshaller castorMarshaller = applicationContext.getBean("castorTargetPackageMarshaller", CastorMarshaller.class);
|
||||||
|
assertNotNull(castorMarshaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void castorMappingLocationMarshaller() throws Exception {
|
||||||
|
CastorMarshaller castorMarshaller = applicationContext.getBean("castorMappingLocationMarshaller", CastorMarshaller.class);
|
||||||
|
assertNotNull(castorMarshaller);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:oxm="http://www.springframework.org/schema/oxm"
|
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
|
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">
|
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">
|
||||||
<!--<oxm:jibx-marshaller id="jibxMarshaller" target-class="org.springframework.oxm.jibx.Flights"/>-->
|
|
||||||
<oxm:xmlbeans-marshaller id="xmlBeansMarshaller" options="xmlBeansOptions"/>
|
<!-- XMLBeans -->
|
||||||
|
<oxm:xmlbeans-marshaller id="xmlBeansMarshaller"
|
||||||
|
options="xmlBeansOptions" />
|
||||||
|
|
||||||
<bean id="xmlBeansOptions" class="org.springframework.oxm.xmlbeans.XmlOptionsFactoryBean">
|
<bean id="xmlBeansOptions" class="org.springframework.oxm.xmlbeans.XmlOptionsFactoryBean">
|
||||||
<property name="options">
|
<property name="options">
|
||||||
|
|
@ -14,10 +16,23 @@
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<oxm:jaxb2-marshaller id="contextPathMarshaller" contextPath="org.springframework.oxm.jaxb.test"/>
|
<!-- JAXB2 -->
|
||||||
<oxm:jaxb2-marshaller id="classesMarshaller">
|
<oxm:jaxb2-marshaller id="jaxb2ContextPathMarshaller"
|
||||||
|
contextPath="org.springframework.oxm.jaxb.test" />
|
||||||
|
|
||||||
|
<oxm:jaxb2-marshaller id="jaxb2ClassesMarshaller">
|
||||||
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb.test.Flights" />
|
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb.test.Flights" />
|
||||||
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb.test.FlightType" />
|
<oxm:class-to-be-bound name="org.springframework.oxm.jaxb.test.FlightType" />
|
||||||
</oxm:jaxb2-marshaller>
|
</oxm:jaxb2-marshaller>
|
||||||
|
|
||||||
|
<!-- Castor -->
|
||||||
|
|
||||||
|
<oxm:castor-marshaller id="castorEncodingMarshaller" encoding="ISO-8859-1" />
|
||||||
|
|
||||||
|
<oxm:castor-marshaller id="castorTargetClassMarshaller" target-class="org.springframework.oxm.castor.Flight" />
|
||||||
|
|
||||||
|
<oxm:castor-marshaller id="castorTargetPackageMarshaller" target-package="org.springframework.oxm.castor" />
|
||||||
|
|
||||||
|
<oxm:castor-marshaller id="castorMappingLocationMarshaller"
|
||||||
|
mapping-location="classpath:org/springframework/oxm/castor/mapping.xml" />
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue