KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > samples > voipservice > routers > PaymentValidationResponseAggregator


1 /*
2  * $Id: PaymentValidationResponseAggregator.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.samples.voipservice.routers;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.config.i18n.Message;
16 import org.mule.impl.MuleMessage;
17 import org.mule.routing.inbound.EventGroup;
18 import org.mule.routing.response.ResponseCorrelationAggregator;
19 import org.mule.samples.voipservice.to.CreditProfileTO;
20 import org.mule.umo.UMOEvent;
21 import org.mule.umo.UMOMessage;
22 import org.mule.umo.routing.RoutingException;
23 import org.mule.umo.transformer.TransformerException;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 /**
29  * @author Binildas Christudas
30  */

31 public class PaymentValidationResponseAggregator extends ResponseCorrelationAggregator
32 {
33
34     protected static transient Log logger = LogFactory.getLog(PaymentValidationResponseAggregator.class);
35
36     protected UMOMessage aggregateEvents(EventGroup events) throws RoutingException
37     {
38
39         UMOEvent event = null;
40         boolean one = false;
41         boolean two = false;
42         CreditProfileTO creditProfileTO = null;
43
44         try
45         {
46             for (Iterator JavaDoc iterator = events.iterator(); iterator.hasNext();)
47             {
48                 event = (UMOEvent)iterator.next();
49                 creditProfileTO = (CreditProfileTO)event.getTransformedMessage();
50                 if (creditProfileTO.getCreditScore() >= CreditProfileTO.CREDIT_LIMIT)
51                 {
52                     one = true;
53                 }
54                 if (creditProfileTO.getCreditAuthorisedStatus() == CreditProfileTO.CREDIT_AUTHORISED)
55                 {
56                     two = true;
57                 }
58             }
59         }
60         catch (TransformerException e)
61         {
62             throw new RoutingException(Message.createStaticMessage("Failed to validate payment service"),
63                 new MuleMessage(events, (Map JavaDoc)null), null, e);
64         }
65         if (one && two && creditProfileTO != null)
66         {
67             creditProfileTO.setValid(true);
68         }
69         return new MuleMessage(creditProfileTO, event.getMessage());
70     }
71
72     protected boolean shouldAggregate(EventGroup events)
73     {
74
75         boolean shouldAggregate = super.shouldAggregate(events);
76         logger.info("--- *** --- shouldAggregate = " + shouldAggregate + " --- *** ---");
77         return shouldAggregate;
78     }
79 }
80
Popular Tags