com.vinculumtech.platform.docmodel
Class DocumentModel

java.lang.Object
  extended bycom.vinculumtech.platform.docmodel.DocumentModel

public class DocumentModel
extends java.lang.Object

The DocumentModel class provides a simple API for managing arbitrary graphs of objects in a typeless fashion. This is especially helpful when binding graphs to GUI components or HTML forms (dynamically), especially when using ImageNode and/or ImageableNode

Every object is a composition of literal values, other objects, or combinations of both. Ultimately, a graph of objects is simply a set of paths and their associated literal values. For example, the Date object can be simply seen as a composition of the year, month, day, hour, minute, second primitive values. A more complex graph like a Purchase Order can be decomposed into its composite literal values where these values have slightly more complex paths. For example, the path to the zip code of the vendor on a hypothetical PO could be 'purchaseOrder.vendor.address.zipcode'.

The DocumentModel and Node classes allow for a complex object graph to be decomposed into a map of paths and their referenced objects or literal values. More commonly, a graph can be decomposed into a map of leaf values.

Given the resulting map, the values can be changed by manipulating the Map object, and then applied to the old graph. That is, to change the year on a Date object, a Map with 'year' and '1960' would be sufficient.

To customize the DocumentModel, subclass the Node class. To handle the Date object, the Date class needs to be paired with a DateNode that exposes the year, month, day, etc properties of the Date class as paths.

A MapNode and ListNode are already provided, thus a path traversing a List would be similiar to 'children[1].firstName'. Or for a Map, 'children.age'. See MapNode and (@link ListNode} for other functions that can be embedded in the path (like children[!] to clear a list).

Note that we use the term path, but the Java Bean specification and related tools use the term property.

