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

Generic codec for C# objects. See below for a detailed description of the encoding/decoding scheme. Note: Since booleans are numbers in JavaScript, all boolean values are encoded into 1 for true and 0 for false. More...

Inheritance diagram for com.mxgraph.mxObjectCodec:
com.mxgraph.mxCellCodec com.mxgraph.mxModelCodec com.mxgraph.mxStylesheetCodec

Public Member Functions

 mxObjectCodec (Object template)
 Constructs a new codec for the specified template object. More...
 
 mxObjectCodec (Object template, string[] exclude, string[] idrefs, Dictionary< string, string > mapping)
 Constructs a new codec for the specified template object. The variables in the optional exclude array are ignored by the codec. Variables in the optional idrefs array are turned into references in the XML. The optional mapping may be used to map from variable names to XML attributes. More...
 
string GetName ()
 Returns the name used for the nodenames and lookup of the codec when classes are encoded and nodes are decoded. For classes to work with this the codec registry automatically adds an alias for the classname if that is different than what this returns. The default implementation returns the classname of the template class. More...
 
virtual bool IsExcluded (Object obj, string attr, Object value, bool write)
 Returns true if the given attribute is to be ignored by the codec. This implementation returns true if the given fieldname is in exclude. More...
 
virtual bool IsReference (Object obj, string attr, Object value, bool write)
 Returns true if the given fieldname is to be treated as a textual reference (ID). This implementation returns true if the given fieldname is in idrefs. More...
 
virtual XmlNode Encode (mxCodec enc, Object obj)
 Encodes the specified object and returns a node representing then given object. Calls beforeEncode after creating the node and afterEncode with the resulting node after processing. Enc is a reference to the calling encoder. It is used to encode complex objects and create references. More...
 
virtual Object BeforeEncode (mxCodec enc, Object obj, XmlNode node)
 Hook for subclassers to pre-process the object before encoding. This returns the input object. The return value of this function is used in encode to perform the default encoding into the given node. More...
 
virtual XmlNode AfterEncode (mxCodec enc, Object obj, XmlNode node)
 Hook for subclassers to Receive-process the node for the given object after encoding and return the Receive-processed node. This implementation returns the input node. The return value of this method is returned to the encoder from encode. More...
 
virtual Object Decode (mxCodec dec, XmlNode node)
 Parses the given node into the object or returns a new object representing the given node. More...
 
virtual Object Decode (mxCodec dec, XmlNode node, Object into)
 Parses the given node into the object or returns a new object representing the given node. Dec is a reference to the calling decoder. It is used to decode complex objects and resolve references. If a node has an id attribute then the object cache is checked for the object. If the object is not yet in the cache then it is constructed using the constructor of template and cached in mxCodec.objects. This implementation decodes all attributes and childs of a node according to the following rules: More...
 
bool ProcessInclude (mxCodec dec, XmlNode node, Object into)
 
virtual XmlNode BeforeDecode (mxCodec dec, XmlNode node, Object obj)
 Hook for subclassers to pre-process the node for the specified object and return the node to be used for further processing by decode. The object is created based on the template in the calling method and is never null. This implementation returns the input node. The return value of this function is used in decode to perform the default decoding into the given object. More...
 
virtual Object AfterDecode (mxCodec dec, XmlNode node, Object obj)
 Hook for subclassers to Receive-process the object after decoding. This implementation returns the given object without any changes. The return value of this method is returned to the decoder from decode. More...
 

Protected Member Functions

virtual Object CloneTemplate (XmlNode node)
 Returns a new instance of the template object for representing the given node. More...
 
virtual void EncodeObject (mxCodec enc, Object obj, XmlNode node)
 Encodes the value of each member in then given obj into the given node using encodeFields and encodeElements. More...
 
void EncodeFields (mxCodec enc, Object obj, XmlNode node)
 Encodes the members of the given object into the given node. More...
 
void EncodeElements (mxCodec enc, Object obj, XmlNode node)
 Encodes the child objects of arrays, dictionaries and enumerables. More...
 
void EncodeValue (mxCodec enc, Object obj, string fieldname, Object value, XmlNode node)
 Converts the given value according to the mappings and id-refs in this codec and uses writeAttribute to write the attribute into the given node. More...
 
