Working on SWS-121

This commit is contained in:
Arjen Poutsma
2007-11-10 16:02:28 +00:00
parent 7ca4e47c60
commit d2adf7793c
13 changed files with 441 additions and 6 deletions

View File

@@ -0,0 +1,41 @@
/*
* 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

@@ -0,0 +1,11 @@
<?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/spring-ws/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/spring-ws/schema/oxm http://www.springframework.org/spring-ws/schema/oxm/spring-oxm-1.1.xsd">
<oxm:jaxb2-marshaller id="contextPathMarshaller" contextPath="org.springframework.oxm.jaxb2"/>
<oxm:jaxb2-marshaller id="classesMarshaller">
<oxm:class name="org.springframework.oxm.jaxb2.Flights"/>
<oxm:class name="org.springframework.oxm.jaxb2.FlightType"/>
</oxm:jaxb2-marshaller>
</beans>

View File

@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>spring-ws</artifactId>
<groupId>org.springframework.ws</groupId>
@@ -28,8 +29,8 @@
<configuration>
<tasks>
<ant antfile="${basedir}/build-maven2.xml" inheritRefs="true">
<property name="maven.test.skip" value="${maven.test.skip}" />
<target name="generate-test-sources" />
<property name="maven.test.skip" value="${maven.test.skip}"/>
<target name="generate-test-sources"/>
</ant>
</tasks>
<testSourceRoot>${project.build.directory}/generated-sources/test/java</testSourceRoot>
@@ -44,8 +45,8 @@
<configuration>
<tasks>
<ant antfile="${basedir}/build-maven2.xml" inheritRefs="true">
<property name="maven.test.skip" value="${maven.test.skip}" />
<target name="test-compile" />
<property name="maven.test.skip" value="${maven.test.skip}"/>
<target name="test-compile"/>
</ant>
</tasks>
</configuration>
@@ -80,6 +81,12 @@
<groupId>org.springframework.ws</groupId>
<artifactId>spring-xml</artifactId>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>test</scope>
</dependency>
<!-- XML handling dependencies -->
<dependency>
<groupId>xml-apis</groupId>
@@ -243,4 +250,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2007, Your Corporation. All Rights Reserved.
*/
package org.springframework.oxm.config;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.oxm.jaxb.Jaxb1Marshaller;
import org.w3c.dom.Element;
/**
* Parser for the <code>&lt;oxm:jaxb1-marshaller/&gt; element.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
class Jaxb1MarshallerBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
protected Class getBeanClass(Element element) {
return Jaxb1Marshaller.class;
}
}

View File

@@ -0,0 +1,62 @@
/*
* 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.config;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
* Parser for the <code>&lt;oxm:jaxb2-marshaller/&gt; element.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
public class Jaxb2MarshallerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
public static final String JAXB2_MARSHALLER_BEAN_NAME = "org.springframework.oxm.jaxb.Jaxb2Marshaller";
protected String getBeanClassName(Element element) {
return JAXB2_MARSHALLER_BEAN_NAME;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
String contextPath = element.getAttribute("contextPath");
if (StringUtils.hasText(contextPath)) {
beanDefinitionBuilder.addPropertyValue("contextPath", contextPath);
}
List classes = DomUtils.getChildElementsByTagName(element, "class");
if (!classes.isEmpty()) {
ManagedList classesToBeBound = new ManagedList();
for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
Element classToBeBound = (Element) iterator.next();
String className = classToBeBound.getAttribute("name");
classesToBeBound.add(className);
}
beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound);
}
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2007, Your Corporation. All Rights Reserved.
*/
package org.springframework.oxm.config;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.oxm.jibx.JibxMarshaller;
import org.w3c.dom.Element;
/**
* Parser for the <code>&lt;oxm:jibx-marshaller/&gt; element.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
class JibxMarshallerBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
protected Class getBeanClass(Element element) {
return JibxMarshaller.class;
}
}

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2007, Your Corporation. All Rights Reserved.
*/
package org.springframework.oxm.config;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/** @author Arjen Poutsma */
public class OxmNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
registerBeanDefinitionParser("jaxb1-marshaller", new Jaxb1MarshallerBeanDefinitionParser());
registerBeanDefinitionParser("jaxb2-marshaller", new Jaxb2MarshallerBeanDefinitionParser());
registerBeanDefinitionParser("jibx-marshaller", new JibxMarshallerBeanDefinitionParser());
registerBeanDefinitionParser("xmlbeans-marshaller", new XmlBeansMarshallerBeanDefinitionParser());
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2007, Your Corporation. All Rights Reserved.
*/
package org.springframework.oxm.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.oxm.xmlbeans.XmlBeansMarshaller;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Parser for the <code>&lt;oxm:xmlbeans-marshaller/&gt; element.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
class XmlBeansMarshallerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
protected Class getBeanClass(Element element) {
return XmlBeansMarshaller.class;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
String optionsName = element.getAttribute("options");
if (StringUtils.hasText(optionsName)) {
beanDefinitionBuilder.addPropertyReference("xmlOptions", optionsName);
}
}
}

