Hemi JavaScript Framework

Hemi

Description

Framework base classes, including: Hemi for creating framework objects and loading external libraries; Hemi.xml for AJAX and JSON requests (libXmlRequest derivative); Hemi.registry for object repository management; Hemi.message for delegating message subscriptions and publications.

Class Index

version 3.1.0

The base set of classes for the Hemi Framework.

This class resides in the global namespace.

Index

Object Index

Objects

Hemi

The core class used to load and manage framework classes.

static Hemi

version

This class resides in the global namespace.

Index

Example Index

Object Index

Property Index

Method Index

Examples

Create Framework Object

Demonstrate how to create a new Framework Object

Example Code

// Create a new object that is also registered
var oNewObject = Hemi.newObject("myObject","1.0", true);
var sId = oNewObject.getObjectId();
// Retrieve the object from the registry
var oLookup = Hemi.registry.service.getObject(sId);

Prepare an Existing Object for the Framework

Demonstrate how to prepare an existing object for the framework and use a custom identifier.

Example Code

// Prepare an existing object and give it a custom id
var oObject = {};
oObject.object_id = "MyCustomId";
Hemi.prepareObject("myObject", "1.0", true, oObject);
// Retrieve the object from the registry
var oLookup = Hemi.registry.service.getObject("MyCustomId");

Objects

DATATYPES

Enumeration of object types.

Properties

FrameworkObject

API definition for any object created by the Hemi Framework.

Properties

Methods

Properties

Syntax

String = Hemi.

Hemi. = String

Methods

_forName

Creates a specific internal object. Includes the definition for base_object, and supports external definitions via class imports. Method is private and should not be directly referenced.

Syntax

o = _forName( s )

Parameters

Returns

o as object: Object based on the specified name.

_implements

Implements a specified feature. Method is private and should not be directly referenced.

Syntax

void _implements( o, n, v )

Parameters

getLibrary

Returns the specified namespace object.

Syntax

NamespaceObject = getLibrary( sName )

Parameters

Returns

NamespaceObject as object: Returns an internal namespace object.

GetSpecifiedAttribute

Returns the value of an attribute if it was specified and the length is greater than zero.

Syntax

v = GetSpecifiedAttribute( o, n )

Parameters

Returns

v as String: Value of the attribute.

guid

Returns a globally unique identifier, relative to the page view. This uses a weak hash.

Syntax

sId = guid( )

Returns

sId as String: A unique id.

hashlight

A very light hash.

Syntax

sHash = hashlight( sData )

Parameters

Returns

sHash as String: A light hash of the input data.

include

Imports the specified namespace.

Syntax

NamespaceObject = include( sName, sPath, bNoEval )

Parameters

Returns

NamespaceObject as object: Returns an internal namespace object.

IsAttributeSet

Tests whether an attribute has been set.

Syntax

b = IsAttributeSet( o, n, b )

Parameters

Returns

b as bit: A bit indicating whether the specified attribute was set.

isImported

Returns the object identifier.

Syntax

bImported = isImported( s )

Parameters

Returns

bImported as boolean: Bit indicating whether the namespace has been imported.

log

Sends a message in the #100.3 message block.

Syntax

void log( sMessage )

Parameters

logDebug

Sends a message in the #100.1 message block.

Syntax

void logDebug( sMessage )

Parameters

logError

Sends a message in the #100.5 message block.

Syntax

void logError( sMessage )

Parameters

logWarning

Sends a message in the #100.4 message block.

Syntax

void logWarning( sMessage )

Parameters

lookup

Verifies the specified hierarchy exists.

Syntax

v = lookup( sPath )

Parameters

Returns

v as boolean: Returns true if the hierachy exists, or the matching object if bObjOut is set to true.

namespace

Creates a hierarchical object namespace from the supplied name.

Syntax

void namespace( sPath, oBase, hContents, bService )

Parameters

newObject

Creates and optionally registers a new FrameworkObject ready for use within the framework.

Syntax

