org.bsf.smartValueObject.container
Class AbstractSmartContainer

java.lang.Object
  |
  +--org.bsf.smartValueObject.container.AbstractSmartContainer
All Implemented Interfaces:
java.io.Serializable, SmartContainer, Versionable
Direct Known Subclasses:
SmartCollection, SmartList, SmartMap, SmartSet

public abstract class AbstractSmartContainer
extends java.lang.Object
implements SmartContainer, Versionable

Skeleton implementation of a versionable container. All other container should extend this to avoid code duplication.

See Also:
SmartContainer, Serialized Form

Field Summary
private  int created
          Number of created objects.
private  int deleted
          Number of deleted objects.
private  org.bsf.smartValueObject.Versionable version
          The version instance for this container.
 
Constructor Summary
AbstractSmartContainer(org.bsf.smartValueObject.Versionable v)
          Initialize the container with a version.
 
Method Summary
 boolean add(java.lang.Object o)
          Implementation for Collection interface.
protected  boolean addObject(java.lang.Object o)
          Adds object w/ versioning.
protected  java.lang.Object addObject(java.lang.Object key, java.lang.Object o)
          Add object via key, w/ versioning.
protected abstract  boolean addToContainer(java.lang.Object o)
          Add object to container.
protected abstract  java.lang.Object addToContainer(java.lang.Object key, java.lang.Object o)
          Adds object to container with key.
 void clear()
          Implementation for Collection/Map/... interface.
protected abstract  void containerClear()
          Deletes all elements from the container.
protected abstract  boolean containerContains(java.lang.Object o)
          Verifies if the container has the specified object.
protected abstract  boolean containerContainsKey(java.lang.Object key)
          Verifies if the container has the specified key.
protected abstract  java.util.Iterator containerIterator()
          Gets the standard iterator for this container.
protected abstract  int containerSize()
          The 'raw' size of the container.
 boolean contains(java.lang.Object o)
          Implementation for Collection interface.
 boolean containsKey(java.lang.Object key)
          Implementation for Map interface.
protected  boolean containsObject(java.lang.Object o)
          Checks if container has specified object, respects versioning.
 boolean containsValue(java.lang.Object o)
          Implementation for Map interface.
 void create()
          Mark object as created.
 void delete()
          Mark object for deletion.
 java.lang.Object get(java.lang.Object key)
          Implementation for Map interface.
abstract  java.lang.Object getContainer()
          Gets the backing container containing all elements.
 int getCreated()
          Number of elements which have been created.
 int getDeleted()
          Number of elements which have been deleted.
protected abstract  java.lang.Object getFromContainer(java.lang.Object key)
          Gets object from container.
 java.util.Iterator getIterator()
          Gets the backing iterator for all elements.
 long getVersionId()
          Gets the version number.
 boolean isCreated()
          Has object been newly created ?
 boolean isDeleted()
          Has object been deleted ?
 boolean isDirty()
          Is object dirty ?
 boolean isEmpty()
          Implementaion for Collection/Map/... interface.
 java.util.Iterator iterator()
          Implementation for Collection interface.
 void markClean()
          Resets flags.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Implementation for Map interface.
protected abstract  boolean removeFromContainer(java.lang.Object o)
          Removes object from container.
protected abstract  java.lang.Object removeKeyFromContainer(java.lang.Object key)
          Removes key from container.
protected  boolean removeObject(java.lang.Object o)
          Removes object while respecting versioning.
protected  java.lang.Object removeObjectByKey(java.lang.Object key)
          Removes object by key, w/ versioning.
 void setVersionId(long id)
          Sets the version number
 int size()
          Number of elements (not counting deleted ones).
 java.lang.Object[] toArray()
          Implementation for Collection/... interface.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Implementation for Collection/... interface.
protected abstract  java.lang.Object[] toObjectArray()
          Retrieves objects as an array.
 void touch()
          Touches the object.
 void touch(java.lang.String s)
          Touches the object, detailling which field has been accessed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

private org.bsf.smartValueObject.Versionable version
The version instance for this container.


created

private int created
Number of created objects.


deleted

private int deleted
Number of deleted objects.

Constructor Detail

AbstractSmartContainer

public AbstractSmartContainer(org.bsf.smartValueObject.Versionable v)
Initialize the container with a version.

Parameters:
v - the version object to use.
Method Detail

addToContainer

protected abstract boolean addToContainer(java.lang.Object o)
Add object to container.

Parameters:
o - the object to be added.
Returns:

addToContainer

protected abstract java.lang.Object addToContainer(java.lang.Object key,
                                                   java.lang.Object o)
Adds object to container with key.

Parameters:
key - the key to use.
o - the object to be added.
Returns:
Throws:
java.lang.UnsupportedOperationException - if the method is not supported.

getFromContainer

protected abstract java.lang.Object getFromContainer(java.lang.Object key)
Gets object from container.

Parameters:
key - the key of the object.
Returns:
Throws:
java.lang.UnsupportedOperationException - if the method is not supported.

removeFromContainer

protected abstract boolean removeFromContainer(java.lang.Object o)
Removes object from container.

Parameters:
o - the object to be removed.
Returns:

removeKeyFromContainer

protected abstract java.lang.Object removeKeyFromContainer(java.lang.Object key)
Removes key from container.

Parameters:
key - the key to be removed.
Returns:
Throws:
java.lang.UnsupportedOperationException - if the method is not supported.

containerContains