bool IsPrimitiveValue (Object value)
 Returns true if the given object is a primitive value. More...
 
void WriteAttribute (mxCodec enc, Object obj, string attr, Object value, XmlNode node)
 Writes the given value into node using writePrimitiveAttribute or writeComplexAttribute depending on the type of the value.
 
void WritePrimitiveAttribute (mxCodec enc, Object obj, string attr, Object value, XmlNode node)
 Writes the given value as an attribute of the given node. More...
 
void WriteComplexAttribute (mxCodec enc, Object obj, string attr, Object value, XmlNode node)
 Writes the given value as a child node of the given node. More...
 
virtual Object ConvertValueToXml (Object value)
 Converts true to "1" and false to "0". All other values are ignored. More...
 
virtual Object ConvertValueFromXml (Type type, Object value)
 Converts XML attribute values to object of the given type. More...
 
string GetAttributeName (string fieldname)
 Returns the XML node attribute name for the given C# field name. That is, it returns the mapping of the field name. More...
 
string GetFieldName (string attributename)
 Returns the C# field name for the given XML attribute name. That is, it returns the reverse mapping of the attribute name. More...
 
Object GetFieldValue (Object obj, string name)
 Returns the value of the field with the specified name in the specified object instance. More...
 
void SetFieldValue (Object obj, string name, Object value)
 Sets the value of the field with the specified name in the specified object instance. More...
 
void DecodeNode (mxCodec dec, XmlNode node, Object obj)
 Calls decodeAttributes and decodeChildren for the given node. More...
 
void DecodeAttributes (mxCodec dec, XmlNode node, Object obj)
 Decodes all attributes of the given node using decodeAttribute. More...
 
void DecodeAttribute (mxCodec dec, XmlNode attr, Object obj)
 Reads the given attribute into the specified object. More...
 
void DecodeChildren (mxCodec dec, XmlNode node, Object obj)
 Reads the given attribute into the specified object. More...
 
void DecodeChild (mxCodec dec, XmlNode child, Object obj)
 Reads the specified child into the given object. More...
 
Object GetFieldTemplate (Object obj, String fieldname, XmlNode child)
 Returns the template instance for the given field. This returns the value of the field, null if the value is an array or an empty collection if the value is a collection. The value is then used to populate the field for a new instance. For strongly typed languages it may be required to override this to return the correct collection instance based on the encoded child. More...
 
void AddObjectValue (Object obj, String fieldname, Object value, Object template)
 Sets the decoded child node as a value of the given object. If the object is a map, then the value is added with the given fieldname as a key. If the fieldname is not empty, then setFieldValue is called or else, if the object is a collection, the value is added to the collection. For strongly typed languages it may be required to override this with the correct code to add an entry to an object. More...
 

Protected Attributes

Object template
 Holds the template object associated with this codec. More...
 
List< string > exclude
 Array containing the variable names that should be ignored by the codec. More...
 
List< string > idrefs
 Array containing the variable names that should be turned into or converted from references. See mxCodec.getId and mxCodec.getObject. More...
 
Dictionary< string, string > mapping
 Maps from from fieldnames to XML attribute names. More...
 
Dictionary< string, string > reverse
 Maps from from XML attribute names to fieldnames. More...
 

Properties

Object Template [get]
 Returns the template object associated with this codec. More...
 

Detailed Description

Generic codec for C# objects. See below for a detailed description of the encoding/decoding scheme. Note: Since booleans are numbers in JavaScript, all boolean values are encoded into 1 for true and 0 for false.

Constructor & Destructor Documentation

com.mxgraph.mxObjectCodec.mxObjectCodec ( Object  template)
inline

Constructs a new codec for the specified template object.

Parameters
templatePrototypical instance of the object to be encoded/decoded.
com.mxgraph.mxObjectCodec.mxObjectCodec ( Object  template,
string[]  exclude,
string[]  idrefs,
Dictionary< string, string >  mapping 
)
inline

Constructs a new codec for the specified template object. The variables in the optional exclude array are ignored by the codec. Variables in the optional idrefs array are turned into references in the XML. The optional mapping may be used to map from variable names to XML attributes.

Parameters
templatePrototypical instance of the object to be encoded/decoded.
excludeOptional array of fieldnames to be ignored.
idrefsOptional array of fieldnames to be converted to/from references.
mappingOptional mapping from field- to attributenames.

