mxGraph
|
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. 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... | |
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.
|
inline |
Constructs a new codec for the specified template object.
template | Prototypical instance of the object to be encoded/decoded. |
|
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. |
|
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.
|
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.
dec | Codec that controls the decoding process. |
node | XML node to be decoded. |
obj | Object that represents the default decoding. |
|
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.
enc | Codec that controls the encoding process. |
obj | Object to be encoded. |
node | XML node that represents the default encoding. |
Reimplemented in com.mxgraph.mxCellCodec.
|
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.
dec | Codec that controls the decoding process. |
node | XML node to be decoded. |
obj | Object to encode the node into. |
Reimplemented in com.mxgraph.mxCellCodec, and com.mxgraph.mxModelCodec.
|
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.
enc | Codec that controls the encoding process. |
obj | Object to be encoded. |
node | XML node to encode the object into. |
|
inlineprotectedvirtual |
Returns a new instance of the template object for representing the given node.
node | XML node that the object is going to represent. |
|
inlineprotectedvirtual |
Converts XML attribute values to object of the given type.
|
inlineprotectedvirtual |
Converts true to "1" and false to "0". All other values are ignored.
|
inlinevirtual |
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. |
Referenced by com.mxgraph.mxCellCodec.BeforeDecode(), com.mxgraph.mxCodec.Decode(), and com.mxgraph.mxCodec.DecodeCell().
|
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:
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.
References com.mxgraph.mxCodec.Objects, and com.mxgraph.mxCodec.PutObject().
|
inlineprotected |
Reads the given attribute into the specified object.
References com.mxgraph.mxCodec.GetObject().
|
inlineprotected |
Decodes all attributes of the given node using decodeAttribute.
|
inlineprotected |
Reads the specified child into the given object.
References com.mxgraph.mxCodec.Decode().
|
inlineprotected |
Reads the given attribute into the specified object.
|
inlineprotected |
Calls decodeAttributes and decodeChildren for the given node.
|
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.
enc | Codec that controls the encoding process. |
obj | Object to be encoded. |
Reimplemented in com.mxgraph.mxStylesheetCodec.
References com.mxgraph.mxCodec.Document.
Referenced by com.mxgraph.mxCodec.Encode().
|
inlineprotected |
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. |
|
inlineprotected |
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. |
|
inlineprotectedvirtual |
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.
References com.mxgraph.mxCodec.GetId(), and com.mxgraph.mxCodec.SetAttribute().
|
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.
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. |
References com.mxgraph.mxCodec.GetId(), and com.mxgraph.mxCodec.IsEncodeDefaults.
|
inlineprotected |
Returns the XML node attribute name for the given C# field name. That is, it returns the mapping of the field name.
|
inlineprotected |
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. |
|
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.
|
inlineprotected |
Returns the value of the field with the specified name in the specified object instance.
|
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.
References com.mxgraph.mxCodecRegistry.GetName().
Referenced by com.mxgraph.mxCodecRegistry.Register().
|
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.
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. |
Reimplemented in com.mxgraph.mxCellCodec.
|
inlineprotected |
Returns true if the given object is a primitive value.
value | Object that should be checked. |
|
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.
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. |
|
inline |
dec | Codec that controls the encoding/decoding process. |
node | XML node to be checked. |
into | Optional object to pass-thru to the codec. |
References com.mxgraph.mxCodec.Decode(), and com.mxgraph.mxUtils.LoadDocument().
|
inlineprotected |
Sets the value of the field with the specified name in the specified object instance.
|
inlineprotected |
Writes the given value as a child node of the given node.
References com.mxgraph.mxCodec.Encode(), and com.mxgraph.mxCodec.SetAttribute().
|
inlineprotected |
Writes the given value as an attribute of the given node.
References com.mxgraph.mxCodec.Document, and com.mxgraph.mxCodec.SetAttribute().
|
protected |
Array containing the variable names that should be ignored by the codec.
|
protected |
Array containing the variable names that should be turned into or converted from references. See mxCodec.getId and mxCodec.getObject.
|
protected |
Maps from from fieldnames to XML attribute names.
|
protected |
Maps from from XML attribute names to fieldnames.
|
protected |
Holds the template object associated with this codec.
|
get |
Returns the template object associated with this codec.
Referenced by com.mxgraph.mxCodecRegistry.Register().