001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.tck.mock;
018:
019: import java.net.URI;
020: import java.util.HashMap;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import javax.jbi.messaging.ExchangeStatus;
025: import javax.jbi.messaging.Fault;
026: import javax.jbi.messaging.MessageExchange;
027: import javax.jbi.messaging.MessagingException;
028: import javax.jbi.messaging.NormalizedMessage;
029: import javax.jbi.servicedesc.ServiceEndpoint;
030: import javax.xml.namespace.QName;
031:
032: public class MockMessageExchange implements MessageExchange {
033:
034: private ServiceEndpoint endpoint;
035: private Exception error;
036: private String exchangeId;
037: private QName interfaceName;
038: private QName operation;
039: private URI pattern;
040: private QName service;
041: private MessageExchange.Role role;
042: private ExchangeStatus status;
043: private NormalizedMessage inMessage;
044: private NormalizedMessage outMessage;
045: private Fault fault;
046: private Map<String, Object> properties = new HashMap<String, Object>();
047:
048: /**
049: * @return the endpoint
050: */
051: public ServiceEndpoint getEndpoint() {
052: return endpoint;
053: }
054:
055: /**
056: * @param endpoint the endpoint to set
057: */
058: public void setEndpoint(ServiceEndpoint endpoint) {
059: this .endpoint = endpoint;
060: }
061:
062: /**
063: * @return the error
064: */
065: public Exception getError() {
066: return error;
067: }
068:
069: /**
070: * @param error the error to set
071: */
072: public void setError(Exception error) {
073: this .error = error;
074: }
075:
076: /**
077: * @return the exchangeId
078: */
079: public String getExchangeId() {
080: return exchangeId;
081: }
082:
083: /**
084: * @param exchangeId the exchangeId to set
085: */
086: public void setExchangeId(String exchangeId) {
087: this .exchangeId = exchangeId;
088: }
089:
090: /**
091: * @return the fault
092: */
093: public Fault getFault() {
094: return fault;
095: }
096:
097: /**
098: * @param fault the fault to set
099: */
100: public void setFault(Fault fault) {
101: this .fault = fault;
102: }
103:
104: /**
105: * @return the in
106: */
107: public NormalizedMessage getInMessage() {
108: return inMessage;
109: }
110:
111: /**
112: * @param in the in to set
113: */
114: public void setInMessage(NormalizedMessage in) {
115: this .inMessage = in;
116: }
117:
118: /**
119: * @return the interfaceName
120: */
121: public QName getInterfaceName() {
122: return interfaceName;
123: }
124:
125: /**
126: * @param interfaceName the interfaceName to set
127: */
128: public void setInterfaceName(QName interfaceName) {
129: this .interfaceName = interfaceName;
130: }
131:
132: /**
133: * @return the operation
134: */
135: public QName getOperation() {
136: return operation;
137: }
138:
139: /**
140: * @param operation the operation to set
141: */
142: public void setOperation(QName operation) {
143: this .operation = operation;
144: }
145:
146: /**
147: * @return the out
148: */
149: public NormalizedMessage getOutMessage() {
150: return outMessage;
151: }
152:
153: /**
154: * @param out the out to set
155: */
156: public void setOutMessage(NormalizedMessage out) {
157: this .outMessage = out;
158: }
159:
160: /**
161: * @return the pattern
162: */
163: public URI getPattern() {
164: return pattern;
165: }
166:
167: /**
168: * @param pattern the pattern to set
169: */
170: public void setPattern(URI pattern) {
171: this .pattern = pattern;
172: }
173:
174: /**
175: * @return the role
176: */
177: public MessageExchange.Role getRole() {
178: return role;
179: }
180:
181: /**
182: * @param role the role to set
183: */
184: public void setRole(MessageExchange.Role role) {
185: this .role = role;
186: }
187:
188: /**
189: * @return the service
190: */
191: public QName getService() {
192: return service;
193: }
194:
195: /**
196: * @param service the service to set
197: */
198: public void setService(QName service) {
199: this .service = service;
200: }
201:
202: /**
203: * @return the status
204: */
205: public ExchangeStatus getStatus() {
206: return status;
207: }
208:
209: /**
210: * @param status the status to set
211: */
212: public void setStatus(ExchangeStatus status) {
213: this .status = status;
214: }
215:
216: public Fault createFault() throws MessagingException {
217: return new MockFault();
218: }
219:
220: public NormalizedMessage createMessage() throws MessagingException {
221: return new MockNormalizedMessage();
222: }
223:
224: public NormalizedMessage getMessage(String name) {
225: if ("in".equalsIgnoreCase(name)) {
226: return getInMessage();
227: } else if ("out".equalsIgnoreCase(name)) {
228: return getOutMessage();
229: }
230: return null;
231: }
232:
233: public Object getProperty(String name) {
234: return properties.get(name);
235: }
236:
237: public Set getPropertyNames() {
238: return properties.keySet();
239: }
240:
241: public boolean isTransacted() {
242: return false;
243: }
244:
245: public void setMessage(NormalizedMessage msg, String name)
246: throws MessagingException {
247: if ("in".equalsIgnoreCase(name)) {
248: setInMessage(msg);
249: } else if ("out".equalsIgnoreCase(name)) {
250: setOutMessage(msg);
251: }
252: }
253:
254: public void setProperty(String name, Object obj) {
255: properties.put(name, obj);
256: }
257:
258: public static class MockFault extends MockNormalizedMessage
259: implements Fault {
260: }
261:
262: }
|