org.salespointframework.core.data
Class CatalogImpl<T extends CatalogItemImpl>

java.lang.Object
  extended by org.salespointframework.core.data.AbstractNameable
      extended by org.salespointframework.core.data.CatalogItemImpl
          extended by org.salespointframework.core.data.CatalogImpl<T>
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<java.lang.Object>, Recoverable, DatasourceChangeListener, ExternalModificationListener, Catalog<T>, CatalogItem, DataBasketEntryDestination, DataBasketEntrySource, DataBasketKeys, ListenableCatalog<T>, Nameable, NameContext, SpAggregate, SpItem, SelfManagingDBEDestination<T>, SelfManagingDBESource<T>
Direct Known Subclasses:
AbstractCurrency, CurrencyImpl

public class CatalogImpl<T extends CatalogItemImpl>
extends CatalogItemImpl
implements ListenableCatalog<T>, NameContext, SelfManagingDBESource<T>, SelfManagingDBEDestination<T>

Pure Java implementation of the Catalog interface.

CatalogImpl can only work together with DataBaskets that are descendants of DataBasketImpl.

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

Field Summary
protected  ListenerHelper m_lhListeners
          The listeners that registered to be informed of changes in this Catalog's contents.
protected  int m_nModCount
          Modification counter.
 
Fields inherited from class org.salespointframework.core.data.AbstractNameable
m_ncContext, m_pcsPropertyListeners, SOME_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.CatalogItem
VALUE_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
CatalogImpl(CatalogIdentifier<T> id)
          Create a new, persistent CatalogImpl.
CatalogImpl(java.lang.String sName)
          Create a new, persistent CatalogImpl.
CatalogImpl(java.lang.String sName, boolean temporary)
          Create a new, CatalogImpl.
 
Method Summary
 void add(T ci, DataBasket db)
          Add the given item to the Catalog.
 void addCatalogChangeListener(CatalogChangeListener ccl)
          Add a listener that listens for changes in this Catalog's contents.
 void checkNameChange(DataBasket db, java.lang.String sOldName, java.lang.String sNewName)
          Check a name change of a CatalogItem in this Catalog.
 void commitAdd(DataBasket db, DataBasketEntry<T> dbe)
          Commit the adding of a CatalogItem.
 void commitRemove(DataBasket db, DataBasketEntry<T> dbe)
          Commit the removal of a CatalogItem.
 boolean contains(java.lang.String sKey, DataBasket db)
          Check whether the Catalog contains a certain CatalogItem.
 CatalogImpl<T> createPeer()
          Create and return an empty CatalogImpl of the same name and class.
 void DatasourceChanged(boolean pumpUp)
          pumps up the change of datasource to catalog listeners
 void externalModificationOccurred()
          simulates a datasource change to handle external modifications
