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.dom4j.Document;
22: import org.dom4j.DocumentHelper;
23: import org.dom4j.Element;
24: import org.dom4j.io.DocumentResult;
25: import org.dom4j.io.DocumentSource;
26: import org.springframework.xml.transform.TransformerObjectSupport;
27:
28: /**
29: * Abstract base class for endpoints that handle the message payload as dom4j elements. Offers the message payload as a
30: * dom4j <code>Element</code>, and allows subclasses to create a response by returning an <code>Element</code>.
31: * <p/>
32: * An <code>AbstractDom4JPayloadEndpoint</code> only accept one payload element. Multiple payload elements are not in
33: * accordance with WS-I.
34: *
35: * @author Arjen Poutsma
36: * @see org.dom4j.Element
37: * @since 1.0.0
38: */
39: public abstract class AbstractDom4jPayloadEndpoint extends
40: TransformerObjectSupport implements PayloadEndpoint {
41:
42: public final Source invoke(Source request) throws Exception {
43: Element requestElement = null;
44: if (request != null) {
45: DocumentResult dom4jResult = new DocumentResult();
46: transform(request, dom4jResult);
47: requestElement = dom4jResult.getDocument().getRootElement();
48: }
49: Document responseDocument = DocumentHelper.createDocument();
50: Element responseElement = invokeInternal(requestElement,
51: responseDocument);
52: return responseElement != null ? new DocumentSource(
53: responseElement) : null;
54: }
55:
56: /**
57: * Template method. Subclasses must implement this. Offers the request payload as a dom4j <code>Element</code>, and
58: * allows subclasses to return a response <code>Element</code>.
59: * <p/>
60: * The given dom4j <code>Document</code> is to be used for constructing a response element, by using
61: * <code>addElement</code>.
62: *
63: * @param requestElement the contents of the SOAP message as dom4j elements
64: * @param responseDocument a dom4j document to be used for constructing a response
65: * @return the response element. Can be <code>null</code> to specify no response.
66: */
67: protected abstract Element invokeInternal(Element requestElement,
68: Document responseDocument) throws Exception;
69: }
|