org.bsf.smartValueObject
Class SmartAccess

java.lang.Object
  |
  +--org.bsf.smartValueObject.SmartAccess

public class SmartAccess
extends java.lang.Object

Class to encapsulate implementation details and scary casts for SmartContainer and Versionable objects. It also allows to obtain iterators for various version states, as well as methods for graph traversals.

See Also:
SmartContainer, Versionable

Nested Class Summary
private static class SmartAccess.DirtyVisitor
          A visitor which searches the graph for dirty objects.
private static class SmartAccess.ResetVisitor
          A visitor which resets all versionable objects.
private static interface SmartAccess.SmartVisitor
          Interface for visiting graphs.
 
Constructor Summary
SmartAccess()
           
 
Method Summary
private static void checkSmartContainer(java.lang.Object o)
          Check if object is smartcontainer, else throw IllegalArgumentException
private static void checkVersionable(java.lang.Object o)
          Check if object is versionable, else throw IllegalArgumentException
static java.util.Iterator createdIterator(java.lang.Object o)
          Gets an iterator for newly created objects.
static int createdSize(java.lang.Object o)
           
static java.util.Iterator deletedIterator(java.lang.Object o)
          Gets an iterator for deleted objects.
static int deletedSize(java.lang.Object o)
           
static java.util.Iterator getSmartContainers(java.lang.Object o)
          Gets all smartcontainers in object o.
static java.util.Iterator getVersionables(java.lang.Object o)
          Gets all versionable objects contained in o (itself a versionable).
static long getVersionId(java.lang.Object o)
          Gets version id from object.
static boolean isCreated(java.lang.Object o)
          Checks if object was created.
static boolean isDeleted(java.lang.Object o)
          Checks if object was deleted.
static boolean isDirty(java.lang.Object o)
          Checks if object is modified.
static boolean isGraphDirty(java.lang.Object o)
          Checks if objects in graph o have been modified.
static boolean isSmartContainer(java.lang.Object o)
          Checks if the object is a smart container.
static boolean isVersionable(java.lang.Object o)
          Checks if the object is versionable.
static java.util.Iterator iterator(java.lang.Object o)
          Gets an iterator for all versionable objects.
private static void log(java.lang.String s)
           
static java.util.Iterator modifiedIterator(java.lang.Object o)
          Gets an iterator for modified objects.
static void reset(java.lang.Object o)
          Resets objects version state.
static void resetGraph(java.lang.Object o)
          Resets all objects on the graph,including the root object.
static boolean sameVersion(java.lang.Object o1, java.lang.Object o2)
          Checks if object o1, o2 have the same version number.
static void setVersionId(java.lang.Object o, long id)
          Sets version id.
private static void traverseGraph(java.lang.Object o, SmartAccess.SmartVisitor visitor)
          Traverses the graph using a visitor.
private static void traverseSmartContainer(java.lang.Object o, SmartAccess.SmartVisitor visitor)
          Traverses the given smart container.
private static void traverseVersionable(java.lang.Object o, SmartAccess.SmartVisitor visitor)
          Traverses the given versionable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmartAccess

public SmartAccess()
Method Detail

createdIterator

public static java.util.Iterator createdIterator(java.lang.Object o)
Gets an iterator for newly created objects.

Parameters:
o - an object of type SmartContainer.
Returns:
the iterator.
Throws:
java.lang.IllegalArgumentException - when passing an object not implementing SmartContainer.

modifiedIterator

public static java.util.Iterator modifiedIterator(java.lang.Object o)
Gets an iterator for modified objects.

Parameters:
o - an object of type SmartContainer.
Returns:
the iterator.
Throws:
java.lang.IllegalArgumentException - when passing an object not implementing SmartContainer.

deletedIterator

public static java.util.Iterator deletedIterator(java.lang.Object o)
Gets an iterator for deleted objects.

Parameters:
o - an object of type SmartContainer.
Returns:
the iterator.
Throws:
java.lang.IllegalArgumentException - when passing an object not implementing SmartContainer.

iterator

public static java.util.Iterator iterator(java.lang.Object o)
Gets an iterator for all versionable objects.

Parameters:
o -
Returns:

createdSize

public static int createdSize(java.lang.Object o)

deletedSize

public static int deletedSize(java.lang.Object o)

getSmartContainers

public static java.util.Iterator getSmartContainers(java.lang.Object o)
Gets all smartcontainers in object o.

Parameters:
o - a versionable object.
Returns:
iterator with all smartcontainers.
See Also:
SmartContainer

getVersionables

public static java.util.Iterator getVersionables(java.lang.Object o)
Gets all versionable objects contained in o (itself a versionable).

Parameters:
o -
Returns:

isSmartContainer

public static boolean isSmartContainer(java.lang.Object o)
Checks if the object is a smart container.

Parameters:
o -
Returns:

isVersionable

public static boolean isVersionable(java.lang.Object o)
Checks if the object is versionable.


isDirty

public static boolean isDirty(java.lang.Object o)
Checks if object is modified.

Parameters:
o - versionable object.
Returns:
Throws:
java.lang.IllegalArgumentException - if object is not versionable.

isGraphDirty

public static boolean isGraphDirty(java.lang.Object o)
Checks if objects in graph o have been modified.

Parameters:
o - versionable object with versionable child objects.
Returns:

traverseGraph

private static void traverseGraph(java.lang.Object o,
                                  SmartAccess.SmartVisitor visitor)
Traverses the graph using a visitor.

Parameters:
o -
visitor -

traverseSmartContainer

private static void traverseSmartContainer(java.lang.Object o,
                                           SmartAccess.SmartVisitor visitor)
Traverses the given smart container.

Parameters:
o -
visitor -

traverseVersionable

private static void traverseVersionable(java.lang.Object o,
                                        SmartAccess.SmartVisitor visitor)
Traverses the given versionable object.

Parameters:
o -
visitor -

isCreated

public static boolean isCreated(java.lang.Object o)
Checks if object was created.

Parameters:
o - versionable object.
Returns:
Throws:
java.lang.IllegalArgumentException - if object is not versionable.

isDeleted

public static boolean isDeleted(java.lang.Object o)
Checks if object was deleted.

Parameters:
o - versionable object.
Returns:
Throws:
java.lang.IllegalArgumentException - if object is not versionable.

reset

public static void reset(java.lang.Object o)
Resets objects version state.

Parameters:
o - versionable object.
Throws:
java.lang.IllegalArgumentException - if object is not versionable.

resetGraph

public static void resetGraph(java.lang.Object o)
Resets all objects on the graph,including the root object.

Parameters:
o -

sameVersion

public static boolean sameVersion(java.lang.Object o1,
                                  java.lang.Object o2)
Checks if object o1, o2 have the same version number.

Parameters:
o1 - versionable object.
o2 - versionable object.
Returns:

getVersionId

public static long getVersionId(java.lang.Object o)
Gets version id from object.

Parameters:
o -
Returns:

setVersionId

public static void setVersionId(java.lang.Object o,
                                long id)
Sets version id.

Parameters:
o -
id -

log

private static void log(java.lang.String s)

checkVersionable

private static void checkVersionable(java.lang.Object o)
Check if object is versionable, else throw IllegalArgumentException

Parameters:
o -

checkSmartContainer

private static void checkSmartContainer(java.lang.Object o)
Check if object is smartcontainer, else throw IllegalArgumentException

Parameters:
o -