pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.component.shop.model
Class ShoppingCart

java.lang.Object
  extended by org.torweg.pulse.component.shop.model.ShoppingCart
All Implemented Interfaces:
java.io.Serializable, ExtendedJDOMable, JDOMable

public class ShoppingCart
extends java.lang.Object
implements ExtendedJDOMable, java.io.Serializable

is a Session based ShoppingCart.

Version:
$Revision: 1522 $
Author:
Christian Schatt, Thomas Weber
See Also:
Serialized Form

Nested Class Summary
static class ShoppingCart.Total
          the Total of the ShoppingCart.
 
Constructor Summary
ShoppingCart(Bundle b, ServiceRequest r)
          creates a new ShoppingCart for the given Bundle and the Locale of the ServiceRequest and adds it to the Session.
 
Method Summary
 void addItem(ShopItem item)
          Adds/increments the given ShopItem to/in the ShoppingCart.
 void addItem(ShopItem item, int amount)
          Adds/increments the given ShopItem to/in the ShoppingCart.
 void clear()
          Removes all ShopItems from the ShoppingCart.
 int containsItem(ShopItem item)
          Determines whether the given ShopItem is in the ShoppingCart.
 org.jdom.Element deserializeToJDOM()
          returns a JDOM representation of the ShoppingCart.
 org.jdom.Element deserializeToJDOM(ServiceRequest r)
          returns a JDOM representation of the ShoppingCart.
 int getAmount(ShopItem item)
          returns the amount of the given items in the cart.
 Bundle getBundle()
          Returns the Bundle of the ShoppingCart.
static ShoppingCart getCart(Bundle bundle, ServiceRequest request)
          returns the ShoppingCart for the current Bundle .
 java.util.Locale getLocale()
          Returns the Locale of the ShoppingCart.
 java.util.Set<ShoppingCartPosition> getPositions()
          Returns the ShoppingCartPositions of the ShoppingCart.
 ShopItem getShopItem(java.lang.String shopItemId)
          returns the ShopItem identified by the given shop-item-id.
 ShoppingCart.Total getTotal(User u, ShopSettings s)
          returns the total of the ShoppingCart.
 boolean isEmpty()
          Determines whether the ShoppingCart is empty.
 void putItem(ShopItem item, int amount)
          puts the given ShopItem to/in the ShoppingCart or removes it, if the amount is zero.
 void removeItem(ShopItem item)
          Removes the given ShopItem from/in the ShoppingCart.
 void setPositions(java.util.Set<ShoppingCartPosition> pos)
          Sets the ShoppingCartPositions of the ShoppingCart omitting all ShoppingCartPositions with an amount which is not greater than zero.
 net.sf.json.JSONObject toJSON(User user)
          returns the cart as JSON.
static boolean validateShopItemId(java.lang.String id)
          validates a given shop-item-id ShopItem.getShopItemId() syntactically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShoppingCart

public ShoppingCart(Bundle b, ServiceRequest r)
creates a new ShoppingCart for the given Bundle and the Locale of the ServiceRequest and adds it to the Session.

Parameters:
b - the bundle
r - the request
Method Detail

getBundle

public final Bundle getBundle()
Returns the Bundle of the ShoppingCart.

Returns:
the Bundle of the ShoppingCart.

getLocale

public final java.util.Locale getLocale()
Returns the Locale of the ShoppingCart.

Returns:
the Locale of the ShoppingCart.

getPositions

public final java.util.Set<ShoppingCartPosition> getPositions()
Returns the ShoppingCartPositions of the ShoppingCart.

Returns:
the ShoppingCartPositions of the ShoppingCart. (shallow copy)

setPositions

public final void setPositions(java.util.Set<ShoppingCartPosition> pos)
Sets the ShoppingCartPositions of the ShoppingCart omitting all ShoppingCartPositions with an amount which is not greater than zero.

Parameters:
pos - the ShoppingCartPositions to be set. (final)

addItem

public final void addItem(ShopItem item)
Adds/increments the given ShopItem to/in the ShoppingCart.

Parameters:
item - the ShopItem to be added/incremented.

addItem

public final void addItem(ShopItem item,
                          int amount)
Adds/increments the given ShopItem to/in the ShoppingCart.

Parameters:
item - the ShopItem to be added/incremented.
amount - the amount of ShopItems to be added/incremented.

putItem

public final void putItem(ShopItem item,
                          int amount)
puts the given ShopItem to/in the ShoppingCart or removes it, if the amount is zero.

Parameters:
item - the ShopItem to be added/incremented.
amount - the amount of ShopItems to be added/incremented.

containsItem

public final int containsItem(ShopItem item)
Determines whether the given ShopItem is in the ShoppingCart.

Parameters:
item - the ShopItem to be sought-after.
Returns:
the amount of ShopItems equal to the given ShopItem.

removeItem

public final void removeItem(ShopItem item)
Removes the given ShopItem from/in the ShoppingCart.

Parameters:
item - the ShopItem to be removed.

getAmount

public int getAmount(ShopItem item)
returns the amount of the given items in the cart.

Parameters:
item - the item
Returns:
the amount

getShopItem

public final ShopItem getShopItem(java.lang.String shopItemId)
returns the ShopItem identified by the given shop-item-id.

Parameters:
shopItemId - a string identifying the ShopItem, starting either with c for Contents or v for Variant followed by the primary key
Returns:
the ShopItem or null, if the item is not in the cart
See Also:
ShopItem.getShopItemId()

validateShopItemId

public static final boolean validateShopItemId(java.lang.String id)
validates a given shop-item-id ShopItem.getShopItemId() syntactically.

Parameters:
id - the shop-item-id
Returns:
true, if and only if the given id is syntactically valid. Otherwise false.

clear

public final void clear()
Removes all ShopItems from the ShoppingCart.


isEmpty

public final boolean isEmpty()
Determines whether the ShoppingCart is empty.

Returns:
true, if the ShoppingCart is empty. Returns false, otherwise.

toJSON

public final net.sf.json.JSONObject toJSON(User user)
returns the cart as JSON.

Parameters:
user - the user used for calculating prices
Returns:
the cart as JSON

getTotal

public final ShoppingCart.Total getTotal(User u, ShopSettings s)
returns the total of the ShoppingCart.

Parameters:
u - the user
s - the ShopSettings
Returns:
the total

getCart

public static final ShoppingCart getCart(Bundle bundle, ServiceRequest request)
returns the ShoppingCart for the current Bundle .

Parameters:
bundle - the current bundle
request - the current request
Returns:
the shopping cart

deserializeToJDOM

public final org.jdom.Element deserializeToJDOM()
returns a JDOM representation of the ShoppingCart.

Specified by:
deserializeToJDOM in interface JDOMable
Returns:
a JDOM representation of the ShoppingCart
See Also:
JDOMable.deserializeToJDOM()

deserializeToJDOM

public final org.jdom.Element deserializeToJDOM(ServiceRequest r)
returns a JDOM representation of the ShoppingCart.

Specified by:
deserializeToJDOM in interface ExtendedJDOMable
Parameters:
r - the request for adding further information
Returns:
a JDOM representation of the ShoppingCart
See Also:
JDOMable.deserializeToJDOM()