01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript.jbi.component;
18:
19: import javax.jbi.messaging.DeliveryChannel;
20: import javax.jbi.messaging.ExchangeStatus;
21: import javax.jbi.messaging.MessageExchange;
22: import javax.jbi.messaging.MessageExchangeFactory;
23: import javax.jbi.messaging.MessagingException;
24: import javax.jbi.servicedesc.ServiceEndpoint;
25: import javax.xml.namespace.QName;
26:
27: import org.apache.servicemix.JbiConstants;
28: import org.apache.servicemix.common.Endpoint;
29: import org.apache.servicemix.common.EndpointSupport;
30:
31: public class EndpointDeliveryChannel implements DeliveryChannel {
32:
33: private DeliveryChannel delegate = null;
34: private Endpoint endpoint = null;
35:
36: public EndpointDeliveryChannel(DeliveryChannel delegate,
37: Endpoint endpoint) {
38: this .delegate = delegate;
39: this .endpoint = endpoint;
40: }
41:
42: public EndpointDeliveryChannel() {
43:
44: }
45:
46: public MessageExchange accept() throws MessagingException {
47: return delegate.accept();
48: }
49:
50: public MessageExchange accept(long timeout)
51: throws MessagingException {
52: return delegate.accept(timeout);
53: }
54:
55: public void close() throws MessagingException {
56: delegate.close();
57: }
58:
59: public MessageExchangeFactory createExchangeFactory() {
60: return delegate.createExchangeFactory();
61: }
62:
63: public MessageExchangeFactory createExchangeFactory(QName name) {
64: return delegate.createExchangeFactory(name);
65: }
66:
67: public MessageExchangeFactory createExchangeFactory(
68: ServiceEndpoint endpoint) {
69: return delegate.createExchangeFactory(endpoint);
70: }
71:
72: public MessageExchangeFactory createExchangeFactoryForService(
73: QName service) {
74: return delegate.createExchangeFactoryForService(service);
75: }
76:
77: public void send(MessageExchange me) throws MessagingException {
78: if (me.getRole() == MessageExchange.Role.CONSUMER
79: && me.getStatus() == ExchangeStatus.ACTIVE) {
80: String key = EndpointSupport.getKey(endpoint);
81: me.setProperty(JbiConstants.SENDER_ENDPOINT, key);
82: delegate.send(me);
83: } else {
84: delegate.send(me);
85: }
86: }
87:
88: public boolean sendSync(MessageExchange messageExchange,
89: long timeout) throws MessagingException {
90: return delegate.sendSync(messageExchange, timeout);
91: }
92:
93: public boolean sendSync(MessageExchange messageExchange)
94: throws MessagingException {
95: return delegate.sendSync(messageExchange);
96: }
97:
98: }
|