SalesPoint Framework v3.0

data.ooimpl
Class DataBasketImpl

java.lang.Object
  |
  +--data.ooimpl.DataBasketImpl

public class DataBasketImpl
extends Object
implements ListenableDataBasket

Pure Java implementation of the DataBasketImpl.SubDataBasket interface.

This DataBasket implementation can be used together with the Catalog and Stock implementations that come with the framework as well as with any other data container that manages all its internal structure on its own, instead of delegating them, e.g. to a data base. For a data base backing you should use other implementations of Stock, Catalog and DataBasketImpl.SubDataBasket, but these are not yet part of the framework.

Since:
v2.0
Version:
2.0 14/06/1999
Author:
Steffen Zschaler
See Also:
Serialized Form

Inner Class Summary
static class DataBasketImpl.DataBasketImplLogEntry
          A LogEntry that describes an action on a DataBasket.
protected static class DataBasketImpl.SubDataBasket
          Internal helper class used by DataBasketImpl, representing a subbasket of a DataBasket.
 
Field Summary
static int COMMIT_ACTION
          Action constant for log(int, log.Loggable).
static int EXCHANGE_REMOVE_ACTION
          Action constant for log(int, log.Loggable).
static LogEntryFilter LOGENTRYFILTER_COMMIT_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a commit action.
static LogEntryFilter LOGENTRYFILTER_DATABASKETIMPLACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl.
static LogEntryFilter LOGENTRYFILTER_EXCHANGE_REMOVE_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a exchange_remove action.
static LogEntryFilter LOGENTRYFILTER_NO_DATABASKETIMPLACTIONS
          A LogEntryFilter that will accept only LogEntries that were not produced by a DataBasketImpl.
static LogEntryFilter LOGENTRYFILTER_PUT_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a put action.
static LogEntryFilter LOGENTRYFILTER_ROLLBACK_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a rollback action.
protected  ListenerHelper m_lhListeners
          The listeners currently listening for events from this DataBasket.
protected  Map m_mpsdbChildren
          The subbaskets of this DataBasket.
static int PUT_ACTION
          Action constant for log(int, log.Loggable).
static int ROLLBACK_ACTION
          Action constant for log(int, log.Loggable).
 
Constructor Summary
DataBasketImpl()
          Create a new DataBasketImpl.
 
Method Summary
 void addDataBasketListener(DataBasketListener dbl)
          Add a listener that will receive events when the DataBasket's contents change.
protected  void clean()
          Remove any items that have already been handled, but so far have not been removed from the DataBasket.
 void commit()
          Commit the contents of all subbaskets of this DataBasket.
 void commit(DataBasketCondition dbc)
          Commit all items in all subbaskets that do match the given condition.
 void commitCurrentSubBasket()
          Commit the current subbasket's contents.
 void commitSubBasket(String sName)
          Commit all entries in a given subbasket.
 boolean contains(DataBasketCondition dbc)
          Check whether any entries matching a particular condition are contained in the DataBasket.
 void exchange(DataBasketEntry dbeOrg, DataBasketEntry dbeNew)
          Exchange a DataBasketEntry with another.
 void fireDataBasketChanged()
          Fire an event to all listeners listening to this DataBasket.
protected  void fireDBEAdded(DataBasketEntry dbe)
          Fire an event to all listeners listening to this DataBasket.
protected  void fireDBERemoved(DataBasketEntry dbe)
          Fire an event to all listeners listening to this DataBasket.
 DataBasketEntry get(DataBasketCondition dbc)
          Get the first entry in the DataBasket that matches the condition.
protected  Object getChildrenLock()
          Return the monitor used to synchronize access to the list of children.
 Object getDBIMonitor()
          Return the monitor used to synchronize access to the internal data structures of the DataBasket.
 int getLogMode()
          Return the current log mode of the DataBasket.
 Iterator iterator(DataBasketCondition dbc)
          Iterate all entries in all subbaskets that match the condition.
 void log(int nAction, Loggable la)
          Log the given event wrapped in a LogEntry that describes the action.
 void put(DataBasketEntry dbe)
          Put a DataBasketEntry into the current subbasket.
 void removeDataBasketListener(DataBasketListener dbl)
          Remove a listener that received events when the DataBasket's contents changed.
 void rollback()
          Rollback the contents of all subbaskets of this DataBasket.
 void rollback(DataBasketCondition dbc)
          Rollback all items in all subbaskets that do match the given condition.
 void rollbackCurrentSubBasket()
          Rollback the current subbasket's contents.
 void rollbackSubBasket(String sName)
          Rollback all entries in a given subbasket.
 void setCurrentSubBasket(String sName)
          Set the current subbasket.
 LogContext setLogContext(LogContext lcNew)
          Set the log context for this DataBasket.
 int setLogMode(int nLogMode)
          Set the log mode for this DataBasket.
 Iterator subBasketIterator(String sName, DataBasketCondition dbc)
          Iterate all entries in a given subbasket that match the given condition.
 Value sumBasket(DataBasketCondition dbc, BasketEntryValue bev, Value vInit)
          Sum up all entries in the DataBasket that match the given condition.
 Value sumCurrentSubBasket(DataBasketCondition dbc, BasketEntryValue bev, Value vInit)
          Sum up all entries in the current subbasket that match the given condition.
 Value sumSubBasket(String sName, DataBasketCondition dbc, BasketEntryValue bev, Value vInit)
          Sum up all entries in a given subbasket that match the given condition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_mpsdbChildren

