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;
018    
019    import javax.jbi.messaging.MessageExchange;
020    import javax.jbi.messaging.MessagingException;
021    import javax.jbi.messaging.NormalizedMessage;
022    import javax.xml.namespace.QName;
023    
024    import org.apache.servicemix.MessageExchangeListener;
025    import org.apache.servicemix.components.util.ComponentSupport;
026    
027    /**
028     * @version $Revision: 470478 $
029     */
030    public class ReceiverComponent extends ComponentSupport implements MessageExchangeListener, Receiver {
031    
032        public static final QName SERVICE = new QName("http://servicemix.org/example/", "receiver");
033        public static final String ENDPOINT = "receiver";
034    
035        private MessageList messageList = new MessageList();
036    
037        public ReceiverComponent() {
038            this(SERVICE, ENDPOINT);
039        }
040        
041        public ReceiverComponent(QName service, String endpoint) {
042            super(service, endpoint);
043        }
044    
045        // MessageExchangeListener interface
046        //-------------------------------------------------------------------------
047        public void onMessageExchange(MessageExchange exchange) throws MessagingException {
048            NormalizedMessage inMessage = getInMessage(exchange);
049            // Copy message to avoid possible closed stream exceptions
050            // when using StreamSource
051            NormalizedMessage copyMessage = exchange.createMessage();
052            getMessageTransformer().transform(exchange, inMessage, copyMessage);
053            messageList.addMessage(copyMessage);
054            done(exchange);
055        }
056    
057        // Receiver interface
058        //-------------------------------------------------------------------------
059        public MessageList getMessageList() {
060            return messageList;
061        }
062    }