IRISLIB database
DynamicAbstractObject Class Reference
Inheritance diagram for DynamicAbstractObject:
Collaboration diagram for DynamicAbstractObject:

Public Member Functions

 clear ()
 remove all elements of the current set, throws an exception if this operation is More...
 
_.Library.Boolean contains (_.Library.DataType key)
 return true if the key is currently an element of the set, false otherwise.
 
_.Library.Boolean containsAll (_.Library.DynamicArray array)
 return true if the set contains() all key[n] where 0n size(array)
 
_.Library.Any get (_.Library.DataType key)
 get the element identified by key
 
_.Library.Iterator iterator ()
 return an iterator over the elements of this set
 
_.Library.DynamicAbstractObject put (_.Library.DataType key, _.Library.Any value, _.Library.String type)
 put the value into the set with the element name (id) of key. More...
 
_.Library.DynamicAbstractObject putAll (_.Library.DynamicAbstractObject key, _.Library.DynamicArray value)
 
_.Library.DynamicAbstractObject putAllIfAbsent (_.Library.DynamicAbstractObject key, _.Library.DynamicArray value)
 
_.Library.AbstractSet putIfAbsent (_.Library.DataType key, _.Library.Any value)
 
_.Library.Any remove (_.Library.DataType key)
 
_.Library.DynamicArray removeAll (_.Library.DynamicArray key)
 
_.Library.DynamicArray removeIf (_.Library.RawString expression)
 remove all of the elements matching the expression More...
 
_.Library.DataType rename (_.Library.DataType currentkey, _.Library.DataType newkey)
 replace the key of the element identified by currentKey with newKey More...
 
_.Library.Any replace (_.Library.DataType key, _.Library.Any value)
 replace the value of the element identified by key with value More...
 
_.Library.DynamicArray replaceAll (_.Library.DynamicArray key, _.Library.DynamicArray value)
 replace all {keys[n], values[n]} members, return an array containing the replaced values More...
 
_.Library.Integer size ()
 return the number of elements in the current set
 
_.Library.String toString ()
 > More...
 

Private Member Functions

_.Library.DynamicAbstractObject Clear ()
 Remove all the data from the dynamic object, leaving a blank object intact. More...
 
_.Iterator.AbstractIterator GetIterator ()
 
_.Library.String GetTypeOf (_.Library.DataType key)
 Find out the type of value. More...
 
_.Library.Integer Size ()
 Find the size of an DynamicArray or a DynamicObject. More...
 
_.Library.String ToJSON (_.Stream.Object outstrm)
 Convert a DynamicAbstractObject into a JSON string. More...
 
_.Library.DynamicAbstractObject __ConvertStreamToValue (value)
 The parameter 'value' must be a Stream. More...
 
_.Library.Boolean _isLabeled ()
 @Override
 

Static Private Member Functions

_.Library.DynamicAbstractObject FromJSON (_.Library.RawString str)
 Given a JSON source, parse the source and return an object of type. More...
 
_.Library.DynamicAbstractObject FromJSONFile (_.Library.RawString filename)
 Given a filename, parse the contents and return an object of type. More...
 
_.Library.DynamicAbstractObject FromOref (_.Library.AbstractSet source)
 FromOref() will return an instance of DynamicAbstractObject populated from the source object. More...
 

Detailed Description

For information on the API provided by this superclass, see Using Dynamic Entities.

Dynamic Entity base class.

Member Function Documentation

◆ Clear()

Remove all the data from the dynamic object, leaving a blank object intact.

For information on the API provided by this superclass, see Using Dynamic Entities.

Dynamic Entity base class.

return $this to allow chaining.

◆ FromJSON()

_.Library.DynamicAbstractObject FromJSON ( _.Library.RawString  str)
staticprivate

Given a JSON source, parse the source and return an object of type.

<class>DynamicAbstractObject</class>. If an error occurs during parsing, an exception will be thrown.

str The input can be from a number of sources

(1) A string value containing the source.
(2) A stream object to read the source from.

Returns An object of type DynamicAbstractObject containing the parsed JSON.

