SalesPoint v3.3 API

data.ooimpl
Class StockImpl<T,ST extends StockItemImpl,CT extends CatalogItemImpl>

java.lang.Object
  extended by data.AbstractNameable
      extended by data.ooimpl.StockItemImpl
          extended by data.ooimpl.StockImpl<T,ST,CT>
All Implemented Interfaces:
DataBasketEntryDestination, DataBasketEntrySource, DataBasketKeys, ListenableStock<ST,CT>, Nameable, NameContext, SelfManagingDBEDestination<ST>, SelfManagingDBESource<ST>, Stock<ST,CT>, StockItem, Serializable, Cloneable, Comparable<Object>
Direct Known Subclasses:
CountingStockImpl, StoringStockImpl

public abstract class StockImpl<T,ST extends StockItemImpl,CT extends CatalogItemImpl>
extends StockItemImpl
implements Stock<ST,CT>, ListenableStock<ST,CT>, NameContext, SelfManagingDBESource<ST>, SelfManagingDBEDestination<ST>

Pure Java implementation of the Stock interface.

StockImpl Stocks can only work together with CatalogImpl Catalogs, StockItemImpl StockItems and DataBasketImpl DataBaskets.

Since:
v2.0
Author:
Steffen Zschaler
See Also:
Serialized Form

Field Summary
protected  CatalogChangeListener m_cclEditListener
          Listens for editing events from the Catalog.
protected  CatalogImpl<CT> m_ciCatalog
          The Catalog that is associated to this Stock.
protected  data.ooimpl.StockImpl.CatalogItemNameListener m_cinlCatalogItemNameListener
          The listener that listens to name changes in CatalogItems in the associated Catalog.
protected  DataBasket m_dbCatalogValidator
          The DataBasket that determines the visibility of the catalog associated with this Stock.
protected  ListenerHelper m_lhListeners
          The listeners listening for events from this Stock.
protected  StockChangeListener m_sclEditCreatorListener
          Listens to the creator, if this is a shallow copy that was created for editing purposes.
 
Fields inherited from class data.AbstractNameable
m_ncContext, m_pcsPropertyListeners
 
Fields inherited from interface data.DataBasketKeys
CATALOG_ITEM_MAIN_KEY, STOCK_ITEM_MAIN_KEY
 
Constructor Summary
StockImpl(StockIdentifier<ST,CT> siId, CatalogImpl<CT> ciRef)
          Create a new StockImpl.
StockImpl(String sName, CatalogImpl<CT> ciRef)
          Create a new StockImpl.
 
Method Summary
 void addStock(Stock<ST,CT> st, DataBasket db, boolean fRemove)
          Add the contents of a Stock to this Stock.
 void addStockChangeListener(StockChangeListener scl)
          Add a listener to receive events when the Stock's contents change.
 void checkNameChange(DataBasket db, String sOldName, String sNewName)
          Check a name change of a StockItem that is contained in this Stock.
 Object clone()
          Create and return a deep clone of the Stock.
 int compareTo(Object o)
          Compare this StockItem to the given object.
 boolean contains(ST si, DataBasket db)
          Check whether the Stock contains the given StockItem.
 boolean contains(String sKey, DataBasket db)
          Check whether the Stock contains an item with the given key.
 boolean containsStock(Stock<ST,CT> st, DataBasket db)
          Check whether the given Stock is completely contained in this Stock.
protected abstract  StockImpl<T,ST,CT> createPeer()
          Create an empty Stock with the same name, associated Catalog and class.
protected  void fillShallowClone(StockImpl<T,ST,CT> stiClone)
          Hook method called to fill the given shallow clone of this Stock.
 Value fillStockWithValue(DataBasket db, Value vTarget, StockFromValueCreator sfvc)
          Increase the Stock's value by a given value.
