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...
Public Member Functions | |
mxObjectCodec (Object template) | |
Constructs a new codec for the specified template object. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
virtual Object | Decode (mxCodec dec, XmlNode node) |
Parses the given node into the object or returns a new object representing the given node. | |
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:
| |
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. | |
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. | |
Protected Member Functions | |
virtual Object | CloneTemplate (XmlNode node) |
Returns a new instance of the template object for representing the given node. | |
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. | |
void | EncodeFields (mxCodec enc, Object obj, XmlNode node) |
Encodes the members of the given object into the given node. | |
void | EncodeElements (mxCodec enc, Object obj, XmlNode node) |
Encodes the child objects of arrays, dictionaries and enumerables. | |
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. | |
bool | IsPrimitiveValue (Object value) |
Returns true if the given object is a primitive value. | |
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. | |
void | WriteComplexAttribute (mxCodec enc, Object obj, string attr, Object value, XmlNode node) |
Writes the given value as a child node of the given node. | |
virtual Object | ConvertValueToXml (Object value) |
Converts true to "1" and false to "0". All other values are ignored. | |
virtual Object | ConvertValueFromXml (Type type, Object value) |
Converts XML attribute values to object of the given type. | |
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. | |
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. | |
Object | GetFieldValue (Object obj, string name) |
Returns the value of the field with the specified name in the specified object instance. | |
void | SetFieldValue (Object obj, string name, Object value) |
Sets the value of the field with the specified name in the specified object instance. | |
void | DecodeNode (mxCodec dec, XmlNode node, Object obj) |
Calls decodeAttributes and decodeChildren for the given node. | |
void | DecodeAttributes (mxCodec dec, XmlNode node, Object obj) |
Decodes all attributes of the given node using decodeAttribute. | |
void | DecodeAttribute (mxCodec dec, XmlNode attr, Object obj) |
Reads the given attribute into the specified object. | |
void | DecodeChildren (mxCodec dec, XmlNode node, Object obj) |
Reads the given attribute into the specified object. | |
void | DecodeChild (mxCodec dec, XmlNode child, Object obj) |
Reads the specified child into the given object. | |
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. | |
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. | |
Protected Attributes | |
Object | template |
Holds the template object associated with this codec. | |
List< string > | exclude |
Array containing the variable names that should be ignored by the codec. | |
List< string > | idrefs |
Array containing the variable names that should be turned into or converted from references. See mxCodec.getId and mxCodec.getObject. | |
Dictionary< string, string > | mapping |
Maps from from fieldnames to XML attribute names. | |
Dictionary< string, string > | reverse |
Maps from from XML attribute names to fieldnames. | |
Properties | |
Object | Template [get] |
Returns the template object associated with this codec. |
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.
com::mxgraph::mxObjectCodec::mxObjectCodec | ( | Object | template | ) | [inline] |
Constructs a new codec for the specified template object.
template | Prototypical 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.
template | Prototypical instance of the object to be encoded/decoded. | |
exclude | Optional array of fieldnames to be ignored. | |
idrefs | Optional array of fieldnames to be converted to/from references. | |
mapping | Optional mapping from field- to attributenames. |
void com::mxgraph::mxObjectCodec::AddObjectValue | ( | Object | obj, | |
String | fieldname, | |||
Object | value, | |||
Object | template | |||
) | [inline, protected] |
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 | |||
) | [inline, virtual] |
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.
dec | Codec that controls the decoding process. | |
node | XML node to be decoded. | |
obj | Object that represents the default decoding. |
virtual XmlNode com::mxgraph::mxObjectCodec::AfterEncode | ( | mxCodec | enc, | |
Object | obj, | |||
XmlNode | node | |||
) | [inline, virtual] |
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.
enc | Codec that controls the encoding process. | |
obj | Object to be encoded. | |
node | XML node that represents the default encoding. |
virtual XmlNode com::mxgraph::mxObjectCodec::BeforeDecode | ( | mxCodec | dec, | |
XmlNode | node, | |||
Object | obj | |||
) | [inline, virtual] |
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.
dec | Codec that controls the decoding process. | |
node | XML node to be decoded. | |
obj | Object to encode the node into. |
Reimplemented in com::mxgraph::mxModelCodec.
virtual Object com::mxgraph::mxObjectCodec::BeforeEncode | ( | mxCodec | enc, | |
Object | obj, | |||
XmlNode | node | |||
) | [inline, virtual] |
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.
enc | Codec that controls the encoding process. | |
obj | Object to be encoded. | |
node | XML node to encode the object into. |
virtual Object com::mxgraph::mxObjectCodec::CloneTemplate | ( | XmlNode | node | ) | [inline, protected, virtual] |
Returns a new instance of the template object for representing the given node.
node | XML node that the object is going to represent. |
virtual Object com::mxgraph::mxObjectCodec::ConvertValueFromXml | ( | Type | type, | |
Object | value | |||
) | [inline, protected, virtual] |
Converts XML attribute values to object of the given type.
virtual Object com::mxgraph::mxObjectCodec::ConvertValueToXml | ( | Object | value | ) | [inline, protected, virtual] |
Converts true to "1" and false to "0". All other values are ignored.
virtual Object com::mxgraph::mxObjectCodec::Decode | ( | mxCodec | dec, | |
XmlNode | node, | |||
Object | into | |||
) | [inline, virtual] |
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:
dec | Codec that controls the encoding process. | |
node | XML node to be decoded. | |
into | Optional objec to encode the node into. |
Reimplemented in com::mxgraph::mxStylesheetCodec.
virtual Object com::mxgraph::mxObjectCodec::Decode | ( | mxCodec | dec, | |
XmlNode | node | |||
) | [inline, virtual] |
Parses the given node into the object or returns a new object representing the given node.
dec | Codec that controls the encoding process. | |
node | XML node to be decoded. |
void com::mxgraph::mxObjectCodec::DecodeAttribute | ( | mxCodec | dec, | |
XmlNode | attr, | |||
Object | obj | |||
) | [inline, protected] |
Reads the given attribute into the specified object.
void com::mxgraph::mxObjectCodec::DecodeAttributes | ( | mxCodec | dec, | |
XmlNode | node, | |||
Object | obj | |||
) | [inline, protected] |
Decodes all attributes of the given node using decodeAttribute.
void com::mxgraph::mxObjectCodec::DecodeChild | ( | mxCodec | dec, | |
XmlNode | child, | |||
Object | obj | |||
) | [inline, protected] |
Reads the specified child into the given object.
void com::mxgraph::mxObjectCodec::DecodeChildren | ( | mxCodec | dec, | |
XmlNode | node, | |||
Object | obj | |||
) | [inline, protected] |
Reads the given attribute into the specified object.
void com::mxgraph::mxObjectCodec::DecodeNode | ( | mxCodec | dec, | |
XmlNode | node, | |||
Object | obj | |||
) | [inline, protected] |
Calls decodeAttributes and decodeChildren for the given node.
virtual XmlNode com::mxgraph::mxObjectCodec::Encode | ( | mxCodec | enc, | |
Object | obj | |||
) | [inline, virtual] |
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.
enc | Codec that controls the encoding process. | |
obj | Object to be encoded. |
Reimplemented in com::mxgraph::mxStylesheetCodec.
void com::mxgraph::mxObjectCodec::EncodeElements | ( | mxCodec | enc, | |
Object | obj, | |||
XmlNode | node | |||
) | [inline, protected] |
Encodes the child objects of arrays, dictionaries and enumerables.
enc | Codec that controls the encoding process. | |
obj | Object whose child objects should be encoded. | |
node | XML node that contains the encoded object. |
void com::mxgraph::mxObjectCodec::EncodeFields | ( | mxCodec | enc, | |
Object | obj, | |||
XmlNode | node | |||
) | [inline, protected] |
Encodes the members of the given object into the given node.
enc | Codec that controls the encoding process. | |
obj | Object whose fields should be encoded. | |
node | XML node that contains the encoded object. |
virtual void com::mxgraph::mxObjectCodec::EncodeObject | ( | mxCodec | enc, | |
Object | obj, | |||
XmlNode | node | |||
) | [inline, protected, virtual] |
Encodes the value of each member in then given obj into the given node using encodeFields and encodeElements.
enc | Codec that controls the encoding process. | |
obj | Object to be encoded. | |
node | XML 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 | |||
) | [inline, protected] |
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.
enc | Codec that controls the encoding process. | |
obj | Object whose member is going to be encoded. | |
fieldname | ||
value | Value of the property to be encoded. | |
node | XML node that contains the encoded object. |
string com::mxgraph::mxObjectCodec::GetAttributeName | ( | string | fieldname | ) | [inline, protected] |
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 | ) | [inline, protected] |
Returns the C# field name for the given XML attribute name. That is, it returns the reverse mapping of the attribute name.
attributename | The attribute name to be mapped. |
Object com::mxgraph::mxObjectCodec::GetFieldTemplate | ( | Object | obj, | |
String | fieldname, | |||
XmlNode | child | |||
) | [inline, protected] |
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 | |||
) | [inline, protected] |
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 | |||
) | [inline, virtual] |
Returns true if the given attribute is to be ignored by the codec. This implementation returns true if the given fieldname is in exclude.
obj | Object instance that contains the field. | |
attr | Fieldname of the field. | |
value | Value of the field. | |
write | Boolean indicating if the field is being encoded or decoded. write is true if the field is being encoded, else it is being decoded. |
bool com::mxgraph::mxObjectCodec::IsPrimitiveValue | ( | Object | value | ) | [inline, protected] |
Returns true if the given object is a primitive value.
value | Object that should be checked. |
virtual bool com::mxgraph::mxObjectCodec::IsReference | ( | Object | obj, | |
string | attr, | |||
Object | value, | |||
bool | write | |||
) | [inline, virtual] |
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.
obj | Object instance that contains the field. | |
attr | Fieldname of the field. | |
value | Value of the field. | |
write | Boolean indicating if the field is being encoded or decoded. write is true if the field is being encoded, else it is being decoded. |
bool com::mxgraph::mxObjectCodec::ProcessInclude | ( | mxCodec | dec, | |
XmlNode | node, | |||
Object | into | |||
) | [inline] |
dec | Codec that controls the encoding/decoding process. | |
node | XML node to be checked. | |
into | Optional object to pass-thru to the codec. |
void com::mxgraph::mxObjectCodec::SetFieldValue | ( | Object | obj, | |
string | name, | |||
Object | value | |||
) | [inline, protected] |
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 | |||
) | [inline, protected] |
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 | |||
) | [inline, protected] |
Writes the given value as an attribute of the given node.
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.
Object com::mxgraph::mxObjectCodec::Template [get] |
Returns the template object associated with this codec.