org.salespointframework.core.data
Class StoringStockImpl<T extends StockItemImpl,CT extends CatalogItemImpl>

java.lang.Object
  extended by org.salespointframework.core.data.AbstractNameable
      extended by org.salespointframework.core.data.StockItemImpl
          extended by org.salespointframework.core.data.StockImpl<java.util.List<T>,T,CT>
              extended by org.salespointframework.core.data.StoringStockImpl<T,CT>
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<java.lang.Object>, java.lang.Iterable<T>, Recoverable, DatasourceChangeListener, ExternalModificationListener, DataBasketEntryDestination, DataBasketEntrySource, DataBasketKeys, ListenableStock<T,CT>, Nameable, NameContext, SpAggregate, SpItem, Stock<T,CT>, StockItem, StoringStock<T,CT>, SelfManagingDBEDestination<T>, SelfManagingDBESource<T>

public class StoringStockImpl<T extends StockItemImpl,CT extends CatalogItemImpl>
extends StockImpl<java.util.List<T>,T,CT>
implements StoringStock<T,CT>

Pure Java implementation of the StoringStock interface.

Since:
v2.0
Version:
2.0 19/08/1999
Author:
Steffen Zschaler

Nested Class Summary
(package private)  class StoringStockImpl.SSICatalogItemNameListener
          Enhanced CatalogItemNameListener, updating the names of the actual StockItems whenever a name change occurs.
 
Nested classes/interfaces inherited from class org.salespointframework.core.data.StockImpl
StockImpl.CatalogItemNameListener
 
Field Summary
protected  java.lang.Class clazz
           
protected  CatalogChangeListener m_cclReferentialIntegrityListener
          Listens to the Stock's Catalog to ensure referential integrity.
private  boolean m_fChangedCatalogItemNameListener
          true, if StockImpl's CatalogItemNameListener was already replaced by an enhanced version.
protected  int m_nModCount
          Modification counter.
 
Fields inherited from class org.salespointframework.core.data.StockImpl
m_cclEditListener, m_ciCatalog, m_cinlCatalogItemNameListener, m_dbCatalogValidator, m_lhListeners, m_sclEditCreatorListener
 
Fields inherited from class org.salespointframework.core.data.StockItemImpl
COMMIT_ACTION, ROLLBACK_ACTION, STARTEDIT_ACTION
 
Fields inherited from class org.salespointframework.core.data.AbstractNameable
m_ncContext, m_pcsPropertyListeners, SOME_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.Nameable
NAME_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.DataBasketKeys
CATALOG_ITEM_MAIN_KEY, STOCK_ITEM_MAIN_KEY
 
Constructor Summary
  StoringStockImpl(Catalog<CT> ciRef)
          Create a new, initially empty StoringStockImpl.
  StoringStockImpl(StockIdentifier<T,CT> id, Catalog<CT> ciRef)
          Create a new, initially empty StoringStockImpl.
  StoringStockImpl(java.lang.String sName, Catalog<CT> ciRef)
          Create a new, initially empty StoringStockImpl.
  StoringStockImpl(java.lang.String sName, Catalog<CT> ciRef, boolean temporary)
          Create a new, initially empty StoringStockImpl.
private StoringStockImpl(java.lang.String sName, Catalog<CT> ciRef, boolean temporary, java.lang.Class<T> clazz)
          Create a new, initially empty StoringStockImpl.
  StoringStockImpl(java.lang.String sName, Catalog<CT> ciRef, java.lang.Class<T> clazz)
          Create a new, initially empty StoringStockImpl.
 
Method Summary
 void add(T si, DataBasket db)
          Add an item to the Stock.
 void commitAdd(DataBasket db, DataBasketEntry<T> dbe)
          Commit the adding of a StockItem.
 void commitRemove(DataBasket db, DataBasketEntry<T> dbe)
          Commit the removal of a StockItem.
 int countItems(java.lang.String sKey, DataBasket db)
          Count the StockItems with a given key that are visible using a given DataBasket.