o = newObject( t, v, r, d, h )

Parameters

Returns

o as FrameworkObject: The new framework object.

prepareObject

Prepares and optionally registers a new FrameworkObject ready for use within the Hemi framework.

Syntax

void prepareObject( t, v, r, o, d )

Parameters

static registry.service

version 3.1.0

Static implementation of hemi.registry.serviceImpl

This class resides in the global namespace.

Index

Method Index

Methods

getApplyStatement

Returns a string statement that can be evaluated to return a reference to the specified method for the registered object.

Syntax

sApplyCode = getApplyStatement( o, f )

Parameters

Returns

sApplyCode as String: A javascript statement which, when evaluated, returns a reference to the function on the object.

getEvalStatement

Returns a string statement that can be evaluated to return a reference to the registered object.

Syntax

sEvalCode = getEvalStatement( o )

Parameters

Returns

sEvalCode as String: A javascript statement which, when evaluated, returns a reference to the object.

registry.serviceImpl

version 3.1.0

Repository service for storing and discovering framework objects.

This class resides in the global namespace.

Index

Method Index

Methods

addObject

Adds the specified object to the registry, and automatically registers the object with the transaction service.

Syntax

b = addObject( o )

Parameters

Returns

b as boolean: Returns true if the object was added to the registry.

canRegister

Verifies whether an object can be added to the registry.

Syntax

b = canRegister( o )

Parameters

Returns

b as boolean: Returns true if the specified object defines an

getObject

Returns the object matching the specified identifier or index.

Syntax

o = getObject( v )

Parameters

Returns

o as object: Object with the specified identifier or index.

getObjectsArray

Returns an array of registered objects.

Syntax

a = getObjectsArray( )

Returns

a as array: Array of registered objects.

getObjectsMap

Returns the object identifier mapping.

Syntax

a = getObjectsMap( )

Returns

a as array: Array of object identifiers directly mapped to the objects array.

isRegistered

Returns true if the specified object is in the registry.

Syntax

b = isRegistered( o )

Parameters

Returns

b as boolean: Returns true if the object is in the registry.

removeObject

Removes the specified object from the registry.

Syntax

b = removeObject( o, b )

Parameters

Returns

b as boolean: Returns true if the object was removed.

sendDestroyTo

Invokes the destroy method on the specified object. Object must be registered. This method will not remove the object from the registry.

Syntax

b = sendDestroyTo( o )

Parameters

Returns

b as boolean: Returns true if the object defined a destroy method and the method was invoked.

sendSigterm

Sends a termination signal to all registered objects for preparation to be destroyed. This method causes all objects to be removed from the registry, and to have any sigterm method invoked.

Syntax

void sendSigterm( )

static message.service

version 3.1.0

Static implementation of hemi.message.serviceImpl

This class resides in the global namespace.

message.serviceImpl

version 3.1.0

Service that delegates subscriptions and publications at a global and object level.

This class resides in the global namespace.

Index

Object Index

Method Index

Objects

Message

Object published to onsendmessage subscribers when the sendMessage method is invoked.

Properties

Methods

_delayPublish

End action for a delayed publication. Cached message is sent directly on to publication. Method is private and should not be directly referenced.

Syntax

void _delayPublish( i )

Parameters

_publish

Publishes the specified data to registered subscribers. Method is private and should not be directly referenced.

Syntax

void _publish( e, v )

Parameters

clearEntries

Clears message entries.

Syntax

void clearEntries( )

flush

Clears delayed delivery cache.

Syntax

void flush( )

getDeliveryDelay

Returns the delay in milliseconds between publication and delivery.

Syntax

d = getDeliveryDelay( )

Returns

d as int: Delay in milliseconds between publication and delivery.

getEntries

Returns the current message buffer.

Syntax

aBuffer = getEntries( )

Returns

aBuffer as array: Array of recent messages.

getReportThreshold

Returns the report threshold for sendMessage. Messages sent below this level will not be propogated.

Syntax

