SalesPoint Framework v3.0

data.ooimpl
Class CatalogImpl

java.lang.Object
  |
  +--data.AbstractNameable
        |
        +--data.ooimpl.CatalogItemImpl
              |
              +--data.ooimpl.CatalogImpl
Direct Known Subclasses:
CurrencyImpl

public class CatalogImpl
extends CatalogItemImpl
implements Catalog, ListenableCatalog, NameContext, SelfManagingDBESource, SelfManagingDBEDestination

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
See Also:
Serialized Form

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 data.AbstractNameable
m_ncContext, m_pcsPropertyListeners
 
Constructor Summary
CatalogImpl(String sName)
          Create a new, initially empty CatalogImpl.
 
Method Summary
 void add(CatalogItem 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, String sOldName, String sNewName)
          Check a name change of a CatalogItem in this Catalog.
 void commitAdd(DataBasket db, DataBasketEntry dbe)
          Commit the adding of a CatalogItem.
 void commitRemove(DataBasket db, DataBasketEntry dbe)
          Commit the removal of a CatalogItem.
 boolean contains(String sKey, DataBasket db)
          Check whether the Catalog contains a certain CatalogItem.
protected  CatalogImpl createPeer()
          Create and return an empty CatalogImpl of the same name and class.
protected  void fireCanEditCatalogItem(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCanRemoveCatalogItem(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemAddCommit(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemAdded(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemAddRollback(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemRemoveCommit(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemRemoved(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCatalogItemRemoveRollback(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireCommitEditCatalogItem(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireEditingCatalogItem(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
protected  void fireRollbackEditCatalogItem(CatalogItem ci, DataBasket db)
          Fire an event to all listeners listening to this Catalog.
 CatalogItem get(String sKey, DataBasket db, boolean fForEdit)
          Get the indicated item from the Catalog.
protected  Map getEditingItemsContainer()
          Get the map of items that are currently being edited.
protected  Map getItemsContainer()
          Get the map of items that are completely contained in this Catalog.
protected  Object getItemsLock()
          Get the monitor synchronizing access to the several items maps.
 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  Map getTemporaryAddedItemsContainer()
          Get the map of items that have been temporaryly added to this Catalog.
protected  Map getTemporaryRemovedItemsContainer()
          Get the map of items that have been temporaryly removed from this Catalog.
 Iterator iterator(DataBasket db, boolean fForEdit)
          Return an iterator of all items in the Catalog.
 Set keySet(DataBasket db)
          Get a set of all keys currently in the Catalog.
 void nameHasChanged(DataBasket db, String sOldName, String sNewName)
          Synchronize the Catalog's internal data with the name change.
 CatalogItem remove(CatalogItem ci, DataBasket db)
          Remove the given item from the Catalog.
 CatalogItem remove(String sKey, DataBasket db)
          Remove the indicated 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 dbe)
          Roll back the adding of a CatalogItem.
 void rollbackRemove(DataBasket db, DataBasketEntry dbe)
          Roll back the removal of a CatalogItem.
 int size(DataBasket db)
          Calculate the size of the Catalog.
 String toString()
          Return a String representation of this Catalog.
 
Methods inherited from class data.ooimpl.CatalogItemImpl
addValueListener, compareTo, equals, getCatalog, getValue, isEditable, removeValueListener, setValue
 
Methods inherited from class 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
 

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(String sName)
Create a new, initially empty CatalogImpl.
Parameters:
sName - the name of the Catalog.
Method Detail

getItemsLock

protected final Object getItemsLock()
Get the monitor synchronizing access to the several items maps.
Override:
Never.

getItemsContainer

protected Map getItemsContainer()
Get the map of items that are completely contained in this Catalog.
Override:
Never.

getTemporaryRemovedItemsContainer

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

getTemporaryAddedItemsContainer

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

getEditingItemsContainer

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

add

public void add(CatalogItem ci,
                DataBasket db)
Add the given item to the Catalog.
Override:
Never.
Specified by:
add in interface Catalog
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 CatalogItem remove(CatalogItem ci,
                          DataBasket db)
                   throws VetoException
Remove the given item from the Catalog.
Override:
Never.
Specified by:
remove in interface Catalog
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.
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 CatalogItem remove(String sKey,
                          DataBasket db)
                   throws VetoException
Remove the indicated item from the Catalog.
Override:
Never.
Specified by:
remove in interface Catalog
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.
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 CatalogItem get(String sKey,
                       DataBasket db,
                       boolean fForEdit)
                throws VetoException
Get the indicated item from the Catalog.
Override:
Never.
Specified by:
get in interface Catalog
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. In this case, a number of events is fired:
  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.
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.

contains

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

Override:
Never.
Specified by:
contains in interface Catalog
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 Iterator iterator(DataBasket db,
                         boolean fForEdit)
Return an iterator of all items in the Catalog.

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

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

keySet

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

Override:
Never.
Specified by:
keySet in interface Catalog
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.
Override:
Never.
Specified by:
size in interface Catalog
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.
Override:
Never.
Instead override createPeer().
Overrides:
getShallowClone in class CatalogItemImpl

createPeer

protected CatalogImpl createPeer()
Create and return an empty CatalogImpl of the same name and class.
Override:
Always.

toString

public String toString()
Return a String representation of this Catalog.
Override:
Sometimes.
Overrides:
toString in class CatalogItemImpl

commitRemove

public void commitRemove(DataBasket db,
                         DataBasketEntry dbe)
Commit the removal of a CatalogItem.
Specified by:
commitRemove in interface SelfManagingDBESource

rollbackRemove

public void rollbackRemove(DataBasket db,
                           DataBasketEntry dbe)
Roll back the removal of a CatalogItem.
Specified by:
rollbackRemove in interface SelfManagingDBESource

commitAdd

public void commitAdd(DataBasket db,
                      DataBasketEntry 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

rollbackAdd

public void rollbackAdd(DataBasket db,
                        DataBasketEntry 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

checkNameChange

public void checkNameChange(DataBasket db,
                            String sOldName,
                            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.

Override:
Sometimes.
Override to enforce stricter naming conventions.
Specified by:
checkNameChange in interface NameContext

nameHasChanged

public void nameHasChanged(DataBasket db,
                           String sOldName,
                           String sNewName)
Synchronize the Catalog's internal data with the name change.
Override:
Never.
Specified by:
nameHasChanged in interface NameContext

getNCMonitor

public final Object getNCMonitor()
Return the monitor used to synchronize access to the Catalog's internal data.
Override:
Never.
Specified by:
getNCMonitor in interface NameContext

addCatalogChangeListener

public void addCatalogChangeListener(CatalogChangeListener ccl)
Add a listener that listens for changes in this Catalog's contents.
Override:
Never.
Specified by:
addCatalogChangeListener in interface ListenableCatalog
Parameters:
ccl - the listener

removeCatalogChangeListener

public void removeCatalogChangeListener(CatalogChangeListener ccl)
Remove a listener that listened for changes in this Catalog's contents.
Override:
Never.
Specified by:
removeCatalogChangeListener in interface ListenableCatalog
Parameters:
ccl - the listener

fireCatalogItemAdded

protected void fireCatalogItemAdded(CatalogItem ci,
                                    DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireCatalogItemAddCommit

protected void fireCatalogItemAddCommit(CatalogItem ci,
                                        DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireCatalogItemAddRollback

protected void fireCatalogItemAddRollback(CatalogItem ci,
                                          DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireCatalogItemRemoved

protected void fireCatalogItemRemoved(CatalogItem ci,
                                      DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireCatalogItemRemoveCommit

protected void fireCatalogItemRemoveCommit(CatalogItem ci,
                                           DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireCatalogItemRemoveRollback

protected void fireCatalogItemRemoveRollback(CatalogItem ci,
                                             DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireCanRemoveCatalogItem

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

fireCanEditCatalogItem

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

fireEditingCatalogItem

protected void fireEditingCatalogItem(CatalogItem ci,
                                      DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireCommitEditCatalogItem

protected void fireCommitEditCatalogItem(CatalogItem ci,
                                         DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

fireRollbackEditCatalogItem

protected void fireRollbackEditCatalogItem(CatalogItem ci,
                                           DataBasket db)
Fire an event to all listeners listening to this Catalog.
Override:
Never.

SalesPoint Framework v3.0