View File

@@ -0,0 +1 @@
http\://www.springframework.org/spring-ws/schema/oxm=org.springframework.oxm.config.OxmNamespaceHandler

View File

@@ -0,0 +1 @@
http\://www.springframework.org/spring-ws/schema/oxm/spring-oxm-1.1.xsd=/org/springframework/oxm/config/spring-oxm-1.1.xsd

View File

@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://www.springframework.org/spring-ws/schema/oxm" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tool="http://www.springframework.org/schema/tool"
targetNamespace="http://www.springframework.org/spring-ws/schema/oxm" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
<xsd:annotation>
<xsd:documentation>
Defines the elements used in Spring's Object/XML Mapping integration.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="jaxb1-marshaller">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation source="java:org.springframework.oxm.jaxb.Jaxb1Marshaller">
Defines a JAXB1 Marshaller.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.oxm.jaxb.Jaxb1Marshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:attribute name="contextPath" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>The JAXB Context path</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="validating" type="xsd:boolean" default="false">
<xsd:annotation>
<xsd:documentation>Whether incoming XML should be validated.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="jaxb2-marshaller">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation source="java:org.springframework.oxm.jaxb.Jaxb2Marshaller">
Defines a JAXB2 Marshaller.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.oxm.jaxb.Jaxb2Marshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:sequence>
<xsd:element name="class" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="name" type="classType" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="contextPath" type="xsd:string">
<xsd:annotation>
<xsd:documentation>The JAXB Context path</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="jibx-marshaller">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation source="java:org.springframework.oxm.jibx.JibxMarshaller">
Defines a JiBX Marshaller.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.oxm.jibx.JibxMarshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:attribute name="target-class" type="classType" use="required"/>
<xsd:attribute name="bindingName" type="xsd:string">
<xsd:annotation>
<xsd:documentation>The binding name used by this marshaller.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="xmlbeans-marshaller">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation source="java:org.springframework.oxm.xmlbeans.XmlBeansMarshaller">
Defines a XMLBeans Marshaller.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:attribute name="options" type="xsd:string">
<xsd:annotation>
<xsd:documentation source="java:org.apache.xmlbeans.XmlOptions">
The bean name of the XmlOptions that is to be used for this marshaller. Typically a
XmlOptionsFactoryBean definition.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.apache.xmlbeans.XmlOptions"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="classType">
<xsd:annotation>
<xsd:documentation source="java:java.lang.Class">A class supported by a marshaller.</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="direct">
<tool:expected-type type="java.lang.Class"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:union memberTypes="xsd:string"/>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,52 @@
/*
* 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.Jaxb1Marshaller;
import org.springframework.oxm.jibx.JibxMarshaller;
import org.springframework.oxm.xmlbeans.XmlBeansMarshaller;
import junit.framework.TestCase;
import org.apache.xmlbeans.XmlOptions;
public class OxmNamespaceHandlerTest extends TestCase {
private ApplicationContext applicationContext;
protected void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("oxmNamespaceHandlerTest.xml", getClass());
}
public void testJaxb1Marshaller() throws Exception {
applicationContext.getBean("jaxb1Marshaller", Jaxb1Marshaller.class);
}
public void testJibxMarshaller() throws Exception {
applicationContext.getBean("jibxMarshaller", JibxMarshaller.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,17 @@
<?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/spring-ws/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/spring-ws/schema/oxm http://www.springframework.org/spring-ws/schema/oxm/spring-oxm-1.1.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"/>
<bean id="xmlBeansOptions" class="org.springframework.oxm.xmlbeans.XmlOptionsFactoryBean">
<property name="options">
<props>
<prop key="SAVE_PRETTY_PRINT">true</prop>
</props>
</property>
</bean>
</beans>