diff options
Diffstat (limited to 'branches/sca-java-1.1/samples/store/src/main/java')
7 files changed, 0 insertions, 387 deletions
diff --git a/branches/sca-java-1.1/samples/store/src/main/java/launch/Launch.java b/branches/sca-java-1.1/samples/store/src/main/java/launch/Launch.java deleted file mode 100644 index 801697abea..0000000000 --- a/branches/sca-java-1.1/samples/store/src/main/java/launch/Launch.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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/branches/sca-java-1.1/samples/store/src/main/java/services/Catalog.java b/branches/sca-java-1.1/samples/store/src/main/java/services/Catalog.java deleted file mode 100644 index 9f784b0848..0000000000 --- a/branches/sca-java-1.1/samples/store/src/main/java/services/Catalog.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/branches/sca-java-1.1/samples/store/src/main/java/services/CatalogImpl.java b/branches/sca-java-1.1/samples/store/src/main/java/services/CatalogImpl.java deleted file mode 100644 index fd44c66bf6..0000000000 --- a/branches/sca-java-1.1/samples/store/src/main/java/services/CatalogImpl.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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/branches/sca-java-1.1/samples/store/src/main/java/services/CurrencyConverter.java b/branches/sca-java-1.1/samples/store/src/main/java/services/CurrencyConverter.java deleted file mode 100644 index 8b0f70907d..0000000000 --- a/branches/sca-java-1.1/samples/store/src/main/java/services/CurrencyConverter.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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/branches/sca-java-1.1/samples/store/src/main/java/services/CurrencyConverterImpl.java b/branches/sca-java-1.1/samples/store/src/main/java/services/CurrencyConverterImpl.java deleted file mode 100644 index 56b5a64c8a..0000000000 --- a/branches/sca-java-1.1/samples/store/src/main/java/services/CurrencyConverterImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.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; - - if (toCurrencyCode.equals("USD")) - return amount / rate; - else if (toCurrencyCode.equals("EUR")) - return amount * rate; - return 0; - } - - public String getCurrencySymbol(String currencyCode) { - if (currencyCode.equals("USD")) - return "$ "; - else if (currencyCode.equals("EUR")) - return "€ "; - return "?"; - } -} diff --git a/branches/sca-java-1.1/samples/store/src/main/java/services/ShoppingCartImpl.java b/branches/sca-java-1.1/samples/store/src/main/java/services/ShoppingCartImpl.java deleted file mode 100644 index 41e9a9eaa3..0000000000 --- a/branches/sca-java-1.1/samples/store/src/main/java/services/ShoppingCartImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 void put(String id, Entry entry) throws NotFoundException { - entry.setUpdated(new Date()); - cart.put(id, 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(); - - int index = item.length()-1; - char digit; - while ((digit = item.charAt(index)) == '.' || Character.isDigit(digit)) { - index--; - } - - total += Float.valueOf(item.substring(index)); - } - return currencySymbol + String.valueOf(total); - } -} diff --git a/branches/sca-java-1.1/samples/store/src/main/java/util/CreateDB.java b/branches/sca-java-1.1/samples/store/src/main/java/util/CreateDB.java deleted file mode 100644 index b8177ee25b..0000000000 --- a/branches/sca-java-1.1/samples/store/src/main/java/util/CreateDB.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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 util; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; - -public class CreateDB { - - public static void main(String[] args) { - System.out.println("Creating database ..."); - - Connection connection = null; - PreparedStatement preparedStatement = null; - - try { - //initialize driver and register it with DriverManager - Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); - - //connect and create the db if not present - connection = DriverManager.getConnection( - "jdbc:derby:target/store_db;create=true", - "", - ""); - - - try { - preparedStatement = connection.prepareStatement("DROP TABLE CATALOG"); - preparedStatement.execute(); - }catch(Exception e) { - //ignore to avoid erros when db is being created from scratch - } - - - preparedStatement = connection.prepareStatement("CREATE TABLE CATALOG(" - + "id NUMERIC(5 , 0) NOT NULL," - + "product_name VARCHAR(30)," - + "currency_code CHAR(3)," - + "price REAL," - + "primary key (id)" - + ")"); - preparedStatement.execute(); - - preparedStatement = connection.prepareStatement("INSERT INTO CATALOG VALUES(0,'Apple', 'USD', 2.99)"); - preparedStatement.execute(); - - preparedStatement = connection.prepareStatement("INSERT INTO CATALOG VALUES(1,'Orange', 'USD', 3.55)"); - preparedStatement.execute(); - - preparedStatement = connection.prepareStatement("INSERT INTO CATALOG VALUES(2,'Pear', 'USD', 1.55)"); - preparedStatement.execute(); - - System.out.println("Done !"); - - } catch (SQLException ex) { - ex.printStackTrace(); - }catch (ClassNotFoundException ex) { - ex.printStackTrace(); - } finally { - if (preparedStatement!=null) { - try { - preparedStatement.close(); - } catch (SQLException ex) { - ex.printStackTrace(); - } - } - - if (connection!=null) { - try { - connection.close(); - } catch (SQLException ex) { - ex.printStackTrace(); - } - } - } - } - -} |