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.eip.patterns;
018    
019    import javax.jbi.messaging.MessageExchange;
020    import javax.jbi.messaging.NormalizedMessage;
021    
022    import org.apache.servicemix.eip.support.AbstractSplitter;
023    import org.apache.servicemix.expression.PropertyExpression;
024    
025    /**
026     * An aggregator specifically written to aggregate messages that have been sent using 
027     * a StaticRecipientList pattern.
028     *
029     * @version $Revision: 376451 $
030     * @org.apache.xbean.XBean element="recipient-list-aggregator"
031     */
032    public class RecipientListAggregator extends SplitAggregator {
033    
034        public RecipientListAggregator() {
035            super();
036            this.count = new PropertyExpression(StaticRecipientList.RECIPIENT_LIST_COUNT);
037            this.index = new PropertyExpression(StaticRecipientList.RECIPIENT_LIST_INDEX);
038            this.corrId = new PropertyExpression(StaticRecipientList.RECIPIENT_LIST_CORRID);
039        }
040    
041        /*
042         * (non-Javadoc)
043         * 
044         * @see org.apache.servicemix.eip.support.Aggregation#buildAggregate(javax.jbi.messaging.NormalizedMessage,
045         *      javax.jbi.messaging.MessageExchange, boolean)
046         */
047        public void buildAggregate(Object aggregation, NormalizedMessage message,
048                MessageExchange exchange, boolean timeout) throws Exception {
049            super.buildAggregate(aggregation, message, exchange, timeout);
050            Object correlationId = message.getProperty(AbstractSplitter.SPLITTER_CORRID);
051            message.setProperty(AbstractSplitter.SPLITTER_CORRID, null);
052            message.setProperty(StaticRecipientList.RECIPIENT_LIST_CORRID, correlationId);
053        }
054    
055    }