iThreshold = getReportThreshold( )

Returns

iThreshold as int: The message threshold.

parseMessage

Parses a message object and returns a formatted construct suitable for printing to a log.

Syntax

sMessage = parseMessage( o )

Parameters

Returns

sMessage as String: Formatted message.

publish

Publishes the specified data to registered subscribers. If delayed delivery is in effect, caches the message data and sends it after the preset delay in milliseconds.

Syntax

void publish( e, v )

Parameters

sendMessage

Sends the specified message as a Message to all onsendmessage subscribers.

Syntax

o = sendMessage( d, s, p )

Parameters

Returns

o as Message: The Message created for this message.

setDeliveryDelay

Sets the delay in milliseconds between publication and delivery.

Syntax

void setDeliveryDelay( d )

Parameters

setReportThreshold

Sets the report threshold for sendMessage. Messages sent below this level will not be propogated.

Syntax

void setReportThreshold( level )

Parameters

sigterm

Termination signal indicating the message service should stop processing messages and subscriptions, and be prepared for destruction.

Syntax

void sigterm( )

subscribe

Subscribes an object to receive message publications for the specified publication name.

Syntax

void subscribe( o, e, f, v )

Parameters

unsubscribe

Unsubscribes an object from receiving message publications for the specified publication name.

Syntax

b = unsubscribe( o, e, f )

Parameters

Returns

b as boolean: Returns true if unsubscribed, false otherwise.

static xml

version 3.1.0

XML Utilities for making AJAX and JSON requests, result caching, request pooling, and XML-XHTML node manipulation.

This class resides in the global namespace.

Index

Example Index

Object Index

Property Index

Method Index

Message Index

Examples

Asynchronous GET

Make an asynchronous request for an XML document.

Syntax

[int] = getXml(path,custom_handler,1,{optional_id});

Example Code

function HandleXml(s,v){
   var oXml = v.xdom;
}
Hemi.xml.getXml("/Data/Test1.xml",HandleXml,1);

Asynchronous POST

Asynchronously post data to the server.

Syntax

[int] = postXml(path,data,custom_handler,1,{optional_id});

Example Code

function HandleXml(s,v){
   var oResponseXml = v.xdom;
}
var oPostThis = Hemi.xml.newXmlDocument("Request");
var oResponseXml = Hemi.xml.postXml("/Data/TestData.aspx",oPostThis,HandlePostXml,1);

Cached Asynchronous GET

Asynchronously request an XML document, and cached the result for later referal.

Syntax

[int] = getXml(path,custom_handler,1,request_id,1);

Example Code

function HandleXml(s,v){
   var oXml = v.xdom;
}
Hemi.xml.getXml("/Data/Test1.xml",HandleXml,1,"cache-me",1);

Synchronous GET

Make a synchronous request for an XML document.

Syntax

[xml_dom_object] = getXml(path);

Example Code

var oXml = Hemi.xml.getXml("/Data/Test1.xml");

Synchronous POST

Synchronously post data to the server.

Syntax

[xml_dom_object] = postXml(path,data);

Example Code

var oPostThis = Hemi.xml.newXmlDocument("Request");
var oData = oPostThis.createElement("data");
oData.setAttribute("id","data-id");
oData.setAttribute("value","data-value");
oPostThis.documentElement.appendChild(oData);
var oResponseXml = Hemi.xml.postXml("/Data/TestData.aspx",oPostThis);

Objects

XmlHttp

Object representing a pooled XMLHTTP resource Object is private and should not be directly referenced.

Properties

XmlObject

Object passed to the event handler following an XML request using getXml or postXml.

Properties

Properties

auto_content_type

Specifies whether to determine posted content type by included post value.

Syntax

boolean = xml.auto_content_type

xml.auto_content_type = boolean

ax_http_control

Specifies the name of the registered ActiveX control to use for XML requests.

Syntax

String = xml.ax_http_control

xml.ax_http_control = String

ax_http_control