protected  void fireCanEditStockItems(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireCanRemoveStockItems(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireEditingStockItems(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsAddCommit(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsAdded(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsAddRollback(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsEditCommit(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsEditRollback(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsRemoveCommit(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsRemoved(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
protected  void fireStockItemsRemoveRollback(StockChangeEvent e)
          Fire an event to all listeners that showed an interest in this Stock.
 Catalog<CT> getCatalog(DataBasket db)
          Get the Catalog associated to this Stock.
protected  Map<String,T> getEditingItemsContainer()
          Get the map of items that are currently being edited.
protected  Map<String,T> getItemsContainer()
          Get the map of items that are actually contained in the Stock.
protected  Object getItemsLock()
          Get the monitor synchronizing access to the Stock's contents.
 Object getNCMonitor()
          Stocks will not allow name changes of StockItem, as a principle.
protected  Map<String,String> getRefIntegrEditContainer()
          Get the map storing information about name changes in CatalogItems.
protected  Map<String,T> getRefIntegrItemsContainer()
          Get the map of items that have been removed from the Stock to ensure referential integrity.
 StockItemImpl getShallowClone()
          Create a shallow clone of the Stock.
protected  Map<String,T> getTemporaryAddedItemsContainer()
          Get the map of items that have been temporaryly added to the Stock.
protected  Map<String,T> getTemporaryRemovedItemsContainer()
          Get the map of items that have been temporaryly removed from the Stock.
protected  void internalSetCatalog(CatalogImpl<CT> ciRef)
          Set the Catalog that this Stock refers to.
 Iterator<ST> iterator(DataBasket db, boolean fForEdit)
          Iterate all items in the Stock.
 Set<String> keySet(DataBasket db)
          Return the set of keys for which StockItems are visible using the given DataBasket.
 void nameHasChanged(DataBasket db, String sOldName, String sNewName)
          Stocks will not allow name changes of StockItem, as a principle.
protected  void prepareReferentialIntegrity(DataBasket db, DataBasketEntry dbe)
          Helper method to be called in the beginning of commitAdd and rollbackRemove.
 void removeStockChangeListener(StockChangeListener scl)
          Remove a listener that received events when the Stock's contents changed.
protected  void setEditingItemsContainer(Map<String,T> mp)
          Set the map of items that are currently being edited.
protected  void setItemsContainer(Map<String,T> mp)
          Set the map of items that are actually contained in the Stock.
protected  void setRefIntegrEditContainer(Map<String,String> mp)
          Set the map storing information about name changes in CatalogItems.
protected  void setRefIntegrItemsContainer(Map<String,T> mp)
          Set the map of items that have been removed from the Stock to ensure referential integrity.
protected  void setStock(StockImpl<?,?,?> sti)
          Set the Stock that contains this Stock.
protected  void setTemporaryAddedItemsContainer(Map<String,T> mp)
          Set the map of items that have been temporaryly added to the Stock.
protected  void setTemporaryRemovedItemsContainer(Map<String,T> mp)
          Set the map of items that have been temporaryly removed from the Stock.
 int size(DataBasket db)
          Get the size of this Stock.
 Value sumStock(DataBasket db, CatalogItemValue civ, Value vInit)
          Sum up the Stock.
 
Methods inherited from class data.ooimpl.StockItemImpl
equals, getAssociatedItem, getStock, toString
 
Methods inherited from class data.AbstractNameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface data.ooimpl.SelfManagingDBESource
commitRemove, rollbackRemove
 
Methods inherited from interface data.ooimpl.SelfManagingDBEDestination
commitAdd, rollbackAdd
 

Field Detail

m_ciCatalog

protected CatalogImpl<CT extends CatalogItemImpl> m_ciCatalog
The Catalog that is associated to this Stock.


m_dbCatalogValidator

protected DataBasket m_dbCatalogValidator
The DataBasket that determines the visibility of the catalog associated with this Stock.

If null, the associated Catalog is visible with any DataBasket, otherwise it is only visible with the DataBasket specified in this field. Requests for the Catalog using a different DataBasket will the be rejected by throwing a DataBasketConflictException.


m_lhListeners

protected ListenerHelper m_lhListeners
The listeners listening for events from this Stock.


m_cinlCatalogItemNameListener

protected data.ooimpl.StockImpl.CatalogItemNameListener m_cinlCatalogItemNameListener
The listener that listens to name changes in CatalogItems in the associated Catalog.


m_cclEditListener

protected final CatalogChangeListener m_cclEditListener
Listens for editing events from the Catalog. Installs m_cinlCatalogItemNameListener if necessary. Also prevents editing, if there are StockItems in DataBaskets, so that we don't get any problems with name changes. Note however, that it might be possible to first edit a CatalogItem and then remove corresponding StockItems which might cause the same problem! Preventing that is not provided by the Framework.


m_sclEditCreatorListener

protected StockChangeListener m_sclEditCreatorListener
Listens to the creator, if this is a shallow copy that was created for editing purposes. This is to follow with any events that the creator might trigger.

Constructor Detail

StockImpl

public StockImpl(String sName,
                 CatalogImpl<CT> ciRef)
Create a new StockImpl.

Parameters:
sName - the name of the new Stock.
ciRef - the Catalog that is referenced by this Stock.

StockImpl

public StockImpl(StockIdentifier<ST,CT> siId,
                 CatalogImpl<CT> ciRef)
Create a new StockImpl.

Parameters:
siId - the id of the new Stock.
ciRef - the Catalog that is referenced by this Stock.
Method Detail

getItemsLock

protected final Object getItemsLock()
Get the monitor synchronizing access to the Stock's contents.

Override:
Never

internalSetCatalog

protected void internalSetCatalog(CatalogImpl<CT> ciRef)
Set the Catalog that this Stock refers to. This method is only used internally.

m_dbCatalogValidator will be set to null.

Parameters:
ciRef - the Catalog to refer to from now on.
Override:
Never

getItemsContainer

protected Map<String,T> getItemsContainer()
Get the map of items that are actually contained in the Stock.

Override:
Never

getTemporaryAddedItemsContainer

protected Map<String,T> getTemporaryAddedItemsContainer()
Get the map of items that have been temporaryly added to the Stock.

Override:
Never

getTemporaryRemovedItemsContainer

protected Map<String,T> getTemporaryRemovedItemsContainer()
Get the map of items that have been temporaryly removed from the Stock.

Override:
Never

getEditingItemsContainer

protected Map<String,T> getEditingItemsContainer()
Get the map of items that are currently being edited.

Override:
Never

getRefIntegrItemsContainer

protected Map<String,T> getRefIntegrItemsContainer()
Get the map of items that have been removed from the Stock to ensure referential integrity.

Override:
Never

getRefIntegrEditContainer

protected Map<String,String> getRefIntegrEditContainer()
Get the map storing information about name changes in CatalogItems.

Override:
Never

setItemsContainer

protected void setItemsContainer(Map<String,T> mp)
Set the map of items that are actually contained in the Stock.

Override:
Never

setTemporaryAddedItemsContainer

protected void setTemporaryAddedItemsContainer(Map<String,T> mp)
Set the map of items that have been temporaryly added to the Stock.

Override:
Never

setTemporaryRemovedItemsContainer

protected void setTemporaryRemovedItemsContainer(Map<String,T> mp)
Set the map of items that have been temporaryly removed from the Stock.

Override:
Never

setEditingItemsContainer

protected void setEditingItemsContainer(Map<String,T> mp)
Set the map of items that are currently being edited.

Override:
Never

setRefIntegrItemsContainer

protected void setRefIntegrItemsContainer(Map<String,T> mp)
Set the map of items that have been removed from the Stock to ensure referential integrity.

Override:
Never

setRefIntegrEditContainer

protected void setRefIntegrEditContainer(Map<String,String> mp)
Set the map storing information about name changes in CatalogItems.

Override:
Never

addStock

public void addStock(Stock<ST,CT> st,
                     DataBasket db,
                     boolean fRemove)
Add the contents of a Stock to this Stock. The method calls Stock.add(T, data.DataBasket) for each item in the source Stock so the same constraints apply and the same exceptions may be thrown.

Specified by:
addStock in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
st - the Stock whose contents is to be added to this Stock.
db - the DataBasket relative to which to perform the actions. addStock will add all items from the source Stock that are visible using this DataBasket. Must be either null or a descendant of DataBasketImpl.
fRemove - if true, the items will be removed from the source Stock prior to adding them to this Stock. Otherwise, they will be cloned prior to adding them to the Stock.
Override:
Never

contains

public boolean contains(String sKey,
                        DataBasket db)
Check whether the Stock contains an item with the given key.

Equivalent to:(Stock.countItems(java.lang.String, data.DataBasket) (sKey, db) > 0).

Specified by:
contains in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to check containment.
db - the DataBasket used to check visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

contains

public boolean contains(ST si,
                        DataBasket db)
Check whether the Stock contains the given StockItem.

Return true if the Stock contains a StockItem that is equal to the given one.

Specified by:
contains in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
si - the StockItem for which to check containment.
db - the DataBasket used to check visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

containsStock

public boolean containsStock(Stock<ST,CT> st,
                             DataBasket db)
Check whether the given Stock is completely contained in this Stock.

Calls Stock.contains(data.StockItem, data.DataBasket) for each item in the given Stock.

Specified by:
containsStock in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
st - the Stock for which to check containment.
db - the DataBasket used to determine visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

iterator

public Iterator<ST> iterator(DataBasket db,
                             boolean fForEdit)
Iterate all items in the Stock.

This method, together with Stock.get(java.lang.String, data.DataBasket, boolean) is the only way of accessing the individual StockItems contained in a Stock. The iterator will deliver all items that are visible using the given DataBasket. Depending on the fForEdit parameter, the items will be retrieved in different ways. See DataBasket for an explanation of the different possibilities.

canEditStockItems and editingStockItems events will be fired if fForEdit == true. VetoExceptions will be converted into UnSupportedOperationExceptions.

Specified by:
iterator in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
db - the DataBasket relative to which to retrieve the StockItems. Must be either null or a descendant of DataBasketImpl.
fForEdit - if true, the StockItems will be retrieved for editing.
Override:
Never

keySet

public Set<String> keySet(DataBasket db)
Return the set of keys for which StockItems are visible using the given DataBasket.

The returned set is static and gives the state of the Stock at the time of the call. It will not automatically update when the contents of the Stock changes.

Specified by:
keySet in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
db - the DataBasket used for determining visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

sumStock

public Value sumStock(DataBasket db,
                      CatalogItemValue civ,
                      Value vInit)
Sum up the Stock.

The method will determine the value of each CatalogItem in the associated Catalog and multiply this by the number of StockItems for the respective key. These products will be added up and the resulting total will be returned.

Specified by:
sumStock in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
db - the DataBasket that is used to determine visibility. Must be either null or a descendant of DataBasketImpl.
civ - the CatalogItemValue used for determining the value of a CatalogItem.
vInit - the initial value. The sum of the Stock will be added to this value.
Returns:
the resulting total. Usually the returned object is the same as the one passed as vInit, only with a changed value.
Override:
Never

fillStockWithValue

public Value fillStockWithValue(DataBasket db,
                                Value vTarget,
                                StockFromValueCreator sfvc)
Increase the Stock's value by a given value.

The method will try to break the given value as exactly as possible into StockItems that will be added to the Stock. The actual algorithm used for breaking up the value will be determined by the last parameter. The return value of the method will specify the remaining value that could not be represented by StockItems by the given algorithm.

Specified by:
fillStockWithValue in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
db - the DataBasket relative to which to perform the operation. Must be either null or a descendant of DataBasketImpl.
vTarget - the value by which to increase the Stock's total value.
sfvc - the strategy used to fill the Stock.
Returns:
the value that remained and could not be represented by StockItems.
Override:
Never

size

public int size(DataBasket db)
Get the size of this Stock. I.e. calculate the number of StockItems that can be seen when using the given DataBasket.

Specified by:
size in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
db - the DataBasket used to determine visibility. Must be either null or a descendant of DataBasketImpl.
Override:
Never

getCatalog

public Catalog<CT> getCatalog(DataBasket db)
Get the Catalog associated to this Stock.

Specified by:
getCatalog in interface Stock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
db - a DataBasket determinig visibility of the stock's catalog.
Override:
Never

getShallowClone

public StockItemImpl getShallowClone()
Create a shallow clone of the Stock. In contrast to a deep clone, the individual items in the Stock are not cloned.

Overrides:
getShallowClone in class StockItemImpl
Override:
Never Instead, override createPeer() and/or fillShallowClone(data.ooimpl.StockImpl).

fillShallowClone

protected void fillShallowClone(StockImpl<T,ST,CT> stiClone)
Hook method called to fill the given shallow clone of this Stock.

Override:
Sometimes Normally you do not have to override this method.

clone

public Object clone()
Create and return a deep clone of the Stock. In contrast to a shallow clone, the individual items themselves are also cloned.

Specified by:
clone in interface StockItem
Overrides:
clone in class StockItemImpl
Override:
Never Instead override createPeer().

createPeer

protected abstract StockImpl<T,ST,CT> createPeer()
Create an empty Stock with the same name, associated Catalog and class.

Override:
Always

setStock

protected void setStock(StockImpl<?,?,?> sti)
Set the Stock that contains this Stock.

Overrides:
setStock in class StockItemImpl
Override:
Never

compareTo

public int compareTo(Object o)
Compare this StockItem to the given object.

Specified by:
compareTo in interface Comparable<Object>
Overrides:
compareTo in class StockItemImpl
Throws:
ClassCastException - if the given object cannot be converted into a StockItem.
Override:
Always The default implementation will assume o to be a StockItem and will compare the names. Stocks, however, will always be greater than StockItems.

checkNameChange

public void checkNameChange(DataBasket db,
                            String sOldName,
                            String sNewName)
                     throws NameContextException
Check a name change of a StockItem that is contained in this Stock.

Stocks will not allow name changes of StockItem, as a principle.

Specified by:
checkNameChange in interface NameContext
Parameters:
db - the DataBasket relative to which the name change is to take place.
sOldName - the name to be changed.
sNewName - the new name.
Throws:
NameContextException - if the name change would not be valid.
Override:
Never

nameHasChanged

public void nameHasChanged(DataBasket db,
                           String sOldName,
                           String sNewName)
Stocks will not allow name changes of StockItem, as a principle.

Specified by:
nameHasChanged in interface NameContext
Parameters:
db - the DataBasket relative to which the name change has taken place.
sOldName - the old name of the object whose name was changed.
sNewName - the new name of the object.
Override:
Never

getNCMonitor

public Object getNCMonitor()
Stocks will not allow name changes of StockItem, as a principle.

Specified by:
getNCMonitor in interface NameContext
Override:
Never

prepareReferentialIntegrity

protected void prepareReferentialIntegrity(DataBasket db,
                                           DataBasketEntry dbe)
Helper method to be called in the beginning of commitAdd and rollbackRemove. Tries to maintain referential integrity by trying to make sure that a CatalogItem exists for the the StockItems that will be brought into the Stock. Must be called from within synchronized (getItemsLock()) {} before any other operation.

Override:
Never

addStockChangeListener

public void addStockChangeListener(StockChangeListener scl)
Add a listener to receive events when the Stock's contents change.

Specified by:
addStockChangeListener in interface ListenableStock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
scl - the listener
Override:
Never

removeStockChangeListener

public void removeStockChangeListener(StockChangeListener scl)
Remove a listener that received events when the Stock's contents changed.

Specified by:
removeStockChangeListener in interface ListenableStock<ST extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
scl - the listener
Override:
Never

fireStockItemsAdded

protected void fireStockItemsAdded(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireStockItemsAddCommit

protected void fireStockItemsAddCommit(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireStockItemsAddRollback

protected void fireStockItemsAddRollback(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireStockItemsRemoved

protected void fireStockItemsRemoved(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireStockItemsRemoveCommit

protected void fireStockItemsRemoveCommit(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireStockItemsRemoveRollback

protected void fireStockItemsRemoveRollback(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireCanRemoveStockItems

protected void fireCanRemoveStockItems(StockChangeEvent e)
                                throws VetoException
Fire an event to all listeners that showed an interest in this Stock.

Throws:
VetoException
Override:
Never

fireCanEditStockItems

protected void fireCanEditStockItems(StockChangeEvent e)
                              throws VetoException
Fire an event to all listeners that showed an interest in this Stock.

Throws:
VetoException
Override:
Never

fireEditingStockItems

protected void fireEditingStockItems(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireStockItemsEditCommit

protected void fireStockItemsEditCommit(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

fireStockItemsEditRollback

protected void fireStockItemsEditRollback(StockChangeEvent e)
Fire an event to all listeners that showed an interest in this Stock.

Override:
Never

SalesPoint v3.3 API