You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/03/24 07:46:31 UTC
svn commit: r640331 - in /incubator/tuscany/java/sca/samples/store: ./
src/main/java/services/ src/main/resources/ src/main/resources/ufservices/
src/main/resources/uiservices/
Author: jsdelfino
Date: Sun Mar 23 23:46:30 2008
New Revision: 640331
URL: http://svn.apache.org/viewvc?rev=640331&view=rev
Log:
Fix for TUSCANY-2128. Integrated fixes and improvements from tutorial version of the store in the store sample.
Added:
incubator/tuscany/java/sca/samples/store/src/main/java/services/Cart.java (with props)
incubator/tuscany/java/sca/samples/store/src/main/java/services/FruitsCatalogImpl.java (with props)
incubator/tuscany/java/sca/samples/store/src/main/java/services/Item.java (with props)
incubator/tuscany/java/sca/samples/store/src/main/java/services/Total.java (with props)
incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/
incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/store.html (with props)
Removed:
incubator/tuscany/java/sca/samples/store/src/main/java/services/CatalogImpl.java
incubator/tuscany/java/sca/samples/store/src/main/resources/ufservices/
Modified:
incubator/tuscany/java/sca/samples/store/pom.xml
incubator/tuscany/java/sca/samples/store/src/main/java/services/Catalog.java
incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverter.java
incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverterImpl.java
incubator/tuscany/java/sca/samples/store/src/main/java/services/ShoppingCartImpl.java
incubator/tuscany/java/sca/samples/store/src/main/resources/store.composite
Modified: incubator/tuscany/java/sca/samples/store/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/pom.xml?rev=640331&r1=640330&r2=640331&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/pom.xml (original)
+++ incubator/tuscany/java/sca/samples/store/pom.xml Sun Mar 23 23:46:30 2008
@@ -44,6 +44,12 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-data-api</artifactId>
+ <version>2.0-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
<version>2.0-incubating-SNAPSHOT</version>
<scope>runtime</scope>
@@ -60,6 +66,7 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-atom-abdera</artifactId>
<version>2.0-incubating-SNAPSHOT</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
Added: incubator/tuscany/java/sca/samples/store/src/main/java/services/Cart.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/Cart.java?rev=640331&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/Cart.java (added)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/Cart.java Sun Mar 23 23:46:30 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.apache.tuscany.sca.implementation.data.collection.Collection;
+import org.osoa.sca.annotations.Remotable;
+
+@Remotable
+public interface Cart extends Collection<String, Item> {
+
+}
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/Cart.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/Cart.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/samples/store/src/main/java/services/Catalog.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/Catalog.java?rev=640331&r1=640330&r2=640331&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/Catalog.java (original)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/Catalog.java Sun Mar 23 23:46:30 2008
@@ -23,5 +23,5 @@
@Remotable
public interface Catalog {
- String[] get();
+ Item[] get();
}
Modified: incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverter.java?rev=640331&r1=640330&r2=640331&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverter.java (original)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverter.java Sun Mar 23 23:46:30 2008
@@ -23,7 +23,7 @@
@Remotable
public interface CurrencyConverter {
- public float getConversion(String fromCurrenycCode, String toCurrencyCode, float amount);
+ public double getConversion(String fromCurrenycCode, String toCurrencyCode, double amount);
public String getCurrencySymbol(String currencyCode);
}
Modified: incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverterImpl.java?rev=640331&r1=640330&r2=640331&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverterImpl.java (original)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/CurrencyConverterImpl.java Sun Mar 23 23:46:30 2008
@@ -6,41 +6,33 @@
* 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.
+ * under the License.
*/
package services;
-import org.osoa.sca.annotations.Property;
-
public class CurrencyConverterImpl implements CurrencyConverter {
- @Property
- public Float rate = 0.7256f;
-
- public float getConversion(String fromCurrencyCode, String toCurrencyCode, float amount) {
- if (fromCurrencyCode.equals(toCurrencyCode))
- return amount;
-
+ public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) {
if (toCurrencyCode.equals("USD"))
- return amount / rate;
+ return amount;
else if (toCurrencyCode.equals("EUR"))
- return amount * rate;
+ return ((double)Math.round(amount * 0.7256 * 100)) /100;
return 0;
}
-
+
public String getCurrencySymbol(String currencyCode) {
if (currencyCode.equals("USD"))
- return "$ ";
+ return "$";
else if (currencyCode.equals("EUR"))
- return "⬠";
+ return "E"; //"â¬";
return "?";
}
}
Added: incubator/tuscany/java/sca/samples/store/src/main/java/services/FruitsCatalogImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/FruitsCatalogImpl.java?rev=640331&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/FruitsCatalogImpl.java (added)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/FruitsCatalogImpl.java Sun Mar 23 23:46:30 2008
@@ -0,0 +1,52 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+public class FruitsCatalogImpl implements Catalog {
+
+ @Property
+ public String currencyCode = "USD";
+
+ @Reference
+ public CurrencyConverter currencyConverter;
+
+ private List<Item> catalog = new ArrayList<Item>();
+
+ @Init
+ public void init() {
+ String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+ catalog.add(new Item("Apple", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99)));
+ catalog.add(new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55)));
+ catalog.add(new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55)));
+ }
+
+ public Item[] get() {
+ Item[] catalogArray = new Item[catalog.size()];
+ catalog.toArray(catalogArray);
+ return catalogArray;
+ }
+}
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/FruitsCatalogImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/FruitsCatalogImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/samples/store/src/main/java/services/Item.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/Item.java?rev=640331&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/Item.java (added)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/Item.java Sun Mar 23 23:46:30 2008
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+
+public class Item {
+ private String name;
+ private String price;
+
+ public Item() {
+ }
+
+ public Item(String name, String price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPrice() {
+ return price;
+ }
+
+ public void setPrice(String price) {
+ this.price = price;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/Item.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/Item.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/samples/store/src/main/java/services/ShoppingCartImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/ShoppingCartImpl.java?rev=640331&r1=640330&r2=640331&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/ShoppingCartImpl.java (original)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/ShoppingCartImpl.java Sun Mar 23 23:46:30 2008
@@ -19,101 +19,93 @@
package services;
-import java.util.Date;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.tuscany.sca.binding.atom.collection.Collection;
-import org.apache.tuscany.sca.binding.atom.collection.NotFoundException;
-
-
-public class ShoppingCartImpl implements Collection {
-
- private static Map<String, Entry> cart = new HashMap<String, Entry>();
-
- public Feed getFeed() {
- Feed feed = Abdera.getNewFactory().newFeed();
- feed.setTitle("shopping cart");
- feed.setSubtitle("Total : " + getTotal());
-
- for (Entry entry : cart.values()) {
- feed.addEntry(entry);
+import org.apache.tuscany.sca.implementation.data.collection.Entry;
+import org.apache.tuscany.sca.implementation.data.collection.NotFoundException;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("COMPOSITE")
+public class ShoppingCartImpl implements Cart, Total {
+
+ private Map<String, Item> cart;
+
+ @Init
+ protected void init() {
+ cart = new HashMap<String, Item>();
+ }
+
+ public Entry<String, Item>[] getAll() {
+ Entry<String, Item>[] entries = new Entry[cart.size()];
+ int i = 0;
+ for (Map.Entry<String, Item> e: cart.entrySet()) {
+ entries[i++] = new Entry<String, Item>(e.getKey(), e.getValue());
}
-
- return feed;
+ return entries;
}
- public Feed query(String queryString) {
- if (queryString.startsWith("name=")) {
- String name = queryString.substring(5);
-
- Feed feed = Abdera.getNewFactory().newFeed();
- feed.setTitle("shopping cart");
- feed.setSubtitle("Total : " + getTotal());
-
- for (Entry entry : cart.values()) {
- if (entry.getTitle().contains(name)) {
- feed.addEntry(entry);
- }
- }
- return feed;
-
+ public Item get(String key) throws NotFoundException {
+ Item item = cart.get(key);
+ if (item == null) {
+ throw new NotFoundException(key);
} else {
- return getFeed();
+ return item;
}
}
- public Entry get(String id) throws NotFoundException {
- return cart.get(id);
- }
-
- public Entry post(Entry entry) {
- System.out.println("post" + entry);
- String id = "cart-" + UUID.randomUUID().toString();
- entry.setId(id);
-
- entry.addLink(id, "edit");
- entry.addLink(id, "alternate");
-
- entry.setEdited(new Date());
-
- cart.put(id, entry);
- return entry;
+ public String post(String key, Item item) {
+ if (key == null) {
+ key ="cart-" + UUID.randomUUID().toString();
+ }
+ cart.put(key, item);
+ return key;
}
- public void put(String id, Entry entry) throws NotFoundException {
- entry.setUpdated(new Date());
- cart.put(id, entry);
+ public void put(String key, Item item) throws NotFoundException {
+ if (!cart.containsKey(key)) {
+ throw new NotFoundException(key);
+ }
+ cart.put(key, item);
}
-
- public void delete(String id) throws NotFoundException {
- if (id.equals(""))
+
+ public void delete(String key) throws NotFoundException {
+ if (key == null || key.equals("")) {
cart.clear();
- else
- cart.remove(id);
+ } else {
+ Item item = cart.remove(key);
+ if (item == null)
+ throw new NotFoundException(key);
+ }
}
- private String getTotal() {
- float total = 0;
+ public Entry<String, Item>[] query(String queryString) {
+ List<Entry<String, Item>> entries = new ArrayList<Entry<String,Item>>();
+ if (queryString.startsWith("name=")) {
+ String name = queryString.substring(5);
+ for (Map.Entry<String, Item> e: cart.entrySet()) {
+ Item item = e.getValue();
+ if (item.getName().equals(name)) {
+ entries.add(new Entry<String, Item>(e.getKey(), e.getValue()));
+ }
+ }
+ }
+ return entries.toArray(new Entry[entries.size()]);
+ }
+
+ public String getTotal() {
+ double total = 0;
String currencySymbol = "";
if (!cart.isEmpty()) {
- String item = ((Entry)cart.values().iterator().next()).getContent();
- currencySymbol = item.substring(item.indexOf("-") + 2, item.indexOf("-") + 3);
+ Item item = cart.values().iterator().next();
+ currencySymbol = item.getPrice().substring(0, 1);
}
- for (Entry entry : cart.values()) {
- String item = entry.getContent();
-
- int index = item.length()-1;
- char digit;
- while ((digit = item.charAt(index)) == '.' || Character.isDigit(digit)) {
- index--;
- }
-
- total += Float.valueOf(item.substring(index));
+ for (Item item : cart.values()) {
+ total += Double.valueOf(item.getPrice().substring(1));
}
return currencySymbol + String.valueOf(total);
}
Added: incubator/tuscany/java/sca/samples/store/src/main/java/services/Total.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/Total.java?rev=640331&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/Total.java (added)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/Total.java Sun Mar 23 23:46:30 2008
@@ -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;
+
+@Remotable
+public interface Total {
+
+ String getTotal();
+
+}
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/Total.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/services/Total.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/samples/store/src/main/resources/store.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/resources/store.composite?rev=640331&r1=640330&r2=640331&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/resources/store.composite (original)
+++ incubator/tuscany/java/sca/samples/store/src/main/resources/store.composite Sun Mar 23 23:46:30 2008
@@ -19,24 +19,27 @@
-->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
- targetNamespace="http://store"
+ targetNamespace="http://store"
name="store">
- <component name="store">
- <t:implementation.widget location="ufservices/store.html"/>
+ <component name="Store">
+ <t:implementation.widget location="uiservices/store.html"/>
<service name="Widget">
- <t:binding.http/>
+ <t:binding.http uri="/store"/>
</service>
<reference name="catalog" target="Catalog">
<t:binding.jsonrpc/>
</reference>
- <reference name="shoppingCart" target="ShoppingCart">
+ <reference name="shoppingCart" target="ShoppingCart/Cart">
<t:binding.atom/>
</reference>
+ <reference name="shoppingTotal" target="ShoppingCart/Total">
+ <t:binding.jsonrpc/>
+ </reference>
</component>
<component name="Catalog">
- <implementation.java class="services.CatalogImpl"/>
+ <implementation.java class="services.FruitsCatalogImpl"/>
<property name="currencyCode">USD</property>
<service name="Catalog">
<t:binding.jsonrpc/>
@@ -46,14 +49,16 @@
<component name="ShoppingCart">
<implementation.java class="services.ShoppingCartImpl"/>
- <service name="Collection">
- <t:binding.atom/>
+ <service name="Cart">
+ <t:binding.atom uri="/ShoppingCart/Cart"/>
+ </service>
+ <service name="Total">
+ <t:binding.jsonrpc/>
</service>
</component>
<component name="CurrencyConverter">
- <implementation.java class="services.CurrencyConverterImpl"/>
- <property name="rate">0.7256</property>
+ <implementation.java class="services.CurrencyConverterImpl"/>
</component>
</composite>
Added: incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/store.html
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/store.html?rev=640331&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/store.html (added)
+++ incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/store.html Sun Mar 23 23:46:30 2008
@@ -0,0 +1,138 @@
+<!--
+ * 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.
+-->
+<html>
+<head>
+<title>Store</title>
+
+<script type="text/javascript" src="store.js"></script>
+
+<script language="JavaScript">
+
+ //@Reference
+ var catalog = new Reference("catalog");
+
+ //@Reference
+ var shoppingCart = new Reference("shoppingCart");
+
+ //@Reference
+ var shoppingTotal = new Reference("shoppingTotal");
+
+ var catalogItems;
+
+ function catalog_getResponse(items) {
+ var catalog = "";
+ for (var i=0; i<items.length; i++) {
+ var item = items[i].name + ' - ' + items[i].price;
+ catalog += '<input name="items" type="checkbox" value="' +
+ item + '">' + item + ' <br>';
+ }
+ document.getElementById('catalog').innerHTML=catalog;
+ catalogItems = items;
+ }
+
+ function shoppingCart_getResponse(feed) {
+ if (feed != null) {
+ var entries = feed.getElementsByTagName("entry");
+ var list = "";
+ for (var i=0; i<entries.length; i++) {
+ var content = entries[i].getElementsByTagName("content")[0];
+ var name = content.getElementsByTagName("name")[0].firstChild.nodeValue;
+ var price = content.getElementsByTagName("price")[0].firstChild.nodeValue;
+ list += name + ' - ' + price + ' <br>';
+ }
+ document.getElementById("shoppingCart").innerHTML = list;
+
+ if (entries.length != 0) {
+ shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ }
+ }
+ }
+
+ function shoppingTotal_getTotalResponse(total) {
+ document.getElementById('total').innerHTML = total;
+ }
+
+ 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>item</title><content type="text/xml">' +
+ '<Item xmlns="http://services/">' +
+ '<name xmlns="">' + catalogItems[i].name + '</name>' + '<price xmlns="">' + catalogItems[i].price + '</price>' +
+ '</Item>' + '</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">'+
+ document.getElementById('shoppingCart').innerHTML+
+ '<br>'+
+ document.getElementById('total').innerHTML+
+ '<br>'+
+ '<br>'+
+ '<input type="submit" value="Continue Shopping">'+
+ '</form>';
+ shoppingCart.del("", null);
+ }
+ function deleteCart() {
+ shoppingCart.del("", null);
+ document.getElementById('shoppingCart').innerHTML = "";
+ document.getElementById('total').innerHTML = "";
+ }
+
+ catalog.get(catalog_getResponse);
+ shoppingCart.get("", shoppingCart_getResponse);
+</script>
+
+</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/Cart/">(feed)</a>
+ </form>
+ </div>
+</body>
+</html>
Propchange: incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/store.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/samples/store/src/main/resources/uiservices/store.html
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org