diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-16 08:53:06 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-16 08:53:06 +0000 |
commit | bee80d90df6104edff19cbb6a318fac3d64296aa (patch) | |
tree | 50032a7895eeeccb50520bcceb6dfb1fd06f2357 /branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore | |
parent | 3d3b8834b93b98cc7d7534e693e937179067eb58 (diff) |
Create 1.5 release branch from current 1.x trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@775437 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore')
5 files changed, 283 insertions, 0 deletions
diff --git a/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/server/ShoppingStoreServer.java b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/server/ShoppingStoreServer.java new file mode 100644 index 0000000000..486946b2fc --- /dev/null +++ b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/server/ShoppingStoreServer.java @@ -0,0 +1,25 @@ +package shoppingstore.server; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class ShoppingStoreServer { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("shoppingstore.composite"); + + try { + System.out.println("ToyApp server started (press enter to shutdown)"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + System.out.println("ToyApp server stopped"); + } + + +} diff --git a/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartService.java b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartService.java new file mode 100644 index 0000000000..e8f383c3e1 --- /dev/null +++ b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartService.java @@ -0,0 +1,35 @@ +package shoppingstore.services.cart; + +import org.osoa.sca.annotations.Remotable; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + +@Remotable +public interface CartService { + + public CartCreateResponse CartCreate(CartCreate cartCreate); + + public CartAddResponse CartAdd(CartAdd cartAdd); + + public CartModifyResponse CartModify(CartModify cartModify); + + public CartClearResponse CartClear(CartClear cartClear); + + public CartGetResponse CartGet(CartGet cartGet); + + //@Init + //public void start(); + + //@Destroy + //public void stop(); + +} diff --git a/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartServiceImpl.java b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartServiceImpl.java new file mode 100644 index 0000000000..1579dbd60d --- /dev/null +++ b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartServiceImpl.java @@ -0,0 +1,144 @@ +package shoppingstore.services.cart; + +import java.util.HashMap; + +import org.osoa.sca.annotations.Scope; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.Cart; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddRequest; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartItem; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartItems; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + +@Scope("COMPOSITE") +public class CartServiceImpl implements CartService { + + private static long ID = 0; + + private HashMap<String, Cart> cartsHash = new HashMap<String, Cart>(); + + public CartAddResponse CartAdd(CartAdd cartAdd) { + System.out.println("Entering cartAdd..."); + System.out.println("CartServiceID: " + this.toString()); + CartAddResponse cartAddResponse = new CartAddResponse(); + + CartAddRequest cartAddRequest = cartAdd.getRequest().get(0); + + //Cart cart = getCart(cartAddRequest.getCartId()); + Cart cart = getCart(cartAdd.getAWSAccessKeyId()); + if(cart == null){ + cartAddResponse.getCart().add(new Cart()); + return cartAddResponse; + } + + CartItem cartItem = new CartItem(); + cartItem.setASIN(cartAddRequest.getItems().getItem().get(0).getASIN()); + cartItem.setQuantity(cartAddRequest.getItems().getItem().get(0).getQuantity().toString()); + cart.getCartItems().getCartItem().add(cartItem); + cartAddResponse.getCart().add(cart); + System.out.println("Exiting cartAdd..."); + return cartAddResponse; + } + + public CartClearResponse CartClear(CartClear cartClear) { + System.out.println("CartServiceID: " + this.toString()); + System.out.println("Entering cartClear..."); + CartClearResponse cartClearResponse = new CartClearResponse(); + + //CartClearRequest cartClearRequest = cartClear.getRequest().get(0); + + //Cart cart = getCart(cartClearRequest.getCartId()); + Cart cart = getCart(cartClear.getAWSAccessKeyId()); + if(cart == null) { + cartClearResponse.getCart().add(new Cart()); + return cartClearResponse; + } + + cart.getCartItems().getCartItem().clear(); + + cartClearResponse.getCart().add(cart); + System.out.println("Exiting cartClear..."); + return cartClearResponse; + } + + public CartCreateResponse CartCreate(CartCreate cartCreate) { + System.out.println("CartServiceID: " + this.toString()); + System.out.println("Entering cartCreate..."); + CartCreateResponse cartCreateResponse = new CartCreateResponse(); + + Cart cart = getCart(cartCreate.getAWSAccessKeyId()); + if(cart != null){ + cartCreateResponse.getCart().add(cart); + System.out.println("User " + cartCreate.getAWSAccessKeyId() + " has already created a cart with ID: " + cart.getCartId()); + return cartCreateResponse; + } + + cart = new Cart(); + cart.setCartId(this.generateID()); + cart.setCartItems(new CartItems()); + addCart(cartCreate.getAWSAccessKeyId(), cart); + + cartCreateResponse.getCart().add(cart); + System.out.println("Exiting cartCreate..."); + return cartCreateResponse; + } + + public CartGetResponse CartGet(CartGet cartGet) { + System.out.println("CartServiceID: " + this.toString()); + System.out.println("Entering cartGet..."); + CartGetResponse cartGetResponse = new CartGetResponse(); + + //CartGetRequest cartGetRequest = cartGet.getRequest().get(0); + + //Cart cart = getCart(cartGetRequest.getCartId()); + Cart cart = getCart(cartGet.getAWSAccessKeyId()); + if(cart == null){ + cartGetResponse.getCart().add(new Cart()); + return cartGetResponse; + } + + cartGetResponse.getCart().add(cart); + System.out.println("Exiting cartGet..."); + return cartGetResponse; + } + + public CartModifyResponse CartModify(CartModify cartModify) { + // TODO Auto-generated method stub + return null; + } + + private synchronized String generateID(){ + ID++; + return String.valueOf(ID); + } + + + private Cart getCart(String cartId){ + Cart cart = null; + System.out.println(this.cartsHash.toString()); + cart = this.cartsHash.get(cartId); + return cart; + } + + private void addCart(String cartId, Cart cart){ + this.cartsHash.put(cartId, cart); + } +/* + public void start() { + System.out.println("Start CartService..."); + } + + public void stop() { + System.out.println("Stop CartService..."); + } +*/ +} diff --git a/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreService.java b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreService.java new file mode 100644 index 0000000000..207125ac75 --- /dev/null +++ b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreService.java @@ -0,0 +1,30 @@ +package shoppingstore.services.proxy; + +import org.osoa.sca.annotations.Remotable; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + + +@Remotable +public interface ShoppingStoreService{ + + public CartCreateResponse CartCreate(CartCreate cartCreate); + + public CartAddResponse CartAdd(CartAdd cartAdd); + + public CartModifyResponse CartModify(CartModify cartModify); + + public CartClearResponse CartClear(CartClear cartClear); + + public CartGetResponse CartGet(CartGet cartGet); + +} diff --git a/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreServiceImpl.java b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreServiceImpl.java new file mode 100644 index 0000000000..8a73631cbb --- /dev/null +++ b/branches/sca-java-1.5/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreServiceImpl.java @@ -0,0 +1,49 @@ +package shoppingstore.services.proxy; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +import shoppingstore.services.cart.CartService; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + +@Scope("COMPOSITE") +public class ShoppingStoreServiceImpl implements ShoppingStoreService { + + private CartService cartService; + + @Reference + public void setCartService(CartService cartService) { + this.cartService = cartService; + } + + public CartAddResponse CartAdd( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd cartAdd) { + return cartService.CartAdd(cartAdd); + } + + public CartClearResponse CartClear( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear cartClear) { + return cartService.CartClear(cartClear); + } + + public CartCreateResponse CartCreate( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate cartCreate) { + return cartService.CartCreate(cartCreate); + } + + public CartGetResponse CartGet( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet cartGet) { + return cartService.CartGet(cartGet); + } + + public CartModifyResponse CartModify( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify cartModify) { + return cartService.CartModify(cartModify); + } + +} |