protected  StockImpl<java.util.List<T>,T,CT> createPeer()
          Create an empty Stock with the same name, associated Catalog and class.
protected  void fillShallowClone(StoringStockImpl<T,CT> stiClone)
          Overridden to accomodate for specific usage of memory.
 java.util.Iterator<T> get(java.lang.String sKey, DataBasket db, boolean fForEdit)
          Iterate all items with a given key.
private  void initReferentialIntegrityListener()
          Internal helper function.
protected  void internalSetCatalog(CatalogImpl<CT> ciRef)
          Overridden because of referential integrity.
private  void reEstablishStockCatalogLink(java.lang.String sKey)
          Private helper function re-establishing the Stock-Catalog connection if any items in this Stock should be Stocks themselves.
(package private)  void relinkCatalog(DataBasket db, int nAction)
          Helper method used to maintain StockImpl - CatalogImpl links in nested Stocks/Catalogs.
 StockItem remove(java.lang.String sKey, DataBasket db)
          Remove one StockItem with the specified key from the Stock.
 T remove(T si, DataBasket db)
          Remove the given StockItem from the Stock.
 void rollbackAdd(DataBasket db, DataBasketEntry<T> dbe)
          Rollback the adding of a StockItem.
 void rollbackRemove(DataBasket db, DataBasketEntry<T> dbe)
          Rollback the removal of a StockItem.
protected  void setStock(StockImpl sti)
          Set the Stock and adjust the Catalog link for all Stocks that are contained in this Stock.
 
Methods inherited from class org.salespointframework.core.data.StockImpl
addStock, addStockChangeListener, checkNameChange, clone, compareTo, contains, contains, containsStock, DatasourceChanged, externalModificationOccurred, fillShallowClone, fillStockWithValue, fireCanEditStockItems, fireCanRemoveStockItems, fireEditingStockItems, fireStockItemsAddCommit, fireStockItemsAdded, fireStockItemsAddRollback, fireStockItemsEditCommit, fireStockItemsEditRollback, fireStockItemsRemoveCommit, fireStockItemsRemoved, fireStockItemsRemoveRollback, getCatalog, getEditingItemsContainer, getItemsContainer, getItemsLock, getNCMonitor, getRefIntegrEditContainer, getRefIntegrItemsContainer, getShallowClone, getTemporaryAddedItemsContainer, getTemporaryRemovedItemsContainer, iterator, iterator, keySet, nameHasChanged, prepareReferentialIntegrity, removeStockChangeListener, setEditingItemsContainer, setItemsContainer, setRefIntegrEditContainer, setRefIntegrItemsContainer, setTemporaryAddedItemsContainer, setTemporaryRemovedItemsContainer, size, sumStock, unsubscribe
 
Methods inherited from class org.salespointframework.core.data.StockItemImpl
equals, firePropertyChanged, getAssociatedItem, getStock, internalSetName, recover, toString
 
Methods inherited from class org.salespointframework.core.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 org.salespointframework.core.data.interfaces.Stock
addStock, contains, contains, containsStock, fillStockWithValue, getCatalog, iterator, keySet, size, sumStock
 
Methods inherited from interface org.salespointframework.core.data.interfaces.StockItem
clone, getAssociatedItem, getStock
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.salespointframework.core.data.interfaces.Nameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from interface org.salespointframework.core.data.interfaces.SpItem
getName
 
Methods inherited from interface org.salespointframework.core.data.events.DatasourceChangeListener
DatasourceChanged
 
Methods inherited from interface org.salespointframework.core.data.events.ExternalModificationListener
externalModificationOccurred
 
Methods inherited from interface java.lang.Iterable
iterator
 

Field Detail

m_nModCount

protected int m_nModCount
Modification counter. Increases by one with every structural modification.


m_cclReferentialIntegrityListener

protected CatalogChangeListener m_cclReferentialIntegrityListener
Listens to the Stock's Catalog to ensure referential integrity.


m_fChangedCatalogItemNameListener