Member Function Documentation

void com.mxgraph.mxObjectCodec.AddObjectValue ( Object  obj,
String  fieldname,
Object  value,
Object  template 
)
inlineprotected

Sets the decoded child node as a value of the given object. If the object is a map, then the value is added with the given fieldname as a key. If the fieldname is not empty, then setFieldValue is called or else, if the object is a collection, the value is added to the collection. For strongly typed languages it may be required to override this with the correct code to add an entry to an object.

virtual Object com.mxgraph.mxObjectCodec.AfterDecode ( mxCodec  dec,
XmlNode  node,
Object  obj 
)
inlinevirtual

Hook for subclassers to Receive-process the object after decoding. This implementation returns the given object without any changes. The return value of this method is returned to the decoder from decode.

Parameters
decCodec that controls the decoding process.
nodeXML node to be decoded.
objObject that represents the default decoding.
Returns
Returns the result of the decoding process.
virtual XmlNode com.mxgraph.mxObjectCodec.AfterEncode ( mxCodec  enc,
Object  obj,
XmlNode  node 
)
inlinevirtual

Hook for subclassers to Receive-process the node for the given object after encoding and return the Receive-processed node. This implementation returns the input node. The return value of this method is returned to the encoder from encode.

Parameters
encCodec that controls the encoding process.
objObject to be encoded.
nodeXML node that represents the default encoding.
Returns
Returns the resulting node of the encoding.
virtual XmlNode com.mxgraph.mxObjectCodec.BeforeDecode ( mxCodec  dec,
XmlNode  node,
Object  obj 
)
inlinevirtual

Hook for subclassers to pre-process the node for the specified object and return the node to be used for further processing by decode. The object is created based on the template in the calling method and is never null. This implementation returns the input node. The return value of this function is used in decode to perform the default decoding into the given object.

Parameters
decCodec that controls the decoding process.
nodeXML node to be decoded.
objObject to encode the node into.
Returns
Returns the node used for the default decoding.

Reimplemented in com.mxgraph.mxModelCodec.

virtual Object com.mxgraph.mxObjectCodec.BeforeEncode ( mxCodec  enc,
Object  obj,
XmlNode  node 
)
inlinevirtual

Hook for subclassers to pre-process the object before encoding. This returns the input object. The return value of this function is used in encode to perform the default encoding into the given node.

Parameters
encCodec that controls the encoding process.
objObject to be encoded.
nodeXML node to encode the object into.
Returns
Returns the object to be encoded by the default encoding.
virtual Object com.mxgraph.mxObjectCodec.CloneTemplate ( XmlNode  node)
inlineprotectedvirtual

Returns a new instance of the template object for representing the given node.

Parameters
nodeXML node that the object is going to represent.
Returns
Returns a new template instance.
virtual Object com.mxgraph.mxObjectCodec.ConvertValueFromXml ( Type  type,
Object  value 
)
inlineprotectedvirtual

Converts XML attribute values to object of the given type.

virtual Object com.mxgraph.mxObjectCodec.ConvertValueToXml ( Object  value)
inlineprotectedvirtual

Converts true to "1" and false to "0". All other values are ignored.

virtual Object com.mxgraph.mxObjectCodec.Decode ( mxCodec  dec,
XmlNode  node 
)
inlinevirtual

Parses the given node into the object or returns a new object representing the given node.

Parameters
decCodec that controls the encoding process.
nodeXML node to be decoded.
Returns
Returns the resulting object that represents the given XML node.

Referenced by com.mxgraph.mxCodec.DecodeCell().

virtual Object com.mxgraph.mxObjectCodec.Decode ( mxCodec  dec,
XmlNode  node,
Object  into 
)
inlinevirtual

