View Javadoc

1   /*
2    * $Id: SetLendersAsRecipients.java 10789 2008-02-12 20:04:43Z dfeist $
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.example.loanbroker.transformers;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.transformer.TransformerException;
15  import org.mule.example.loanbroker.bank.Bank;
16  import org.mule.example.loanbroker.messages.LoanBrokerQuoteRequest;
17  import org.mule.routing.outbound.StaticRecipientList;
18  import org.mule.transformer.AbstractMessageAwareTransformer;
19  
20  /**
21   * Set the Recipient List property on the LoanBrokerQuoteRequest message based on the
22   * list of banks in LoanBrokerQuoteRequest.getLenders()
23   */
24  public class SetLendersAsRecipients extends AbstractMessageAwareTransformer
25  {
26  
27      public SetLendersAsRecipients()
28      {
29          this.registerSourceType(LoanBrokerQuoteRequest.class);
30          this.setReturnClass(MuleMessage.class);
31      }
32  
33      public Object transform(MuleMessage message, String outputEncoding) throws TransformerException
34      {
35          Object src = message.getPayload();
36          Bank[] lenders = ((LoanBrokerQuoteRequest) src).getLenders();
37  
38          String recipients = "";
39          for (int i = 0; i < lenders.length; i++)
40          {
41              if (i > 0) recipients += ",";
42              recipients += lenders[i].getEndpoint();
43          }
44  
45          logger.debug("Setting recipients to '" + recipients + "'");
46          message.setProperty(StaticRecipientList.RECIPIENTS_PROPERTY, recipients);
47          return message;
48      }
49  
50  }