Skip to main content

%ZEN.proxyObject

Class %ZEN.proxyObject Extends %RegisteredObject [ Deprecated, Final, System = 3 ]

The Zen Proxy class provides a way to assemble data that can be conveniently passed between the web client and the server. It works in conjunction with the zenProxy JavaScript class defined in zenutils.js. The zenProxy class is the client-side representation of the server-side %ZEN.proxyObject class and vice versa.
The %ZEN.proxyObject class is useful for cases where you do not know what run-time properties will exist when you are designing your application (perhaps it is user-configurable).
The proxy class can be used in several ways. You can use it to send an arbitrary set of data values from the client to a server-side method. To do this, create an instance of zenProxy in a client-side JavaScript method: // create instance of zenProxy var obj = new zenProxy(); obj.name = 'Smith'; obj.code = 'CRM114'; The zenProxy object is basically a generic JavaScript object with a few pre-defined behaviors. You can dynamically add properties to it simply by setting them. These properties should have literal values, that is, they should not refer to other JavaScript objects.
If you define a server-side ZenMethod whose signature includes an argument of type %ZEN.proxyObject, then you can invoke this method from the client passing it an instance of a zenProxy object. Zen will automatically marshal the values in the zenProxy object into an instance of the %ZEN.proxyObject object.
For example, suppose you have defined a server method: ClassMethod MyMethod(pProxy as %ZEN.proxyObject) As %Boolean [ZenMethod] { Set tName = pProxy.name Set tCode = pProxy.code Quit 1 } The client can invoke this method as it would any other Zen method, passing an instance of zenProxy as the pProxy argument: var obj = new zenProxy(); obj.name = 'Smith'; obj.code = 'CRM114'; var ok = this.MyMethod(obj); The MyMethod method will see the values 'Smith' and 'CRM114' for the properties name and code, respectively.
You can also use the %ZEN.proxyObject class to pass values from a server method back to the client. To do this, create a server method whose return type is %ZEN.proxyObject: ClassMethod GetServerInfo() As %ZEN.proxyObject [ZenMethod] { Set tProxy = ##class(%ZEN.proxyObject).%New() Set tProxy.whatever = "Some server value" Quit tProxy } The client can invoke this method and use its return value as an object: var obj = this.GetServerInfo(); alert(obj.whatever); The %ZEN.proxyObject does not actually define any properties. Instead it maintains an internal array of property names along with their corresponding values and uses dynamic dispatch to handle references to specific properties. This means that there is no name checking for properties of %ZEN.proxyObject (the same behavior as JavaScript objects). You can remove the current set of properties within a %ZEN.proxyObject object using the %Clear method. You can find out what the current set of properties is (as a local array) or supply a new set using the %CopyToArray and %CopyFromArray methods.
The client-side zenProxy class defines only one public method, clear, which deletes the current set of properties from the object. In all other ways, you can treat is an instance of JavaScript Object.
You can get the set of values within a %ZEN.Auxiliary.dataController objects using its getDataAsObject method.
When using the %ZEN.proxyObject class keep the following things in mind:

  • All properties must have literal values (numbers or strings).
  • You have to use property names that are valid in both the client and server environments. This means that names have to agree in case. It also means that you cannot have two properties with the same name but different case. Note that %ZEN.proxyObject DOES support various property names that are valid in Javascript but were not traditionally valid Objectscript property names. In general, these property names include symbols like "$" and "_" that are relatively common in Javascript. To reference such a property in a %ZEN.proxyObject instance, simply delimit the property name using quotes: Set myProperty = tProxy."my_property" Set tProxy."$$foo" = "bar"

Properties

%changed

Property %changed As %ZEN.Datatype.boolean(XMLPROJECTION = "NONE") [ InitialExpression = 0, Internal ];

Internal property used to track if this object is modified.

%index

Property %index As %ZEN.Datatype.integer(XMLPROJECTION = "NONE") [ Internal ];

Internal property used to client index of this object.

%data

Property %data As %ZEN.Datatype.string(XMLPROJECTION = "NONE") [ Internal, MultiDimensional ];

Internal array of data values within the proxy, indexed by series and property name.

Methods

%DispatchGetProperty

Method %DispatchGetProperty(pProperty As %String) [ Final, Internal ]

Property dispatch method to catch references to virtual properties.
This should not be called directly.

%DispatchSetProperty

Method %DispatchSetProperty(pProperty As %String, pValue As %String) [ Final, Internal ]

Property dispatch method to catch references to virtual properties.
This should not be called directly.

%Clear

Method %Clear() [ Final ]

Delete all properties and data currently in the proxy object.

%CopyToArray

Method %CopyToArray(Output pArray) [ Final ]

Copy the properties in this proxyObject into a local array subscripted by property name.

%CopyFromArray

Method %CopyFromArray(ByRef pArray) [ Final ]

Copy the values from a local array (subscripted by property name) into this proxyObject.

%ZENDeserialize

Method %ZENDeserialize(pState As %String, ByRef pObjSet) As %Status [ Final, Internal ]

%ObjectSynch

Method %ObjectSynch() As %Status [ Final, Internal ]

Synchronize this object with its client version.

%Serialize

Method %Serialize() As %Status [ Final, Internal ]

Serialize this object so that it can be shipped to the client.

%Create

ClassMethod %Create(pState As %String) As %ZEN.proxyObject [ Internal ]

Given a string from the client, see if it contains a packed representation of a proxyObject. If it does, unpack and return a new object, otherwise return "".

hasJSONContent

Method hasJSONContent(pFormat As %String) As %Boolean [ Internal ]

Drill down just enough to find out if the object has any content displayable as JSON given the current pFormat options

%ToJSON

Method %ToJSON(pLevel As %Integer = 0, pFormat As %String = "aelotw") As %Status [ Internal ]

Write out the contents of this proxy object to the current device in JSON format.
This method is called when a proxy object is used in conjunction with the %ZEN.Auxiliary.jsonProvider component.
pFormat is a flags string to control output formatting options.
The following character option codes are supported:
1-9 : indent with this number of spaces (4 is the default with the 'i' format specifier)
a - output null arrays/objects
b - line break before opening { of objects
c - output the ObjectScript-specific "_class" and "_id" properties (if a child property is an instance of a concrete object class)
e - output empty object properties
i - indent with 4 spaces unless 't' or 1-9
l - output empty lists
n - newline (lf)
o - output empty arrays/objects
q - output numeric values unquoted even when they come from a non-numeric property
s - use strict JSON output - NOTE: special care should be taken when sending data to a browser, as using this flag may expose you to cross site scripting (XSS) vulnerabilities if the data is sent inside <script> tags. Zen uses this technique extensively, so this flag should NOT be specified for jsonProviders in Zen pages.
t - indent with tab character
u - output pre-converted to UTF-8 instead of in native internal format
w - Windows-style cr/lf newline

%Print

Method %Print(pLevel As %Integer = 0) [ Internal ]

Utility method.
Print out contents of this proxy object to the current device.

Enumerate

Method Enumerate(Client As %ZEN.proxyObjectEnumeratee, pLevel As %Integer = 0) As %Status [ Internal ]

Enumerate the contents of this proxy object, calling Client for each node

DeleteDocument

ClassMethod DeleteDocument(pWhere As %ZEN.Datatype.string, pDocumentID As %ZEN.Datatype.string = "") As %Status

DeleteDocument will delete a document identified by ID from the specified global or local variable reference (GLVN). If a document with the specified ID does not exist in that GLVN then DeleteDocument will return an error in the returned %Status value.

ParameterspWhereInputGlobal or local variable reference. This is the location from where the proxyObject instance will be deleted.
pDocumentIDInputThe document ID.

DocumentExists

ClassMethod DocumentExists(pWhere As %ZEN.Datatype.string, pDocumentID As %ZEN.Datatype.string = "") As %ZEN.Datatype.boolean

DocumentExists() returns a boolean value indicate whether or not the documentID exists in the global/local variable reference (GLVN).

ParameterspWhereInputGlobal or local variable reference where documents are stored.
pDocumentIDInputThe document ID.

OpenDocument

ClassMethod OpenDocument(pWhere As %ZEN.Datatype.string, pDocumentID As %ZEN.Datatype.string, Output pStatus As %Status = "") As %ZEN.proxyObject

OpenDocument will retrieve a previously saved document from the specified global or local variable reference (GLVN) with the specified pDocumentID and return an oref referencing an instance of %ZEN.proxyObject. If a document with the specified ID does not exist in that GLVN then OpenDocument will return an error in the output pStatus parameter.

Parameters

pWhere

Input

Global or local variable reference. This is the location where the proxyObject instance will be saved.

pDocumentID

Input

The ID of the document to be opened.

pStatus

Output

The returned %Status value, indicating success or failure.

OpenEmbeddedDocument

ClassMethod OpenEmbeddedDocument(pWhere As %ZEN.Datatype.string, pDocumentID As %ZEN.Datatype.string, pObjectID As %ZEN.Datatype.string, Output pStatus As %Status = "") As %ZEN.proxyObject

OpenEmbeddedDocument will retrieve a document embedded in a previously saved document from the specified global or local variable reference (GLVN) with the specified pDocumentID and return an oref referencing an instance of %ZEN.proxyObject. If a document with the specified documentID does not exist in that GLVN then OpenDocument will return an error in the output pStatus parameter. If an embedded document with the specified objectID does not exist in that GLVN then OpenDocument will return an error in the output pStatus parameter.

Parameters

pWhere

Input

Global or local variable reference. This is the location where the proxyObject instance will be saved.

pDocumentID

Input

The ID of the document containing the embedded document.

pObjectID

Input

The objectID of the document embedded in the specified pDocumentID.

pStatus

Output

The returned %Status value, indicating success or failure.

SaveDocument

Method SaveDocument(pWhere As %ZEN.Datatype.string, pDocumentID As %ZEN.Datatype.string = "") As %Status

SaveDocument will save the proxyObject to a global or local variable reference (GLVN) with the specified pDocumentID. If a document with the same ID already exists in that GLVN then SaveDocument will return an error in the returned %Status value.

ParameterspWhereInputGlobal or local variable reference. This is the location where the proxyObject instance will be saved.
pDocumentIDInputThe document ID. This value must be unique within the GLVN specified in pWhere.

loadObject

ClassMethod loadObject(pObject As %Library.RegisteredObject, pWhere As %ZEN.Datatype.string, pDocumentID As %ZEN.Datatype.string, pObjectID As %ZEN.Datatype.integer, ByRef pOQ, ByRef pOREF) [ Internal ]

loadList

ClassMethod loadList(pObject As %Collection.AbstractList, pWhere As %ZEN.Datatype.string, pDocumentID As %ZEN.Datatype.string, pObjectID As %ZEN.Datatype.integer, ByRef pOQ, ByRef pOREF) [ Internal ]