1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.examples.loanbroker.bank; |
12 | |
|
13 | |
import org.mule.config.ConfigurationException; |
14 | |
import org.mule.config.i18n.MessageFactory; |
15 | |
import org.mule.examples.loanbroker.LocaleMessage; |
16 | |
import org.mule.examples.loanbroker.messages.LoanBrokerQuoteRequest; |
17 | |
import org.mule.examples.loanbroker.messages.LoanQuote; |
18 | |
import org.mule.impl.UMODescriptorAware; |
19 | |
import org.mule.umo.UMODescriptor; |
20 | |
import org.mule.umo.endpoint.UMOEndpoint; |
21 | |
|
22 | |
import java.io.Serializable; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import org.apache.commons.logging.Log; |
26 | |
import org.apache.commons.logging.LogFactory; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class Bank implements UMODescriptorAware, Serializable, BankService |
34 | |
{ |
35 | |
|
36 | |
|
37 | |
|
38 | |
private static final long serialVersionUID = 4108271137166107769L; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | protected static final Log logger = LogFactory.getLog(Bank.class); |
44 | |
|
45 | |
private String bankName; |
46 | |
private double primeRate; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
private String endpoint; |
52 | |
|
53 | |
public Bank() |
54 | 0 | { |
55 | 0 | this.primeRate = Math.random() * 10; |
56 | 0 | } |
57 | |
|
58 | |
public Bank(String bankname) |
59 | |
{ |
60 | 0 | this(); |
61 | 0 | this.bankName = bankname; |
62 | |
|
63 | |
|
64 | 0 | this.endpoint = bankName; |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
public void setDescriptor(UMODescriptor descriptor) throws ConfigurationException |
70 | |
{ |
71 | 0 | this.bankName = descriptor.getName(); |
72 | |
|
73 | 0 | List endpoints = descriptor.getInboundRouter().getEndpoints(); |
74 | 0 | if ((endpoints == null) || (endpoints.size() != 1)) |
75 | |
{ |
76 | 0 | throw new ConfigurationException(MessageFactory.createStaticMessage("Bank is expected to have exactly 1 incoming endpoint.")); |
77 | |
} |
78 | |
|
79 | |
|
80 | 0 | this.endpoint = ((UMOEndpoint) endpoints.get(0)).getName(); |
81 | 0 | } |
82 | |
|
83 | |
public LoanQuote getLoanQuote(LoanBrokerQuoteRequest request) |
84 | |
{ |
85 | 0 | LoanQuote quote = new LoanQuote(); |
86 | 0 | quote.setBankName(getBankName()); |
87 | 0 | quote.setInterestRate(primeRate); |
88 | 0 | logger.info(LocaleMessage.receivedRate(quote)); |
89 | |
|
90 | 0 | return quote; |
91 | |
} |
92 | |
|
93 | |
public String getBankName() |
94 | |
{ |
95 | 0 | return bankName; |
96 | |
} |
97 | |
|
98 | |
public void setBankName(String bankName) |
99 | |
{ |
100 | 0 | this.bankName = bankName; |
101 | 0 | } |
102 | |
|
103 | |
public double getPrimeRate() |
104 | |
{ |
105 | 0 | return primeRate; |
106 | |
} |
107 | |
|
108 | |
public void setPrimeRate(double primeRate) |
109 | |
{ |
110 | 0 | this.primeRate = primeRate; |
111 | 0 | } |
112 | |
|
113 | |
public String getEndpoint() |
114 | |
{ |
115 | 0 | return endpoint; |
116 | |
} |
117 | |
public void setEndpoint(String endpoint) |
118 | |
{ |
119 | 0 | this.endpoint = endpoint; |
120 | 0 | } |
121 | |
} |