View Javadoc

1   /*
2    * $Id: SetLendersAsRecipients.java 10498 2008-01-24 10:19:31Z 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.LoanBrokerQuoteRequest;
15  import org.mule.routing.outbound.StaticRecipientList;
16  import org.mule.transformers.AbstractEventAwareTransformer;
17  import org.mule.umo.UMOEventContext;
18  import org.mule.umo.UMOMessage;
19  import org.mule.umo.transformer.TransformerException;
20  
21  /**
22   * Set the Recipient List property on the LoanBrokerQuoteRequest message based on the
23   * list of banks in LoanBrokerQuoteRequest.getLenders()
24   */
25  public class SetLendersAsRecipients extends AbstractEventAwareTransformer
26  {
27  
28      public SetLendersAsRecipients()
29      {
30          this.registerSourceType(LoanBrokerQuoteRequest.class);
31          this.setReturnClass(UMOMessage.class);
32      }
33  
34      public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException
35      {
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          UMOMessage msg = context.getMessage();
46          context.getMessage().setProperty(StaticRecipientList.RECIPIENTS_PROPERTY, recipients);
47          return msg;
48      }
49  
50  }