01: /*
02: * Copyright 2006 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;
18:
19: import javax.xml.transform.Source;
20:
21: import org.jdom.Element;
22: import org.jdom.transform.JDOMResult;
23: import org.jdom.transform.JDOMSource;
24: import org.springframework.xml.transform.TransformerObjectSupport;
25:
26: /**
27: * Abstract base class for endpoints that handle the message payload as JDOM elements.
28: * <p/>
29: * <p>Offers the message payload as a JDOM {@link Element}, and allows subclasses to create a response by returning an
30: * <code>Element</code>.
31: * <p/>
32: * <pAn <code>AbstractJDomPayloadEndpoint</code> can accept only <i>one</i> payload element. Multiple payload elements
33: * are not in accordance with WS-I.
34: *
35: * @author Arjen Poutsma
36: * @since 1.0.0
37: */
38: public abstract class AbstractJDomPayloadEndpoint extends
39: TransformerObjectSupport implements PayloadEndpoint {
40:
41: public final Source invoke(Source request) throws Exception {
42: Element requestElement = null;
43: if (request != null) {
44: JDOMResult jdomResult = new JDOMResult();
45: transform(request, jdomResult);
46: requestElement = jdomResult.getDocument().getRootElement();
47: }
48: Element responseElement = invokeInternal(requestElement);
49: return responseElement != null ? new JDOMSource(responseElement)
50: : null;
51: }
52:
53: /**
54: * Template method. Subclasses must implement this. Offers the request payload as a JDOM <code>Element</code>, and
55: * allows subclasses to return a response <code>Element</code>.
56: *
57: * @param requestElement the contents of the SOAP message as JDOM element
58: * @return the response element. Can be <code>null</code> to specify no response.
59: */
60: protected abstract Element invokeInternal(Element requestElement)
61: throws Exception;
62: }
|