summaryrefslogtreecommitdiffstats
path: root/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/BigBank/Accounts/StockQuoteServiceImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/BigBank/Accounts/StockQuoteServiceImpl.cpp')
-rw-r--r--sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/BigBank/Accounts/StockQuoteServiceImpl.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/BigBank/Accounts/StockQuoteServiceImpl.cpp b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/BigBank/Accounts/StockQuoteServiceImpl.cpp
new file mode 100644
index 0000000000..8ce6d410c2
--- /dev/null
+++ b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/BigBank/Accounts/StockQuoteServiceImpl.cpp
@@ -0,0 +1,63 @@
+
+#if defined(WIN32) || defined (_WINDOWS)
+#pragma warning(disable: 4786)
+#endif
+
+#include "StockQuoteServiceImpl.h"
+#include "StockQuoteExternalService.h"
+
+#include "osoa/sca/sca.h"
+#include "commonj/sdo/SDO.h"
+
+using namespace osoa::sca;
+using namespace commonj::sdo;
+
+namespace com{
+ namespace bigbank{
+ namespace stockquote {
+
+
+ float StockQuoteServiceImpl::getQuote(const char *symbol)
+ {
+ ComponentContext myContext = ComponentContext::getCurrent();
+
+ // Use an SCA reference to get the stock price
+ StockQuoteExternalService* stockQuoteExternalService =
+ (StockQuoteExternalService*)myContext.
+ getService("StockQuoteExternal");
+
+ if (stockQuoteExternalService == 0)
+ {
+ std::cout << "unable to find external stock quote service" << std::endl;
+ return 0.1f;
+ }
+
+ // Create a data object representing the requests (use dynamic API until static is available)
+ DataObjectPtr requestDO;
+
+ // Invoke the service
+ const char* result = stockQuoteExternalService->GetQuote(symbol);
+
+ //std::cout << result<< std::endl;
+
+ float stockPrice = 0.0f;
+
+ try
+ {
+ XMLHelperPtr xmlHelper = HelperProvider::getXMLHelper(myContext.getDataFactory());
+ XMLDocumentPtr stockDoc = xmlHelper->load(result);
+ if (stockDoc->getRootDataObject())
+ {
+ stockPrice=stockDoc->getRootDataObject()->getFloat("Stock.0/Last");
+ }
+ }
+ catch (SDORuntimeException e)
+ {
+ std::cout << e << std::endl;
+ return 0.0f;
+ }
+ return stockPrice;
+ }
+ }
+ }
+} \ No newline at end of file