From a40e527938d76ba71f211da7e327adb50384ba69 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:26:33 +0000 Subject: Moving 1.x tags git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835157 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/store/src/main/java/launch/Launch.java | 34 ++++++++ .../store/src/main/java/services/Catalog.java | 27 ++++++ .../store/src/main/java/services/CatalogImpl.java | 49 +++++++++++ .../src/main/java/services/CurrencyConverter.java | 29 +++++++ .../main/java/services/CurrencyConverterImpl.java | 38 +++++++++ .../src/main/java/services/ShoppingCartImpl.java | 99 ++++++++++++++++++++++ 6 files changed, 276 insertions(+) create mode 100644 sca-java-1.x/tags/1.0/samples/store/src/main/java/launch/Launch.java create mode 100644 sca-java-1.x/tags/1.0/samples/store/src/main/java/services/Catalog.java create mode 100644 sca-java-1.x/tags/1.0/samples/store/src/main/java/services/CatalogImpl.java create mode 100644 sca-java-1.x/tags/1.0/samples/store/src/main/java/services/CurrencyConverter.java create mode 100644 sca-java-1.x/tags/1.0/samples/store/src/main/java/services/CurrencyConverterImpl.java create mode 100644 sca-java-1.x/tags/1.0/samples/store/src/main/java/services/ShoppingCartImpl.java (limited to 'sca-java-1.x/tags/1.0/samples/store/src/main/java') diff --git a/sca-java-1.x/tags/1.0/samples/store/src/main/java/launch/Launch.java b/sca-java-1.x/tags/1.0/samples/store/src/main/java/launch/Launch.java new file mode 100644 index 0000000000..801697abea --- /dev/null +++ b/sca-java-1.x/tags/1.0/samples/store/src/main/java/launch/Launch.java @@ -0,0 +1,34 @@ +/* + * 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 org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Launch { + public static void main(String[] args) throws Exception { + System.out.println("Starting ..."); + SCADomain scaDomain = SCADomain.newInstance("store.composite"); + System.out.println("store.composite ready for big business !!!"); + System.in.read(); + System.out.println("Stopping ..."); + scaDomain.close(); + System.out.println(); + } +} diff --git a/sca-java-1.x/tags/1.0/samples/store/src/main/java/services/Catalog.java b/sca-java-1.x/tags/1.0/samples/store/src/main/java/services/Catalog.java new file mode 100644 index 0000000000..9f784b0848 --- /dev/null +++ b/sca-java-1.x/tags/1.0/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/tags/1.0/samples/store/src/main/java/services/CatalogImpl.java b/sca-java-1.x/tags/1.0/samples/store/src/main/java/services/CatalogImpl.java new file mode 100644 index 0000000000..fd44c66bf6 --- /dev/null +++ b/sca-java-1.x/tags/1.0/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 catalog = new ArrayList(); + + @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/tags/1.0/samples/store/src/main/java/services/CurrencyConverter.java b/sca-java-1.x/tags/1.0/samples/store/src/main/java/services/CurrencyConverter.java new file mode 100644 index 0000000000..8b0f70907d --- /dev/null +++ b/sca-java-1.x/tags/1.0/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/tags/1.0/samples/store/src/main/java/services/CurrencyConverterImpl.java b/sca-java-1.x/tags/1.0/samples/store/src/main/java/services/CurrencyConverterImpl.java new file mode 100644 index 0000000000..0ae8f345ce --- /dev/null +++ b/sca-java-1.x/tags/1.0/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/tags/1.0/samples/store/src/main/java/services/ShoppingCartImpl.java b/sca-java-1.x/tags/1.0/samples/store/src/main/java/services/ShoppingCartImpl.java new file mode 100644 index 0000000000..f3934717f8 --- /dev/null +++ b/sca-java-1.x/tags/1.0/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 cart = new HashMap(); + + 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); + } +} -- cgit v1.2.3