private boolean m_fChangedCatalogItemNameListener
true, if StockImpl's CatalogItemNameListener was already replaced by an enhanced version. Used internally only.


clazz

protected java.lang.Class clazz
Constructor Detail

StoringStockImpl

public StoringStockImpl(Catalog<CT> ciRef)
Create a new, initially empty StoringStockImpl. Stock Name(Id) is generated by random

Parameters:
ciRef - the Catalog that is being referenced by the Stock.

StoringStockImpl

public StoringStockImpl(StockIdentifier<T,CT> id,
                        Catalog<CT> ciRef)
Create a new, initially empty StoringStockImpl.

Parameters:
id - the id of the new Stock.
ciRef - the Catalog that is being referenced by the Stock.

StoringStockImpl

public StoringStockImpl(java.lang.String sName,
                        Catalog<CT> ciRef)
Create a new, initially empty StoringStockImpl.

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

StoringStockImpl

public StoringStockImpl(java.lang.String sName,
                        Catalog<CT> ciRef,
                        boolean temporary)
Create a new, initially empty StoringStockImpl.

Parameters:
sName - the name of the new Stock.
ciRef - the Catalog that is being referenced by the Stock.
temporary - creates a temporary stock, which will not be persisted

StoringStockImpl

public StoringStockImpl(java.lang.String sName,
                        Catalog<CT> ciRef,
                        java.lang.Class<T> clazz)
Create a new, initially empty StoringStockImpl.

Parameters:
sName - the name of the new Stock.
ciRef - the Catalog that is being referenced by the Stock.
clazz - if you use an own implementation of StockItem you need to set the Class

StoringStockImpl

private StoringStockImpl(java.lang.String sName,
                         Catalog<CT> ciRef,
                         boolean temporary,
                         java.lang.Class<T> clazz)
Create a new, initially empty StoringStockImpl.

Method Detail

internalSetCatalog

protected void internalSetCatalog(CatalogImpl<CT> ciRef)
Overridden because of referential integrity.

Overrides:
internalSetCatalog in class StockImpl<java.util.List<T extends StockItemImpl>,T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
ciRef - the Catalog to refer to from now on.

initReferentialIntegrityListener

private void initReferentialIntegrityListener()
Internal helper function.


reEstablishStockCatalogLink

private void reEstablishStockCatalogLink(java.lang.String sKey)
Private helper function re-establishing the Stock-Catalog connection if any items in this Stock should be Stocks themselves.


add

public void add(T si,
                DataBasket db)
Add an item to the Stock.

The item will only be visible to users of the same DataBasket. Only after a DataBasket.commit() was performed on the DataBasket, the item will become visible to other users.

A addedStockItems event will be fired.

Specified by:
add in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
si - the item to be added.
db - the DataBasket relative to which the item will be added. Must be either null or a descendant of DataBasketImpl.
Throws:
CatalogConflictException - if the items key is not contained in the corresponding Catalog.
DataBasketConflictException - if the item has already been added/removed using another DataBasket.

get

public java.util.Iterator<T> get(java.lang.String sKey,
                                 DataBasket db,
                                 boolean fForEdit)
Iterate all items with a given key.

This method, together with Stock.iterator(org.salespointframework.core.data.interfaces.DataBasket, boolean) is the only way of accessing the individual StockItems contained in a Stock. The iterator will deliver all items that have the specified key and 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:
get in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to retrieve the StockItems.
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.

countItems

public int countItems(java.lang.String sKey,
                      DataBasket db)
Count the StockItems with a given key that are visible using a given DataBasket.

Specified by:
countItems in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to count the StockItems.
db - the DataBasket that is used to determine visibility. Must be either null or a descendant of DataBasketImpl.

remove

public StockItem remove(java.lang.String sKey,
                        DataBasket db)
                 throws VetoException
Remove one StockItem with the specified key from the Stock.

If there are any StockItems with the specified key, one will be removed. There is no guarantee as to which StockItem will be removed. The removed item, if any, will be returned.

canRemoveStockItems and removedStockItems events will be fired.

