From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../bigbank.account/AccountServiceImpl.cpp | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 tags/native-sca-1.0.incubating-M3/samples/CppBigBank/bigbank.account/AccountServiceImpl.cpp (limited to 'tags/native-sca-1.0.incubating-M3/samples/CppBigBank/bigbank.account/AccountServiceImpl.cpp') diff --git a/tags/native-sca-1.0.incubating-M3/samples/CppBigBank/bigbank.account/AccountServiceImpl.cpp b/tags/native-sca-1.0.incubating-M3/samples/CppBigBank/bigbank.account/AccountServiceImpl.cpp new file mode 100644 index 0000000000..8544b36e7e --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3/samples/CppBigBank/bigbank.account/AccountServiceImpl.cpp @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) +#endif + +#include "osoa/sca/sca.h" + +#include "AccountServiceImpl.h" +#include "StockQuoteService.h" +#include "AccountDataService.h" + +using namespace std; +using namespace commonj::sdo; +using namespace osoa::sca; +using namespace services::accountdata; +using namespace services::stockquote; + +/** + * AccountServiceImpl component implementation + */ +namespace services +{ + namespace account + { + + DataObjectPtr /*AccountReport**/ + AccountServiceImpl::getAccountReport(const string customerID) + { + ComponentContext theContext = ComponentContext::getCurrent(); + + commonj::sdo::DataFactoryPtr factory = theContext.getDataFactory(); + + commonj::sdo::DataObjectPtr newReport = + factory->create("http://www.bigbank.com/AccountService","AccountReport"); + + // Get the accountDataService service + AccountDataService *dataService = + (AccountDataService*)theContext.getService("accountDataService"); + + // would be better to return a list of accounts - this only + // gets the first of each. + + commonj::sdo::DataObjectPtr checking = + dataService->getCheckingAccount(customerID); + + if (checking != 0) + { + commonj::sdo::DataObjectList& dl = newReport->getList("checking"); + checking->setFloat("balance", + fromUSDollarToCurrency(checking->getFloat("balance"))); + dl.append(checking); + } + + commonj::sdo::DataObjectPtr savings = dataService->getSavingsAccount(customerID); + + if (savings != 0) + { + commonj::sdo::DataObjectList& dl = newReport->getList("savings"); + savings->setFloat("balance", + fromUSDollarToCurrency(savings->getFloat("balance"))); + dl.append(savings); + } + + // Get the stockQuoteService service + StockQuoteService* stockService = + (StockQuoteService*)theContext.getService("stockQuoteService"); + + commonj::sdo::DataObjectPtr stocks = dataService->getStockAccount(customerID); + + if (stocks != 0) + { + commonj::sdo::DataObjectList& dl = newReport->getList("stocks"); + + float value = 10.0f; + try { + value = stockService->getQuote( + stocks->getCString("symbol")); + } + catch (ServiceRuntimeException& e) + { + std::cout << "Fault from stock quote service" << e << std::endl; + } + stocks->setFloat("balance", + fromUSDollarToCurrency(stocks->getInteger("quantity") * + value)); + dl.append(stocks); + } + + return newReport; + } + + float AccountServiceImpl::fromUSDollarToCurrency(float value) + { + // Get the "currency" property + ComponentContext myContext = ComponentContext::getCurrent(); + + commonj::sdo::DataObjectInstance properties = myContext.getProperties(); + if (properties) + { + const char* currency = properties->getCString("currency"); + if (currency != 0) + { + std::cout << "Currency is : " << currency << std::endl; + if (!strcmp(currency,"USD")) return value; + if (!strcmp(currency,"EURO")) return 0.8f * value; + } + } + return 0.0f; + } + + } // End account +} // End services -- cgit v1.2.3