Specifies the name of the registered ActiveX control to use for XML requests.

Syntax

String = xml.ax_http_control

xml.ax_http_control = String

form_content_type

Specifies the content type to use when auto_content_type is true and the post value is a string.

Syntax

String = xml.form_content_type

xml.form_content_type = String

gadget_base_path

Specifies the base path to use when operating in Gadget mode. The base path should be in the format of a file URI, such as file:///c:/....

Syntax

String = xml.gadget_base_path

xml.gadget_base_path = String

gadget_control

Specifies the name of the registered ActiveX control to use for XML requests when in Gadget mode.

Syntax

String = xml.gadget_control

xml.gadget_control = String

gadget_mode

Specifies whether the xml package is operating in a mode that better supports Windows Sidebar Gadgets.

Syntax

boolean = xml.gadget_mode

xml.gadget_mode = boolean

text_content_type

Specifies the content type to use requesting and receiving text data (eg: JSON).

Syntax

String = xml.text_content_type

xml.text_content_type = String

Default Value

xml_content_type

Specifies the content type to use posting data.

Syntax

String = xml.xml_content_type

xml.xml_content_type = String

Default Value

Methods

_request_xmlhttp

Assembles and opens an XMLHTTP Request. Method is private and should not be directly referenced.

Syntax

v = _request_xmlhttp( p, h, a, i, x, d, c, t )

Parameters

Returns

v as variant: Returns a boolean value for asynchronous requests, and an XML Document for synchronous requests.

clear

Clears the request maps and caches.

Syntax

void clear( )

clearCache

Clears the response cache.

Syntax

void clearCache( )

getCacheEnabled

Syntax

b = getCacheEnabled( )

Returns

b as boolean: boolean indicating whether caching is enabled.

getCDATAValue

Returns a concatenation of all CDATA values that are immediate children of the specified node.

Syntax

v = getCDATAValue( n )

Parameters

Returns

v as String: Returns a concatenation of all child CDATA values.

getInnerText

Returns a concatenation of text nodes belonging to all children of the specified node.

Syntax

sTxt = getInnerText( n )

Parameters

Returns

sTxt as String: Returns the inner text of the specified node.

getJSON

Retrieve a JSON object from the specified path.

Syntax

v = getJSON( p, h, a, i, c )

Parameters

Returns

v as variant: Returns boolean for asynchronous operations, and a JSON object for synchronous operations.

getPoolEnabled

Syntax

b = getPoolEnabled( )

Returns

b as boolean: boolean indicating whether pooling is enabled.

getRequestArray

Returns an array of XML requests.

Syntax

aRequests = getRequestArray( )

Returns

aRequests as array: An array of requests.

getText

Retrieve text from the specified path.

Syntax

v = getText( p, h, a, i, c )

Parameters

Returns

v as variant: Returns boolean for asynchronous operations, and text for synchronous operations.

getXml

Retrieve an XML document from the specified path.

Syntax

v = getXml( p, h, a, i, c )

Parameters

Returns

v as variant: Returns boolean for asynchronous operations, and an XMLDocument object for synchronous operations.

getXmlHttpArray

Syntax

aXml = getXmlHttpArray( )

Returns

aXml as array: Array of XmlHttp objects.

getXmlHttpObjectFromPool

Retrieves the next available XmlHttp object from the pool of available resources. Method is private and should not be directly referenced.

Syntax

oXml = getXmlHttpObjectFromPool( y )

Parameters

Returns

oXml as XmlHttp: An XmlHttp object.

JSONReviver

Custom reviver for handling date values.

Syntax

r = JSONReviver( k, v )

Parameters

Returns

r as String: Revived key value for use with JSON.

newXmlDocument

Syntax

oXml = newXmlDocument( s )

Parameters

Returns

oXml as XMLDocument: XMLDocument object.

newXmlHttpObject

Creates a new XMLHTTPRequest object. Method is private and should not be directly referenced.

Syntax

v = newXmlHttpObject( b, i, z )

Parameters

