|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.domain.DomainObjectTraversal
This class provides a general purpose framework for iterating over a domain object's properties, processing attributes and traversing associations as required.
Subclasses should implement the startXXX and endXXX methods to provide whatever processing logic they require upon encountering attributes, roles, associations and objects.
The DomainObjectTraversalAdapter
provides a means to control which properties are processed and,
most importantly, which associations are traversed. When
registering an adapter, a 'use context' is supplied allowing
different adapters to be used according to the requirements of any
implementing subclass. It is recommended that the use context be
based on the fully qualified name of the class using
DomainObjectTraversal, e.g.,
com.arsdigita.cms.ui.DomainObjectRenderer.
The path argument provided to the adapter and the startXXX ad endXXX methods indicates which associations are currently being traversed. The first element in the path is always '/object'. If it then starts to traverse the 'rootCategory' association, the path will become '/object/rootCategory'. For self-recursive associations, rather than building up a long repeating string, the path will be shortened by adding a '+' for each element that is repeated. For example, '/object/container+' indicates that the container association has been followed two or more times.
Nested Class Summary | |
protected static class |
DomainObjectTraversal.AdapterKey
|
Field Summary | |
static String |
LINK_NAME
|
Constructor Summary | |
DomainObjectTraversal()
|
Method Summary | |
protected String |
appendToPath(String path,
String name)
|
protected abstract void |
beginAssociation(DomainObject obj,
String path,
Property property)
Method called when the processing of an association starts |
protected void |
beginLink(DomainObject obj,
String path)
Method called when the processing of a Link Object starts |
protected abstract void |
beginObject(DomainObject obj,
String path)
Method called when the processing of an object starts |
protected abstract void |
beginRole(DomainObject obj,
String path,
Property property)
Method called when the processing of a role starts |
protected abstract void |
endAssociation(DomainObject obj,
String path,
Property property)
Method called when the procesing of an association completes |
protected void |
endLink(DomainObject obj,
String path)
Method called when the procesing of a Link Object completes |
protected abstract void |
endObject(DomainObject obj,
String path)
Method called when the procesing of an object completes |
protected abstract void |
endRole(DomainObject obj,
String path,
Property property)
Method called when the procesing of a role completes |
static DomainObjectTraversalAdapter |
findAdapter(ObjectType type,
String context)
Retrieves the closest matching traversal adapter for an object type in a given context. |
protected abstract void |
handleAttribute(DomainObject obj,
String path,
Property property)
Method called when an attribute is encountered |
static DomainObjectTraversalAdapter |
lookupAdapter(ObjectType type,
String context)
Retrieves the traversal adapter for an object type in a given context. |
protected String |
nameFromPath(String path)
|
protected String |
parentFromPath(String path)
|
static void |
registerAdapter(ObjectType type,
DomainObjectTraversalAdapter adapter,
String context)
Registers a traversal adapter for an object type in a given context. |
static void |
registerAdapter(String type,
DomainObjectTraversalAdapter adapter,
String context)
Registers a traversal adapter for an object type in a given context. |
protected abstract void |
revisitObject(DomainObject obj,
String path)
Method called when a previously visited object is encountered for a second time. |
static void |
unregisterAdapter(ObjectType type,
String context)
Unregisteres a traversal adapter for an object type in a given context |
static void |
unregisterAdapter(String type,
String context)
Unregisteres a traversal adapter for an object type in a given context |
void |
walk(DomainObject obj,
String context)
Walks over properties of a domain object, invoking methods to handle assoications, roles and attributes. |
protected void |
walk(DomainObject obj,
String context,
DomainObjectTraversalAdapter adapter)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String LINK_NAME
Constructor Detail |
public DomainObjectTraversal()
Method Detail |
public static void registerAdapter(ObjectType type, DomainObjectTraversalAdapter adapter, String context)
type
- the object type whose items will be traversedadapter
- the adapter for controlling object traversalcontext
- the context in which the adapter should be usedpublic static void unregisterAdapter(ObjectType type, String context)
type
- the object type whose items will be traversedcontext
- the context in which the adapter should be usedpublic static void registerAdapter(String type, DomainObjectTraversalAdapter adapter, String context)
type
- the object type whose items will be traversedadapter
- the adapter for controlling object traversalcontext
- the context in which the adapter should be usedpublic static void unregisterAdapter(String type, String context)
type
- the object type whose items will be traversedcontext
- the context in which the adapter should be usedpublic static DomainObjectTraversalAdapter lookupAdapter(ObjectType type, String context)
type
- the object type to lookupcontext
- the adapter contextpublic static DomainObjectTraversalAdapter findAdapter(ObjectType type, String context)
type
- the object type to search forcontext
- the adapter contextpublic void walk(DomainObject obj, String context)
obj
- the domain object to traversecontext
- the context for the traversal adapterprotected void walk(DomainObject obj, String context, DomainObjectTraversalAdapter adapter)
protected abstract void beginObject(DomainObject obj, String path)
protected abstract void endObject(DomainObject obj, String path)
protected void beginLink(DomainObject obj, String path)
protected void endLink(DomainObject obj, String path)
protected abstract void revisitObject(DomainObject obj, String path)
protected abstract void handleAttribute(DomainObject obj, String path, Property property)
protected abstract void beginRole(DomainObject obj, String path, Property property)
protected abstract void endRole(DomainObject obj, String path, Property property)
protected abstract void beginAssociation(DomainObject obj, String path, Property property)
protected abstract void endAssociation(DomainObject obj, String path, Property property)
protected String appendToPath(String path, String name)
protected String nameFromPath(String path)
protected String parentFromPath(String path)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |