KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > sca > bigbank > account > AccountServiceImpl


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.sca.bigbank.account;
18
19 import java.util.ArrayList JavaDoc;
20
21 import org.apache.servicemix.sca.bigbank.accountdata.AccountDataService;
22 import org.apache.servicemix.sca.bigbank.accountdata.CheckingAccount;
23 import org.apache.servicemix.sca.bigbank.accountdata.SavingsAccount;
24 import org.apache.servicemix.sca.bigbank.accountdata.StockAccount;
25 import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteRequest;
26 import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteResponse;
27 import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteService;
28 import org.osoa.sca.annotations.Property;
29 import org.osoa.sca.annotations.Reference;
30 import org.osoa.sca.annotations.Service;
31
32 @Service(interfaces=AccountService.class)
33 public class AccountServiceImpl implements AccountService {
34
35     @Property
36     public String JavaDoc currency = "USD";
37
38     @Reference
39     public AccountDataService accountDataService;
40     @Reference
41     public StockQuoteService stockQuoteService;
42
43     public AccountServiceImpl() {
44     }
45
46     public AccountReportResponse getAccountReport(AccountReportRequest request) {
47         AccountReportResponse report = new AccountReportResponse();
48         String JavaDoc customerID = request.getCustomerID();
49         report.setAccountSummaries(new ArrayList JavaDoc<AccountSummary>());
50         report.getAccountSummaries().add(getCheckAccountSummary(customerID));
51         report.getAccountSummaries().add(getSavingsAccountSummary(customerID));
52         report.getAccountSummaries().add(getStockAccountSummary(customerID));
53         return report;
54     }
55     
56     private AccountSummary getCheckAccountSummary(String JavaDoc customerID) {
57         CheckingAccount checking = accountDataService.getCheckingAccount(customerID);
58         AccountSummary summary = new AccountSummary();
59         summary.setAccountNumber(checking.getAccountNumber());
60         summary.setAccountType("Checking");
61         summary.setBalance(checking.getBalance());
62         return summary;
63     }
64
65     private AccountSummary getSavingsAccountSummary(String JavaDoc customerID) {
66         SavingsAccount savings = accountDataService.getSavingsAccount(customerID);
67         AccountSummary summary = new AccountSummary();
68         summary.setAccountNumber(savings.getAccountNumber());
69         summary.setAccountType("Savings");
70         summary.setBalance(savings.getBalance());
71         return summary;
72     }
73
74     private AccountSummary getStockAccountSummary(String JavaDoc customerID) {
75         StockAccount stock = accountDataService.getStockAccount(customerID);
76         AccountSummary summary = new AccountSummary();
77         summary.setAccountNumber(stock.getAccountNumber());
78         summary.setAccountType("Stock");
79         float quote = getQuote(stock.getSymbol());
80         summary.setBalance(quote * stock.getQuantity());
81         return summary;
82     }
83     
84     private float getQuote(String JavaDoc symbol) {
85         StockQuoteRequest req = new StockQuoteRequest();
86         req.setSymbol(symbol);
87         StockQuoteResponse rep = stockQuoteService.getQuote(req);
88         return rep.getResult();
89     }
90
91 }
92
Popular Tags