Author: jsdelfino
Date: Thu Nov  1 19:34:58 2007
New Revision: 591198

URL: http://svn.apache.org/viewvc?rev=591198&view=rev
Log:
Starting to add a variation of the store that maintains the shopping cart in a 
database.

Added:
    incubator/tuscany/java/sca/tutorial/assets/services/Total.java   (with 
props)
    incubator/tuscany/java/sca/tutorial/assets/services/db/
    
incubator/tuscany/java/sca/tutorial/assets/services/db/ShoppingCartTableImpl.java
   (with props)
    incubator/tuscany/java/sca/tutorial/store/launch/LaunchStoreDB.java   (with 
props)
    incubator/tuscany/java/sca/tutorial/store/store-db.composite   (with props)
Removed:
    incubator/tuscany/java/sca/tutorial/assets/uiservices/
Modified:
    incubator/tuscany/java/sca/tutorial/assets/pom.xml
    incubator/tuscany/java/sca/tutorial/assets/services/ShoppingCartImpl.java
    incubator/tuscany/java/sca/tutorial/store-eu/store-eu.composite
    incubator/tuscany/java/sca/tutorial/store-eu/uiservices/store.html
    incubator/tuscany/java/sca/tutorial/store/store-merger.composite
    incubator/tuscany/java/sca/tutorial/store/store.composite
    incubator/tuscany/java/sca/tutorial/store/uiservices/store.html

Modified: incubator/tuscany/java/sca/tutorial/assets/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/assets/pom.xml?rev=591198&r1=591197&r2=591198&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/assets/pom.xml (original)
+++ incubator/tuscany/java/sca/tutorial/assets/pom.xml Thu Nov  1 19:34:58 2007
@@ -40,14 +40,25 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-sca-api</artifactId>
             <version>1.1-incubating-SNAPSHOT</version>
-            <scope>compile</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-binding-feed</artifactId>
             <version>1.1-incubating-SNAPSHOT</version>
-            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-data</artifactId>
+            <version>1.1-incubating-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>10.1.2.1</version>
         </dependency>
 
         <dependency>

Modified: 
incubator/tuscany/java/sca/tutorial/assets/services/ShoppingCartImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/assets/services/ShoppingCartImpl.java?rev=591198&r1=591197&r2=591198&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/assets/services/ShoppingCartImpl.java 
(original)
+++ incubator/tuscany/java/sca/tutorial/assets/services/ShoppingCartImpl.java 
Thu Nov  1 19:34:58 2007
@@ -32,16 +32,13 @@
 import com.sun.syndication.feed.atom.Feed;
 import com.sun.syndication.feed.atom.Link;
 
