Author: jsdelfino
Date: Thu Sep 21 22:40:38 2006
New Revision: 448819
URL: http://svn.apache.org/viewvc?view=rev&rev=448819
Log:
Improvements to the Ruby BigBank sample. Integrated StockQuote Web service and
simplified generation of AccountReport document
Modified:
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/AccountServiceImpl.rb
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/StockQuoteServiceImpl.rb
Modified:
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/AccountServiceImpl.rb
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/AccountServiceImpl.rb?view=diff&rev=448819&r1=448818&r2=448819
==============================================================================
---
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/AccountServiceImpl.rb
(original)
+++
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/AccountServiceImpl.rb
Thu Sep 21 22:40:38 2006
@@ -31,22 +31,9 @@
def getAccountReport(customerID)
- report = Document.new <<-eof
- <AccountReport xmlns="http://www.bigbank.com/AccountService"
- xsi:type="AccountReport"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- eof
-
checking = @accountDataService.getCheckingAccount(customerID)
- checking.root.elements["balance"].text =
fromUSDollarToCurrency(checking.root.elements["balance"].text)
- ne = report.root.add_element("checking")
- checking.root.each_element() {|e| ne.add_element(e)}
-
savings = @accountDataService.getSavingsAccount(customerID)
- savings.root.elements["balance"].text =
fromUSDollarToCurrency(savings.root.elements["balance"].text)
-
- ne = report.root.add_element("savings")
- savings.root.each_element() {|e| ne.add_element(e)}
stock = @accountDataService.getStockAccount(customerID);
symbol = stock.root.elements["symbol"].text
@@ -55,20 +42,53 @@
price = @stockQuoteService.getQuote(symbol);
balance = fromUSDollarToCurrency(price.to_f * quantity.to_f)
- stock.root.elements["balance"].text = balance.to_s
-
- ne = report.root.add_element("stock")
- stock.root.each_element() {|e| ne.add_element(e)}
- print report
+ report = Document.new <<-eof
+ <AccountReport xmlns="http://www.bigbank.com/AccountService"
+ xsi:type="AccountReport"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <checking>
+ <accountNumber>
+ #{ checking.root.elements["accountNumber"].text }
+ </accountNumber>
+ <balance>
+ #{ fromUSDollarToCurrency(checking.root.elements["balance"].text) }
+ </balance>
+ </checking>
+
+ <savings>
+ <accountNumber>
+ #{ savings.root.elements["accountNumber"].text }
+ </accountNumber>
+ <balance>
+ #{ fromUSDollarToCurrency(savings.root.elements["balance"].text) }
+ </balance>
+ </savings>
+
+ <stocks>
+ <accountNumber>
+ #{ stock.root.elements["accountNumber"].text }
+ </accountNumber>
+ <symbol>
+ #{ symbol }
+ </symbol>
+ <quantity>
+ #{ quantity }
+ </quantity>
+ <balance>
+ #{ balance }
+ </balance>
+ </stocks>
+
+ </AccountReport>
+ eof
return report
end
def fromUSDollarToCurrency(value)
- print "Currency is: ", @currency, "\n"
- return value * 0.8 if @currency == "EURO"
- return value
+ return value.to_f * 0.8 if @currency == "EURO"
+ return value.to_f
end
end
Modified:
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/StockQuoteServiceImpl.rb
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/StockQuoteServiceImpl.rb?view=diff&rev=448819&r1=448818&r2=448819
==============================================================================
---
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/StockQuoteServiceImpl.rb
(original)
+++
incubator/tuscany/cpp/sca/samples/RubyBank/bigbank.account/StockQuoteServiceImpl.rb
Thu Sep 21 22:40:38 2006
@@ -30,7 +30,12 @@
def getQuote(symbol)
print "Ruby - StockQuoteServiceImpl.getQuote ", symbol, "\n"
- return 80.0
+ result = @webService.GetQuote(symbol)
+ doc = Document.new(result)
+
+ price = doc.root.elements["Stock"].elements["Last"].text;
+
+ return price.to_f
end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]