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