Parses the given node into the object or returns a new object representing the given node. Dec is a reference to the calling decoder. It is used to decode complex objects and resolve references. If a node has an id attribute then the object cache is checked for the object. If the object is not yet in the cache then it is constructed using the constructor of template and cached in mxCodec.objects. This implementation decodes all attributes and childs of a node according to the following rules:

  • If the variable name is in exclude or if the attribute name is "id" or "as" then it is ignored.
  • If the variable name is in idrefs then mxCodec.getObject is used to replace the reference with an object.
  • The variable name is mapped using a reverse mapping.
  • If the value has a child node, then the codec is used to create a child object with the variable name taken from the "as" attribute.
  • If the object is an array and the variable name is empty then the value or child object is appended to the array.
  • If an add child has no value or the object is not an array then the child text content is evaluated using mxUtils.eval. If no object exists for an ID in idrefs a warning is issued using mxLog.warn. Returns the resulting object that represents the given XML node or the configured given object.
Parameters
decCodec that controls the encoding process.
nodeXML node to be decoded.
intoOptional objec to encode the node into.
Returns
Returns the resulting object that represents the given XML node or the object given to the method as the into parameter.

Reimplemented in com.mxgraph.mxStylesheetCodec.

void com.mxgraph.mxObjectCodec.DecodeAttribute ( mxCodec  dec,
XmlNode  attr,
Object  obj 
)
inlineprotected

Reads the given attribute into the specified object.

void com.mxgraph.mxObjectCodec.DecodeAttributes ( mxCodec  dec,
XmlNode  node,
Object  obj 
)
inlineprotected

Decodes all attributes of the given node using decodeAttribute.

void com.mxgraph.mxObjectCodec.DecodeChild ( mxCodec  dec,
XmlNode  child,
Object  obj 
)
inlineprotected

Reads the specified child into the given object.

void com.mxgraph.mxObjectCodec.DecodeChildren ( mxCodec  dec,
XmlNode  node,
Object  obj 
)
inlineprotected

Reads the given attribute into the specified object.

void com.mxgraph.mxObjectCodec.DecodeNode ( mxCodec  dec,
XmlNode  node,
Object  obj 
)
inlineprotected

Calls decodeAttributes and decodeChildren for the given node.

virtual XmlNode com.mxgraph.mxObjectCodec.Encode ( mxCodec  enc,
Object  obj 
)
inlinevirtual

Encodes the specified object and returns a node representing then given object. Calls beforeEncode after creating the node and afterEncode with the resulting node after processing. Enc is a reference to the calling encoder. It is used to encode complex objects and create references.

Parameters
encCodec that controls the encoding process.
objObject to be encoded.
Returns
Returns the resulting XML node that represents the given object.

Reimplemented in com.mxgraph.mxStylesheetCodec.

void com.mxgraph.mxObjectCodec.EncodeElements ( mxCodec  enc,
Object  obj,
XmlNode  node 
)
inlineprotected

Encodes the child objects of arrays, dictionaries and enumerables.

Parameters
encCodec that controls the encoding process.
objObject whose child objects should be encoded.
nodeXML node that contains the encoded object.
void com.mxgraph.mxObjectCodec.EncodeFields ( mxCodec  enc,
Object  obj,
XmlNode  node 
)
inlineprotected

Encodes the members of the given object into the given node.

Parameters
encCodec that controls the encoding process.
objObject whose fields should be encoded.
nodeXML node that contains the encoded object.
virtual void com.mxgraph.mxObjectCodec.EncodeObject ( mxCodec  enc,
Object  obj,
XmlNode  node 
)
inlineprotectedvirtual

Encodes the value of each member in then given obj into the given node using encodeFields and encodeElements.

Parameters
encCodec that controls the encoding process.
objObject to be encoded.
nodeXML node that contains the encoded object.

Reimplemented in com.mxgraph.mxModelCodec.

void com.mxgraph.mxObjectCodec.EncodeValue ( mxCodec  enc,
Object  obj,
string  fieldname,
Object  value,
XmlNode  node 
)
inlineprotected

Converts the given value according to the mappings and id-refs in this codec and uses writeAttribute to write the attribute into the given node.

Parameters
encCodec that controls the encoding process.
objObject whose member is going to be encoded.
fieldname
valueValue of the property to be encoded.
nodeXML node that contains the encoded object.

References com.mxgraph.mxCodec.IsEncodeDefaults.

string com.mxgraph.mxObjectCodec.GetAttributeName ( string  fieldname)
inlineprotected

Returns the XML node attribute name for the given C# field name. That is, it returns the mapping of the field name.

string com.mxgraph.mxObjectCodec.GetFieldName ( string  attributename)
inlineprotected