NOTE: RFC 7159 specifies that the default encoding for JSON values uses UTF-8. This implies that for streams not containing 16-bit Unicode it may be necessary to explicitly convert individual character values via a call to $ZCONVERT (e.g. $zcvt(value,"I","UTF8") ) or entire streams by setting the TranslateTable attribute of the stream to "UTF8".

set filename = "c:/iscsrc/json/greg4.json" set stream = ##class(Stream.FileCharacter).New() set sc = stream.LinkToFile(filename) if ('sc) { w "Error on linking file "_filename,! q } try { set obj = ##class(DynamicAbstractObject).FromJSON(stream) } catch ex { w "Error. Unable to parse file "_filename,! w "Error type "_ex.Name,! w "Error code "_ex.Code,! w "Error location "_ex.Location,! set obj = "" } q obj

set src = "{""name"" : ""greg"", ""weight"" : 220 }" set obj = ##class(DynamicAbstractObject).FromJSON(src)

◆ FromJSONFile()

_.Library.DynamicAbstractObject FromJSONFile ( _.Library.RawString  filename)
staticprivate

Given a filename, parse the contents and return an object of type.

<class>DynamicAbstractObject</class>. If an error occurs during parsing, an exception will be thrown.

filename A file URI where the source can be read. The file must be encoded as UTF-8.

Returns An object of type DynamicAbstractObject containing the parsed JSON.

◆ FromOref()

_.Library.DynamicAbstractObject FromOref ( _.Library.AbstractSet  source)
staticprivate

FromOref() will return an instance of DynamicAbstractObject populated from the source object.

request object

NameDescription
source Oref of the object to be cast as a DynamicAbstractObject.
returnValue An oref referencing the DynamicAbstractObject.


    set person = ##class(Sample.Person).OpenId(50)
    set object = ##class(DynamicObject).FromOref(person)
    

◆ GetIterator()

_.Iterator.AbstractIterator GetIterator ( )
private

Perform an iteration of all the values in a DynamicAbstractObject subclass.

In the example below, we will output all values contained in a <class>DynamicArray</class> or a <class>DynamicObject</class>.

set iter = AbstractObject.GetIterator() while iter.GetNext(.key, .value, .type ) { write "key = "_key_", value = "_value_", type = "_type,! }

See the descriptions of the <method class="%Iterator.AbstractIterator">GetNext</method> in the <class>Iterator.Array</class> and <class>Iterator.Object</class> classes for more details.

Reimplemented in DynamicObject, and DynamicArray.

◆ GetTypeOf()

_.Library.String GetTypeOf ( _.Library.DataType  key)
private

Find out the type of value.

Returns One of the following strings are returned.
"null" - JSON null
"boolean" - Either "true" or "false"
"number" - Any numeric value
"oref" - An ObjectHandle (an ObjectScript oref)
"object" - A nested object
"array" - A nested array
"string" - Normal text string
"unassigned" - The value is unassigned

◆ Size()

_.Library.Integer Size ( )
private

Find the size of an DynamicArray or a DynamicObject.

Returns An integer showing the size of the array or object. In the case of an array, the size includes unassigned entries within the array. In the case of an object, the size only includes elements that have assigned values.

◆ ToJSON()

_.Library.String ToJSON ( _.Stream.Object  outstrm)
private

Convert a DynamicAbstractObject into a JSON string.

outstrm is optional. There are a number of possibilities:
(1) Parameter outstrm is not defined and the method is called via 'DO'. In this case the JSON string is written to the current output device.
(2) Parameter outstrm is not defined and the method is called as an expression. In this case the JSON string becomes the value of the expression.
(3) Parameter outstrm is defined. If it is Stream object then the JSON string will be written to the stream. If outstrm is present but not an object then it is presumed to be a fully qualified file specification. In that case, a <class>Stream.FileCharacter</class> stream is created, linked to that file and the JSON string is written to that stream. On completion, this stream is saved. The full path to the file must be defined. If outstrm is an object but is not an instance of Stream.Object then an exception will be thrown.