protected Map m_mpsdbChildren
The subbaskets of this DataBasket.

m_lhListeners

protected ListenerHelper m_lhListeners
The listeners currently listening for events from this DataBasket.

PUT_ACTION

public static final int PUT_ACTION
Action constant for log(int, log.Loggable).

EXCHANGE_REMOVE_ACTION

public static final int EXCHANGE_REMOVE_ACTION
Action constant for log(int, log.Loggable).

COMMIT_ACTION

public static final int COMMIT_ACTION
Action constant for log(int, log.Loggable).

ROLLBACK_ACTION

public static final int ROLLBACK_ACTION
Action constant for log(int, log.Loggable).

LOGENTRYFILTER_DATABASKETIMPLACTIONS

public static final LogEntryFilter LOGENTRYFILTER_DATABASKETIMPLACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl.

LOGENTRYFILTER_NO_DATABASKETIMPLACTIONS

public static final LogEntryFilter LOGENTRYFILTER_NO_DATABASKETIMPLACTIONS
A LogEntryFilter that will accept only LogEntries that were not produced by a DataBasketImpl.

LOGENTRYFILTER_PUT_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_PUT_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a put action.

LOGENTRYFILTER_EXCHANGE_REMOVE_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_EXCHANGE_REMOVE_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a exchange_remove action.

LOGENTRYFILTER_COMMIT_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_COMMIT_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a commit action.

LOGENTRYFILTER_ROLLBACK_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_ROLLBACK_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a rollback action.
Constructor Detail

DataBasketImpl

public DataBasketImpl()
Create a new DataBasketImpl.
Method Detail

getChildrenLock

protected final Object getChildrenLock()
Return the monitor used to synchronize access to the list of children.
Override:
Never.

rollback

public void rollback()
Rollback the contents of all subbaskets of this DataBasket.
Override:
Never.

commit

public void commit()
Commit the contents of all subbaskets of this DataBasket.
Override:
Never.

rollback

public void rollback(DataBasketCondition dbc)
Rollback all items in all subbaskets that do match the given condition.
Override:
Never.
Parameters:
dbc - the condition to be matched. null means rollback unconditionally.

commit

public void commit(DataBasketCondition dbc)
Commit all items in all subbaskets that do match the given condition.
Override:
Never.
Parameters:
dbc - the condition to be matched. null means commit unconditionally.

rollbackSubBasket

public void rollbackSubBasket(String sName)
Rollback all entries in a given subbasket.
Override:
Never.
Parameters:
sName - the name of the subbasket.

rollbackCurrentSubBasket

public void rollbackCurrentSubBasket()
Rollback the current subbasket's contents.
Override:
Never.

commitSubBasket

public void commitSubBasket(String sName)
Commit all entries in a given subbasket.
Override:
Never.
Parameters:
sName - the name of the subbasket.

commitCurrentSubBasket

public void commitCurrentSubBasket()
Commit the current subbasket's contents.
Override:
Never.

setCurrentSubBasket

public void setCurrentSubBasket(String sName)
Set the current subbasket.
Override:
Never.
Parameters:
sName - the name of the new current subbasket. If the subbasket does not yet exist, it is created prior to being made the current subbasket.

iterator

public Iterator iterator(DataBasketCondition dbc)
Iterate all entries in all subbaskets that match the condition.
Override:
Never.
Parameters:
dbc - the condition to be matched.
Returns:
an iterator that iterates all the entries in the DataBasket that match the condition. The iterator will not support the remove() method.

subBasketIterator

public Iterator subBasketIterator(String sName,
                                  DataBasketCondition dbc)
Iterate all entries in a given subbasket that match the given condition.
Override:
Never.
Parameters:
dbc - the condition to be matched.
Returns:
an iterator that iterates all the entries in the given subbasket that match the condition. The iterator will not support the remove() method.

sumBasket

public Value sumBasket(DataBasketCondition dbc,
                       BasketEntryValue bev,
                       Value vInit)
Sum up all entries in the DataBasket that match the given condition.
Override:
Never.
Parameters:
dbc - the condition to be matched.
bev - an object used for determining the value of a DataBasketEntry.
vInit - the value that is to be used for adding up. All adding is performed by calling Value.addAccumulating(data.Value) on this object.
Returns:
the sum in vInit.

sumSubBasket

public Value sumSubBasket(String sName,
                          DataBasketCondition dbc,
                          BasketEntryValue bev,
                          Value vInit)
