mxCodecRegistry

Singleton class that acts as a global registry for codecs.

Adding an mxCodec

1.  Define a default codec with a new instance of the object to be handled.

var codec = new mxObjectCodec(new mxGraphModel());

2.  Define the functions required for encoding and decoding objects.

codec.encode = function(enc, obj) { ... }
codec.decode = function(dec, node, into) { ... }

3.  Register the codec in the mxCodecRegistry.

mxCodecRegistry.register(codec);

mxObjectCodec.decode may be used to either create a new instance of an object or to configure an existing instance, in which case the into argument points to the existing object.  In this case, we say the codec “configures” the object.

Summary
mxCodecRegistrySingleton class that acts as a global registry for codecs.
Variables
codecsMaps from constructor names to codecs.
aliasesMaps from classnames to codecnames.
Functions
registerRegisters a new codec and associates the name of the template constructor in the codec with the codec object.
addAliasAdds an alias for mapping a classname to a codecname.
getCodecReturns a codec that handles objects that are constructed using the given constructor.

Variables

codecs

Maps from constructor names to codecs.

aliases

Maps from classnames to codecnames.

Functions

register

register: function(codec)

Registers a new codec and associates the name of the template constructor in the codec with the codec object.

Parameters

codecmxObjectCodec to be registered.

addAlias

addAlias: function(classname,
codecname)

Adds an alias for mapping a classname to a codecname.

getCodec

getCodec: function(ctor)

Returns a codec that handles objects that are constructed using the given constructor.

Parameters

ctorJavaScript constructor function.
register: function(codec)
Registers a new codec and associates the name of the template constructor in the codec with the codec object.
addAlias: function(classname,
codecname)
Adds an alias for mapping a classname to a codecname.
getCodec: function(ctor)
Returns a codec that handles objects that are constructed using the given constructor.
XML codec for JavaScript object graphs.
Singleton class that acts as a global registry for codecs.
mxObjectCodec.prototype.decode = function(dec,
node,
into)
Parses the given node into the object or returns a new object representing the given node.
Generic codec for JavaScript objects that implements a mapping between JavaScript objects and XML nodes that maps each field or element to an attribute or child node, and vice versa.
Close