...
The first thing you do is to create a folder on you disk into which you will download the TUSCANY distribution.
Next you download the latest release distribution. Launch your browser and enter one of the
following URL's.
Latest Release - http://cwiki.apache.org/TUSCANY/sca-java-releases.html
Download both the bin zip as well as the src zip to the folder that you created on your disk. Once
you completed the download you should see the following on your disk.
Next you unzip the bin zip in place, you should see the following folder file structure on your disk
after unzip is complete.
...
Code Block |
---|
package services; public class CurrencyConverterImpl implements CurrencyConverter { public float getConversion(String fromCurrencyCode, String toCurrencyCode, float amount) { if (toCurrencyCode.equals("USD")) return amount; else if (toCurrencyCode.equals("EUR")) return amount*0.7256f; return 0; } public String getCurrencySymbol(String currencyCode) { if (currencyCode.equals("USD")) return "$"; else if (currencyCode.equals("EUR")) return "€?"; return "?"; } } |
After completing these steps the content of the "store" project will look as follows.
...
The Text editor will open on the new created html file. Replace the content of the editor by copy-paste
of the following html snippet.
Code Block |
---|
<html><html> <head> <title>Store</title> <script type="text/javascript" src="binding-atom.js"></script> <script type="text/javascript" src="binding-jsonrpc.js"></script> <script language="JavaScript"> //Reference catalog = (new JSONRpcClient("../Catalog")).Catalog; //Reference shoppingCart = new AtomClient("../ShoppingCart"); function catalog_getResponse(items) { var catalog = ""; for (var i=0; i<items.length; i++) catalog \+= '<input name="items" type="checkbox" value="' + items\[i\] + '">' + items\[i\]\+ ' <br>'; document.getElementById('catalog').innerHTML=catalog; } function shoppingCart_getResponse(feed) { if (feed \!= null) { var entries = feed.getElementsByTagName("entry"); var list = ""; for (var i=0; i<entries.length; i++) { var item = entries\[i\].getElementsByTagName("content")\[0\].firstChild.nodeValue; list \+= item + ' <br>'; } document.getElementById("shoppingCart").innerHTML = list; if (list \!= "") { document.getElementById('total').innerHTML = feed.getElementsByTagName("subtitle")\[0\].firstChild.nodeValue; } } function shoppingCart_postResponse(entry) { shoppingCart.get("", shoppingCart_getResponse); } function addToCart() { var items = document.catalogForm.items; var j = 0; for (var i=0; i<items.length; i++) if (items\[i\].checked) { var entry = '<entry xmlns="http://www.w3.org/2005/Atom">' + '<title>cart-item</title>' + '<content type="text">'+items\[i\].value+'</content>' + '</entry>'; shoppingCart.post(entry, shoppingCart_postResponse); items\[i\].checked = false; } } function checkoutCart() { document.getElementById('store').innerHTML='<h2>' + 'Thanks for Shopping With Us\!</h2>'\+ '<h2>Your Order</h2>'\+ '<form name="orderForm" action="/ufs/store.html">'\+ document.getElementById('shoppingCart').innerHTML\+ '<br>'\+ document.getElementById('total').innerHTML\+ '<br>'\+ '<br>'\+ '<input type="submit" value="Continue Shopping">'\+ '</form>'; shoppingCart.delete("", null); } function deleteCart() { shoppingCart.delete("", null); document.getElementById('shoppingCart').innerHTML = ""; document.getElementById('total').innerHTML = ""; } window.onload = function() { catalog.get(catalog_getResponse); shoppingCart.get("", shoppingCart_getResponse); } </script> <link rel="stylesheet" type="text/css" href="style.css" /></head><body> > </head> <body> <h1>Store</h1> <div id="store"> <h2>Catalog</h2> <form name="catalogForm"> <div id="catalog" ></div> <br> <input type="button" onClick="addToCart()" value="Add to Cart"> </form> <br> <h2>Your Shopping Cart</h2> <form name="shoppingCartForm"> <div id="shoppingCart"></div> <br> <div id="total"></div> <br> <input type="button" onClick="checkoutCart()" value="Checkout"> <input type="button" onClick="deleteCart()" value="Empty"> <a href="../ShoppingCart/"> <img src="http://projects.apache.org/images/blue-icon.png" border="0"> </a> </form> </div> </body> </html> |
<<Under construction >>