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,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>