View Javadoc

1   /*
2    * $Id: SetLendersAsRecipients.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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 CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.examples.loanbroker.transformers;
12  
13  import org.mule.examples.loanbroker.bank.Bank;
14  import org.mule.examples.loanbroker.messages.CustomerQuoteRequest;
15  import org.mule.examples.loanbroker.messages.LoanBrokerQuoteRequest;
16  import org.mule.routing.outbound.StaticRecipientList;
17  import org.mule.transformers.AbstractEventAwareTransformer;
18  import org.mule.umo.UMOEventContext;
19  import org.mule.umo.UMOMessage;
20  import org.mule.umo.transformer.TransformerException;
21  
22  /**
23   * Set the Recipient List property on the LoanBrokerQuoteRequest message based on the
24   * list of banks in LoanBrokerQuoteRequest.getLenders()
25   */
26  public class SetLendersAsRecipients extends AbstractEventAwareTransformer
27  {
28  
29      public SetLendersAsRecipients()
30      {
31          this.registerSourceType(LoanBrokerQuoteRequest.class);
32          this.setReturnClass(CustomerQuoteRequest.class);
33      }
34  
35      public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException
36      {
37          Bank[] lenders = ((LoanBrokerQuoteRequest)src).getLenders();
38  
39          String recipients = "";
40          for (int i = 0; i < lenders.length; i++)
41          {
42              if (i > 0) recipients += ",";
43              recipients += lenders[i].getEndpoint();
44          }
45  
46          UMOMessage msg = context.getMessage();
47          context.getMessage().setProperty(StaticRecipientList.RECIPIENTS_PROPERTY, recipients);
48          return msg;
49      }
50  
51  }