Returns the C# field name for the given XML attribute name. That is, it returns the reverse mapping of the attribute name.

Parameters
attributenameThe attribute name to be mapped.
Returns
String that represents the mapped field name.
Object com.mxgraph.mxObjectCodec.GetFieldTemplate ( Object  obj,
String  fieldname,
XmlNode  child 
)
inlineprotected

Returns the template instance for the given field. This returns the value of the field, null if the value is an array or an empty collection if the value is a collection. The value is then used to populate the field for a new instance. For strongly typed languages it may be required to override this to return the correct collection instance based on the encoded child.

Object com.mxgraph.mxObjectCodec.GetFieldValue ( Object  obj,
string  name 
)
inlineprotected

Returns the value of the field with the specified name in the specified object instance.

string com.mxgraph.mxObjectCodec.GetName ( )
inline

Returns the name used for the nodenames and lookup of the codec when classes are encoded and nodes are decoded. For classes to work with this the codec registry automatically adds an alias for the classname if that is different than what this returns. The default implementation returns the classname of the template class.

virtual bool com.mxgraph.mxObjectCodec.IsExcluded ( Object  obj,
string  attr,
Object  value,
bool  write 
)
inlinevirtual

Returns true if the given attribute is to be ignored by the codec. This implementation returns true if the given fieldname is in exclude.

Parameters
objObject instance that contains the field.
attrFieldname of the field.
valueValue of the field.
writeBoolean indicating if the field is being encoded or decoded. write is true if the field is being encoded, else it is being decoded.
Returns
Returns true if the given attribute should be ignored.
bool com.mxgraph.mxObjectCodec.IsPrimitiveValue ( Object  value)
inlineprotected

Returns true if the given object is a primitive value.

Parameters
valueObject that should be checked.
Returns
Returns true if the given object is a primitive value.
virtual bool com.mxgraph.mxObjectCodec.IsReference ( Object  obj,
string  attr,
Object  value,
bool  write 
)
inlinevirtual

Returns true if the given fieldname is to be treated as a textual reference (ID). This implementation returns true if the given fieldname is in idrefs.

Parameters
objObject instance that contains the field.
attrFieldname of the field.
valueValue of the field.
writeBoolean indicating if the field is being encoded or decoded. write is true if the field is being encoded, else it is being decoded.
Returns
Returns true if the given attribute should be handled as a reference.
bool com.mxgraph.mxObjectCodec.ProcessInclude ( mxCodec  dec,
XmlNode  node,
Object  into 
)
inline

Parameters
decCodec that controls the encoding/decoding process.
nodeXML node to be checked.
intoOptional object to pass-thru to the codec.
Returns
Returns true if the given node was processed as an include.
void com.mxgraph.mxObjectCodec.SetFieldValue ( Object  obj,
string  name,
Object  value 
)
inlineprotected

Sets the value of the field with the specified name in the specified object instance.

void com.mxgraph.mxObjectCodec.WriteComplexAttribute ( mxCodec  enc,
Object  obj,
string  attr,
Object  value,
XmlNode  node 
)
inlineprotected

Writes the given value as a child node of the given node.

void com.mxgraph.mxObjectCodec.WritePrimitiveAttribute ( mxCodec  enc,
Object  obj,
string  attr,
Object  value,
XmlNode  node 
)
inlineprotected

Writes the given value as an attribute of the given node.

Member Data Documentation

List<string> com.mxgraph.mxObjectCodec.exclude
protected

Array containing the variable names that should be ignored by the codec.

List<string> com.mxgraph.mxObjectCodec.idrefs
protected

Array containing the variable names that should be turned into or converted from references. See mxCodec.getId and mxCodec.getObject.

Dictionary<string, string> com.mxgraph.mxObjectCodec.mapping
protected

Maps from from fieldnames to XML attribute names.

Dictionary<string, string> com.mxgraph.mxObjectCodec.reverse
protected

Maps from from XML attribute names to fieldnames.

Object com.mxgraph.mxObjectCodec.template
protected

Holds the template object associated with this codec.

Property Documentation

Object com.mxgraph.mxObjectCodec.Template
get

Returns the template object associated with this codec.

Returns
Returns the template object.

Referenced by com.mxgraph.mxCodecRegistry.Register().


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