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.common;
018:
019: import javax.jbi.messaging.DeliveryChannel;
020: import javax.jbi.messaging.ExchangeStatus;
021: import javax.jbi.messaging.MessageExchange;
022: import javax.jbi.messaging.MessageExchangeFactory;
023: import javax.jbi.messaging.MessagingException;
024: import javax.jbi.messaging.MessageExchange.Role;
025: import javax.jbi.servicedesc.ServiceEndpoint;
026: import javax.xml.namespace.QName;
027:
028: /**
029: * This class is a wrapper around an existing DeliveryChannel
030: * that will be given to service engine endpoints so that
031: * they are able to send messages and to interact with the
032: * JBI container.
033: *
034: * @author gnodet
035: */
036: public class EndpointDeliveryChannel implements DeliveryChannel {
037:
038: private final DeliveryChannel channel;
039: private final Endpoint endpoint;
040:
041: public EndpointDeliveryChannel(Endpoint endpoint)
042: throws MessagingException {
043: this .endpoint = endpoint;
044: this .channel = endpoint.getServiceUnit().getComponent()
045: .getComponentContext().getDeliveryChannel();
046: }
047:
048: public MessageExchange accept() throws MessagingException {
049: throw new UnsupportedOperationException();
050: }
051:
052: public MessageExchange accept(long timeout)
053: throws MessagingException {
054: throw new UnsupportedOperationException();
055: }
056:
057: public void close() throws MessagingException {
058: throw new UnsupportedOperationException();
059: }
060:
061: public MessageExchangeFactory createExchangeFactory() {
062: return channel.createExchangeFactory();
063: }
064:
065: public MessageExchangeFactory createExchangeFactory(
066: QName interfaceName) {
067: return channel.createExchangeFactory(interfaceName);
068: }
069:
070: public MessageExchangeFactory createExchangeFactory(
071: ServiceEndpoint endpoint) {
072: return channel.createExchangeFactory(endpoint);
073: }
074:
075: public MessageExchangeFactory createExchangeFactoryForService(
076: QName serviceName) {
077: return channel.createExchangeFactoryForService(serviceName);
078: }
079:
080: public void send(MessageExchange exchange)
081: throws MessagingException {
082: if (exchange.getStatus() == ExchangeStatus.ACTIVE
083: && exchange.getRole() == Role.CONSUMER) {
084: ServiceMixComponent comp = endpoint.getServiceUnit()
085: .getComponent();
086: comp.prepareConsumerExchange(exchange, endpoint);
087: }
088: channel.send(exchange);
089: }
090:
091: public boolean sendSync(MessageExchange exchange, long timeout)
092: throws MessagingException {
093: if (exchange.getStatus() == ExchangeStatus.ACTIVE
094: && exchange.getRole() == Role.CONSUMER) {
095: ServiceMixComponent comp = endpoint.getServiceUnit()
096: .getComponent();
097: comp.prepareConsumerExchange(exchange, endpoint);
098: }
099: return channel.sendSync(exchange, timeout);
100: }
101:
102: public boolean sendSync(MessageExchange exchange)
103: throws MessagingException {
104: if (exchange.getStatus() == ExchangeStatus.ACTIVE
105: && exchange.getRole() == Role.CONSUMER) {
106: ServiceMixComponent comp = endpoint.getServiceUnit()
107: .getComponent();
108: comp.prepareConsumerExchange(exchange, endpoint);
109: }
110: return channel.sendSync(exchange);
111: }
112: }
|