NOTE: RFC 7159 specifies that the default encoding for JSON values uses UTF-8. When writing a stream containing 8-bit characters this implies that it may be necessary to explicitly convert individual values via a call to $ZCONVERT (e.g. $zcvt(value,"O","UTF8") ) or entire streams by setting the TranslateTable attribute of the stream to "UTF8"

set obj = {"title" : "MR" , "lastname" : "JONES"} set obj.firstname = "JIMMY" do obj.ToJSON() {"title":"MR","lastname":"JONES","firstname":"JIMMY"} set source = obj.ToJSON() write source {"title":"MR","lastname":"JONES","firstname":"JIMMY"}

◆ __ConvertStreamToValue()

_.Library.DynamicAbstractObject __ConvertStreamToValue (   value)
private

The parameter 'value' must be a Stream.

The contents of 'value' will be

placed in a <class>DynamicString</class>, <class>DynamicBinary</class> or <class>DynamicBase64</class> object.

Returns The generated <class>DynamicString</class>, <class>DynamicBinary</class> or <class>DynamicBase64</class> object.

◆ clear()

clear ( )

remove all elements of the current set, throws an exception if this operation is

not supported or the set cannot be cleared.

◆ put()

put the value into the set with the element name (id) of key.

If an element with this key is already present in the set then that element's value is replaced by value

parameters:

  • key: key to put into the set
  • value: value to put into the set
  • type: type of the value, refer to <method>GetTypeOf</method> for a list of supported types

returns:

  • oref referencing the modified DAO, this may be different from the current oref

throws:

  • exception

◆ putAll()

put all {keys[n], values[n]} elements where 0n size(keys) into the DAO

parameters:

  • keys: array of keys to put into the DAO
  • values: array of values to put into the DAO

returns:

  • oref referencing the modified DAO

throws:

  • exception

◆ putAllIfAbsent()

put all {keys[n], values[n]} elements where 0n size(keys) and keys[n] is not already associated with a value in the set.

parameters:

  • keys: array of keys to be put into the set
  • values: array of values to be put into the set

returns:

  • oref referencing the modified set

throws:

  • exception

◆ putIfAbsent()

_.Library.AbstractSet putIfAbsent ( _.Library.DataType  key,
_.Library.Any  value 
)

put the {key, value} element into the set. If contains(key) is false or get(key) is null then put(key,value)

parameters:

  • key: key to put into the set
  • value: value to put into the set

returns:

  • oref referencing the modified set

throws:

  • exception

◆ remove()

remove the element identified by key from the set

parameters:

  • key: key of element to be removed from the set

returns:

  • the removed element or null if that element doesn't exist

throws:

  • exception

◆ removeAll()

remove all elements identified by keys[n] where 0n size(keys) from the set

parameters:

  • keys: array of keys to be removed from the set

returns:

  • array of removed elements (null element if key doesn't exist)

throws:

  • exception

◆ removeIf()

_.Library.DynamicArray removeIf ( _.Library.RawString  expression)

remove all of the elements matching the expression

parameters:

  • expression: elements matching expression are to be removed

returns:

  • array of removed elements (null element if key doesn't exist)

throws:

  • exception

◆ rename()

_.Library.DataType rename ( _.Library.DataType  currentkey,
_.Library.DataType  newkey 
)

replace the key of the element identified by currentKey with newKey

parameters:

  • currentkey - current key of the element to be renamed
  • newkey - new key to assign to the element

returns:

  • the current key if the element exists, null otherwise

throws:

  • exception

◆ replace()

_.Library.Any replace ( _.Library.DataType  key,
_.Library.Any  value 
)

replace the value of the element identified by key with value

parameters:

  • key - key of the element to be replaced
  • value - new value of the element

returns:

  • return the previous value of the element

throws:

  • exception

◆ replaceAll()

replace all {keys[n], values[n]} members, return an array containing the replaced values

parameters:

  • keys: array of keys of the elements to be replaced
  • values: array of values of the elements

returns:

  • array of previous element values

throws:

  • exception

◆ toString()

_.Library.String toString ( )

>

The toString() method returns the contents of a set as a string.