KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > samples > loanbroker > DefaultLenderService


1 /*
2  * $Id: DefaultLenderService.java 3982 2006-11-22 14:28:01Z lajos $
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.loanbroker;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.MuleManager;
16 import org.mule.impl.RequestContext;
17 import org.mule.routing.outbound.StaticRecipientList;
18 import org.mule.umo.UMOMessage;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * <code>DefaultLenderService</code> is responsible for contacting the relevant
25  * banks depending on the amount of the loan
26  */

27 public class DefaultLenderService
28 {
29     /**
30      * logger used by this class
31      */

32     protected transient Log logger = LogFactory.getLog(getClass());
33
34     public void setLenderList(BankQuoteRequest request)
35     {
36         Bank[] l = getLenderList(request.getLoanRequest().getCreditProfile(), new Double JavaDoc(
37             request.getLoanRequest().getLoanAmount()));
38         request.setLenders(l);
39     }
40
41     public Bank[] getLenderList(CreditProfile creditProfile, Double JavaDoc loanAmount)
42     {
43         Bank[] lenders;
44         if ((loanAmount.doubleValue() >= 20000)) // &&
45
// (creditProfile.getCreditScore()
46
// >= 600) &&
47
// (creditProfile.getCreditHistoryLength()
48
// >= 8))
49
{
50             lenders = new Bank[2];
51             lenders[0] = new Bank("Bank1", getEndpoint("Bank1"));
52             lenders[1] = new Bank("Bank2", getEndpoint("Bank2"));
53
54         }
55         else if (((loanAmount.doubleValue() >= 10000) && (loanAmount.doubleValue() <= 19999))) // &&
56
// (creditProfile.getCreditScore()
57
// >=
58
// 400)
59
// &&
60
// (creditProfile.getCreditHistoryLength()
61
// >=
62
// 3))
63
{
64             lenders = new Bank[2];
65             lenders[0] = new Bank("Bank3", getEndpoint("Bank3"));
66             lenders[1] = new Bank("Bank4", getEndpoint("Bank4"));
67         }
68         else
69         {
70             lenders = new Bank[1];
71             lenders[0] = new Bank("Bank5", getEndpoint("Bank5"));
72         }
73
74         List recipients = new ArrayList JavaDoc(lenders.length);
75         for (int i = 0; i < lenders.length; i++)
76         {
77             recipients.add(lenders[i].getEndpoint());
78         }
79
80         UMOMessage m = RequestContext.getEventContext().getMessage();
81         m.setProperty(StaticRecipientList.RECIPIENTS_PROPERTY, recipients);
82         return lenders;
83     }
84
85     /**
86      * A helper method used to make it easier to configure this sample with differet
87      * endpoints for testing purposes
88      *
89      * @param name
90      * @return
91      */

92     private String JavaDoc getEndpoint(String JavaDoc name)
93     {
94         String JavaDoc endpoint = MuleManager.getInstance().lookupEndpointIdentifier(name, null);
95
96         if (endpoint.startsWith("axis") || endpoint.startsWith("xfire") || endpoint.startsWith("glue")
97                         || endpoint.startsWith("soap"))
98         {
99             int i = endpoint.indexOf('?');
100             if (i > -1)
101             {
102                 endpoint = endpoint.replaceFirst("\\?", "/" + name + "?method=getLoanQuote\\&");
103             }
104             else
105             {
106                 endpoint += "/" + name + "?method=getLoanQuote";
107             }
108         }
109
110         return endpoint;
111     }
112
113 }
114
Popular Tags