mxGraph
Public Member Functions | Static Public Member Functions | Protected Attributes | Properties | List of all members
com.mxgraph.mxCodec Class Reference

XML codec for .NET object graphs. In order to resolve forward references when reading files the XML document that contains the data must be passed to the constructor. More...

Public Member Functions

 mxCodec ()
 Constructs an XML encoder/decoder with a new owner document. More...
 
 mxCodec (XmlDocument document)
 Constructs an XML encoder/decoder for the specified owner document. The document is required to resolve forward ID references. This means if you parse a graphmodel that is represented in XML you must also pass the document that contains the XML to the constructor, otherwise forward references will not be resolved. More...
 
Object PutObject (string id, Object obj)
 Assoiates the given object with the given ID. More...
 
Object GetObject (string id)
 Returns the decoded object for the element with the specified ID in document. If the object is not known then lookup is used to find an object. If no object is found, then the element with the respective ID from the document is parsed using decode. More...
 
Object Lookup (string id)
 Hook for subclassers to implement a custom lookup mechanism for cell IDs. This implementation always returns null. More...
 
XmlNode GetElementById (string id)
 Returns the element with the given ID from the document. More...
 
XmlNode GetElementById (string id, string attributeName)
 Returns the element with the given ID from document. The optional attr argument specifies the name of the ID attribute. Default is id. The XPath expression used to find the element is //*[@id='arg'] where id is the name of the ID attribute (attributeName) and arg is the given id. More...
 
string GetId (Object obj)
 Returns the ID of the specified object. This implementation calls reference first and if that returns null handles the object as an mxCell by returning their IDs using mxCell.getId. If no ID exists for the given cell, then an on-the-fly ID is generated using mxCellPath.create. More...
 
string Reference (Object obj)
 Hook for subclassers to implement a custom method for retrieving IDs from objects. This implementation always returns null. More...
 
XmlNode Encode (Object obj)
 Encodes the specified object and returns the resulting XML node. More...
 
Object Decode (XmlNode node)
 Decodes the given XML node using decode(XmlNode, Object). More...
 
Object Decode (XmlNode node, Object into)
 Decodes the given XML node. The optional "into" argument specifies an existing object to be used. If no object is given, then a new instance is created using the constructor from the codec. The function returns the passed in object or the new instance if no object was given. More...
 
void EncodeCell (mxICell cell, XmlNode node, bool includeChildren)
 Encoding of cell hierarchies is built-into the core, but is a higher-level function that needs to be explicitely used by the respective object encoders (eg. mxModelCodec, mxChildChangeCodec and mxRootChangeCodec). This implementation writes the given cell and its children as a (flat) sequence into the given node. The children are not encoded if the optional includeChildren is false. The function is in charge of adding the result into the given node and has no return value. More...
 
mxICell DecodeCell (XmlNode node, bool restoreStructures)
 Decodes cells that have been encoded using inversion, ie. where the user object is the enclosing node in the XML, and restores the group and graph structure in the cells. Returns a new mxCell instance that represents the given node. More...
 
void InsertIntoGraph (mxICell cell)
 Inserts the given cell into its parent and terminal cells. More...
 

Static Public Member Functions

static void SetAttribute (XmlNode node, string attribute, Object value)
 Sets the attribute on the specified node to value. This is a helper method that makes sure the attribute and value arguments are not null. More...
 

Protected Attributes

XmlDocument document
 Holds the owner document of the codec. More...
 
Dictionary< string, object > objects = new Dictionary<string, Object>()
 Maps from IDs to objects. More...
 
bool encodeDefaults = false
 Specifies if default values should be encoded. Default is false. More...
 

Properties

XmlDocument Document [get, set]
 Sets or returns the owner document of the codec. More...
 
bool IsEncodeDefaults [get, set]
 Sets or returns if default values of member variables should be encoded. More...
 
Dictionary< string, object > Objects [get]
 Returns the object lookup table. More...
 

Detailed Description

XML codec for .NET object graphs. In order to resolve forward references when reading files the XML document that contains the data must be passed to the constructor.

