summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services')
-rw-r--r--sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/Catalog.java27
-rw-r--r--sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CatalogImpl.java49
-rw-r--r--sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CurrencyConverter.java29
-rw-r--r--sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CurrencyConverterImpl.java38
-rw-r--r--sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/ShoppingCartImpl.java99
5 files changed, 242 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/Catalog.java b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/Catalog.java
new file mode 100644
index 0000000000..9f784b0848
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/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 {
+ String[] get();
+}
diff --git a/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CatalogImpl.java b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CatalogImpl.java
new file mode 100644
index 0000000000..fd44c66bf6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CatalogImpl.java
@@ -0,0 +1,49 @@
+/*
+ * 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 CatalogImpl implements Catalog {
+ @Property
+ public String currencyCode = "USD";
+ @Reference
+ public CurrencyConverter currencyConverter;
+ private List<String> catalog = new ArrayList<String>();
+
+ @Init
+ public void init() {
+ String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+ catalog.add("Apple - " + currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99f));
+ catalog.add("Orange - " + currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55f));
+ catalog.add("Pear - " + currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55f));
+ }
+
+ public String[] get() {
+ String[] catalogArray = new String[catalog.size()];
+ catalog.toArray(catalogArray);
+ return catalogArray;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CurrencyConverter.java b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CurrencyConverter.java
new file mode 100644
index 0000000000..8b0f70907d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/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 float getConversion(String fromCurrenycCode, String toCurrencyCode, float amount);
+
+ public String getCurrencySymbol(String currencyCode);
+}
diff --git a/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CurrencyConverterImpl.java b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/CurrencyConverterImpl.java
new file mode 100644
index 0000000000..0ae8f345ce
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/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 float getConversion(String fromCurrencyCode, String toCurrencyCode, float amount) {
+ if (toCurrencyCode.equals("USD"))
+ return amount;
+ else if (toCurrencyCode.equals("EUR"))
+ return amount * 0.7256f;
+ return 0;
+ }
+
+ public String getCurrencySymbol(String currencyCode) {
+ if (currencyCode.equals("USD"))
+ return "$";
+ else if (currencyCode.equals("EUR"))
+ return "€";
+ return "?";
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/ShoppingCartImpl.java b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/ShoppingCartImpl.java
new file mode 100644
index 0000000000..f3934717f8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.0.1/samples/store/src/main/java/services/ShoppingCartImpl.java
@@ -0,0 +1,99 @@
+/*
+ * 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.Date;
+import java.util.HashMap;
+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 ShoppingCartImpl implements Collection {
+
+ 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;
+ }
+
+ 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);
+
+ Link link = new Link();
+ link.setRel("edit");
+ link.setHref(id);
+ entry.getOtherLinks().add(link);
+ link = new Link();
+ link.setRel("alternate");
+ link.setHref(id);
+ entry.getAlternateLinks().add(link);
+
+ entry.setCreated(new Date());
+
+ cart.put(id, entry);
+ return entry;
+ }
+
+ public Entry put(String id, Entry entry) throws NotFoundException {
+ entry.setUpdated(new Date());
+ cart.put(id, entry);
+ return entry;
+ }
+
+ public void delete(String id) throws NotFoundException {
+ if (id.equals(""))
+ cart.clear();
+ else
+ cart.remove(id);
+ }
+
+ private String getTotal() {
+ float total = 0;
+ String currencySymbol = "";
+ if (!cart.isEmpty()) {
+ String item = ((Content)cart.values().iterator().next().getContents().get(0)).getValue();
+ currencySymbol = item.substring(item.indexOf("-") + 2, item.indexOf("-") + 3);
+ }
+ for (Entry entry : cart.values()) {
+ String item = ((Content)entry.getContents().get(0)).getValue();
+ total += Float.valueOf(item.substring(item.indexOf("-") + 3));
+ }
+ return currencySymbol + String.valueOf(total);
+ }
+}