01: /*
02: * $Id: DefaultLoanBroker.java 10789 2008-02-12 20:04:43Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.example.loanbroker;
12:
13: import org.mule.example.loanbroker.messages.CreditProfile;
14: import org.mule.example.loanbroker.messages.Customer;
15: import org.mule.example.loanbroker.messages.CustomerQuoteRequest;
16: import org.mule.example.loanbroker.messages.LoanBrokerQuoteRequest;
17: import org.mule.example.loanbroker.messages.LoanQuote;
18:
19: import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22:
23: /**
24: * <code>LoanBroker</code> is the Service that starts the loan request process. The
25: * broker also receives the final quote.
26: */
27: public class DefaultLoanBroker implements LoanBrokerService {
28: /**
29: * logger used by this class
30: */
31: protected final Log logger = LogFactory.getLog(getClass());
32:
33: private final AtomicInteger quotes = new AtomicInteger(0);
34: private final AtomicInteger requests = new AtomicInteger(0);
35: private final AtomicInteger profiles = new AtomicInteger(0);
36:
37: public Object getLoanQuote(CustomerQuoteRequest request)
38: throws LoanBrokerException {
39: int requests = incRequests();
40: if (logger.isInfoEnabled()) {
41: String[] params = new String[] { String.valueOf(requests),
42: request.getCustomer().getName(),
43: String.valueOf(request.getCustomer().getSsn()),
44: String.valueOf(request.getLoanAmount()),
45: String.valueOf(request.getLoanDuration()) };
46:
47: logger.info("\n***** "
48: + LocaleMessage.receivedRequest(params));
49: }
50: return request;
51: }
52:
53: public LoanBrokerQuoteRequest receiveLoanBrokerQuoteRequest(
54: LoanBrokerQuoteRequest request) {
55: // Just pass through
56: return request;
57: }
58:
59: public Customer receiveCustomer(Customer customer) {
60: // Just pass through
61: return customer;
62: }
63:
64: public Object receiveCreditProfile(CreditProfile profile) {
65: int profiles = incProfiles();
66: if (logger.isInfoEnabled()) {
67: String[] params = new String[] { String.valueOf(profiles),
68: String.valueOf(profile.getCreditScore()),
69: String.valueOf(profile.getCreditHistory()) };
70:
71: logger.info("\n***** "
72: + LocaleMessage.receivedProfile(params));
73: }
74: return profile;
75: }
76:
77: public Object receiveQuote(LoanQuote quote) {
78: int quotes = incQuotes();
79: if (logger.isInfoEnabled()) {
80: String[] params = new String[] { String.valueOf(quotes),
81: quote.toString() };
82: logger.info("\n***** "
83: + LocaleMessage.receivedQuote(params));
84: }
85: return quote;
86: }
87:
88: protected int incQuotes() {
89: return quotes.incrementAndGet();
90: }
91:
92: protected int incRequests() {
93: return requests.incrementAndGet();
94: }
95:
96: protected int incProfiles() {
97: return profiles.incrementAndGet();
98: }
99: }
|