-public class ShoppingCartImpl implements Collection {
+public class ShoppingCartImpl implements Collection, Total {
 
     private static Map<String, Entry> cart = new HashMap<String, Entry>();
 
     public Feed getFeed() {
         Feed feed = new Feed();
         feed.setTitle("shopping cart");
-        Content subtitle = new Content();
-        subtitle.setValue("Total : " + getTotal());
-        feed.setSubtitle(subtitle);
         feed.getEntries().addAll(cart.values());
         return feed;
     }
@@ -83,7 +80,7 @@
             cart.remove(id);
     }
 
-    private String getTotal() {
+    public String getTotal() {
         double total = 0;
         String currencySymbol = "";
         if (!cart.isEmpty()) {

Added: incubator/tuscany/java/sca/tutorial/assets/services/Total.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/assets/services/Total.java?rev=591198&view=auto
==============================================================================
--- incubator/tuscany/java/sca/tutorial/assets/services/Total.java (added)
+++ incubator/tuscany/java/sca/tutorial/assets/services/Total.java Thu Nov  1 
19:34:58 2007
@@ -0,0 +1,29 @@
+/*
+ * 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.    
+ */
+
+package services;
+
+import org.osoa.sca.annotations.Remotable;
+
[EMAIL PROTECTED]
+public interface Total {
+    
+    String getTotal();
+
+}

Propchange: incubator/tuscany/java/sca/tutorial/assets/services/Total.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/tutorial/assets/services/Total.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/tutorial/assets/services/db/ShoppingCartTableImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/assets/services/db/ShoppingCartTableImpl.java?rev=591198&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/tutorial/assets/services/db/ShoppingCartTableImpl.java
 (added)
+++ 
incubator/tuscany/java/sca/tutorial/assets/services/db/ShoppingCartTableImpl.java
 Thu Nov  1 19:34:58 2007
@@ -0,0 +1,139 @@
+/*
+ * 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.    
+ */
+
+package services.db;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.sca.binding.feed.collection.Collection;
+import org.apache.tuscany.sca.binding.feed.collection.NotFoundException;
+
+import com.sun.syndication.feed.atom.Content;
+import com.sun.syndication.feed.atom.Entry;
+import com.sun.syndication.feed.atom.Feed;
+import com.sun.syndication.feed.atom.Link;
+
+public class ShoppingCartTableImpl implements Collection {
+    
+    private static Map<String, String> cart = new HashMap<String, String>();
+
+    public Feed getFeed() {
+        Feed feed = new Feed();
+        feed.setTitle("shopping cart");
+        for (Map.Entry<String, String> item: getAllData().entrySet()) {
+            feed.getEntries().add(createEntry(item.getKey(), item.getValue()));
+        }
+        return feed;
+    }
+    
+    private Entry createEntry(String key, String item) {
+        Entry entry = new Entry();
+        entry.setId(key);
+        entry.setTitle("cart-item");
+
+        Content content = new Content();
+        content.setType(Content.TEXT);
+        content.setValue(item);
+        List contents = new ArrayList();
+        contents.add(content);
+        entry.setContents(contents);
+
+        Link link = new Link();
+        link.setRel("edit");
+        link.setHref(key);
+        entry.getOtherLinks().add(link);
+        link = new Link();
+        link.setRel("alternate");
+        link.setHref(key);
+        entry.getAlternateLinks().add(link);
+
+        entry.setCreated(new Date());
+
+        return entry;
+    }
+
+    public Entry get(String id) throws NotFoundException {
+        return createEntry(id, cart.get(id));
+    }
+
+    public Entry post(Entry entry) {
+        System.out.println("post" + entry);
+        String item = ((Content)entry.getContents().get(0)).getValue();
+        String key = postData(item);
+        return createEntry(key, item);
+    }
+
+    public Entry put(String id, Entry entry) throws NotFoundException {
+        String item = ((Content)entry.getContents().get(0)).getValue();
+        item = putData(id, item);
+        return createEntry(id, item);
+    }
+
+    public void delete(String id) throws NotFoundException {
+        deleteData(id);
+    }
+
+    private Map<String, String> getAllData() {
+        return cart;
+    }
+
+    private String getData(String key) throws NotFoundException {
+        return cart.get(key);
+    }
+
+    private String postData(String item) {
+        String key = "cart-" + UUID.randomUUID().toString();
+        cart.put(key, item);
+        return key;
+    }
+
+    private String putData(String key, String item) throws NotFoundException {
+        cart.put(key, item);
+        return item;
+    }
+    
+    private void deleteData(String key) throws NotFoundException {
+        if (key == null || key.equals(""))
+            cart.clear();
+        else
+            cart.remove(key);
+    }
+
+    private Map<String, String> queryData(String queryString) {
+        return getAllData();
+    }
+    
+    public String getTotal() {
+        double total = 0;
+        String currencySymbol = "";
+        if (!cart.isEmpty()) {
+            String item = cart.values().iterator().next();
+            currencySymbol = item.substring(item.indexOf("-") + 2, 
item.indexOf("-") + 3);
+        }
+        for (String item : cart.values()) {
+            total += Double.valueOf(item.substring(item.indexOf("-") + 3));
+        }
+        return currencySymbol + String.valueOf(total);
+    }
+}

Propchange: 
incubator/tuscany/java/sca/tutorial/assets/services/db/ShoppingCartTableImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/tutorial/assets/services/db/ShoppingCartTableImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/tutorial/store-eu/store-eu.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/store-eu/store-eu.composite?rev=591198&r1=591197&r2=591198&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/store-eu/store-eu.composite (original)
+++ incubator/tuscany/java/sca/tutorial/store-eu/store-eu.composite Thu Nov  1 
19:34:58 2007
@@ -25,14 +25,17 @@
     <component name="Store">
         <t:implementation.widget location="uiservices/store.html"/>
         <service name="Widget">
-               <t:binding.http uri="http://localhost:8102/ui"/> 
+               <t:binding.http uri="http://localhost:8103/ui"/> 
         </service>
                <reference name="catalog" target="Catalog">
                        <t:binding.jsonrpc/>
                 </reference>
-                <reference name="shoppingCart" target="ShoppingCart">
+                <reference name="shoppingCartCollection" 
target="ShoppingCart/Collection">
                        <t:binding.atom/>
                 </reference>
+                <reference name="shoppingCartTotal" 
target="ShoppingCart/Total">
+                       <t:binding.jsonrpc/>
+                </reference>
     </component>
     
        <component name="Catalog">
@@ -48,9 +51,12 @@
        </component>
        
        <component name="ShoppingCart">
-               <implementation.java class="services.ShoppingCartImpl"/>
+               <implementation.java class="services.db.ShoppingCartTableImpl"/>
                <service name="Collection">
                        <t:binding.atom/>
+               </service>      
+               <service name="Total">
+                       <t:binding.jsonrpc/>
                </service>      
        </component>
     

Modified: incubator/tuscany/java/sca/tutorial/store-eu/uiservices/store.html
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/store-eu/uiservices/store.html?rev=591198&r1=591197&r2=591198&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/store-eu/uiservices/store.html 
(original)
+++ incubator/tuscany/java/sca/tutorial/store-eu/uiservices/store.html Thu Nov  
1 19:34:58 2007
@@ -28,7 +28,10 @@
        var catalog = new Reference("catalog");
        
        //@Reference
-       var shoppingCart = new Reference("shoppingCart");
+       var shoppingCartCollection = new Reference("shoppingCartCollection");
+
+       //@Reference
+       var shoppingCartTotal = new Reference("shoppingCartTotal");
 
 
        function catalog_getResponse(items) {
@@ -40,7 +43,7 @@
                document.getElementById('catalog').innerHTML=catalog;
        }
        
-       function shoppingCart_getResponse(feed) {
+       function shoppingCartCollection_getResponse(feed) {
                if (feed != null) {
                        var entries = feed.getElementsByTagName("entry");       
       
                        var list = "";
@@ -49,21 +52,28 @@
                                list += item + ' <br>';
                        }
                        document.getElementById("shoppingCart").innerHTML = 
list;
-                       document.getElementById('total').innerHTML = 
feed.getElementsByTagName("subtitle")[0].firstChild.nodeValue;
+
+                       if (entries.length != 0) {                      
+                               
shoppingCartTotal.getTotal(shoppingCartTotal_getTotalResponse);
+                       }
                }
        }
-       function shoppingCart_postResponse(entry) {
-               shoppingCart.get("", shoppingCart_getResponse);
+       
+       function shoppingCartTotal_getTotalResponse(total) {
+               document.getElementById('total').innerHTML = total;
+       }
+       
+       function shoppingCartCollection_postResponse(entry) {
+               shoppingCartCollection.get("", 
shoppingCartCollection_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);
+                               shoppingCartCollection.post(entry, 
shoppingCartCollection_postResponse);
                                items[i].checked = false;
                        }
        }
@@ -79,16 +89,16 @@
                                        '<br>'+
                                        '<input type="submit" value="Continue 
Shopping">'+ 
                                '</form>';
-               shoppingCart.del("", null);
+               shoppingCartCollection.del("", null);
        }
        function deleteCart() {
-               shoppingCart.del("", null);
+               shoppingCartCollection.del("", null);
                document.getElementById('shoppingCart').innerHTML = "";
                document.getElementById('total').innerHTML = "";        
        }       
 
        catalog.get(catalog_getResponse);
-       shoppingCart.get("", shoppingCart_getResponse);
+       shoppingCartCollection.get("", shoppingCartCollection_getResponse);
 </script>
 
 </head>
@@ -114,7 +124,7 @@
                <br>            
                <input type="button" onClick="checkoutCart()" value="Checkout"> 
                <input type="button" onClick="deleteCart()" value="Empty">     
-               <a href="../ShoppingCart/">(feed)</a>
+               <a href="../ShoppingCart/Collection/">(feed)</a>
        </form>    
   </div>
 </body>

Added: incubator/tuscany/java/sca/tutorial/store/launch/LaunchStoreDB.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/store/launch/LaunchStoreDB.java?rev=591198&view=auto
==============================================================================
--- incubator/tuscany/java/sca/tutorial/store/launch/LaunchStoreDB.java (added)
+++ incubator/tuscany/java/sca/tutorial/store/launch/LaunchStoreDB.java Thu Nov 
 1 19:34:58 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.    
+ */
+
+package launch;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+import org.apache.tuscany.sca.node.util.SCAContributionUtil;
+
+public class LaunchStoreDB {
+    public static void main(String[] args) throws Exception {
+        System.out.println("Starting ...");
+        SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+        SCANode node = nodeFactory.createSCANode(null, 
"http://localhost:9999";);
+        
+        URL contribution = 
SCAContributionUtil.findContributionFromClass(LaunchStoreDB.class);
+        node.addContribution("http://store";, contribution);
+        
+        node.addToDomainLevelComposite(new QName("http://store";, "store-db"));
+        node.start();
+
+        System.out.println("store.composite ready for big business !!!");
+        System.in.read();
+        
+        System.out.println("Stopping ...");
+        node.stop();
+        node.destroy();
+        System.out.println();
+    }
+}

Propchange: incubator/tuscany/java/sca/tutorial/store/launch/LaunchStoreDB.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/tutorial/store/launch/LaunchStoreDB.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/tutorial/store/store-db.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/store/store-db.composite?rev=591198&view=auto
==============================================================================
--- incubator/tuscany/java/sca/tutorial/store/store-db.composite (added)
+++ incubator/tuscany/java/sca/tutorial/store/store-db.composite Thu Nov  1 
19:34:58 2007
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite     xmlns="http://www.osoa.org/xmlns/sca/1.0";
+               xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0";
+               targetNamespace="http://store";
+               name="store-db">
+               
+    <component name="Store">
+        <t:implementation.widget location="uiservices/store.html"/>
+        <service name="Widget">
+               <t:binding.http uri="http://localhost:8102/ui"/> 
+        </service>
+               <reference name="catalog" target="Catalog">
+                       <t:binding.jsonrpc/>
+                </reference>
+                <reference name="shoppingCartCollection" 
target="ShoppingCart/Collection">
+                       <t:binding.atom/>
+                </reference>
+                <reference name="shoppingCartTotal" 
target="ShoppingCart/Total">
+                       <t:binding.jsonrpc/>
+                </reference>
+    </component>
+    
+       <component name="Catalog">
+               <implementation.java 
class="services.merger.MergedCatalogImpl"/> 
+               <property name="currencyCode">USD</property>
+               <service name="Catalog">
+                       <t:binding.jsonrpc/>
+                       <binding.ws uri="CatalogWebService"/>
+               </service>
+               <reference name="fruitsCatalog" target="FruitsCatalog"/>        
+               <reference name="vegetablesCatalog" 
target="CloudVegetablesCatalog"/>   
+               <reference name="currencyConverter" 
target="CurrencyConverter"/>        
+       </component>
+       
+       <component name="FruitsCatalog">
+               <implementation.java class="services.FruitsCatalogImpl"/> 
+               <property name="currencyCode">USD</property>
+               <reference name="currencyConverter" 
target="CurrencyConverter"/>        
+       </component> 
+       
+       <component name="ShoppingCart">
+               <implementation.java class="services.db.ShoppingCartTableImpl"/>
+               <service name="Collection">
+                       <t:binding.atom/>
+               </service>      
+               <service name="Total">
+                       <t:binding.jsonrpc/>
+               </service>      
+       </component>
+    
+       <component name="CurrencyConverter">
+               <implementation.java class="services.CurrencyConverterImpl"/>
+       </component>     
+
+</composite>

Propchange: incubator/tuscany/java/sca/tutorial/store/store-db.composite
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/tutorial/store/store-db.composite
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/tutorial/store/store-merger.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/store/store-merger.composite?rev=591198&r1=591197&r2=591198&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/store/store-merger.composite (original)
+++ incubator/tuscany/java/sca/tutorial/store/store-merger.composite Thu Nov  1 
19:34:58 2007
@@ -30,9 +30,12 @@
                <reference name="catalog" target="Catalog">
                        <t:binding.jsonrpc/>
                 </reference>
-                <reference name="shoppingCart" target="ShoppingCart">
+                <reference name="shoppingCartCollection" 
target="ShoppingCart/Collection">
                        <t:binding.atom/>
                 </reference>
+                <reference name="shoppingCartTotal" 
target="ShoppingCart/Total">
+                       <t:binding.jsonrpc/>
+                </reference>
     </component>
     
        <component name="Catalog">
@@ -54,9 +57,12 @@
        </component> 
        
        <component name="ShoppingCart">
-               <implementation.java class="services.ShoppingCartImpl"/>
+               <implementation.java class="services.db.ShoppingCartTableImpl"/>
                <service name="Collection">
                        <t:binding.atom/>
+               </service>      
+               <service name="Total">
+                       <t:binding.jsonrpc/>
                </service>      
        </component>
     

Modified: incubator/tuscany/java/sca/tutorial/store/store.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/store/store.composite?rev=591198&r1=591197&r2=591198&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/store/store.composite (original)
+++ incubator/tuscany/java/sca/tutorial/store/store.composite Thu Nov  1 
19:34:58 2007
@@ -30,9 +30,12 @@
                <reference name="catalog" target="Catalog">
                        <t:binding.jsonrpc/>
                 </reference>
-                <reference name="shoppingCart" target="ShoppingCart">
+                <reference name="shoppingCartCollection" 
target="ShoppingCart/Collection">
                        <t:binding.atom/>
                 </reference>
+                <reference name="shoppingCartTotal" 
target="ShoppingCart/Total">
+                       <t:binding.jsonrpc/>
+                </reference>
     </component>
     
        <component name="Catalog">
@@ -49,6 +52,9 @@
                <service name="Collection">
                        <t:binding.atom/>
                </service>      
+               <service name="Total">
+                       <t:binding.jsonrpc/>
+               </service>      
        </component>
     
        <component name="CurrencyConverter">

Modified: incubator/tuscany/java/sca/tutorial/store/uiservices/store.html
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/store/uiservices/store.html?rev=591198&r1=591197&r2=591198&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/store/uiservices/store.html (original)
+++ incubator/tuscany/java/sca/tutorial/store/uiservices/store.html Thu Nov  1 
19:34:58 2007
@@ -28,7 +28,10 @@
        var catalog = new Reference("catalog");
        
        //@Reference
-       var shoppingCart = new Reference("shoppingCart");
+       var shoppingCartCollection = new Reference("shoppingCartCollection");
+
+       //@Reference
+       var shoppingCartTotal = new Reference("shoppingCartTotal");
 
 
        function catalog_getResponse(items) {
@@ -40,7 +43,7 @@
                document.getElementById('catalog').innerHTML=catalog;
        }
        
-       function shoppingCart_getResponse(feed) {
+       function shoppingCartCollection_getResponse(feed) {
                if (feed != null) {
                        var entries = feed.getElementsByTagName("entry");       
       
                        var list = "";
@@ -49,21 +52,28 @@
                                list += item + ' <br>';
                        }
                        document.getElementById("shoppingCart").innerHTML = 
list;
-                       document.getElementById('total').innerHTML = 
feed.getElementsByTagName("subtitle")[0].firstChild.nodeValue;
+
+                       if (entries.length != 0) {                      
+                               
shoppingCartTotal.getTotal(shoppingCartTotal_getTotalResponse);
+                       }
                }
        }
-       function shoppingCart_postResponse(entry) {
-               shoppingCart.get("", shoppingCart_getResponse);
+       
+       function shoppingCartTotal_getTotalResponse(total) {
+               document.getElementById('total').innerHTML = total;
+       }
+       
+       function shoppingCartCollection_postResponse(entry) {
+               shoppingCartCollection.get("", 
shoppingCartCollection_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);
+                               shoppingCartCollection.post(entry, 
shoppingCartCollection_postResponse);
                                items[i].checked = false;
                        }
        }
@@ -79,16 +89,16 @@
                                        '<br>'+
                                        '<input type="submit" value="Continue 
Shopping">'+ 
                                '</form>';
-               shoppingCart.del("", null);
+               shoppingCartCollection.del("", null);
        }
        function deleteCart() {
-               shoppingCart.del("", null);
+               shoppingCartCollection.del("", null);
                document.getElementById('shoppingCart').innerHTML = "";
                document.getElementById('total').innerHTML = "";        
        }       
 
        catalog.get(catalog_getResponse);
-       shoppingCart.get("", shoppingCart_getResponse);
+       shoppingCartCollection.get("", shoppingCartCollection_getResponse);
 </script>
 
 </head>
@@ -113,7 +123,7 @@
                <br>            
                <input type="button" onClick="checkoutCart()" value="Checkout"> 
                <input type="button" onClick="deleteCart()" value="Empty">     
-               <a href="../ShoppingCart/">(feed)</a>
+               <a href="../ShoppingCart/Collection/">(feed)</a>
        </form>    
   </div>
 </body>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to