protected  void fireCanEditCatalogItem(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCanRemoveCatalogItem(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemAddCommit(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemAdded(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemAddRollback(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
 void fireCatalogItemDataChanged(java.beans.PropertyChangeEvent pce)
          called by CatalogItem to indicate a change in its data
protected  void fireCatalogItemRemoveCommit(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemRemoved(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemRemoveRollback(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCommitEditCatalogItem(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireEditingCatalogItem(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireRollbackEditCatalogItem(T ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
 T get(java.lang.String sKey, DataBasket db, boolean fForEdit)
          Get the indicated item from the Catalog.
 CatalogImpl getEditableCopy(DataBasket db)
          Convenience method, which gets an editable ShallowClone of this Catalog from its parent Catalog and returns it.
protected  java.util.Map<java.lang.String,T> getEditingItemsContainer()
          Get the map of items that are currently being edited.
protected  java.util.Map<java.lang.String,T> getItemsContainer()
          Get the map of items that are completely contained in this Catalog.
protected  java.lang.Object getItemsLock()
          Get the monitor synchronizing access to the several items maps.
 java.lang.Object getNCMonitor()
          Return the monitor used to synchronize access to the Catalog's internal data.
protected  CatalogItemImpl getShallowClone()
          Create a shallow clone of this Catalog.
protected  java.util.Map<java.lang.String,T> getTemporaryAddedItemsContainer()
          Get the map of items that have been temporarily added to this Catalog.
protected  java.util.Map<java.lang.String,T> getTemporaryRemovedItemsContainer()
          Get the map of items that have been temporarily removed from this Catalog.
 boolean isPersistent()
          returns true, if this catalog is a persistent one.
 java.util.Iterator<T> iterator(DataBasket db, boolean fForEdit)
          Return an iterator of all items in the Catalog.
 java.util.Set<java.lang.String> keySet(DataBasket db)
          Get a set of all keys currently in the Catalog.
 void nameHasChanged(DataBasket db, java.lang.String sOldName, java.lang.String sNewName)
          Synchronize the Catalog's internal data with the name change.
 T remove(java.lang.String sKey, DataBasket db)
          Remove the indicated item from the Catalog.
 T remove(T ci, DataBasket db)
          Remove the given item from the Catalog.
 void removeCatalogChangeListener(CatalogChangeListener ccl)
          Remove a listener that listened for changes in this Catalog's contents.
 void rollbackAdd(DataBasket db, DataBasketEntry<T> dbe)
          Roll back the adding of a CatalogItem.
 void rollbackRemove(DataBasket db, DataBasketEntry<T> dbe)
          Roll back the removal of a CatalogItem.
 int size(DataBasket db)
          Calculate the size of the Catalog.
 java.lang.String toString()
          Return a String representation of this Catalog.
 
Methods inherited from class org.salespointframework.core.data.CatalogItemImpl
addValueListener, compareTo, equals, firePropertyChanged, getCatalog, getImage, getImageBytes, getInternalShallowClone, getValue, isEditable, recover, removeValueListener, setImage, setImageBytes, setValue
 
Methods inherited from class org.salespointframework.core.data.AbstractNameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.salespointframework.core.data.interfaces.CatalogItem
addValueListener, firePropertyChanged, getCatalog, getImage, getValue, removeValueListener, setImage
 
Methods inherited from interface org.salespointframework.core.data.interfaces.Nameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.salespointframework.core.data.interfaces.SpItem
getName
 

Field Detail

m_lhListeners

protected ListenerHelper m_lhListeners
The listeners that registered to be informed of changes in this Catalog's contents.


m_nModCount

protected int m_nModCount
Modification counter. Will be increased by one for each structural modification.

Constructor Detail

CatalogImpl

public CatalogImpl(java.lang.String sName)
Create a new, persistent CatalogImpl.

Parameters:
sName - the name of the Catalog.

CatalogImpl

public CatalogImpl(java.lang.String sName,
                   boolean temporary)
Create a new, CatalogImpl.

Parameters:
sName - the name of the Catalog.
temporary - true, if catalog should not be persistent

CatalogImpl

public CatalogImpl(CatalogIdentifier<T> id)
Create a new, persistent CatalogImpl.

Parameters:
id - The identifier of the Catalog.
Method Detail

getItemsLock

protected final java.lang.Object getItemsLock()
Get the monitor synchronizing access to the several items maps.


getItemsContainer

protected java.util.Map<java.lang.String,T> getItemsContainer()
Get the map of items that are completely contained in this Catalog.


getTemporaryRemovedItemsContainer

protected java.util.Map<java.lang.String,T> getTemporaryRemovedItemsContainer()
Get the map of items that have been temporarily removed from this Catalog.


getTemporaryAddedItemsContainer

protected java.util.Map<java.lang.String,T> getTemporaryAddedItemsContainer()
Get the map of items that have been temporarily added to this Catalog.


getEditingItemsContainer

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


isPersistent

public boolean isPersistent()
returns true, if this catalog is a persistent one. This means: all final changes are written to the underlying data source.

Returns:
true, if catalog is persistent

add

public void add(T ci,
                DataBasket db)
Add the given item to the Catalog.

Specified by:
add in interface Catalog<T extends CatalogItemImpl>
Parameters:
ci - the CatalogItem to be added.
db - the DataBasket relative to which to perform the operation. Must be null or a descendant of DataBasketImpl.
Throws:
NotEditableException - if the Catalog is currently not editable.
DuplicateKeyException - if a CatalogItem of the same name does already exist in the Catalog.
DataBasketConflictException - if the CatalogItem cannot be added because an item of the same name has already been added/removed using another DataBasket.

remove

public T remove(T ci,
                DataBasket db)
                                 throws VetoException
Remove the given item from the Catalog.

Specified by:
remove in interface Catalog<T extends CatalogItemImpl>
Parameters:
ci - the CatalogItem to be removed.
db - the DataBasket relative to which to perform the operation. Must be null or a descendant of DataBasketImpl.
Returns:
the item that was actually removed.
Throws:
NotEditableException - if the Catalog is currently not editable.
VetoException - if one of the listeners vetos the removal.
DataBasketConflictException - if the CatalogItem cannot be removed because an item of the same name has already been added using another DataBasket.

remove

public T remove(java.lang.String sKey,
                DataBasket db)
                                 throws VetoException
Remove the indicated item from the Catalog.

Specified by:
remove in interface Catalog<T extends CatalogItemImpl>
Parameters:
sKey - the key of the CatalogItem to be removed.
db - the DataBasket relative to which to perform the operation. Must be null or a descendant of DataBasketImpl.
Returns:
the item that was actually removed.
Throws:
NotEditableException - if the Catalog is currently not editable.
VetoException - if one of the listeners vetos the removal.
DataBasketConflictException - if the CatalogItem cannot be removed because an item of the same name has already been added using another DataBasket.

get

public T get(java.lang.String sKey,
             DataBasket db,
             boolean fForEdit)
                              throws VetoException
Get the indicated item from the Catalog.

Specified by:
get in interface Catalog<T extends CatalogItemImpl>
Parameters:
sKey - the key for which to retrieve the item.
db - the DataBasket relative to which to perform the operation. Must be null or a descendant of DataBasketImpl.
fForEdit - if true, the item will be retrieved for editing. Only in this case changes made to the CatalogItem can be undone via a rollback of the DataBasket. Therefore the DataBasket must not be null if a CatalogItem is desired to be editable! A number of events is fired if fForEdit is true:
  1. canEditCatalogItem with the original item.
  2. a shallow clone of the item is created.
  3. editingCatalogItem with the newly created clone.
  4. addCatalogItem with the newly created clone and removeCatalogItem with the original item.
  5. The newly created clone is returned for editing.
Returns:
the item that is associated with the given key.
Throws:
NotEditableException - if the Catalog is not currently editable, but an attempt is made to edit one of its items.
VetoException - if one of the listeners vetos the editing.
DataBasketConflictException - if the CatalogItem cannot be retrieved because it is not visible to users of the given DataBasket.

getEditableCopy

public CatalogImpl getEditableCopy(DataBasket db)
                            throws VetoException
Convenience method, which gets an editable ShallowClone of this Catalog from its parent Catalog and returns it. If the Catalog is already editable or there is no parent Catalog, no copy will be created and the original Catalog is returned.

Parameters:
db - the DataBasket which is passed to get method. Must not be null!
Returns:
this Catalog, if editable, otherwise a clone of this Catalog.
Throws:
VetoException

contains

public boolean contains(java.lang.String sKey,
                        DataBasket db)
Check whether the Catalog contains a certain CatalogItem.

Will return true only if an item of the given key is contained in the Catalog and if that item is visible to users of the given DataBasket.

Specified by:
contains in interface Catalog<T extends CatalogItemImpl>
Parameters:
sKey - the key for which to check containment.
db - the DataBasket that defines visibility of items. Must be null or a descendant of DataBasketImpl.

iterator

public java.util.Iterator<T> iterator(DataBasket db,
                                      boolean fForEdit)
Return an iterator of all items in the Catalog.

The iterator will conceptually call get(java.lang.String, org.salespointframework.core.data.interfaces.DataBasket, boolean) for each CatalogItem, using the given parameters.

Specified by:
iterator in interface Catalog<T extends CatalogItemImpl>
Parameters:
db - the DataBasket that defines visibility.
fForEdit - if true, the items are retrieved for editing. VetoException will be converted into UnsupportedOperationExceptions.

keySet

public java.util.Set<java.lang.String> keySet(DataBasket db)
Get a set of all keys currently in the Catalog.

This will retrieve a static set that gives the state of the Catalog at the time of the call.

Specified by:
keySet in interface Catalog<T extends CatalogItemImpl>
Parameters:
db - the DataBasket used to determine visibility of elements. Must be null or a descendant of DataBasketImpl.

size

public int size(DataBasket db)
Calculate the size of the Catalog. I.e. count the CatalogItems that are visible to users of the given DataBasket.

Specified by:
size in interface Catalog<T extends CatalogItemImpl>
Parameters:
db - the DataBasket used to determine visibility. Must be null or a descendant of DataBasketImpl.

getShallowClone

protected CatalogItemImpl getShallowClone()
Create a shallow clone of this Catalog. A shallow clone means that the individual items themselves will not be cloned.

Specified by:
getShallowClone in class CatalogItemImpl

createPeer

public CatalogImpl<T> createPeer()
Create and return an empty CatalogImpl of the same name and class.


toString

public java.lang.String toString()
Return a String representation of this Catalog.

Overrides:
toString in class CatalogItemImpl

commitRemove

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

Specified by:
commitRemove in interface SelfManagingDBESource<T extends CatalogItemImpl>
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)
Roll back the removal of a CatalogItem.

Specified by:
rollbackRemove in interface SelfManagingDBESource<T extends CatalogItemImpl>
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 CatalogItem. In addition to the addedCatalogItemCommit event this may trigger an editingCatalogItemCommit event with the CatalogItem that has been edited.

Specified by:
commitAdd in interface SelfManagingDBEDestination<T extends CatalogItemImpl>
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)
Roll back the adding of a CatalogItem. In addition to the addedCatalogItemRollback event this may trigger an editingCatalogItemRollback event with the CatalogItem that has been edited.

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

checkNameChange

public void checkNameChange(DataBasket db,
                            java.lang.String sOldName,
                            java.lang.String sNewName)
                     throws NameContextException
Check a name change of a CatalogItem in this Catalog.

The name change will be allowed if the item is editable and the new name can be guaranteed to be unique.

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.

nameHasChanged

public void nameHasChanged(DataBasket db,
                           java.lang.String sOldName,
                           java.lang.String sNewName)
Synchronize the Catalog's internal data with the name change.

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.

getNCMonitor

public final java.lang.Object getNCMonitor()
Return the monitor used to synchronize access to the Catalog's internal data.

Specified by:
getNCMonitor in interface NameContext

addCatalogChangeListener

public void addCatalogChangeListener(CatalogChangeListener ccl)
Add a listener that listens for changes in this Catalog's contents.

Specified by:
addCatalogChangeListener in interface ListenableCatalog<T extends CatalogItemImpl>
Parameters:
ccl - the listener

removeCatalogChangeListener

public void removeCatalogChangeListener(CatalogChangeListener ccl)
Remove a listener that listened for changes in this Catalog's contents.

Specified by:
removeCatalogChangeListener in interface ListenableCatalog<T extends CatalogItemImpl>
Parameters:
ccl - the listener

fireCatalogItemAdded

protected void fireCatalogItemAdded(T ci,
                                    DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCatalogItemAddCommit

protected void fireCatalogItemAddCommit(T ci,
                                        DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCatalogItemAddRollback

protected void fireCatalogItemAddRollback(T ci,
                                          DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCatalogItemRemoved

protected void fireCatalogItemRemoved(T ci,
                                      DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCatalogItemRemoveCommit

protected void fireCatalogItemRemoveCommit(T ci,
                                           DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCatalogItemRemoveRollback

protected void fireCatalogItemRemoveRollback(T ci,
                                             DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCanRemoveCatalogItem

protected void fireCanRemoveCatalogItem(T ci,
                                        DataBasket db)
                                 throws VetoException
Fire an event to all listeners listening to this Catalog.

Throws:
VetoException

fireCanEditCatalogItem

protected void fireCanEditCatalogItem(T ci,
                                      DataBasket db)
                               throws VetoException
Fire an event to all listeners listening to this Catalog.

Throws:
VetoException

fireEditingCatalogItem

protected void fireEditingCatalogItem(T ci,
                                      DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCommitEditCatalogItem

protected void fireCommitEditCatalogItem(T ci,
                                         DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireRollbackEditCatalogItem

protected void fireRollbackEditCatalogItem(T ci,
                                           DataBasket db)
Fire an event to all listeners listening to this Catalog.


fireCatalogItemDataChanged

public void fireCatalogItemDataChanged(java.beans.PropertyChangeEvent pce)
called by CatalogItem to indicate a change in its data

Parameters:
pce - change event

DatasourceChanged

public void DatasourceChanged(boolean pumpUp)
pumps up the change of datasource to catalog listeners

Specified by:
DatasourceChanged in interface DatasourceChangeListener
Parameters:
pumpUp - true if the event should be pumped up to hosts, because this event is mostly triggered twice. first time to invalidate caches. second time for load new data

externalModificationOccurred

public void externalModificationOccurred()
simulates a datasource change to handle external modifications

Specified by:
externalModificationOccurred in interface ExternalModificationListener