SalesPoint Framework v3.0

data.ooimpl
Class StockImpl

java.lang.Object
  |
  +--data.AbstractNameable
        |
        +--data.ooimpl.StockItemImpl
              |
              +--data.ooimpl.StockImpl
Direct Known Subclasses:
CountingStockImpl, StoringStockImpl

public abstract class StockImpl
extends StockItemImpl
implements Stock, ListenableStock, NameContext, SelfManagingDBESource, SelfManagingDBEDestination

Pure Java implementation of the Stock interface.

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

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

Field Summary
protected  CatalogChangeListener m_cclEditListener
          Listens for editing events from the Catalog.
protected  CatalogImpl 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
 
Constructor Summary
StockImpl(String sName, CatalogImpl ciRef)
          Create a new StockImpl.
 
Method Summary
 void addStock(Stock 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(StockItem 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, DataBasket db)
          Check whether the given Stock is completely contained in this Stock.
protected abstract  StockImpl createPeer()
          Create an empty Stock with the same name, associated Catalog and class.
protected  void fillShallowClone(StockImpl 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 getCatalog(DataBasket db)
          Get the Catalog associated to this Stock.
protected  Map getEditingItemsContainer()
          Get the map of items that are currently being edited.
protected  Map 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 getRefIntegrEditContainer()
          Get the map storing information about name changes in CatalogItems.
protected  Map 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 getTemporaryAddedItemsContainer()
          Get the map of items that have been temporaryly added to the Stock.
protected  Map getTemporaryRemovedItemsContainer()
          Get the map of items that have been temporaryly removed from the Stock.
protected  void internalSetCatalog(CatalogImpl ciRef)
          Set the Catalog that this Stock refers to.
 Iterator iterator(DataBasket db, boolean fForEdit)
          Iterate all items in the Stock.
 Set 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 mp)
          Set the map of items that are currently being edited.
protected  void setItemsContainer(Map mp)
          Set the map of items that are actually contained in the Stock.
protected  void setRefIntegrEditContainer(Map mp)
          Set the map storing information about name changes in CatalogItems.
protected  void setRefIntegrItemsContainer(Map 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 mp)
          Set the map of items that have been temporaryly added to the Stock.
protected  void setTemporaryRemovedItemsContainer(Map 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
 

Field Detail

m_ciCatalog

protected CatalogImpl 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! This is not provided for in 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 ciRef)
Create a new StockImpl.
Parameters:
sName - the name 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 ciRef)
Set the Catalog that this Stock refers to. This method is only used internally.

m_dbCatalogValidator will be set to null.

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

getItemsContainer

protected Map getItemsContainer()
Get the map of items that are actually contained in the Stock.
Override:
Never.

getTemporaryAddedItemsContainer

protected Map getTemporaryAddedItemsContainer()
Get the map of items that have been temporaryly added to the Stock.
Override:
Never.

getTemporaryRemovedItemsContainer

protected Map getTemporaryRemovedItemsContainer()
Get the map of items that have been temporaryly removed from the Stock.
Override:
Never.

getEditingItemsContainer

protected Map getEditingItemsContainer()
Get the map of items that are currently being edited.
Override:
Never.

getRefIntegrItemsContainer

protected Map getRefIntegrItemsContainer()
Get the map of items that have been removed from the Stock to ensure referential integrity.
Override:
Never.

getRefIntegrEditContainer

protected Map getRefIntegrEditContainer()
Get the map storing information about name changes in CatalogItems.
Override:
Never.

setItemsContainer

protected void setItemsContainer(Map mp)
Set the map of items that are actually contained in the Stock.
Override:
Never.

setTemporaryAddedItemsContainer

protected void setTemporaryAddedItemsContainer(Map mp)
Set the map of items that have been temporaryly added to the Stock.
Override:
Never.

setTemporaryRemovedItemsContainer

protected void setTemporaryRemovedItemsContainer(Map mp)
Set the map of items that have been temporaryly removed from the Stock.
Override:
Never.

setEditingItemsContainer

protected void setEditingItemsContainer(Map mp)
Set the map of items that are currently being edited.
Override:
Never.

setRefIntegrItemsContainer

protected void setRefIntegrItemsContainer(Map mp)
Set the map of items that have been removed from the Stock to ensure referential integrity.
Override:
Never.

setRefIntegrEditContainer

protected void setRefIntegrEditContainer(Map mp)
Set the map storing information about name changes in CatalogItems.
Override:
Never.

addStock

public void addStock(Stock st,
                     DataBasket db,
                     boolean fRemove)
Add the contents of a Stock to this Stock. The method calls Stock.add(data.StockItem, data.DataBasket) for each item in the source Stock so the same constraints apply and the same exceptions may be thrown.
Override:
Never.
Specified by:
addStock in interface Stock
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.

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).

Override:
Never.
Specified by:
contains in interface Stock
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.

contains

public boolean contains(StockItem 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.

Override:
Never.
Specified by:
contains in interface Stock
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.

containsStock

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

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

Override:
Never.
Specified by:
containsStock in interface Stock
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.

iterator

public Iterator 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.

Override:
Never.
Specified by:
iterator in interface Stock
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.

keySet

public Set 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.

Override:
Never.
Specified by:
keySet in interface Stock
Parameters:
db - the DataBasket used for determining visibility. Must be either null or a descendant of DataBasketImpl.

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.

Override:
Never.
Specified by:
sumStock in interface Stock
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.

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.

Override:
Never.
Specified by:
fillStockWithValue in interface Stock
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.

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.
Override:
Never.
Specified by:
size in interface Stock
Parameters:
db - the DataBasket used to determine visibility. Must be either null or a descendant of DataBasketImpl.

getCatalog

public Catalog getCatalog(DataBasket db)
Get the Catalog associated to this Stock.
Override:
Never.
Specified by:
getCatalog in interface Stock

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.
Override:
Never.
Instead, override createPeer() and/or fillShallowClone(data.ooimpl.StockImpl).
Overrides:
getShallowClone in class StockItemImpl

fillShallowClone

protected void fillShallowClone(StockImpl 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.
Override:
Never.
Instead override createPeer().
Overrides:
clone in class StockItemImpl

createPeer

protected abstract StockImpl 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.
Override:
Never.
Overrides:
setStock in class StockItemImpl

compareTo

public int compareTo(Object o)
Compare this StockItem to the given object.
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.
Throws:
ClassCastException - if the given object cannot be converted into a StockItem.
Overrides:
compareTo in class StockItemImpl

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.

Override:
Never.
Specified by:
checkNameChange in interface NameContext

nameHasChanged

public void nameHasChanged(DataBasket db,
                           String sOldName,
                           String sNewName)
Stocks will not allow name changes of StockItem, as a principle.
Override:
Never.
Specified by:
nameHasChanged in interface NameContext

getNCMonitor

public Object getNCMonitor()
Stocks will not allow name changes of StockItem, as a principle.
Override:
Never.
Specified by:
getNCMonitor in interface NameContext

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.
Override:
Never.
Specified by:
addStockChangeListener in interface ListenableStock

removeStockChangeListener

public void removeStockChangeListener(StockChangeListener scl)
Remove a listener that received events when the Stock's contents changed.
Override:
Never.
Specified by:
removeStockChangeListener in interface ListenableStock

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.
Override:
Never.

fireCanEditStockItems

protected void fireCanEditStockItems(StockChangeEvent e)
                              throws VetoException
Fire an event to all listeners that showed an interest in this Stock.
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 Framework v3.0