protected abstract boolean containerContains(java.lang.Object o)
Verifies if the container has the specified object.

Parameters:
o -
Returns:

containerContainsKey

protected abstract boolean containerContainsKey(java.lang.Object key)
Verifies if the container has the specified key.

Parameters:
key -
Returns:

containerSize

protected abstract int containerSize()
The 'raw' size of the container.

Returns:
size of the container.

containerIterator

protected abstract java.util.Iterator containerIterator()
Gets the standard iterator for this container.

Returns:
iterator.

containerClear

protected abstract void containerClear()
Deletes all elements from the container.


toObjectArray

protected abstract java.lang.Object[] toObjectArray()
Retrieves objects as an array.

Returns:
Throws:
java.lang.UnsupportedOperationException - if the method is not supported.

removeObject

protected boolean removeObject(java.lang.Object o)
Removes object while respecting versioning.

Parameters:
o - the object to be removed.
Returns:

removeObjectByKey

protected java.lang.Object removeObjectByKey(java.lang.Object key)
Removes object by key, w/ versioning.

Parameters:
key -
Returns:

addObject

protected boolean addObject(java.lang.Object o)
Adds object w/ versioning.

Parameters:
o -
Returns:

addObject

protected java.lang.Object addObject(java.lang.Object key,
                                     java.lang.Object o)
Add object via key, w/ versioning.

Parameters:
key -
o -
Returns:

containsObject

protected boolean containsObject(java.lang.Object o)
Checks if container has specified object, respects versioning.

Parameters:
o -
Returns:

add

public boolean add(java.lang.Object o)
Implementation for Collection interface.

Parameters:
o -
Returns:
See Also:
Collection.add(java.lang.Object)

contains

public boolean contains(java.lang.Object o)
Implementation for Collection interface.

Parameters:
o -
Returns:
See Also:
Collection.contains(java.lang.Object)

containsValue

public boolean containsValue(java.lang.Object o)
Implementation for Map interface.

Parameters:
o -
Returns:
See Also:
Map.containsValue(java.lang.Object)

containsKey

public boolean containsKey(java.lang.Object key)
Implementation for Map interface.

Parameters:
key -
Returns:
See Also:
Map.containsValue(java.lang.Object)

iterator

public java.util.Iterator iterator()
Implementation for Collection interface.

Returns:
See Also:
Collection.iterator()

clear

public void clear()
Implementation for Collection/Map/... interface.

See Also:
Collection.clear(), Map.clear()

isEmpty

public boolean isEmpty()
Implementaion for Collection/Map/... interface.

Returns:
See Also:
Collection.isEmpty(), Map.isEmpty()

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Implementation for Map interface.

Parameters:
key -
value -
Returns:
See Also:
Map.put(java.lang.Object, java.lang.Object)

get

public java.lang.Object get(java.lang.Object key)
Implementation for Map interface.

Parameters:
key -
Returns:
See Also:
Map.get(java.lang.Object)

toArray

public java.lang.Object[] toArray()
Implementation for Collection/... interface.

Returns:
See Also:
Collection.toArray()

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Implementation for Collection/... interface.

Returns:
See Also:
Collection.toArray()

getCreated

public int getCreated()
Description copied from interface: SmartContainer
Number of elements which have been created.

Specified by:
getCreated in interface SmartContainer
Returns:
number of created elements.

getDeleted

public int getDeleted()
Description copied from interface: SmartContainer
Number of elements which have been deleted.

Specified by:
getDeleted in interface SmartContainer
Returns:
number of deleted elements.

getIterator

public java.util.Iterator getIterator()
Description copied from interface: SmartContainer
Gets the backing iterator for all elements.

Specified by:
getIterator in interface SmartContainer
Returns:
the underlying iterator.

size

public int size()
Description copied from interface: SmartContainer
Number of elements (not counting deleted ones).

Specified by:
size in interface SmartContainer
Returns:
number of existing elements.

getContainer

public abstract java.lang.Object getContainer()
Description copied from interface: SmartContainer
Gets the backing container containing all elements.

Specified by:
getContainer in interface SmartContainer
Returns:
the underlying container.

touch

public void touch()
Description copied from interface: Versionable
Touches the object. Signals that a field has been written to.

Specified by:
touch in interface Versionable

touch

public void touch(java.lang.String s)
Description copied from interface: Versionable
Touches the object, detailling which field has been accessed.

Specified by:
touch in interface Versionable
Parameters:
s - which was touched

isDirty

public boolean isDirty()
Description copied from interface: Versionable
Is object dirty ?

Specified by:
isDirty in interface Versionable

isCreated

public boolean isCreated()
Description copied from interface: Versionable
Has object been newly created ?

Specified by:
isCreated in interface Versionable

isDeleted

public boolean isDeleted()
Description copied from interface: Versionable
Has object been deleted ?

Specified by:
isDeleted in interface Versionable

markClean

public void markClean()
Description copied from interface: Versionable
Resets flags.

Specified by:
markClean in interface Versionable

getVersionId

public long getVersionId()
Description copied from interface: Versionable
Gets the version number.

Specified by:
getVersionId in interface Versionable

setVersionId

public void setVersionId(long id)
Description copied from interface: Versionable
Sets the version number

Specified by:
setVersionId in interface Versionable

delete

public void delete()
Description copied from interface: Versionable
Mark object for deletion.

Specified by:
delete in interface Versionable

create

public void create()
Description copied from interface: Versionable
Mark object as created.

Specified by:
create in interface Versionable