Specified by:
remove in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
sKey - the key for which to remove an item.
db - the DataBasket relative to which to remove the item. Must be either null or a descendant of DataBasketImpl.
Returns:
the removed item
Throws:
VetoException - if a listener vetoed the removal.
DataBasketConflictException - if the item cannot be removed due to conflicts from DataBasket usage.

remove

public T remove(T si,
                DataBasket db)
                               throws VetoException
Remove the given StockItem from the Stock.

If the given StockItem is contained in the Stock, it will be removed. The removed item, if any, will be returned.

canRemoveStockItems and removedStockItems events will be fired.

Specified by:
remove in interface Stock<T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
si - the StockItem to be removed.
db - the DataBasket relative to which to remove the item. Must be either null or a descendant of DataBasketImpl.
Returns:
the removed item
Throws:
VetoException - if a listener vetoed the removal.
DataBasketConflictException - if the item cannot be removed due to conflicts from DataBasket usage.

fillShallowClone

protected void fillShallowClone(StoringStockImpl<T,CT> stiClone)
Overridden to accomodate for specific usage of memory.


createPeer

protected StockImpl<java.util.List<T>,T,CT> createPeer()
Description copied from class: StockImpl
Create an empty Stock with the same name, associated Catalog and class.

Specified by:
createPeer in class StockImpl<java.util.List<T extends StockItemImpl>,T extends StockItemImpl,CT extends CatalogItemImpl>

setStock

protected void setStock(StockImpl sti)
Set the Stock and adjust the Catalog link for all Stocks that are contained in this Stock.

Overrides:
setStock in class StockImpl<java.util.List<T extends StockItemImpl>,T extends StockItemImpl,CT extends CatalogItemImpl>

relinkCatalog

void relinkCatalog(DataBasket db,
                   int nAction)
Helper method used to maintain StockImpl - CatalogImpl links in nested Stocks/Catalogs. For internal use only.

Overrides:
relinkCatalog in class StockImpl<java.util.List<T extends StockItemImpl>,T extends StockItemImpl,CT extends CatalogItemImpl>
Parameters:
db - the DataBasket that is protecting this activity.
nAction - the action that occurred. Can be either StockItemImpl.COMMIT_ACTION, StockItemImpl.ROLLBACK_ACTION, StockItemImpl.STARTEDIT_ACTION.

commitRemove

public void commitRemove(DataBasket db,
                         DataBasketEntry<T> dbe)
Commit the removal of a StockItem.

A commitRemoveStockItems will be fired.

Specified by:
commitRemove in interface SelfManagingDBESource<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the rollback request
dbe - the DataBasketEntry describing the operation to rollback.

rollbackRemove

public void rollbackRemove(DataBasket db,
                           DataBasketEntry<T> dbe)
Rollback the removal of a StockItem.

A rollbackRemoveStockItems will be fired. Also, the Stock will try to make sure, that a corresponding CatalogItem exists.

Specified by:
rollbackRemove in interface SelfManagingDBESource<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the commit request
dbe - the DataBasketEntry describing the operation to commit.

commitAdd

public void commitAdd(DataBasket db,
                      DataBasketEntry<T> dbe)
Commit the adding of a StockItem.

A commitAddStockItems will be fired. A commitEditStockItems event may be fired as a consequence of this method. Also, the Stock will try to make sure, that a corresponding CatalogItem exists.

Specified by:
commitAdd in interface SelfManagingDBEDestination<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the commit request
dbe - the DataBasketEntry describing the operation to commit.

rollbackAdd

public void rollbackAdd(DataBasket db,
                        DataBasketEntry<T> dbe)
Rollback the adding of a StockItem.

A commitAddStockItems will be fired. A commitEditStockItems event may be fired as a consequence of this method.

Specified by:
rollbackAdd in interface SelfManagingDBEDestination<T extends StockItemImpl>
Parameters:
db - the DataBasket that issued the rollback request
dbe - the DataBasketEntry describing the operation to rollback.