home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 136
/
MOBICLIC136.ISO
/
pc
/
DATA
/
HOTE
/
libs
/
amfphp
/
amfphp.swf
/
scripts
/
__Packages
/
mx
/
remoting
/
RecordSet.as
< prev
next >
Wrap
Text File
|
2011-07-20
|
17KB
|
596 lines
class mx.remoting.RecordSet extends Object
{
static var version = "1.2.0.124";
static var init = mx.remoting.RecordSet.registerRecordSet();
function RecordSet(columnNames)
{
var _loc1_ = this;
super();
mx.events.EventDispatcher.initialize(_loc1_);
_loc1_._items = new Array();
_loc1_.uniqueID = 0;
if(_loc1_.mTitles == null)
{
if(_loc1_.serverInfo == null)
{
if(_loc1_.serverinfo != null)
{
_loc1_.serverInfo = _loc1_.serverinfo;
}
}
if(_loc1_.serverInfo == null)
{
_loc1_.mTitles = columnNames;
}
else if(_loc1_.serverInfo.version != 1)
{
mx.remoting.NetServices.trace("RecordSet","warning",100,"Received incompatible RecordSet version from server");
}
else
{
_loc1_.mTitles = _loc1_.serverInfo.columnNames;
_loc1_.mRecordsAvailable = 0;
_loc1_.setData(_loc1_.serverInfo.cursor != null ? _loc1_.serverInfo.cursor - 1 : 0,_loc1_.serverInfo.initialData);
if(_loc1_.serverInfo.initialData.length != _loc1_.serverInfo.totalCount)
{
_loc1_.mRecordSetID = _loc1_.serverInfo.id;
if(_loc1_.mRecordSetID != null)
{
_loc1_.serviceName = _loc1_.serverInfo.serviceName != null ? _loc1_.serverInfo.serviceName : "RecordSet";
_loc1_.mTotalCount = _loc1_.serverInfo.totalCount;
_loc1_.mDeliveryMode = "ondemand";
_loc1_.mAllNotified = false;
_loc1_.mOutstandingRecordCount = 0;
}
else
{
mx.remoting.NetServices.trace("RecordSet","warning",102,"Missing some records, but there\'s no RecordSet id");
}
}
_loc1_.serverInfo = null;
}
}
}
function addItem(item)
{
this.addItemAt(this.__get__length(),item);
}
function addItemAt(index, item)
{
var _loc1_ = index;
var _loc2_ = this;
var _loc3_ = true;
if(_loc1_ < _loc2_.__get__length() && _loc1_ >= 0)
{
_loc2_.items.splice(_loc1_,0,item);
addr55:
if(_loc3_)
{
item.__ID__ = _loc2_.uniqueID++;
}
_loc2_.updateViews("addItems",_loc1_,_loc1_);
}
else if(_loc1_ == _loc2_.__get__length())
{
_loc2_.items[_loc1_] = item;
§§goto(addr55);
}
else
{
_loc3_ = false;
mx.remoting.NetServices.trace("Cannot add an item outside the bounds of the RecordSet");
}
}
function addEventListener(event, listener)
{
}
function clear()
{
var _loc1_ = this;
if(!_loc1_.checkLocal())
{
var _loc2_ = _loc1_.items.length;
_loc1_.items.splice(0);
_loc1_.uniqueID = 0;
_loc1_.updateViews("removeItems",0,_loc2_);
}
}
function contains(itmToCheck)
{
var _loc2_ = itmToCheck;
if(this.isObjectEmpty(_loc2_))
{
return false;
}
var itemAtIndex;
var _loc3_ = undefined;
var _loc1_ = 0;
while(true)
{
if(_loc1_ >= this.items.length)
{
return false;
}
itemAtIndex = this.items[_loc1_];
_loc3_ = true;
for(var t in _loc2_)
{
if(_loc2_[t] != itemAtIndex[t])
{
_loc3_ = false;
break;
}
}
if(_loc3_)
{
break;
}
_loc1_ = _loc1_ + 1;
}
return true;
}
function getColumnNames()
{
return this.mTitles;
}
function get columnNames()
{
return this.getColumnNames();
}
function getLocalLength()
{
return this.items.length;
}
function getLength()
{
var _loc1_ = this;
if(_loc1_.mRecordSetID != null)
{
return _loc1_.mTotalCount;
}
return _loc1_.items.length;
}
function getIterator()
{
var _loc1_ = new mx.remoting.RecordSetIterator(this);
return _loc1_;
}
function get length()
{
return this.getLength();
}
function getItemAt(index)
{
var _loc1_ = index;
var _loc2_ = this;
if(_loc1_ < 0 || _loc1_ >= _loc2_.__get__length())
{
return null;
}
if(_loc2_.mRecordSetID == null)
{
return _loc2_.items[_loc1_];
}
_loc2_.requestRecord(_loc1_);
var _loc3_ = _loc2_.items[_loc1_];
if(_loc3_ == 1)
{
return "in progress";
}
return _loc3_;
}
function getItemID(index)
{
return this.items[index].__ID__;
}
function get items()
{
return this._items;
}
function initialize(info)
{
}
function filter(filterFunction, context)
{
if(this.checkLocal())
{
}
var _loc3_ = new mx.remoting.RecordSet(this.mTitles);
var rcount = this.__get__length();
var _loc2_ = 0;
while(_loc2_ < rcount)
{
var _loc1_ = this.getItemAt(_loc2_);
if(_loc1_ != null && _loc1_ != 1 && filterFunction(_loc1_,context))
{
_loc3_.addItem(_loc1_);
}
_loc2_ = _loc2_ + 1;
}
return _loc3_;
}
function sortItems(compareFunc, optionFlags)
{
var _loc1_ = this;
if(!_loc1_.checkLocal())
{
_loc1_.items.sort(compareFunc,optionFlags);
_loc1_.updateViews("sort");
}
}
function sortItemsBy(fieldNames, order, optionFlags)
{
var _loc1_ = this;
if(!_loc1_.checkLocal())
{
if(typeof order == "string")
{
_loc1_.items.sortOn(fieldNames);
if(order.toUpperCase() == "DESC")
{
_loc1_.items.reverse();
}
}
else
{
_loc1_.items.sortOn(fieldNames,optionFlags);
}
_loc1_.updateViews("sort");
}
}
function sort(compareFunc)
{
var _loc1_ = this;
if(!_loc1_.checkLocal())
{
_loc1_.items.sort(compareFunc);
_loc1_.updateViews("sort");
}
}
function isEmpty()
{
return this.items.length == 0;
}
function isLocal()
{
return this.mRecordSetID == null;
}
function isFullyPopulated()
{
return this.isLocal();
}
function getRemoteLength()
{
var _loc1_ = this;
if(_loc1_.isLocal())
{
return _loc1_.mRecordsAvailable;
}
return _loc1_.mTotalCount;
}
function getNumberAvailable()
{
var _loc1_ = this;
if(_loc1_.isLocal())
{
return _loc1_.getLength();
}
return _loc1_.mRecordsAvailable;
}
function replaceItemAt(index, item)
{
var _loc1_ = index;
var _loc2_ = this;
if(_loc1_ >= 0 && _loc1_ <= _loc2_.__get__length())
{
var _loc3_ = _loc2_.getItemID(_loc1_);
_loc2_.items[_loc1_] = item;
_loc2_.items[_loc1_].__ID__ = _loc3_;
_loc2_.updateViews("updateItems",_loc1_,_loc1_);
}
}
function removeAll()
{
this.clear();
}
function removeItemAt(index)
{
var _loc1_ = index;
var _loc2_ = this;
var _loc3_ = _loc2_._items[_loc1_];
_loc2_._items.splice(_loc1_,1);
var rItems = [_loc2_._items[_loc1_]];
var rIDs = [_loc2_.getItemID(_loc1_)];
_loc2_.dispatchEvent({type:"modelChanged",eventName:"removeItems",firstItem:_loc1_,lastItem:_loc1_,removedItems:rItems,removedIDs:rIDs});
return _loc3_;
}
function removeEventListener(event, listener)
{
}
function requestRange(range)
{
var _loc1_ = range.getStart();
var _loc2_ = range.getEnd();
return this.internalRequestRange(_loc1_,_loc2_);
}
function setDeliveryMode(mode, pagesize, numPrefetchPages)
{
var _loc1_ = this;
var _loc2_ = pagesize;
var _loc3_ = numPrefetchPages;
_loc1_.mDeliveryMode = mode.toLowerCase();
_loc1_.stopFetchAll();
if(_loc2_ == null || _loc2_ <= 0)
{
_loc2_ = 25;
}
switch(_loc1_.mDeliveryMode)
{
case "ondemand":
break;
case "page":
if(_loc3_ == null)
{
_loc3_ = 0;
}
_loc1_.mPageSize = _loc2_;
_loc1_.mNumPrefetchPages = _loc3_;
break;
case "fetchall":
_loc1_.stopFetchAll();
_loc1_.startFetchAll(_loc2_);
break;
default:
mx.remoting.NetServices.trace("RecordSet","warning",107,"SetDeliveryMode: unknown mode string");
}
}
function editField(index, fieldName, value)
{
this.changeFieldValue(index,fieldName,value);
}
function getEditingData(index, fieldName)
{
return this.items[index][fieldName];
}
function setField(index, fieldName, value)
{
this.changeFieldValue(index,fieldName,value);
}
function changeFieldValue(index, fieldName, value)
{
var _loc1_ = index;
var _loc2_ = this;
if(!_loc2_.checkLocal())
{
if(!(_loc1_ < 0 || _loc1_ >= _loc2_.getLength()))
{
_loc2_.items[_loc1_][fieldName] = value;
_loc2_.updateViews("updateItems",_loc1_,_loc1_);
}
}
}
function isObjectEmpty(objToCheck)
{
var _loc2_ = objToCheck;
var _loc1_ = true;
for(var _loc3_ in _loc2_)
{
_loc1_ = false;
return _loc1_;
break;
}
return _loc1_;
}
function arrayToObject(anArray)
{
if(this.mTitles == null)
{
mx.remoting.NetServices.trace("RecordSet","warning",105,"getItem: titles are not available");
return null;
}
var _loc3_ = new Object();
var alen = anArray.length;
var _loc2_ = undefined;
var _loc1_ = 0;
while(_loc1_ < alen)
{
_loc2_ = this.mTitles[_loc1_];
if(_loc2_ == null)
{
_loc2_ = "column" + _loc1_ + 1;
}
_loc3_[_loc2_] = anArray[_loc1_];
_loc1_ = _loc1_ + 1;
}
return _loc3_;
}
function checkLocal()
{
if(this.isLocal())
{
return false;
}
mx.remoting.NetServices.trace("RecordSet","warning",108,"Operation not allowed on partial recordset");
return true;
}
function getRecordSetService()
{
var _loc1_ = this;
if(_loc1_.mRecordSetService == null)
{
if(_loc1_.gateway_conn == null)
{
_loc1_.gateway_conn = mx.remoting.NetServices.createGatewayConnection();
}
else if(_global.netDebugInstance != undefined)
{
_loc1_.gateway_conn = _loc1_.gateway_conn.clone();
}
if(_global.netDebugInstance != undefined)
{
_loc1_.gateway_conn.setupRecordSet();
_loc1_.gateway_conn.setDebugId("RecordSet " + _loc1_.mRecordSetID);
}
_loc1_.mRecordSetService = _loc1_.gateway_conn.getService(_loc1_.serviceName,_loc1_);
if(_loc1_.mRecordSetService == null)
{
mx.remoting.NetServices.trace("RecordSet","warning",101,"Failed to create RecordSet service");
_loc1_.mRecordSetService = null;
}
}
return _loc1_.mRecordSetService;
}
function internalRequestRange(index, lastIndex)
{
var _loc1_ = index;
var _loc2_ = this;
var highestRequested = -1;
if(_loc1_ < 0)
{
_loc1_ = 0;
}
if(lastIndex >= _loc2_.getRemoteLength())
{
lastIndex = _loc2_.getRemoteLength() - 1;
}
var _loc3_ = undefined;
var last;
while(_loc1_ <= lastIndex)
{
while(_loc1_ <= lastIndex && _loc2_.items[_loc1_] != null)
{
_loc1_ = _loc1_ + 1;
}
_loc3_ = _loc1_;
while(_loc1_ <= lastIndex && _loc2_.items[_loc1_] == null)
{
_loc2_.mOutstandingRecordCount = _loc2_.mOutstandingRecordCount + 1;
_loc2_.items[_loc1_] = 1;
_loc1_ = _loc1_ + 1;
}
last = _loc1_ - 1;
if(_loc3_ <= last)
{
_loc2_.logger.logInfo(" Fetching records from index [" + _loc3_ + "] to index [" + last + "]");
_loc2_.getRecordSetService().getRecords(_loc2_.mRecordSetID,_loc3_ + 1,last - _loc3_ + 1);
highestRequested = last;
_loc2_.updateViews("fetchRows",_loc3_,last);
}
}
return highestRequested;
}
function removeItems(index, len)
{
var _loc3_ = index;
var _loc2_ = new Array();
var _loc1_ = 0;
while(_loc1_ < len)
{
_loc2_.push(this.getItemID(_loc3_ + _loc1_));
_loc1_ = _loc1_ + 1;
}
var oldItems = this.items.splice(_loc3_,len);
this.dispatchEvent({type:"modelChanged",eventName:"removeItems",firstItem:_loc3_,lastItem:_loc3_ + len - 1,removedItems:oldItems,removedIDs:_loc2_});
}
function getRecords_Result(info)
{
var _loc1_ = this;
var _loc2_ = info;
_loc1_.setData(_loc2_.Cursor - 1,_loc2_.Page);
_loc1_.mOutstandingRecordCount -= _loc2_.Page.length;
_loc1_.updateViews("updateItems",_loc2_.Cursor - 1,_loc2_.Cursor - 1 + _loc2_.Page.length - 1);
if(_loc1_.mRecordsAvailable == _loc1_.mTotalCount && !_loc1_.mAllNotified)
{
_loc1_.updateViews("allRows");
_loc1_.mRecordSetService.release();
_loc1_.mAllNotified = true;
_loc1_.mRecordSetID = null;
_loc1_.mRecordSetService = null;
}
}
function release_Result()
{
}
function requestOneRecord(index)
{
var _loc1_ = this;
var _loc2_ = index;
if(_loc1_.items[_loc2_] == null)
{
if(_loc1_.mDeliveryMode == "ondemand")
{
_loc1_.logger.logInfo(" INFO: Fetching Record [" + _loc2_ + "]");
}
_loc1_.getRecordSetService().getRecords(_loc1_.mRecordSetID,_loc2_ + 1,1);
_loc1_.mOutstandingRecordCount = _loc1_.mOutstandingRecordCount + 1;
_loc1_.items[_loc2_] = 1;
_loc1_.updateViews("fetchRows",_loc2_,_loc2_);
}
}
function requestRecord(index)
{
var _loc1_ = this;
if(_loc1_.mDeliveryMode != "page")
{
_loc1_.requestOneRecord(index);
}
else
{
var _loc2_ = int(index / _loc1_.mPageSize) * _loc1_.mPageSize;
var _loc3_ = _loc2_ + _loc1_.mPageSize * (_loc1_.mNumPrefetchPages + 1) - 1;
_loc1_.internalRequestRange(_loc2_,_loc3_);
}
}
function _setParentService(service)
{
this.gateway_conn = service.nc;
}
function setData(start, dataArray)
{
var _loc1_ = this;
var datalen = dataArray.length;
var _loc3_ = undefined;
var rec;
var _loc2_ = 0;
while(_loc2_ < datalen)
{
_loc3_ = _loc2_ + start;
rec = _loc1_.items[_loc3_];
if(rec != null && rec != 1)
{
mx.remoting.NetServices.trace("RecordSet","warning",106,"Already got record # " + _loc3_);
}
else
{
_loc1_.mRecordsAvailable += 1;
}
_loc1_.items[_loc3_] = _loc1_.arrayToObject(dataArray[_loc2_]);
_loc1_.items[_loc3_].__ID__ = _loc1_.uniqueID++;
_loc2_ = _loc2_ + 1;
}
}
function startFetchAll(pagesize)
{
var _loc1_ = this;
if(_loc1_.mDataFetcher != null)
{
_loc1_.mDataFetcher.disable();
}
_loc1_.mDataFetcher = new mx.remoting.RsDataFetcher(_loc1_,pagesize);
}
function stopFetchAll()
{
this.mDataFetcher.disable();
this.mDataFetcher = null;
}
function updateViews(event, first, last)
{
this.dispatchEvent({type:"modelChanged",eventName:event,firstItem:first,lastItem:last});
}
static function registerRecordSet()
{
Object.registerClass("RecordSet",mx.remoting.RecordSet);
return true;
}
}