A contract for identifying instances, specifying their classes, attributes, elements and values, and ultimately reconstructing those instances.
Instances are identified using the Id
's semantics for equality. The
methods of this interface can be called in any order; the id serves to
associate each method invocation with the instance(s) to pertains to.
The only constraint is that reconstruct()
will throw if the context
lacks enough information to fully initialize the requested instance
or any instance reachable from it. Reference cycles are supported.
For example, given
serializable class Person(name, employer) { shared String name; shared Company employer; } serializable class Company(name) { shared String name; shared late Person owner; }
And an instance graph corresponding to:
value wonkaInc = Company("Wonka Inc."); value willy = Person("Willy Wonka", wonkaInc); value umpaLumpa = Person("Umpa lumpa", wonkaInc); wonkaInc.owner = willy;
Then we could reconstruct that instance graph like so:
value dc = deserialization<String>(); dc.attribute("ww", `value Person.name`, "wwn"); dc.attribute("ww", `value Person.employer`, "wi"); dc.attribute("ul", `value Person.name`, "uln"); dc.attribute("ul", `value Person.employer`, "wi"); dc.attribute("wi", `value Company.name`, "win"); dc.attribute("wi", `value Company.owner`, "ww"); dc.instanceValue("win", "Wonka Inc."); dc.instanceValue("wwn", "Willy Wonka"); dc.instanceValue("uln", "Umpa lumpa"); dc.instance("wi", `Company`); dc.instance("ww", `Person`); dc.instance("ul", `Person`); value wonkaInc2 = dc.reconstruct<Company>("wi"); value willy2 = dc.reconstruct<Person>("ww"); value umpaLumpa2 = dc.reconstruct<Person>("ul"); assert(wonkaInc2.owner === willy2); assert(willy2.employer === wonkaInc2); assert(umpaLumpa2.employer === wonkaInc2);
The calls to attribute
, instanceValue()
and instance()
could be
in any order.
no type hierarchy
no supertypes hierarchy
no subtypes hierarchy
Methods | |
attribute | Source Codeshared formal void attribute(Id instanceId, ValueDeclaration attribute, Id attributeValueId) The value of the given Throws
|
element | Source Codeshared formal void element(Id instanceId, Integer index, Id elementValueId) The value at the given Throws
|
instance | Source Codeshared formal void instance(Id instanceId, ClassModel<Anything,Nothing> clazz) The given Throws
|
instanceValue | Source Codeshared formal void instanceValue(Id instanceId, Anything instanceValue) The instance with the given This can used to register non-serializable instances with the context, for example object declarations. |
memberInstance | Source Codeshared formal void memberInstance(Id containerId, Id instanceId) The given This is used for member class instances. Throws
|
reconstruct | Source Codeshared formal Instance reconstruct<Instance>(Id instanceId) Get the instance with the given Throws
|
Inherited Methods |
Methods inherited from: Object |