This commit is contained in:
Arjen Poutsma
2007-11-14 04:38:56 +00:00
parent b1a1a5a433
commit c635d1826d
18 changed files with 511 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
/*
* 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.ws.config;
import java.io.IOException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.XmlMappingException;
/**
* @author Arjen Poutsma
* @since 1.1.0
*/
public class DummyMarshaller implements Marshaller, Unmarshaller {
public void marshal(Object graph, Result result) throws XmlMappingException, IOException {
throw new UnsupportedOperationException();
}
public boolean supports(Class clazz) {
throw new UnsupportedOperationException();
}
public Object unmarshal(Source source) throws XmlMappingException, IOException {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.ws.config;
import java.util.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter;
import org.springframework.ws.server.endpoint.adapter.XPathParamAnnotationMethodEndpointAdapter;
import junit.framework.TestCase;
public class SwsNamespaceHandlerTigerTest extends TestCase {
private ApplicationContext applicationContext;
protected void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("swsNamespaceHandlerTest-tiger.xml", getClass());
}
public void testMarshallingEndpoints() throws Exception {
Map result = applicationContext.getBeansOfType(GenericMarshallingMethodEndpointAdapter.class);
assertFalse("no MarshallingMethodEndpointAdapter found", result.isEmpty());
}
public void testXpathEndpoints() throws Exception {
Map result = applicationContext.getBeansOfType(XPathParamAnnotationMethodEndpointAdapter.class);
assertFalse("no XPathParamAnnotationMethodEndpointAdapter found", result.isEmpty());
}
}

View File

@@ -0,0 +1,19 @@
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:sws="http://www.springframework.org/spring-ws/schema/sws" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/beans/spring-tx-2.0.xsd
http://www.springframework.org/spring-ws/schema/sws http://www.springframework.org/spring-ws/schema/sws/spring-ws-1.1.xsd">
<sws:marshalling-endpoints/>
<bean id="marshaller" class="org.springframework.ws.config.DummyMarshaller"/>
<sws:xpath-endpoints>
<sws:namespace prefix="sws" uri="http://www.springframework.org/spring-ws"/>
</sws:xpath-endpoints>
</beans>

View File

@@ -0,0 +1,70 @@
/*
* 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.ws.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.core.JdkVersion;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Parser for the <code>&lt;sws:marshalling-endpoints/&gt; element.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
class MarshallingEndpointsBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
private static final String GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME =
"org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter";
private static final String MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME =
"org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter";
protected boolean shouldGenerateIdAsFallback() {
return true;
}
protected String getBeanClassName(Element element) {
if (JdkVersion.isAtLeastJava15()) {
try {
ClassUtils.forName(GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME);
return GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
}
catch (ClassNotFoundException e) {
// ignore, fall through;
}
}
return MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
String marshallerName = element.getAttribute("marshaller");
if (StringUtils.hasText(marshallerName)) {
beanDefinitionBuilder.addPropertyReference("marshaller", marshallerName);
}
String unmarshallerName = element.getAttribute("unmarshaller");
if (StringUtils.hasText(unmarshallerName)) {
beanDefinitionBuilder.addPropertyReference("unmarshaller", unmarshallerName);
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.ws.config;
import org.springframework.beans.factory.xml.NamespaceHandler;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/**
* {@link NamespaceHandler} for the '<code>sws</code>' namespace.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
public class SwsNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
registerBeanDefinitionParser("marshalling-endpoints", new MarshallingEndpointsBeanDefinitionParser());
registerBeanDefinitionParser("xpath-endpoints", new XPathEndpointsBeanDefinitionParser());
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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.ws.config;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
* Parser for the <code>&lt;sws:xpath-endpoints/&gt; element.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
class XPathEndpointsBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
private static final String XPATH_PARAM_ANNOTATION_METHOD_ENDPOINT_ADAPTER_CLASS_NAME =
"org.springframework.ws.server.endpoint.adapter.XPathParamAnnotationMethodEndpointAdapter";
protected boolean shouldGenerateIdAsFallback() {
return true;
}
protected String getBeanClassName(Element element) {
return XPATH_PARAM_ANNOTATION_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
List namespaceElements = DomUtils.getChildElementsByTagName(element, "namespace");
if (!namespaceElements.isEmpty()) {
Properties namespaces = new Properties();
for (Iterator iterator = namespaceElements.iterator(); iterator.hasNext();) {
Element namespaceElement = (Element) iterator.next();
String prefix = namespaceElement.getAttribute("prefix");
String uri = namespaceElement.getAttribute("uri");
namespaces.setProperty(prefix, uri);
}
beanDefinitionBuilder.addPropertyValue("namespaces", namespaces);
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://www.springframework.org/spring-ws/schema/sws" 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/sws" 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 configuration elements for Spring Web Services.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="marshalling-endpoints">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
Indicates that a unmarshaller should be used to convert incoming request
messages into method parameters, and return values marshalled into a response message.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="unmarshaller" type="xsd:string" default="marshaller">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.oxm.Unmarshaller">
The bean name of the Unmarshaller that is to be used to convert XML into objects.
This attribute is not required, and only needs to be specified
explicitly if the bean name of the desired Unmarshaller
is not 'marshaller'.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.oxm.Unmarshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="marshaller" type="xsd:string" default="marshaller">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.oxm.Marshaller">
The bean name of the Marshaller that is to be used to convert objects into XML.
This attribute is not required, and only needs to be specified
explicitly if the bean name of the desired Marshaller
is not 'marshaller'.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.oxm.Marshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="xpath-endpoints">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
Indicates that a endpoints using @XPathParam annotations should be detected.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="namespace" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Bind a namespace URI to a prefix
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="prefix" type="xsd:string" use="required"/>
<xsd:attribute name="uri" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

View File

@@ -0,0 +1,44 @@
/*
* 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.ws.config;
import java.io.IOException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.XmlMappingException;
/**
* @author Arjen Poutsma
* @since 1.1.0
*/
public class DummyMarshaller implements Marshaller, Unmarshaller {
public void marshal(Object graph, Result result) throws XmlMappingException, IOException {
throw new UnsupportedOperationException();
}
public boolean supports(Class clazz) {
throw new UnsupportedOperationException();
}
public Object unmarshal(Source source) throws XmlMappingException, IOException {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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.ws.config;
import java.util.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter;
import junit.framework.TestCase;
public class SwsNamespaceHandlerTest extends TestCase {
private ApplicationContext applicationContext;
protected void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("swsNamespaceHandlerTest.xml", getClass());
}
public void testMarshallingMethods() throws Exception {
Map result = applicationContext.getBeansOfType(MarshallingMethodEndpointAdapter.class);
assertFalse("no MarshallingMethodEndpointAdapter found", result.isEmpty());
}
}

View File

@@ -0,0 +1,15 @@
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:sws="http://www.springframework.org/spring-ws/schema/sws" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/beans/spring-tx-2.0.xsd
http://www.springframework.org/spring-ws/schema/sws http://www.springframework.org/spring-ws/schema/sws/spring-ws-1.1.xsd">
<sws:marshalling-endpoints/>
<bean id="marshaller" class="org.springframework.ws.config.DummyMarshaller"/>
</beans>

View File

@@ -36,10 +36,10 @@ import org.w3c.dom.Element;
*/
class Jaxb2MarshallerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
public static final String JAXB2_MARSHALLER_BEAN_NAME = "org.springframework.oxm.jaxb.Jaxb2Marshaller";
public static final String JAXB2_MARSHALLER_CLASS_NAME = "org.springframework.oxm.jaxb.Jaxb2Marshaller";
protected String getBeanClassName(Element element) {
return JAXB2_MARSHALLER_BEAN_NAME;
return JAXB2_MARSHALLER_CLASS_NAME;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
@@ -49,7 +49,7 @@ class Jaxb2MarshallerBeanDefinitionParser extends AbstractSingleBeanDefinitionPa
}
List classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound");
if (!classes.isEmpty()) {
ManagedList classesToBeBound = new ManagedList();
ManagedList classesToBeBound = new ManagedList(classes.size());
for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
Element classToBeBound = (Element) iterator.next();
String className = classToBeBound.getAttribute("name");

View File

@@ -4,9 +4,15 @@
package org.springframework.oxm.config;
import org.springframework.beans.factory.xml.NamespaceHandler;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/** @author Arjen Poutsma */
/**
* {@link NamespaceHandler} for the '<code>oxm</code>' namespace.
*
* @author Arjen Poutsma
* @since 1.1.0
*/
public class OxmNamespaceHandler extends NamespaceHandlerSupport {
public void init() {

23
pom.xml
View File

@@ -124,7 +124,27 @@
<inherited>false</inherited>
<executions>
<execution>
<id>make-assembly</id>
<id>make-all-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Spring-WS-Version>${version}</Spring-WS-Version>
</manifestEntries>
</archive>
<descriptors>
<descriptor>src/assembly/all.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>make-minimal-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
@@ -132,7 +152,6 @@
<configuration>
<descriptors>
<descriptor>src/assembly/minimal.xml</descriptor>
<descriptor>src/assembly/all.xml</descriptor>
</descriptors>
</configuration>
</execution>

View File

@@ -21,7 +21,22 @@
<outputFileNameMapping/>
<includeDependencies>false</includeDependencies>
<unpack>true</unpack>
<unpackOptions>
<includes>
<include>**/oxm/*</include>
</includes>
<excludes>
<exclude>**/spring.handlers</exclude>
<exclude>**/spring.schemas</exclude>
</excludes>
</unpackOptions>
</binaries>
</moduleSet>
</moduleSets>
<fileSets>
<fileSet>
<directory>src/main/resources/META-INF</directory>
<outputDirectory>META-INF</outputDirectory>
</fileSet>
</fileSets>
</assembly>

View File

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

View File

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