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.context;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21:
22: import org.springframework.util.Assert;
23: import org.springframework.ws.WebServiceMessage;
24: import org.springframework.ws.WebServiceMessageFactory;
25:
26: /**
27: * Default implementation of <code>MessageContext</code>.
28: *
29: * @author Arjen Poutsma
30: * @since 1.0.0
31: */
32: public class DefaultMessageContext extends AbstractMessageContext {
33:
34: private final WebServiceMessageFactory messageFactory;
35:
36: private WebServiceMessage request;
37:
38: private WebServiceMessage response;
39:
40: /** Construct a new, empty instance of the <code>DefaultMessageContext</code> with the given message factory. */
41: public DefaultMessageContext(WebServiceMessageFactory messageFactory) {
42: this (messageFactory.createWebServiceMessage(), messageFactory);
43: }
44:
45: /**
46: * Construct a new instance of the <code>DefaultMessageContext</code> with the given request message and message
47: * factory.
48: */
49: public DefaultMessageContext(WebServiceMessage request,
50: WebServiceMessageFactory messageFactory) {
51: Assert.notNull(request, "request must not be null");
52: Assert.notNull(messageFactory,
53: "messageFactory must not be null");
54: this .request = request;
55: this .messageFactory = messageFactory;
56: }
57:
58: public WebServiceMessage getRequest() {
59: return request;
60: }
61:
62: public WebServiceMessage getResponse() {
63: if (response == null) {
64: response = messageFactory.createWebServiceMessage();
65: }
66: return response;
67: }
68:
69: public boolean hasResponse() {
70: return response != null;
71: }
72:
73: public void readResponse(InputStream inputStream)
74: throws IOException {
75: if (response != null) {
76: throw new IllegalStateException(
77: "Response message already created");
78: } else {
79: response = messageFactory
80: .createWebServiceMessage(inputStream);
81: }
82: }
83:
84: }
|