Constructor & Destructor Documentation

com.mxgraph.mxCodec.mxCodec ( )
inline

Constructs an XML encoder/decoder with a new owner document.

com.mxgraph.mxCodec.mxCodec ( XmlDocument  document)
inline

Constructs an XML encoder/decoder for the specified owner document. The document is required to resolve forward ID references. This means if you parse a graphmodel that is represented in XML you must also pass the document that contains the XML to the constructor, otherwise forward references will not be resolved.

Parameters
documentOptional XML document that contains the data. If no document is specified then a new document is created using mxUtils.createDocument

References com.mxgraph.mxUtils.CreateDocument().

Member Function Documentation

Object com.mxgraph.mxCodec.Decode ( XmlNode  node)
inline

Decodes the given XML node using decode(XmlNode, Object).

Parameters
nodeXML node to be decoded.
Returns
Returns an object that represents the given node.

Referenced by com.mxgraph.mxObjectCodec.DecodeChild(), and com.mxgraph.mxObjectCodec.ProcessInclude().

Object com.mxgraph.mxCodec.Decode ( XmlNode  node,
Object  into 
)
inline

Decodes the given XML node. The optional "into" argument specifies an existing object to be used. If no object is given, then a new instance is created using the constructor from the codec. The function returns the passed in object or the new instance if no object was given.

Parameters
nodeXML node to be decoded.
intoOptional object to be decodec into.
Returns
Returns an object that represents the given node.

References com.mxgraph.mxObjectCodec.Decode(), and com.mxgraph.mxCodecRegistry.GetCodec().

mxICell com.mxgraph.mxCodec.DecodeCell ( XmlNode  node,
bool  restoreStructures 
)
inline

Decodes cells that have been encoded using inversion, ie. where the user object is the enclosing node in the XML, and restores the group and graph structure in the cells. Returns a new mxCell instance that represents the given node.

Parameters
nodeXML node that contains the cell data.
restoreStructuresBoolean indicating whether the graph structure should be restored by calling insert and insertEdge on the parent and terminals, respectively.
Returns
Graph cell that represents the given node.

References com.mxgraph.mxObjectCodec.Decode(), and com.mxgraph.mxCodecRegistry.GetCodec().

Referenced by com.mxgraph.mxModelCodec.BeforeDecode().

XmlNode com.mxgraph.mxCodec.Encode ( Object  obj)
inline

Encodes the specified object and returns the resulting XML node.

Parameters
objObject to be encoded.
Returns
Returns an XML node that represents the given object.

References com.mxgraph.mxObjectCodec.Encode(), com.mxgraph.mxCodecRegistry.GetCodec(), and com.mxgraph.mxCodecRegistry.GetName().

Referenced by com.mxgraph.mxObjectCodec.WriteComplexAttribute().

void com.mxgraph.mxCodec.EncodeCell ( mxICell  cell,
XmlNode  node,
bool  includeChildren 
)
inline

Encoding of cell hierarchies is built-into the core, but is a higher-level function that needs to be explicitely used by the respective object encoders (eg. mxModelCodec, mxChildChangeCodec and mxRootChangeCodec). This implementation writes the given cell and its children as a (flat) sequence into the given node. The children are not encoded if the optional includeChildren is false. The function is in charge of adding the result into the given node and has no return value.

Parameters
cellmxCell to be encoded.
nodeParent XML node to add the encoded cell into.
includeChildrenBoolean indicating if the method should include all descendents

References com.mxgraph.mxICell.ChildCount(), and com.mxgraph.mxICell.GetChildAt().

Referenced by com.mxgraph.mxModelCodec.EncodeObject().

XmlNode com.mxgraph.mxCodec.GetElementById ( string  id)
inline

Returns the element with the given ID from the document.

Parameters
idID of the element to be returned.
Returns
Returns the element for the given ID.
XmlNode com.mxgraph.mxCodec.GetElementById ( string  id,
string  attributeName 
)
inline

Returns the element with the given ID from document. The optional attr argument specifies the name of the ID attribute. Default is id. The XPath expression used to find the element is //*[@id='arg'] where id is the name of the ID attribute (attributeName) and arg is the given id.