Sum up all entries in a given subbasket that match the given condition.
Override:
Never.
Parameters:
sName - the name of the subbasket that is to be summed up.
dbc - the condition to be matched.
bev - an object used for determining the value of a DataBasketEntry.
vInit - the value that is to be used for adding up. All adding is performed by calling Value.addAccumulating(data.Value) on this object.
Returns:
the sum in vInit.

sumCurrentSubBasket

public Value sumCurrentSubBasket(DataBasketCondition dbc,
                                 BasketEntryValue bev,
                                 Value vInit)
Sum up all entries in the current subbasket that match the given condition.
Override:
Never.
Parameters:
dbc - the condition to be matched.
bev - an object used for determining the value of a DataBasketEntry.
vInit - the value that is to be used for adding up. All adding is performed by calling Value.addAccumulating(data.Value) on this object.
Returns:
the sum in vInit.

put

public void put(DataBasketEntry dbe)
Put a DataBasketEntry into the current subbasket. DataBasketEntries that are to be put into a DataBasketImpl must be instances of, or of subclasses of, DataBasketEntryImpl.
Override:
Never.
Parameters:
dbe - the entry to be put in.
Throws:
ClassCastException - if ! (dbe instanceof DataBasketEntryImpl).

exchange

public void exchange(DataBasketEntry dbeOrg,
                     DataBasketEntry dbeNew)
Exchange a DataBasketEntry with another.
Override:
Never.
Parameters:
dbeOrg - the original DataBasketEntry, to be replaced.
dbeNew - the replacement.

get

public DataBasketEntry get(DataBasketCondition dbc)
Get the first entry in the DataBasket that matches the condition.
Override:
Never.
Parameters:
dbc - the condition

contains

public boolean contains(DataBasketCondition dbc)
Check whether any entries matching a particular condition are contained in the DataBasket.
Override:
Never.
Parameters:
dbc - the condition
Returns:
true if an entry that matches the condition could be found.

setLogContext

public LogContext setLogContext(LogContext lcNew)
Set the log context for this DataBasket.

All operations as defined through setLogMode(int) will be logged using the given log context. If the current log context is null no logging of any kind will occur.

The actual LogEntries written are defined by the DataBasketEntries that participate in the activities that are logged. The DataBasket will wrap those LogEntries into LogEntries that give the type of operation performed.

Override:
Never.
Parameters:
lcNew - the new log context
Returns:
the previous log context, if any.
See Also:
log(int, log.Loggable)

setLogMode

public int setLogMode(int nLogMode)
Set the log mode for this DataBasket.

The current log mode decides what operations on the DataBasket are being logged. The default value is DataBasket.LOG_MODE_NONE, indicating that no logging occurs. Other possibilities are:

The actual LogEntries written are defined by the DataBasketEntries that participate in the activities that are logged. The DataBasket will wrap those LogEntries into LogEntries that give the type of operation performed.

Override:
Never.
Parameters:
nLogMode - the new log mode.
Returns:
the previous log mode.
See Also:
log(int, log.Loggable)

getLogMode

public int getLogMode()
Return the current log mode of the DataBasket. For information on the possible values and their meaning, please refer to setLogMode(int).
Override:
Never.

log

public void log(int nAction,
                Loggable la)
Log the given event wrapped in a LogEntry that describes the action.

If the action needs to be logged in the current log mode, a new DataBasketImpl.DataBasketImplLogEntry is created that wraps the LogEntry produced by the given Loggable. This LogEntry is then logged using the current LogContext.

Override:
Never.
See Also:
setLogContext(log.LogContext), setLogMode(int)

getDBIMonitor

public Object getDBIMonitor()
Return the monitor used to synchronize access to the internal data structures of the DataBasket. Whenever a container wants to access a DataBasket implemented in this way, it must first synchronize over the DataBasket's monitor and then synchronize over its own monitor(s).
Override:
Never.

clean

protected void clean()
Remove any items that have already been handled, but so far have not been removed from the DataBasket.

This method is usually called by the framework only. It assumes, that it is called from within a synchronized block synchronizing on the monitor returned by getDBIMonitor().

Override:
Never.

addDataBasketListener

public void addDataBasketListener(DataBasketListener dbl)
Add a listener that will receive events when the DataBasket's contents change.
Override:
Never.
Specified by:
addDataBasketListener in interface ListenableDataBasket

removeDataBasketListener

public void removeDataBasketListener(DataBasketListener dbl)
Remove a listener that received events when the DataBasket's contents changed.
Override:
Never.
Specified by:
removeDataBasketListener in interface ListenableDataBasket

fireDataBasketChanged

public void fireDataBasketChanged()
Fire an event to all listeners listening to this DataBasket.
Override:
Never.
Specified by:
fireDataBasketChanged in interface ListenableDataBasket

fireDBEAdded

protected void fireDBEAdded(DataBasketEntry dbe)
Fire an event to all listeners listening to this DataBasket.
Override:
Never.

fireDBERemoved

protected void fireDBERemoved(DataBasketEntry dbe)
Fire an event to all listeners listening to this DataBasket.
Override:
Never.

SalesPoint Framework v3.0