01: /*
02: * Copyright 2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.ws.server.endpoint.mapping;
18:
19: import java.lang.reflect.Method;
20: import javax.xml.namespace.QName;
21: import javax.xml.transform.TransformerFactory;
22:
23: import org.springframework.util.StringUtils;
24: import org.springframework.ws.context.MessageContext;
25: import org.springframework.ws.server.EndpointMapping;
26: import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
27: import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
28:
29: /**
30: * Implementation of the {@link EndpointMapping} interface that uses the {@link PayloadRoot} annotation to map methods
31: * to request payload root elements.
32: * <p/>
33: * Endpoints typically have the following form:
34: * <pre>
35: * @Endpoint
36: * public class MyEndpoint{
37: * @Payload(localPart = "Request",
38: * namespace = "http://springframework.org/spring-ws")
39: * public Source doSomethingWithRequest() {
40: * ...
41: * }
42: * }
43: * </pre>
44: *
45: * @author Arjen Poutsma
46: * @since 1.0.0
47: */
48: public class PayloadRootAnnotationMethodEndpointMapping extends
49: AbstractAnnotationMethodEndpointMapping {
50:
51: private static TransformerFactory transformerFactory;
52:
53: static {
54: transformerFactory = TransformerFactory.newInstance();
55: }
56:
57: protected String getLookupKeyForMessage(
58: MessageContext messageContext) throws Exception {
59: QName qName = PayloadRootUtils.getPayloadRootQName(
60: messageContext.getRequest().getPayloadSource(),
61: transformerFactory);
62: return qName != null ? qName.toString() : null;
63: }
64:
65: protected String getLookupKeyForMethod(Method method) {
66: PayloadRoot annotation = method
67: .getAnnotation(PayloadRoot.class);
68: if (annotation != null) {
69: QName qname;
70: if (StringUtils.hasLength(annotation.localPart())
71: && StringUtils.hasLength(annotation.namespace())) {
72: qname = new QName(annotation.namespace(), annotation
73: .localPart());
74: } else {
75: qname = new QName(annotation.localPart());
76: }
77: return qname.toString();
78: } else {
79: return null;
80: }
81: }
82:
83: }
|