Parameters
idID of the element to be returned.
attributeNameOptional string for the attributename. Default is id.
Returns
Returns the element for the given ID.

References com.mxgraph.mxUtils.SelectSingleNode().

string com.mxgraph.mxCodec.GetId ( Object  obj)
inline

Returns the ID of the specified object. This implementation calls reference first and if that returns null handles the object as an mxCell by returning their IDs using mxCell.getId. If no ID exists for the given cell, then an on-the-fly ID is generated using mxCellPath.create.

Parameters
objObject to return the ID for.
Returns
Returns the ID for the given object.

References com.mxgraph.mxCellPath.Create().

Referenced by com.mxgraph.mxObjectCodec.EncodeObject(), and com.mxgraph.mxObjectCodec.EncodeValue().

Object com.mxgraph.mxCodec.GetObject ( string  id)
inline

Returns the decoded object for the element with the specified ID in document. If the object is not known then lookup is used to find an object. If no object is found, then the element with the respective ID from the document is parsed using decode.

Parameters
idID of the object to be returned.
Returns
Returns the object for the given ID.

Referenced by com.mxgraph.mxObjectCodec.DecodeAttribute().

void com.mxgraph.mxCodec.InsertIntoGraph ( mxICell  cell)
inline
Object com.mxgraph.mxCodec.Lookup ( string  id)
inline

Hook for subclassers to implement a custom lookup mechanism for cell IDs. This implementation always returns null.

Parameters
idID of the object to be returned.
Returns
Returns the object for the given ID.
Object com.mxgraph.mxCodec.PutObject ( string  id,
Object  obj 
)
inline

Assoiates the given object with the given ID.

Parameters
idID for the object to be associated with.
objObject to be associated with the ID.
Returns
Returns the given object.

Referenced by com.mxgraph.mxStylesheetCodec.Decode(), and com.mxgraph.mxObjectCodec.Decode().

string com.mxgraph.mxCodec.Reference ( Object  obj)
inline

Hook for subclassers to implement a custom method for retrieving IDs from objects. This implementation always returns null.

Parameters
objObject whose ID should be returned.
Returns
Returns the ID for the given object.
static void com.mxgraph.mxCodec.SetAttribute ( XmlNode  node,
string  attribute,
Object  value 
)
inlinestatic

Sets the attribute on the specified node to value. This is a helper method that makes sure the attribute and value arguments are not null.

Parameters
nodeXML node to set the attribute for.
attributeAttributename to be set.
valueNew value of the attribute.

Referenced by com.mxgraph.mxObjectCodec.EncodeObject(), com.mxgraph.mxObjectCodec.WriteComplexAttribute(), and com.mxgraph.mxObjectCodec.WritePrimitiveAttribute().

Member Data Documentation

XmlDocument com.mxgraph.mxCodec.document
protected

Holds the owner document of the codec.

bool com.mxgraph.mxCodec.encodeDefaults = false
protected

Specifies if default values should be encoded. Default is false.

Dictionary<string, object> com.mxgraph.mxCodec.objects = new Dictionary<string, Object>()
protected

Maps from IDs to objects.

Property Documentation

XmlDocument com.mxgraph.mxCodec.Document
getset

Sets or returns the owner document of the codec.

Returns
Returns the owner document.

Referenced by com.mxgraph.mxStylesheetCodec.Encode(), com.mxgraph.mxObjectCodec.Encode(), com.mxgraph.mxModelCodec.EncodeObject(), and com.mxgraph.mxObjectCodec.WritePrimitiveAttribute().

bool com.mxgraph.mxCodec.IsEncodeDefaults
getset

Sets or returns if default values of member variables should be encoded.

Referenced by com.mxgraph.mxObjectCodec.EncodeValue().

Dictionary<string, object> com.mxgraph.mxCodec.Objects
get

Returns the object lookup table.

Referenced by com.mxgraph.mxStylesheetCodec.Decode(), and com.mxgraph.mxObjectCodec.Decode().


The documentation for this class was generated from the following file: