Separate the ShoppingCart interface into multiple separate interfaces to better match the "introducing" scenario

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@824057 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
slaws 2009-10-11 11:58:29 +00:00
parent c51362e7ef
commit 598eb48d98
9 changed files with 105 additions and 66 deletions

View file

@ -66,7 +66,7 @@
<reference name="flightBook" target="Trip/Book"/>
<reference name="carBook" target="Car/Book"/>
<reference name="tripBook" target="Trip/Book"/>
<reference name="shoppingCart" target="ShoppingCart"/>
<reference name="cartUpdates" target="ShoppingCart/CartUpdates"/>
</component>
</composite>

View file

@ -23,7 +23,6 @@
<component name="ShoppingCart">
<implementation.java class="com.tuscanyscatours.shoppingcart.impl.ShoppingCartImpl"/>
<service name="ShoppingCart"/>
<reference name="cartStore" target="CartStore"/>
<reference name="payment">
<binding.ws uri="http://localhost:8081/Payment" />
@ -32,7 +31,6 @@
<component name="CartStore">
<implementation.java class="com.tuscanyscatours.shoppingcart.impl.CartStoreImpl"/>
<service name="CartStore"/>
</component>
</composite>

View file

@ -51,7 +51,8 @@
</service>
<reference name="travelCatalogSearch" target="TravelCatalog/TravelCatalogSearch"/>
<reference name="tripBooking" target="TripBooking"/>
<reference name="shoppingCart" target="ShoppingCart"/>
<reference name="cartInitialize" target="ShoppingCart/CartInitialize"/>
<reference name="cartCheckout" target="ShoppingCart/CartCheckout"/>
</component>
</composite>

View file

@ -18,13 +18,6 @@
*/
package com.tuscanyscatours.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.annotations.Context;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
@ -34,7 +27,8 @@ import com.tuscanyscatours.SCAToursCart;
import com.tuscanyscatours.SCAToursSearch;
import com.tuscanyscatours.common.TripItem;
import com.tuscanyscatours.common.TripLeg;
import com.tuscanyscatours.shoppingcart.ShoppingCart;
import com.tuscanyscatours.shoppingcart.CartCheckout;
import com.tuscanyscatours.shoppingcart.CartInitialize;
import com.tuscanyscatours.travelcatalog.TravelCatalogSearch;
import com.tuscanyscatours.tripbooking.TripBooking;
@ -53,7 +47,10 @@ public class SCAToursImpl implements SCAToursSearch, SCAToursBooking, SCAToursCa
protected TripBooking tripBooking;
@Reference
protected ShoppingCart shoppingCart;
protected CartInitialize cartInitialize;
@Reference
protected CartCheckout cartCheckout;
// SCAToursSearch methods
@ -71,17 +68,17 @@ public class SCAToursImpl implements SCAToursSearch, SCAToursBooking, SCAToursCa
// SCAToursCart methods
public String newCart(){
String cartId = shoppingCart.newCart();
String cartId = cartInitialize.newCart();
return cartId;
}
public TripItem[] getTrips(String cartId){
return shoppingCart.getTrips(cartId);
return cartInitialize.getTrips(cartId);
}
public void checkout(String cartId){
// need to get the user id from the context here but
// just make one up for the time being
shoppingCart.checkout(cartId, "c-0");
cartCheckout.checkout(cartId, "c-0");
}
}

View file

@ -0,0 +1,26 @@
/*
* 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 com.tuscanyscatours.shoppingcart;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface CartCheckout {
void checkout(String cartId,String name);
}

View file

@ -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 com.tuscanyscatours.shoppingcart;
import org.osoa.sca.annotations.Remotable;
import com.tuscanyscatours.common.TripItem;
@Remotable
public interface CartInitialize {
String newCart();
TripItem[] getTrips(String cartId);
}

View file

@ -1,37 +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 com.tuscanyscatours.shoppingcart;
import org.osoa.sca.annotations.Conversational;
import org.osoa.sca.annotations.EndsConversation;
import org.osoa.sca.annotations.Remotable;
import com.tuscanyscatours.common.TripItem;
/**
* The ShoppingCart service interface
*/
@Remotable
public interface ShoppingCart{
String newCart();
void addTrip(String cartId,TripItem trip);
void removeTrip(String cartId,TripItem trip);
TripItem[] getTrips(String cartId);
void checkout(String cartId,String name);
}
/*
* 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 com.tuscanyscatours.shoppingcart;
import org.osoa.sca.annotations.Remotable;
import com.tuscanyscatours.common.TripItem;
@Remotable
public interface CartUpdates {
void addTrip(String cartId,TripItem trip);
void removeTrip(String cartId,TripItem trip);
}

View file

@ -18,32 +18,28 @@
*/
package com.tuscanyscatours.shoppingcart.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.annotations.Context;
import org.osoa.sca.annotations.ConversationID;
import org.osoa.sca.annotations.Destroy;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
import com.tuscanyscatours.common.TripItem;
import com.tuscanyscatours.payment.Payment;
import com.tuscanyscatours.shoppingcart.CartInitialize;
import com.tuscanyscatours.shoppingcart.CartStore;
import com.tuscanyscatours.shoppingcart.ShoppingCart;
import com.tuscanyscatours.shoppingcart.CartCheckout;
import com.tuscanyscatours.shoppingcart.CartUpdates;
/**
* An implementation of the ShoppingCart service
*/
@Service(interfaces={ShoppingCart.class})
public class ShoppingCartImpl implements ShoppingCart{
@Service(interfaces={CartInitialize.class, CartUpdates.class, CartCheckout.class})
public class ShoppingCartImpl implements CartInitialize, CartUpdates, CartCheckout{
@Reference
protected Payment payment;

View file

@ -26,7 +26,7 @@ import org.osoa.sca.annotations.Service;
import com.tuscanyscatours.common.Book;
import com.tuscanyscatours.common.TripItem;
import com.tuscanyscatours.shoppingcart.ShoppingCart;
import com.tuscanyscatours.shoppingcart.CartUpdates;
import com.tuscanyscatours.tripbooking.TripBooking;
/**
@ -48,7 +48,7 @@ public class TripBookingImpl implements TripBooking{
protected Book tripBook;
@Reference
protected ShoppingCart shoppingCart;
protected CartUpdates cartUpdates;
@Context
protected ComponentContext componentContext;
@ -81,8 +81,8 @@ public class TripBookingImpl implements TripBooking{
}
// add trip to the shopping cart
ServiceReference<ShoppingCart> cart = componentContext.getServiceReference(ShoppingCart.class,
"shoppingCart");
ServiceReference<CartUpdates> cart = componentContext.getServiceReference(CartUpdates.class,
"cartUpdates");
cart.setConversationID(cartId);
cart.getService().addTrip(cartId, trip);