Returns

v as variant: Return value is determined by the specified parameters.

parseXmlDocument

Syntax

oXml = parseXmlDocument( s )

Parameters

Returns

oXml as XMLDocument: XMLDocument object.

postJSON

Posts a JSON object to the specified path and returns any JSON response.

Syntax

v = postJSON( p, d, h, a, i )

Parameters

Returns

v as variant: Returns boolean for asynchronous operations, and a JSON object for synchronous operations.

postText

Posts text to the specified path and returns any text response.

Syntax

v = postText( p, d, h, a, i )

Parameters

Returns

v as variant: Returns boolean for asynchronous operations, and text for synchronous operations.

postXml

Posts an XML document to the specified path and returns any XML response.

Syntax

v = postXml( p, d, h, a, i )

Parameters

Returns

v as variant: Returns boolean for asynchronous operations, and an XMLDocument object for synchronous operations.

queryNode

Returns a DOM Node selected from the specified document and based on the specified parent node name, node name, and attribute name and values.

Syntax

aNodes = queryNode( d, p, n, a, v )

Parameters

Returns

aNodes as DOMNode: Returns a DOM Node based on the specified parent node name, node name, and attribute name and value.

queryNodes

Returns an array of DOM Nodes selected from the specified document and based on the specified parent node name, node name, and attribute name and values.

Syntax

aNodes = queryNodes( d, p, n, a, v )

Parameters

Returns

aNodes as array: Returns an array of DOM Nodes based on the specified parent node name, node name, and attribute name and value.

removeChildren

Removes all child nodes of the specified node.

Syntax

void removeChildren( o, b )

Parameters

resetXmlHttpObjectPool

Resets the current pool with new instances of XMLHttpRequest objects.

Syntax

void resetXmlHttpObjectPool( )

returnXmlHttpObjectToPool

Returns an in-use XmlHttp object to the pool of available resources. Method is private and should not be directly referenced.

Syntax

void returnXmlHttpObjectToPool( i, y )

Parameters

selectNodes

Returns an array of DOM Nodes selected from the specified document and based on the specified path.

Syntax

aNodes = selectNodes( d, p, c )

Parameters

Returns

aNodes as array: Returns an array of DOM Nodes based on the specified xpath query.

selectSingleNode

Returns a DOM Node selected from the specified document and based on the specified path.

Syntax

v = selectSingleNode( d, p, c )

Parameters

Returns

v as String: Returns a DOM Node based on the specified xpath query.

serialize

Returns a string representation of the specified node and its children.

Syntax

s = serialize( n )

Parameters

Returns

s as String: String representation of the specified node.

setCacheEnabled

Syntax

void setCacheEnabled( b )

Parameters

setInnerXHTML

Copies the child nodes of the specified source node into the specified target node.

Syntax

v = setInnerXHTML( t, s, p, d, z, c, h, ch )

Parameters

Returns

v as variant: Depending on the type of copy operation, returns a reference to the newly created node.

setPoolEnabled

Syntax

void setPoolEnabled( b )

Parameters

testXmlHttpObject

Tests whether an XMLHTTPRequest object can be created.

Syntax

b = testXmlHttpObject( )

Returns

b as boolean: Bit indicating whether a new XMLHTTPRequest object was created.

transformNode

Transforms the specified Document with the specified XSL document.

Syntax

v = transformNode( x, s, n, i, j, p, t )

Parameters

Returns

v as variant: Depending on the type of copy operation, returns a reference to the newly created node.

Messages

onloadxml

Message published to all subscribers when an xml request has completed loading. This message is published for text and JSON requests made through the XML request.

Syntax

// User-specified script to subscribe to message
org.cote.js.message.MessageService.subscribe("onloadxml",_handle_message);
// Internal: how the message is published to subscribers
org.cote.js.message.MessageService.publish("onloadxml" , oXml );
// User-specified script to handle the message subscription
function _handle_message("onloadxml" , oXml ){
// message handler code
}

Parameters