com.arsdigita.domain
Class DomainObjectTraversal

java.lang.Object
  extended bycom.arsdigita.domain.DomainObjectTraversal
Direct Known Subclasses:
DomainObjectTextRenderer, DomainObjectXMLRenderer

public abstract class DomainObjectTraversal
extends Object

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

LINK_NAME

public static final String LINK_NAME
See Also:
Constant Field Values
Constructor Detail

DomainObjectTraversal

public DomainObjectTraversal()
Method Detail

registerAdapter

public static void registerAdapter(ObjectType type,
                                   DomainObjectTraversalAdapter adapter,
                                   String context)
Registers a traversal adapter for an object type in a given context.

Parameters:
type - the object type whose items will be traversed
adapter - the adapter for controlling object traversal
context - the context in which the adapter should be used

unregisterAdapter

public static void unregisterAdapter(ObjectType type,
                                     String context)
Unregisteres a traversal adapter for an object type in a given context

Parameters:
type - the object type whose items will be traversed
context - the context in which the adapter should be used

registerAdapter

public static void registerAdapter(String type,
                                   DomainObjectTraversalAdapter adapter,
                                   String context)
Registers a traversal adapter for an object type in a given context.

Parameters:
type - the object type whose items will be traversed
adapter - the adapter for controlling object traversal
context - the context in which the adapter should be used

unregisterAdapter

public static void unregisterAdapter(String type,
                                     String context)
Unregisteres a traversal adapter for an object type in a given context

Parameters:
type - the object type whose items will be traversed
context - the context in which the adapter should be used

lookupAdapter

public static DomainObjectTraversalAdapter lookupAdapter(ObjectType type,
                                                         String context)
Retrieves the traversal adapter for an object type in a given context.

Parameters:
type - the object type to lookup
context - the adapter context

findAdapter

public static DomainObjectTraversalAdapter findAdapter(ObjectType type,
                                                       String context)
Retrieves the closest matching traversal adapter for an object type in a given context. The algorithm looks for an exact match, then considers the supertype, and the supertype's supertype. If no match could be found at all, returns null

Parameters:
type - the object type to search for
context - the adapter context

walk

public void walk(DomainObject obj,
                 String context)
Walks over properties of a domain object, invoking methods to handle assoications, roles and attributes.

Parameters:
obj - the domain object to traverse
context - the context for the traversal adapter

walk

protected void walk(DomainObject obj,
                    String context,
                    DomainObjectTraversalAdapter adapter)

beginObject

protected abstract void beginObject(DomainObject obj,
                                    String path)
Method called when the processing of an object starts


endObject

protected abstract void endObject(DomainObject obj,
                                  String path)
Method called when the procesing of an object completes


beginLink

protected void beginLink(DomainObject obj,
                         String path)
Method called when the processing of a Link Object starts


endLink

protected void endLink(DomainObject obj,
                       String path)
Method called when the procesing of a Link Object completes


revisitObject

protected abstract void revisitObject(DomainObject obj,
                                      String path)
Method called when a previously visited object is encountered for a second time.


handleAttribute

protected abstract void handleAttribute(DomainObject obj,
                                        String path,
                                        Property property)
Method called when an attribute is encountered


beginRole

protected abstract void beginRole(DomainObject obj,
                                  String path,
                                  Property property)
Method called when the processing of a role starts


endRole

protected abstract void endRole(DomainObject obj,
                                String path,
                                Property property)
Method called when the procesing of a role completes


beginAssociation

protected abstract void beginAssociation(DomainObject obj,
                                         String path,
                                         Property property)
Method called when the processing of an association starts


endAssociation

protected abstract void endAssociation(DomainObject obj,
                                       String path,
                                       Property property)
Method called when the procesing of an association completes


appendToPath

protected String appendToPath(String path,
                              String name)

nameFromPath

protected String nameFromPath(String path)

parentFromPath

protected String parentFromPath(String path)


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC