|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.partnersoft.cog.Cog
public class Cog
A Configurable Object Graph.
A Cog is a Configurable Object Graph, where the term "graph" is used in the mathematical structure sense of a network of connected nodes. The structure is that of a double-linked tree, where each Cog knows its single parent and one or more children. Branch nodes form stuctures or collections of subnodes.
Cogs have datatypes. The typing structure is separated from the data structure to allow e.g. loading an older version of a datatype and upgrading it by manipulating the contents. However, the typing structure allows rich description of the contents and how to read, edit, and report them.
While Cogs can be used to serialize Java objects, they are most useful as a runtime-configurable object-oriented data structure for describing user data, business objects, interface structures and other payloads.
The tree structure lends itself naturally to hierarchical traversal and storage in formats such as XML. It does not map as easily into relational structures like SQL, but it is possible by using the unique ID structure included.
Cogs are arranged in a tree structure. A twist on this structure is that the children may be accessed by name or ID as well as by order in the child list. The tree structure is double-linked so that you can traverse up or down with equal facility.
Be aware that Cogs are designed primarily for ease of use and flexibility, and not for size or time performance.
Copyright 2005-2009 Partner Software, Inc.
| Constructor Summary | |
|---|---|
Cog()
Creates an empty, unnamed, detached node with no type. |
|
Cog(CogSchema schema,
java.lang.String typeName)
Creates a root cog with the given schema and type name. |
|
Cog(java.util.Collection contents)
Creates a cog node and adds the objects in the given collection to it via addAll(). |
|
Cog(java.util.Map contents)
Creates a cog node and adds the objects in the given map to it via putAll(). |
|
Cog(java.lang.String xmlString)
Creates a cog from the given XML string. |
|
Cog(java.lang.String typeName,
java.lang.String name)
Creates an empty node of the given type and name. |
|
Cog(java.lang.String typeName,
java.lang.String name,
java.lang.Object data)
Creates an empty node with the given typeName, name, and data. |
|
| Method Summary | |
|---|---|
Cog |
add(Cog newChild)
Adds a node as a child. |
Cog |
add(java.lang.String childName)
Creates and adds a blank child node. |
Cog |
add(java.lang.String typeName,
java.lang.String childName)
Creates and adds a new child. |
Cog |
add(java.lang.String typeName,
java.lang.String childName,
java.lang.Object data)
Creates and adds a new child with data value. |
void |
addAll(java.util.Collection items)
Adds all items in the given collection via addObject(). |
void |
addObject(java.lang.Object object)
Treating this cog as a list, adds the given object to the end. |
Cog |
childAt(int index)
Returns the child at the given index. |
Cog |
childNamed(java.lang.String childName)
Returns the first direct child with the given name. |
Cog |
childWithId(java.lang.String id)
Returns the child with the given unique ID. |
void |
cleanStructure()
Attempts to clean up the structure and type names of this cog using its type information. |
Cog |
copy()
Creates a complete, deep copy of this Cog. |
void |
detachNode()
Removes this cog and attaches its descendants to this cog's current parent. |
Cog |
detachNodeFor(Path path)
Removes the given relative node using detachNode(). |
Cog |
detachNodeFor(java.lang.String pathString)
Removes the given relative node using detachNode(). |
void |
detachTree()
Removes this cog and its descendants from its parent. |
Cog |
detachTreeFor(Path path)
Removes the given relative node using detachTree(). |
Cog |
detachTreeFor(java.lang.String pathString)
Removes the given relative node using detachTree(). |
boolean |
equals(java.lang.Object nother)
|
void |
fireChanged(java.lang.String what)
|
java.util.ArrayList |
getArrayList(Path path)
|
java.util.ArrayList |
getArrayList(java.lang.String path)
|
boolean |
getBoolean(Path path)
|
boolean |
getBoolean(java.lang.String path)
|
byte[] |
getBytes(Path path)
|
byte[] |
getBytes(java.lang.String path)
|
int |
getChildCount()
Returns the number of children. |
Naming<java.lang.Object> |
getChildData()
Gets the child data as a Naming. |
java.util.List<Cog> |
getChildren()
Returns an immutable list of children. |
java.lang.Object |
getData()
Returns the payload data. |
java.lang.Object |
getData(Path path)
Gets the data object from the node specified by the path. |
java.lang.Object |
getData(java.lang.String path)
Same as getData(Path path) but automatically creates the Path object from the given string. |
double |
getDouble(Path path)
|
double |
getDouble(java.lang.String path)
|
float |
getFloat(Path path)
|
float |
getFloat(java.lang.String path)
|
java.lang.String |
getGuid()
Globally-unique ID (GUID) for this object. |
CogHeader |
getHeader()
Returns the CogHeader attached to the root. |
int |
getId()
Numeric ID for this object. |
int |
getIndex()
Returns the index location of this node in its parent's child list, or 0 if this is root. |
int |
getInt(Path path)
|
int |
getInt(java.lang.String path)
|
java.util.List |
getList(Path path)
|
java.util.List |
getList(java.lang.String path)
|
long |
getLong(Path path)
|
long |
getLong(java.lang.String path)
|
java.lang.String |
getName()
Name of this object. |
Naming |
getNaming(Path path)
|
Naming |
getNaming(java.lang.String path)
|
Cog |
getNode(Path path)
Gets the node specified by the path. |
Cog |
getNode(java.lang.String path)
Same as getNode(Path path) but automatically creates the Path object from the given string. |
java.lang.Object |
getObject(Path path)
Gets the object specified by the path. |
java.lang.Object |
getObject(java.lang.String path)
Same as getObject(Path path) but automatically creates the Path object from the given string. |
Cog |
getOrCreateNodeFor(Path path)
Gets a descendant of this node, according to the given path. |
Cog |
getParent()
Returns the parent cog, or null if this is a root Cog. |
Path |
getPath()
Returns the full path to this Cog from the root. |
Cog |
getRoot()
Returns the root of the structure this cog is in. |
CogSchema |
getSchema()
Returns the schema for this Cog structure. |
short |
getShort(Path path)
|
short |
getShort(java.lang.String path)
|
java.lang.String |
getString(Path path)
|
java.lang.String |
getString(java.lang.String path)
|
java.lang.String |
getStringButNullBlanks(Path path)
|
java.lang.String |
getStringButNullBlanks(java.lang.String path)
|
CogType |
getType()
Returns the CogType corresponding to the type name in the schema. |
java.lang.String |
getTypeName()
|
boolean |
isAncestorOf(Cog nother)
Returns true if this node is an ancestor of the given node. |
boolean |
isDescendantOf(Cog nother)
Returns true if this node is a descendant of the given node. |
boolean |
isLeaf()
Returns true if this is a leaf node with no children. |
boolean |
isRoot()
Returns true if this is the root of a Cog hierarchy. |
java.util.Iterator<Cog> |
iterator()
Iterates through the children. |
java.util.List<Cog> |
listAncestors()
Returns all ancestors of this node as a new list in order from parent to root. |
java.util.List<Cog> |
listChildren()
Returns a freshly-allocated list of this node's children. |
java.util.List<Cog> |
listChildrenNamed(java.lang.String name)
Returns a freshly-allocated list of the children with the given name. |
java.util.List<Cog> |
listDescendants()
Returns all descendants of this node as a new list. |
Cog |
nodeFor(Path path)
Gets a another node relative to this one, according to the given path. |
Cog |
nodeFor(java.lang.String pathString)
Gets a another node relative to this one, according to the given path string. |
void |
putAll(java.util.Map map)
Adds all items in the given map via putAll(). |
void |
putArrayList(Path path,
java.util.ArrayList value)
|
void |
putArrayList(java.lang.String path,
java.util.ArrayList value)
|
void |
putBoolean(Path path,
boolean value)
|
void |
putBoolean(java.lang.String path,
boolean value)
|
void |
putBytes(Path path,
byte[] value)
|
void |
putBytes(java.lang.String path,
byte[] value)
|
void |
putData(Path path,
java.lang.Object data)
Places the given data object at a node specified by the given path. |
void |
putData(Path path,
java.lang.String typeName,
java.lang.Object data)
Places the given data object at a node specified by the given path. |
void |
putData(java.lang.String path,
java.lang.Object data)
Same as putData(Path path, Object data) but automatically creates the Path object from the given string. |
void |
putData(java.lang.String path,
java.lang.String typeName,
java.lang.Object data)
Same as putData(Path path, typeName, Object data) but automatically creates the Path object from the given string. |
void |
putDouble(Path path,
double value)
|
void |
putDouble(java.lang.String path,
double value)
|
void |
putFloat(Path path,
float value)
|
void |
putFloat(java.lang.String path,
float value)
|
void |
putInt(Path path,
int value)
|
void |
putInt(java.lang.String path,
int value)
|
void |
putList(Path path,
java.util.List value)
|
void |
putList(Path path,
java.lang.String typeName,
java.util.List value)
|
void |
putList(java.lang.String path,
java.util.List value)
|
void |
putList(java.lang.String path,
java.lang.String typeName,
java.util.List value)
|
void |
putLong(Path path,
long value)
|
void |
putLong(java.lang.String path,
long value)
|
void |
putNaming(Path path,
Naming value)
|
void |
putNaming(java.lang.String path,
Naming value)
|
void |
putNode(Path path,
Cog node)
Places the given node at the location specified by the given path. |
void |
putNode(java.lang.String path,
Cog node)
Same as putNode(Path path, Cog node) but automatically creates the Path object from the given string. |
void |
putObject(Path path,
java.lang.Object object)
Places the given object at the location specified by the given path. |
void |
putObject(java.lang.String path,
java.lang.Object object)
Same as putObject(Path path, Object object) but automatically creates the Path object from the given string. |
void |
putShort(Path path,
short value)
|
void |
putShort(java.lang.String path,
short value)
|
void |
putString(Path path,
java.lang.String value)
|
void |
putString(Path path,
java.lang.String typeName,
java.lang.String value)
|
void |
putString(java.lang.String path,
java.lang.String value)
|
void |
putString(java.lang.String path,
java.lang.String typeName,
java.lang.String value)
|
Cog |
renameChild(java.lang.String oldName,
java.lang.String newName)
Renames the given child node. |
Cog |
setChildAt(int index,
Cog child)
Sets the child at the given index. |
void |
setChildData(Naming<java.lang.Object> childData)
Sets the child data using the given named values. |
void |
setData(java.lang.Object newData)
Sets the payload data. |
void |
setGuid(java.lang.String newGuid)
|
void |
setId(int newID)
|
void |
setName(java.lang.String newName)
|
void |
setParent(Cog newParent)
Sets the parent cog. |
void |
setSchema(CogSchema newSchema)
Sets the schema for this Cog structure. |
void |
setTypeName(java.lang.String newTypeName)
|
java.lang.String |
toDetailedString()
Gives a more detailed String representation of the entire Cog structure from this node down. |
java.util.List |
toList()
Converts this cog to an List of objects, where the objects are generated via the toObject() method on each child. |
Naming |
toNaming()
Converts this cog to an Naming of objects, where the objects are generated via the toObject() method on each child. |
java.lang.Object |
toObject()
Converts the cog to a Java object. |
java.lang.String |
toString()
|
java.util.List<CogValidationException> |
validate()
Validates this node and all of its children. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Cog()
public Cog(java.lang.String xmlString)
throws java.io.IOException
java.io.IOException
public Cog(CogSchema schema,
java.lang.String typeName)
public Cog(java.util.Collection contents)
public Cog(java.util.Map contents)
public Cog(java.lang.String typeName,
java.lang.String name)
public Cog(java.lang.String typeName,
java.lang.String name,
java.lang.Object data)
| Method Detail |
|---|
public Cog add(Cog newChild)
public Cog add(java.lang.String childName)
public Cog add(java.lang.String typeName,
java.lang.String childName)
public Cog add(java.lang.String typeName,
java.lang.String childName,
java.lang.Object data)
public void addAll(java.util.Collection items)
items - public void addObject(java.lang.Object object)
public Cog childAt(int index)
throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
public Cog setChildAt(int index,
Cog child)
throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsExceptionpublic Cog childNamed(java.lang.String childName)
public Cog childWithId(java.lang.String id)
public void cleanStructure()
public Cog copy()
public void detachNode()
public Cog detachNodeFor(Path path)
public Cog detachNodeFor(java.lang.String pathString)
public void detachTree()
public Cog detachTreeFor(Path path)
public Cog detachTreeFor(java.lang.String pathString)
public boolean equals(java.lang.Object nother)
equals in class java.lang.Objectpublic void fireChanged(java.lang.String what)
public java.util.ArrayList getArrayList(Path path)
public java.util.ArrayList getArrayList(java.lang.String path)
public boolean getBoolean(Path path)
public boolean getBoolean(java.lang.String path)
public int getChildCount()
public Naming<java.lang.Object> getChildData()
public java.util.List<Cog> getChildren()
public java.lang.Object getData()
public java.lang.Object getData(Path path)
public java.lang.Object getData(java.lang.String path)
public double getDouble(Path path)
public double getDouble(java.lang.String path)
public float getFloat(Path path)
public float getFloat(java.lang.String path)
public java.lang.String getGuid()
Identifiable
getGuid in interface Identifiablepublic CogHeader getHeader()
public int getId()
Identifiable
getId in interface Identifiablepublic int getInt(Path path)
public int getInt(java.lang.String path)
public java.util.List getList(Path path)
public java.util.List getList(java.lang.String path)
public long getLong(Path path)
public long getLong(java.lang.String path)
public java.lang.String getName()
Identifiable
getName in interface Identifiablepublic Naming getNaming(Path path)
public Naming getNaming(java.lang.String path)
public Cog getNode(Path path)
public Cog getNode(java.lang.String path)
public java.lang.Object getObject(Path path)
public java.lang.Object getObject(java.lang.String path)
public Cog getOrCreateNodeFor(Path path)
public Cog getParent()
public int getIndex()
public Path getPath()
public Cog getRoot()
public CogSchema getSchema()
public short getShort(Path path)
public short getShort(java.lang.String path)
public byte[] getBytes(Path path)
public byte[] getBytes(java.lang.String path)
public java.lang.String getString(Path path)
public java.lang.String getString(java.lang.String path)
public java.lang.String getStringButNullBlanks(Path path)
public java.lang.String getStringButNullBlanks(java.lang.String path)
public CogType getType()
public java.lang.String getTypeName()
public boolean isAncestorOf(Cog nother)
public boolean isDescendantOf(Cog nother)
public boolean isLeaf()
public boolean isRoot()
public java.util.Iterator<Cog> iterator()
iterator in interface java.lang.Iterable<Cog>public java.util.List<Cog> listAncestors()
public java.util.List<Cog> listChildren()
public java.util.List<Cog> listChildrenNamed(java.lang.String name)
public java.util.List<Cog> listDescendants()
public Cog nodeFor(Path path)
public Cog nodeFor(java.lang.String pathString)
public void putAll(java.util.Map map)
public void putArrayList(Path path,
java.util.ArrayList value)
public void putArrayList(java.lang.String path,
java.util.ArrayList value)
public void putBoolean(Path path,
boolean value)
public void putBoolean(java.lang.String path,
boolean value)
public void putData(Path path,
java.lang.Object data)
public void putData(Path path,
java.lang.String typeName,
java.lang.Object data)
public void putData(java.lang.String path,
java.lang.Object data)
public void putData(java.lang.String path,
java.lang.String typeName,
java.lang.Object data)
public void putDouble(Path path,
double value)
public void putDouble(java.lang.String path,
double value)
public void putFloat(Path path,
float value)
public void putFloat(java.lang.String path,
float value)
public void putInt(Path path,
int value)
public void putInt(java.lang.String path,
int value)
public void putList(Path path,
java.util.List value)
public void putList(Path path,
java.lang.String typeName,
java.util.List value)
public void putList(java.lang.String path,
java.util.List value)
public void putList(java.lang.String path,
java.lang.String typeName,
java.util.List value)
public void putLong(Path path,
long value)
public void putLong(java.lang.String path,
long value)
public void putNaming(Path path,
Naming value)
public void putNaming(java.lang.String path,
Naming value)
public void putNode(Path path,
Cog node)
public void putNode(java.lang.String path,
Cog node)
public void putObject(Path path,
java.lang.Object object)
public void putObject(java.lang.String path,
java.lang.Object object)
public void putShort(Path path,
short value)
public void putShort(java.lang.String path,
short value)
public void putString(Path path,
java.lang.String value)
public void putString(Path path,
java.lang.String typeName,
java.lang.String value)
public void putString(java.lang.String path,
java.lang.String value)
public void putString(java.lang.String path,
java.lang.String typeName,
java.lang.String value)
public void putBytes(java.lang.String path,
byte[] value)
public void putBytes(Path path,
byte[] value)
public Cog renameChild(java.lang.String oldName,
java.lang.String newName)
public void setChildData(Naming<java.lang.Object> childData)
public void setData(java.lang.Object newData)
public void setGuid(java.lang.String newGuid)
public void setId(int newID)
public void setName(java.lang.String newName)
public void setParent(Cog newParent)
public void setSchema(CogSchema newSchema)
public void setTypeName(java.lang.String newTypeName)
public java.lang.String toDetailedString()
public java.util.List toList()
public Naming toNaming()
public java.lang.Object toObject()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.util.List<CogValidationException> validate()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||