summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.5/tutorials/store/assets
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-04-18 07:36:53 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-04-18 07:36:53 +0000
commit6c7ad7c110656f47273dc23228b41e46023492f3 (patch)
tree348f4838b71e73278bd01153e93db88e22e9c189 /branches/sca-java-1.5/tutorials/store/assets
parent5395b820e60118c68eab9c442af3c53e0e2d7f50 (diff)
Create 1.5 branch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@766260 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.5/tutorials/store/assets')
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/META-INF/sca-contribution.xml27
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/pom.xml92
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/Cart.java28
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/Catalog.java27
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverter.java29
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverterImpl.java38
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/FruitsCatalogImpl.java52
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/Item.java66
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/ShoppingCartImpl.java112
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/Total.java29
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/VegetablesCatalogImpl.java42
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/db/ShoppingCartTableImpl.java171
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/db/cart.sql27
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/map/FruitsCatalogImpl.java56
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/market/MarketCatalogImpl.java66
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/services/merger/MergedCatalogImpl.java66
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/tutorial.html37
-rw-r--r--branches/sca-java-1.5/tutorials/store/assets/uiservices/store.html159
18 files changed, 1124 insertions, 0 deletions
diff --git a/branches/sca-java-1.5/tutorials/store/assets/META-INF/sca-contribution.xml b/branches/sca-java-1.5/tutorials/store/assets/META-INF/sca-contribution.xml
new file mode 100644
index 0000000000..cba1564cb4
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/META-INF/sca-contribution.xml
@@ -0,0 +1,27 @@
+<?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.
+-->
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0">
+ <export.java package="services"/>
+ <export.java package="services.market"/>
+ <export.java package="services.merger"/>
+ <export.java package="services.db"/>
+ <export.java package="services.map"/>
+ <export.resource uri="uiservices/store.html"/>
+</contribution> \ No newline at end of file
diff --git a/branches/sca-java-1.5/tutorials/store/assets/pom.xml b/branches/sca-java-1.5/tutorials/store/assets/pom.xml
new file mode 100644
index 0000000000..dd2bdada40
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/pom.xml
@@ -0,0 +1,92 @@
+<?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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-tutorial-store</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tutorial-assets</artifactId>
+ <name>Apache Tuscany SCA Store Tutorial Reusable Assets</name>
+
+ <repositories>
+ <repository>
+ <id>apache.incubator</id>
+ <url>http://people.apache.org/repo/m2-incubating-repository</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-data-api</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.3.1.4</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+ <sourceDirectory>${basedir}</sourceDirectory>
+ <resources>
+ <resource>
+ <directory>${basedir}</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ <exclude>**/.*/**</exclude>
+ <exclude>pom.xml</exclude>
+ <exclude>build.xml</exclude>
+ <exclude>target/**</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-maven-ant-generator</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <configuration>
+ <pathToRootDir>../../..</pathToRootDir>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/Cart.java b/branches/sca-java-1.5/tutorials/store/assets/services/Cart.java
new file mode 100644
index 0000000000..9e6226d963
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/Cart.java
@@ -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.data.collection.Collection;
+import org.osoa.sca.annotations.Remotable;
+
+@Remotable
+public interface Cart extends Collection<String, Item> {
+
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/Catalog.java b/branches/sca-java-1.5/tutorials/store/assets/services/Catalog.java
new file mode 100644
index 0000000000..2c3b19f579
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/Catalog.java
@@ -0,0 +1,27 @@
+/*
+ * 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 Catalog {
+ Item[] get();
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverter.java b/branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverter.java
new file mode 100644
index 0000000000..e104a0423a
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverter.java
@@ -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 CurrencyConverter {
+ public double getConversion(String fromCurrenycCode, String toCurrencyCode, double amount);
+
+ public String getCurrencySymbol(String currencyCode);
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverterImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverterImpl.java
new file mode 100644
index 0000000000..c354aed447
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/CurrencyConverterImpl.java
@@ -0,0 +1,38 @@
+/*
+ * 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 CurrencyConverterImpl implements CurrencyConverter {
+ public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) {
+ if (toCurrencyCode.equals("USD"))
+ return amount;
+ else if (toCurrencyCode.equals("EUR"))
+ return ((double)Math.round(amount * 0.7256 * 100)) /100;
+ return 0;
+ }
+
+ public String getCurrencySymbol(String currencyCode) {
+ if (currencyCode.equals("USD"))
+ return "$";
+ else if (currencyCode.equals("EUR"))
+ return "E"; //"€";
+ return "?";
+ }
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/FruitsCatalogImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/FruitsCatalogImpl.java
new file mode 100644
index 0000000000..377b3d7e59
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/FruitsCatalogImpl.java
@@ -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;
+ }
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/Item.java b/branches/sca-java-1.5/tutorials/store/assets/services/Item.java
new file mode 100644
index 0000000000..81cefcdbef
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/Item.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+ private String origin;
+
+ public Item() {
+ }
+
+ public Item(String name, String price, String origin) {
+ this.name = name;
+ this.price = price;
+ this.origin = origin;
+ }
+
+ 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;
+ }
+
+ public String getOrigin() {
+ return origin;
+ }
+
+ public void setOrigin(String origin) {
+ this.origin = origin;
+ }
+
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/ShoppingCartImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/ShoppingCartImpl.java
new file mode 100644
index 0000000000..9889921a96
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/ShoppingCartImpl.java
@@ -0,0 +1,112 @@
+/*
+ * 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.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.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
+ public 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 entries;
+ }
+
+ public Item get(String key) throws NotFoundException {
+ Item item = cart.get(key);
+ if (item == null) {
+ throw new NotFoundException(key);
+ } else {
+ return item;
+ }
+ }
+
+ 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 key, Item item) throws NotFoundException {
+ if (!cart.containsKey(key)) {
+ throw new NotFoundException(key);
+ }
+ cart.put(key, item);
+ }
+
+ public void delete(String key) throws NotFoundException {
+ if (key == null || key.equals("")) {
+ cart.clear();
+ } else {
+ Item item = cart.remove(key);
+ if (item == null)
+ throw new NotFoundException(key);
+ }
+ }
+
+ 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()) {
+ Item item = cart.values().iterator().next();
+ currencySymbol = item.getPrice().substring(0, 1);
+ }
+ for (Item item : cart.values()) {
+ total += Double.valueOf(item.getPrice().substring(1));
+ }
+ return currencySymbol + String.valueOf(total);
+ }
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/Total.java b/branches/sca-java-1.5/tutorials/store/assets/services/Total.java
new file mode 100644
index 0000000000..8f464e526f
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/Total.java
@@ -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();
+
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/VegetablesCatalogImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/VegetablesCatalogImpl.java
new file mode 100644
index 0000000000..8bfbc757db
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/VegetablesCatalogImpl.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+public class VegetablesCatalogImpl implements Catalog {
+ private List<Item> catalog = new ArrayList<Item>();
+
+ @Init
+ public void init() {
+ catalog.add(new Item("Broccoli", "$2.99"));
+ catalog.add(new Item("Asparagus", "$3.55"));
+ catalog.add(new Item("Cauliflower", "$1.55"));
+ }
+
+ public Item[] get() {
+ Item[] catalogArray = new Item[catalog.size()];
+ catalog.toArray(catalogArray);
+ return catalogArray;
+ }
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/db/ShoppingCartTableImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/db/ShoppingCartTableImpl.java
new file mode 100644
index 0000000000..cfc52c563c
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/db/ShoppingCartTableImpl.java
@@ -0,0 +1,171 @@
+/*
+ * 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.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+import org.osoa.sca.ServiceRuntimeException;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+
+import services.Cart;
+import services.Item;
+import services.Total;
+
+public class ShoppingCartTableImpl implements Cart, Total {
+
+ @Property
+ public String database;
+
+ private Connection connection;
+
+ @Init
+ public void init() throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver", true, Thread.currentThread().getContextClassLoader());
+ String baseDir = System.getProperty("basedir");
+ String url = "jdbc:derby:directory:" + (baseDir != null? baseDir + "/" + database : database);
+ System.out.println("Connecting to database: " + url);
+ connection = DriverManager.getConnection(url, "", "");
+ }
+
+ @Destroy
+ public void shutdown() throws Exception {
+ if(connection != null) {
+ connection.close();
+ connection = null;
+ }
+ }
+
+ public Entry<String, Item>[] getAll() {
+ try {
+ Statement statement = connection.createStatement();
+ ResultSet results = statement.executeQuery("select * from Cart");
+ List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
+ while (results.next()) {
+ Item item = new Item(results.getString("name"), results.getString("price"));
+ entries.add(new Entry<String, Item>(results.getString("id"), item));
+ }
+ return entries.toArray(new Entry[entries.size()]);
+ } catch (SQLException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public Item get(String key) throws NotFoundException {
+ try {
+ Statement statement = connection.createStatement();
+ ResultSet results = statement.executeQuery("select * from Cart where id = '" + key + "'");
+ if (results.next()) {
+ return new Item(results.getString("name"), results.getString("price"));
+ } else {
+ throw new NotFoundException(key);
+ }
+ } catch (SQLException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public String post(String key, Item item) {
+ if (key == null) {
+ key = "cart-" + UUID.randomUUID().toString();
+ }
+ try {
+ Statement statement = connection.createStatement();
+ String query = "insert into Cart values ('" + key + "', '" + item.getName() + "', '" + item.getPrice() + "')";
+ System.out.println(query);
+ statement.executeUpdate(query);
+ } catch (SQLException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ return key;
+ }
+
+ public void put(String key, Item item) throws NotFoundException {
+ try {
+ Statement statement = connection.createStatement();
+ String query = "update into Cart set name = '" + item.getName() + "', price = '" + item.getPrice() + "' where id = '" + key + "'";
+ System.out.println(query);
+ int count = statement.executeUpdate(query);
+ if (count == 0)
+ throw new NotFoundException(key);
+ } catch (SQLException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public void delete(String key) throws NotFoundException {
+ try {
+ Statement statement = connection.createStatement();
+ if (key == null || key.equals("")) {
+ String query = "delete from Cart";
+ System.out.println(query);
+ statement.executeUpdate(query);
+ } else {
+ String query = "delete from Cart where id = '" + key + "'";
+ System.out.println(query);
+ int count = statement.executeUpdate(query);
+ if (count == 0)
+ throw new NotFoundException(key);
+ }
+ } catch (SQLException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public Entry<String, Item>[] query(String queryString) {
+ try {
+ Statement statement = connection.createStatement();
+ ResultSet results = statement.executeQuery("select * from Cart where " + queryString);
+ List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
+ while (results.next()) {
+ Item item = new Item(results.getString("name"), results.getString("price"));
+ entries.add(new Entry<String, Item>(results.getString("id"), item));
+ }
+ return entries.toArray(new Entry[entries.size()]);
+ } catch (SQLException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public String getTotal() {
+ Entry<String, Item>[] entries = getAll();
+ double total = 0;
+ String currencySymbol = "";
+ if (entries.length > 0) {
+ Item item = entries[0].getData();
+ currencySymbol = item.getPrice().substring(0, 1);
+ }
+ for (Entry<String, Item> entry : entries) {
+ Item item = entry.getData();
+ total += Double.valueOf(item.getPrice().substring(1));
+ }
+ return currencySymbol + total;
+ }
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/db/cart.sql b/branches/sca-java-1.5/tutorials/store/assets/services/db/cart.sql
new file mode 100644
index 0000000000..750e23ebde
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/db/cart.sql
@@ -0,0 +1,27 @@
+--
+-- 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.
+--
+
+DROP TABLE CART;
+
+CREATE TABLE CART(
+ id VARCHAR(50) NOT NULL,
+ name VARCHAR(50),
+ price VARCHAR(10),
+ primary key (id)
+);
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/map/FruitsCatalogImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/map/FruitsCatalogImpl.java
new file mode 100644
index 0000000000..b160ba7be0
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/map/FruitsCatalogImpl.java
@@ -0,0 +1,56 @@
+/*
+ * 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.map;
+
+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;
+
+import services.Catalog;
+import services.CurrencyConverter;
+import services.Item;
+
+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), "34.425744,-119.711151"));
+ catalog.add(new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55), "25.811018,-80.130844"));
+ catalog.add(new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55), "36.596649,-121.8964"));
+ }
+
+ public Item[] get() {
+ Item[] catalogArray = new Item[catalog.size()];
+ catalog.toArray(catalogArray);
+ return catalogArray;
+ }
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/market/MarketCatalogImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/market/MarketCatalogImpl.java
new file mode 100644
index 0000000000..bd2c7d76a2
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/market/MarketCatalogImpl.java
@@ -0,0 +1,66 @@
+
+/*
+ * 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.market;
+
+import java.util.Vector;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import services.Catalog;
+import services.CurrencyConverter;
+import services.Item;
+
+
+public class MarketCatalogImpl implements Catalog {
+
+ @Property
+ public String currencyCode = "USD";
+
+ @Reference
+ public CurrencyConverter currencyConverter;
+
+ @Reference(required=false)
+ protected Catalog[] goodsCatalog;
+
+
+ public Item[] get() {
+
+ String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+ Vector<Item> catalog = new Vector<Item>();
+
+ for (int i = 0; i < goodsCatalog.length; i++) {
+ Item[] items = goodsCatalog[i].get();
+
+ for (Item item : items) {
+ double price = Double.valueOf(item.getPrice().substring(1));
+ price = currencyConverter.getConversion("USD", currencyCode, price);
+ catalog.addElement(new Item(item.getName(), currencySymbol + price));
+ }
+ }
+
+ Item[] catalogArray = new Item[catalog.size()];
+ catalog.copyInto(catalogArray);
+
+ return catalogArray;
+ }
+
+} \ No newline at end of file
diff --git a/branches/sca-java-1.5/tutorials/store/assets/services/merger/MergedCatalogImpl.java b/branches/sca-java-1.5/tutorials/store/assets/services/merger/MergedCatalogImpl.java
new file mode 100644
index 0000000000..c02b4e821e
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/services/merger/MergedCatalogImpl.java
@@ -0,0 +1,66 @@
+/*
+ * 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.merger;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import services.Catalog;
+import services.CurrencyConverter;
+import services.Item;
+
+public class MergedCatalogImpl implements Catalog {
+
+ @Property
+ public String currencyCode = "USD";
+
+ @Reference
+ public CurrencyConverter currencyConverter;
+
+ @Reference
+ public Catalog fruitsCatalog;
+
+ @Reference
+ public Catalog vegetablesCatalog;
+
+ public Item[] get() {
+ String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+
+ Item[] fruits = fruitsCatalog.get();
+ Item[] vegetables = vegetablesCatalog.get();
+
+ Item[] catalog = new Item[fruits.length + vegetables.length];
+ int i =0;
+ for (Item item: fruits) {
+ double price = Double.valueOf(item.getPrice().substring(1));
+ price = currencyConverter.getConversion("USD", currencyCode, price);
+ catalog[i++] = new Item(item.getName(), currencySymbol + price);
+ }
+
+ for (Item item: vegetables) {
+ double price = Double.valueOf(item.getPrice().substring(1));
+ price = currencyConverter.getConversion("USD", currencyCode, price);
+ catalog[i++] = new Item(item.getName(), currencySymbol + price);
+ }
+
+ return catalog;
+ }
+
+}
diff --git a/branches/sca-java-1.5/tutorials/store/assets/tutorial.html b/branches/sca-java-1.5/tutorials/store/assets/tutorial.html
new file mode 100644
index 0000000000..14f81e0c22
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/tutorial.html
@@ -0,0 +1,37 @@
+<html>
+<!--
+ * 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.
+ -->
+<head>
+<title>Apache Tuscany - Online Store Tutorial</title>
+</head>
+
+<body>
+<h1>Apache Tuscany - Online Store Tutorial
+<h2><a href="http://localhost:9990/ui/home">Online Store - SCA Domain</a>
+<h2><a href="http://localhost:8100/ui/store.html">Online Store - Fruits</a>
+<h2><a href="http://localhost:8200/VegetablesCatalogWebService?wsdl">Vegetables Catalog Web Service</a>
+<h2><a href="http://localhost:8101/ui/store.html">Merger - Fruits and Vegetables</a>
+<h2><a href="http://localhost:8102/ui/store.html">Online Store - Cart Database</a>
+<h2><a href="http://localhost:8103/ui/store.html">Online Store - Supplier</a>
+<h2><a href="http://localhost:8105/ui/store.html">Online Store - Marketplace</a>
+<h2><a href="http://localhost:8333/CatalogWebService?wsdl">Merged Catalog Web Service</a>
+<h2><a href="http://localhost:8104/ui/store-eu.html">EU Online Store</a>
+<h2><a href="http://localhost:8106/mashup/store-mash.html">Online Store Mashup</a>
+</body>
+</html> \ No newline at end of file
diff --git a/branches/sca-java-1.5/tutorials/store/assets/uiservices/store.html b/branches/sca-java-1.5/tutorials/store/assets/uiservices/store.html
new file mode 100644
index 0000000000..dfe28bb260
--- /dev/null
+++ b/branches/sca-java-1.5/tutorials/store/assets/uiservices/store.html
@@ -0,0 +1,159 @@
+<!--
+ * 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 tuscany.sca.Reference("catalog");
+
+ //@Reference
+ var shoppingCart = new tuscany.sca.Reference("shoppingCart");
+
+ //@Reference
+ var shoppingTotal = new tuscany.sca.Reference("shoppingTotal");
+
+ var catalogItems;
+
+ function catalog_getResponse(items,exception) {
+ if(exception){
+ alert(exception.message);
+ return;
+ }
+ 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) {
+ try {
+ shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ }
+ catch(e) {
+ alert(e);
+ }
+ }
+ }
+ }
+
+ function shoppingTotal_getTotalResponse(total,exception) {
+ if(exception){
+ alert(exception.message);
+ return;
+ }
+ 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 = "";
+ }
+
+ function init() {
+ try {
+ catalog.get(catalog_getResponse);
+ shoppingCart.get("", shoppingCart_getResponse);
+ }
+ catch(e) {
+ alert(e);
+ }
+ }
+
+</script>
+
+</head>
+
+<body onload="init()">
+<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>