diff options
Diffstat (limited to 'branches/sca-java-1.x/tutorials/store/assets/services')
5 files changed, 90 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/tutorials/store/assets/services/Order.java b/branches/sca-java-1.x/tutorials/store/assets/services/Order.java new file mode 100644 index 0000000000..07a9f9d0b0 --- /dev/null +++ b/branches/sca-java-1.x/tutorials/store/assets/services/Order.java @@ -0,0 +1,40 @@ +/* + * 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 Order { + private Item[] items; + + public Order() { + } + + public Order(Item[] items) { + this.items = items; + } + + public Item[] getItems() { + return items; + } + + public void setItems(Item[] items) { + this.items = items; + } +} diff --git a/branches/sca-java-1.x/tutorials/store/assets/services/ShoppingCartImpl.java b/branches/sca-java-1.x/tutorials/store/assets/services/ShoppingCartImpl.java index 9889921a96..d297a8ccf1 100644 --- a/branches/sca-java-1.x/tutorials/store/assets/services/ShoppingCartImpl.java +++ b/branches/sca-java-1.x/tutorials/store/assets/services/ShoppingCartImpl.java @@ -28,6 +28,7 @@ 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.Reference; import org.osoa.sca.annotations.Scope; @Scope("COMPOSITE") @@ -35,6 +36,9 @@ public class ShoppingCartImpl implements Cart, Total { private Map<String, Item> cart; + @Reference(required=false) + protected Warehouse warehouse; + @Init public void init() { cart = new HashMap<String, Item>(); @@ -109,4 +113,17 @@ public class ShoppingCartImpl implements Cart, Total { } return currencySymbol + String.valueOf(total); } + + public void confirmTotal() { + if (warehouse != null){ + System.out.println("Confirm total"); + try { + Order order = new Order(cart.values().toArray(new Item[cart.values().size()])); + warehouse.addOrder(order); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + cart.clear(); + } } diff --git a/branches/sca-java-1.x/tutorials/store/assets/services/Total.java b/branches/sca-java-1.x/tutorials/store/assets/services/Total.java index 8f464e526f..b29b321e25 100644 --- a/branches/sca-java-1.x/tutorials/store/assets/services/Total.java +++ b/branches/sca-java-1.x/tutorials/store/assets/services/Total.java @@ -25,5 +25,6 @@ import org.osoa.sca.annotations.Remotable; public interface Total { String getTotal(); + void confirmTotal(); } diff --git a/branches/sca-java-1.x/tutorials/store/assets/services/Warehouse.java b/branches/sca-java-1.x/tutorials/store/assets/services/Warehouse.java new file mode 100644 index 0000000000..f04b0dd52d --- /dev/null +++ b/branches/sca-java-1.x/tutorials/store/assets/services/Warehouse.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.osoa.sca.annotations.Remotable; + +@Remotable +public interface Warehouse { + void addOrder(Order order); + Order[] getOrders(); +} diff --git a/branches/sca-java-1.x/tutorials/store/assets/services/db/ShoppingCartTableImpl.java b/branches/sca-java-1.x/tutorials/store/assets/services/db/ShoppingCartTableImpl.java index cfc52c563c..24eca045ab 100644 --- a/branches/sca-java-1.x/tutorials/store/assets/services/db/ShoppingCartTableImpl.java +++ b/branches/sca-java-1.x/tutorials/store/assets/services/db/ShoppingCartTableImpl.java @@ -168,4 +168,8 @@ public class ShoppingCartTableImpl implements Cart, Total { } return currencySymbol + total; } + + public void confirmTotal() { + + } } |