It should also be noted that OGNL (http://www.ognl.org/) has a more expressive syntax, but has no discovery mechanism to return a set of value paths and the values they reference.

Version:
$Id: //depot/carrierwave/src/shared/com/vinculumtech/platform/docmodel/DocumentModel.java#9 $
See Also:
DocumentModelFactory, ImageableDocumentModelFactory

Constructor Summary
DocumentModel(java.lang.Object rootObject)
           
DocumentModel(java.util.Properties properties, TypeMap nodeTypeMap)
          Supports a DocumentModel without a root.
DocumentModel(java.util.Properties properties, TypeMap nodeTypeMap, java.lang.Object rootObject)
           
DocumentModel(TypeMap nodeTypeMap, java.lang.Object rootObject)
           
 
Method Summary
 void applyPathMap(java.util.Map pathMap)
          Sets all the values for each path in the given pathMap.
protected  Node createNode(java.lang.Class type)
           
protected  Node createNode(java.lang.Object value)
           
static TypeMap getDefaultNodeTypeMap()
          Returns a clone of the static default map.
 java.lang.Object getMetaDataAt(java.lang.String path, java.lang.String identifier)
          Returns the meta-data value for the given identifier referenced by the given path.
 Node getNode(java.lang.Object value)
          Returns a Node instance for the given value.
 Node getNodeFor(java.lang.Class type)
           
protected  java.lang.Object getNodeOrValue(java.lang.Object value)
           
 TypeMap getNodeTypeMap()
           
 java.util.Map getPathMap(int depth, boolean dependentsInclusive)
          Returns a complete map of all paths and referenced values.
 java.util.Map getPathMap(int depth, boolean dependentsInclusive, boolean leavesOnly)
          Returns a complete map of all paths and referenced values.
 java.util.Map getPathMap(int depth, boolean dependentsInclusive, boolean leavesOnly, java.lang.String matches)
          Returns a complete map of all paths and referenced values.
 java.util.Properties getProperties()
           
 Node getRootNode()
          Returns the Node instance representing the root object of this document.
 java.lang.Object getValueAt(java.lang.String path)
          Returns the value referenced by the given path.
protected  java.util.Map getValueMap()
          Maintains a map of values to nodes, or values to themselves if they there is no node available for the value type.
static java.lang.Object instantiateClass(java.lang.Class type, java.lang.Class[] types, java.lang.Object[] values)
           
 java.lang.Object instantiateNode(java.lang.Class nodeType, java.lang.Object value)
           
 boolean isCoerceValue()
           
 void setCoerceValue(boolean coerceValue)
          Set to true if String values should be converted to the declared type.
 void setNodeTypeMap(TypeMap nodeTypeMap)
           
protected  void setProperties(java.util.Properties properties)
           
protected  void setRootNode(Node rootNode)
           
 java.lang.Object setValueAt(java.lang.String path, java.lang.Object value)
          Replaces the old value referenced by the path with the new value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentModel

public DocumentModel(java.lang.Object rootObject)

DocumentModel

public DocumentModel(TypeMap nodeTypeMap,
                     java.lang.Object rootObject)

DocumentModel

public DocumentModel(java.util.Properties properties,
                     TypeMap nodeTypeMap,
                     java.lang.Object rootObject)

DocumentModel

public DocumentModel(java.util.Properties properties,
                     TypeMap nodeTypeMap)
Supports a DocumentModel without a root.

Method Detail

getDefaultNodeTypeMap

public static TypeMap getDefaultNodeTypeMap()
Returns a clone of the static default map.


isCoerceValue

public boolean isCoerceValue()

setCoerceValue

public void setCoerceValue(boolean coerceValue)
Set to true if String values should be converted to the declared type.

Parameters:
coerceValue -

getProperties

public java.util.Properties getProperties()

setProperties

protected void setProperties(java.util.Properties properties)

getNodeTypeMap

public TypeMap getNodeTypeMap()

setNodeTypeMap

public void setNodeTypeMap(TypeMap nodeTypeMap)

getRootNode

public Node getRootNode()
Returns the Node instance representing the root object of this document.

Returns:

setRootNode

protected void setRootNode(Node rootNode)

getValueMap

protected java.util.Map getValueMap()
Maintains a map of values to nodes, or values to themselves if they there is no node available for the value type.


getNode

public Node getNode(java.lang.Object value)
Returns a Node instance for the given value.

Parameters:
value -
Returns:

getNodeOrValue

protected java.lang.Object getNodeOrValue(java.lang.Object value)

getNodeFor

public Node getNodeFor(java.lang.Class type)

createNode

protected Node createNode(java.lang.Object value)

createNode

protected Node createNode(java.lang.Class type)

getValueAt

public java.lang.Object getValueAt(java.lang.String path)
Returns the value referenced by the given path.

Parameters:
path -
Returns:

getMetaDataAt

public java.lang.Object getMetaDataAt(java.lang.String path,
                                      java.lang.String identifier)
Returns the meta-data value for the given identifier referenced by the given path.

Parameters:
path -
identifier -
Returns:

setValueAt

public java.lang.Object setValueAt(java.lang.String path,
                                   java.lang.Object value)
Replaces the old value referenced by the path with the new value. The old value is returned.

Parameters:
path -
value -
Returns:

getPathMap

public java.util.Map getPathMap(int depth,
                                boolean dependentsInclusive)
Returns a complete map of all paths and referenced values.

Parameters:
depth -
dependentsInclusive -
Returns:

getPathMap

public java.util.Map getPathMap(int depth,
                                boolean dependentsInclusive,
                                boolean leavesOnly)
Returns a complete map of all paths and referenced values.

Parameters:
depth -
dependentsInclusive -
leavesOnly -
Returns:

getPathMap

public java.util.Map getPathMap(int depth,
                                boolean dependentsInclusive,
                                boolean leavesOnly,
                                java.lang.String matches)
Returns a complete map of all paths and referenced values.

Parameters:
depth -
dependentsInclusive -
leavesOnly -
matches -
Returns:

applyPathMap

public void applyPathMap(java.util.Map pathMap)
Sets all the values for each path in the given pathMap.

Parameters:
pathMap -

instantiateNode

public java.lang.Object instantiateNode(java.lang.Class nodeType,
                                        java.lang.Object value)

instantiateClass

public static java.lang.Object instantiateClass(java.lang.Class type,
                                                java.lang.Class[] types,
                                                java.lang.Object[] values)


Copyright (C) 2002 Vinculum Technologies, Inc. All Rights Reserved.