|
DataIO
Hemi JavaScript Framework Data IO.
Hemi Framework: Data IOOverviewThe Data IO Service provides an IO layer for sending and receiving data requests through registered providers. Generic requests are made for a specified bus and include descriptive information, actions, and payloads. Data IO providers responds for specific bus types, and directs the request to a target for the action. When the action is completed (synchronously or asynchronously), the provider writes the results to the response. Additional ReadingObject ModelPortions of the Data IO object model, including Group and Data, were adapted from the Account Manager API.
Request ModelThe Data IO Service uses a modified REST model based on the Core Web (using Account Manager) HTTP Handler processing model. This model uses a coarse-to-fine declaration to identify the nearest approximate API for handling the request. In the Data IO Service, registered providers are invoked for all requests on the specified bus. Request SyntaxThe following example represents the syntax of a new Data IO request. var oInstruction = Hemi.data.io.service.newIOInstruction(); var oRequest = Hemi.data.io.service.newIORequest( iBus, sApplication, sContext, sCatalog, sAction, sId, sName, bDetailsOnly, bAsync, bCache, oInstruction );
Response ModelResponses may be handled in one of three ways:
The validity of the IOResponse object is subject to the interpretation of the implementation. The recommended use is to use the status property to store boolean success or failure conditions, the responseGroups array for retrieving a result of Group values, and the responseData array for retrieving a result of Data values. Example RequestHemi.include("hemi.data.io");
// Demo IO Provider demonstrated below
Hemi.include("demo.io.provider");
var oInstruction = Hemi.data.io.service.newIOInstruction(
bPaginate,
iStartRecord,
iRecordCount,
sOrder,
sGroup
);
var oRequest = Hemi.data.io.service.newIORequest(
BUS_TYPE,
sApplicationName,
sContext,
sCatalog,
sAction,
sId,
sName,
bDetailsOnly,
bAsync,
bCache,
oInstruction
);
Hemi.data.io.service.openRequest(
Hemi.data.io.service.getSubject(),
oRequest,
HandleGridLoad
);
function HandleIOLoad(oService, oSubject, oRequest, oResponse){
/// ...
}Example ProviderThe following is an example of a new Data IO Provider:
(function () {
HemiEngine.include("hemi.event");
HemiEngine.include("hemi.data.io");
HemiEngine.namespace("demo.io.provider", HemiEngine, {
service: null,
serviceImpl: function () {
this.ready_state = 4;
Hemi.prepareObject("demo_io_provider", "1.0", 1, true, 1);
Hemi.util.logger.addLogger(this, "IO Provider", "Demo IO Provider", "001");
// callback upon service registration
//
this.handle_io_register = function (oService) {
// Identify service as supporting the named Request and Action combinations
//
this.getProperties().useRegisteredApi = 1;
this.implement("Catalog", "List");
this.implement("Action", "Read");
};
this.handle_io_request = function(oService, oSubject, oRequest, oResponse ){
/// If the general method is not handled, the handling moves to the specific
/// implementation
///
return 0;
};
/// Synchronous handling example
///
this.requestCatalogList = function(oService, oSubject, oRequest, oResponse){
if(oRequest.requestApplication != "My App"){
/// Skip requests this provider doesn't want to handle
return 1;
}
var sCtx = oRequest.requestContext;
if(
oRequest.requestContext == "PublicDirectory"
&&
oRequest.requestCatalog == "CalendarWidgets"
){
/// Create a policy indicating a read operation is permitted
///
var oPolicy = Hemi.data.io.service.NewPolicy();
oPolicy.read = 1;
/// Get the list of 'CalendarWidgets' from wherever
///
var aWidgets = ...;
/// Copy the source data into the DataIO format
for(var i = 0; i < aWidgets.length; i++){
var oData = Hemi.data.io.service.NewData();
oData.id = ...;
oData.name = ...;
oData.value = ...;
oData.mimeType = ...;
oData.size = ...;
oData.path = ...;
oData.policies.push(oPolicy);
oResponse.writeData(oData, this, 0, Hemi.data.io.service.getBusType().ANY);
}
}
return 1;
};
// Registry the object for a STATIC bus
//
Hemi.data.io.service.register(
this,
Hemi.data.io.service.getBusType().STATIC
);
}
}, 1);
}());
|