var escapeJSONChar=function(){
var _1=["\b","\t","\n","\f","\r"];
return function(c){
if(c=="\""||c=="\\"){
return "\\"+c;
}
if(c.charCodeAt(0)>=32){
return c;
}
for(var i=0;i<_1.length;i++){
if(c==_1[i]){
return "\\"+c;
}
}
return c;
};
}();
function escapeJSONString(s){
var _2=s.split("");
for(var i=0;i<_2.length;i++){
_2[i]=escapeJSONChar(_2[i]);
}
return "\""+_2.join("")+"\"";
};
function toJSON(o){
var _3="$_$jabsorbed$813492";
var _4;
var _5=[];
function _6(){
var _7;
while(_4){
_7=_4[_3].prev;
delete _4[_3];
_4=_7;
}
};
var _8={};
var _9;
function _a(o,p,_b){
var v=[],_c,_d,_e,_f,i;
if(o===null||o===undefined){
return "null";
}else{
if(typeof o==="string"){
return escapeJSONString(o);
}else{
if(typeof o==="number"){
return o.toString();
}else{
if(typeof o==="boolean"){
return o.toString();
}else{
if(o[_3]){
_c=[_b];
_e=p;
while(_e){
if(_d){
_d.unshift(_e[_3].ref);
}
if(_e===o){
_f=_e;
_d=[_f[_3].ref];
}
_c.unshift(_e[_3].ref);
_e=_e[_3].parent;
}
if(_f){
if(JSONRpcClient.fixupCircRefs){
_c.shift();
_d.shift();
_5.push([_c,_d]);
return _8;
}else{
_6();
throw new Error("circular reference detected!");
}
}else{
if(JSONRpcClient.fixupDuplicates){
_d=[o[_3].ref];
_e=o[_3].parent;
while(_e){
_d.unshift(_e[_3].ref);
_e=_e[_3].parent;
}
_c.shift();
_d.shift();
_5.push([_c,_d]);
return _8;
}
}
}else{
o[_3]={parent:p,prev:_4,ref:_b};
_4=o;
}
if(o.constructor===Date){
return "{javaClass: \"java.util.Date\", time: "+o.valueOf()+"}";
}else{
if(o.constructor===Array){
for(i=0;i<o.length;i++){
_9=_a(o[i],o,i);
v.push(_9===_8?null:_9);
}
return "["+v.join(", ")+"]";
}else{
for(var _10 in o){
if(_10===_3){
}else{
if(o[_10]===null||o[_10]===undefined){
v.push("\""+_10+"\": null");
}else{
if(typeof o[_10]=="function"){
}else{
_9=_a(o[_10],o,_10);
if(_9!==_8){
v.push(escapeJSONString(_10)+": "+_9);
}
}
}
}
}
return "{"+v.join(", ")+"}";
}
}
}
}
}
}
};
_9=_a(o,null,"root");
_6();
if(_5.length){
return {json:_9,fixups:_5};
}else{
return {json:_9};
}
};
function JSONRpcClient(){
var _11=0,req,_12,_13,_14,_15,_16=(typeof arguments[0]),_17=true;
if(_16==="function"){
this.readyCB=arguments[0];
_11++;
}else{
if(arguments[0]&&_16==="object"&&arguments[0].length){
this._addMethods(arguments[0]);
_11++;
_17=false;
}
}
this.serverURL=arguments[_11];
this.user=arguments[_11+1];
this.pass=arguments[_11+2];
this.objectID=0;
if(_17){
this._addMethods(["system.listMethods"]);
req=JSONRpcClient._makeRequest(this,"system.listMethods",[]);
if(this.readyCB){
_14=this;
req.cb=function(_18,e){
if(!e){
_14._addMethods(_18);
}
_14.readyCB(_18,e);
};
}
if(!this.readyCB){
_13=JSONRpcClient._sendRequest(this,req);
this._addMethods(_13);
}else{
JSONRpcClient.async_requests.push(req);
JSONRpcClient.kick_async();
}
}
};
JSONRpcClient.prototype.createCallableProxy=function(_19,_1a){
var cp,req,_1b,_1c,i;
cp=new JSONRPCCallableProxy(_19,_1a);
for(_1c in JSONRpcClient.knownClasses[_1a]){
cp[_1c]=JSONRpcClient.bind(JSONRpcClient.knownClasses[_1a][_1c],cp);
}
return cp;
};
function JSONRPCCallableProxy(){
this.objectID=arguments[0];
this.javaClass=arguments[1];
this.JSONRPCType="CallableReference";
};
JSONRpcClient.knownClasses={};
JSONRpcClient.Exception=function(_1d){
var m;
for(var _1e in _1d){
if(_1d.hasOwnProperty(_1e)){
this[_1e]=_1d[_1e];
}
}
if(this.trace){
m=this.trace.match(/^([^:]*)/);
if(m){
this.name=m[0];
}
}
if(!this.name){
this.name="JSONRpcClientException";
}
};
JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION=490;
JSONRpcClient.Exception.CODE_ERR_CLIENT=550;
JSONRpcClient.Exception.CODE_ERR_PARSE=590;
JSONRpcClient.Exception.CODE_ERR_NOMETHOD=591;
JSONRpcClient.Exception.CODE_ERR_UNMARSHALL=592;
JSONRpcClient.Exception.CODE_ERR_MARSHALL=593;
JSONRpcClient.Exception.prototype=new Error();
JSONRpcClient.Exception.prototype.toString=function(_1f,msg){
var str="";
if(this.name){
str+=this.name;
}
if(this.message){
str+=": "+this.message;
}
if(str.length==0){
str="no exception information given";
}
return str;
};
JSONRpcClient.default_ex_handler=function(e){
var str="";
for(a in e){
str+=a+"\t"+e[a]+"\n";
}
alert(str);
};
JSONRpcClient.toplevel_ex_handler=JSONRpcClient.default_ex_handler;
JSONRpcClient.profile_async=false;
JSONRpcClient.max_req_active=1;
JSONRpcClient.requestId=1;
JSONRpcClient.fixupCircRefs=true;
JSONRpcClient.fixupDuplicates=true;
JSONRpcClient.transformDates=false;
JSONRpcClient.bind=function(_20,_21){
return function(){
return _20.apply(_21,arguments);
};
};
JSONRpcClient._createMethod=function(_22,_23){
var _24=function(){
var _25=[],_26;
for(var i=0;i<arguments.length;i++){
_25.push(arguments[i]);
}
if(typeof _25[0]=="function"){
_26=_25.shift();
}
var req=JSONRpcClient._makeRequest(this,_23,_25,this.objectID,_26);
if(!_26){
return JSONRpcClient._sendRequest(_22,req);
}else{
JSONRpcClient.async_requests.push(req);
JSONRpcClient.kick_async();
return req.requestId;
}
};
return _24;
};
JSONRpcClient.prototype.createObject=function(){
var _27=[],_28=null,_29,_2a,req;
for(var i=0;i<arguments.length;i++){
_27.push(arguments[i]);
}
if(typeof _27[0]=="function"){
_28=_27.shift();
}
_29=_27[0]+".$constructor";
_2a=_27[1];
req=JSONRpcClient._makeRequest(this,_29,_2a,0,_28);
if(_28===null){
return JSONRpcClient._sendRequest(this,req);
}else{
JSONRpcClient.async_requests.push(req);
JSONRpcClient.kick_async();
return req.requestId;
}
};
JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX=".ref";
JSONRpcClient.prototype._addMethods=function(_2b,_2c){
var _2d,obj,_2e,n,_2f,_30=[],_31,_32,_33,_34;
for(var i=0;i<_2b.length;i++){
obj=this;
_2e=_2b[i].split(".");
_33=_2b[i].indexOf("[");
_34=_2b[i].indexOf("]");
if((_2b[i].substring(0,JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX.length)==JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX)&&(_33!=-1)&&(_34!=-1)&&(_33<_34)){
_31=_2b[i].substring(_33+1,_34);
}else{
for(n=0;n<_2e.length-1;n++){
_2d=_2e[n];
if(obj[_2d]){
obj=obj[_2d];
}else{
obj[_2d]={};
obj=obj[_2d];
}
}
}
_2d=_2e[_2e.length-1];
if(_31){
_2f=JSONRpcClient._createMethod(this,_2d);
if(!JSONRpcClient.knownClasses[_31]){
JSONRpcClient.knownClasses[_31]={};
}
JSONRpcClient.knownClasses[_31][_2d]=_2f;
}else{
_2f=JSONRpcClient._createMethod(this,_2b[i]);
if((!obj[_2d])&&(!_2c)){
obj[_2d]=JSONRpcClient.bind(_2f,this);
}
_30.push(_2f);
}
_31=null;
}
return _30;
};
JSONRpcClient._getCharsetFromHeaders=function(_35){
var _36,_37,i;
try{
_36=_35.getResponseHeader("Content-type");
_37=_36.split(/\s*;\s*/);
for(i=0;i<_37.length;i++){
if(_37[i].substring(0,8)=="charset="){
return _37[i].substring(8,_37[i].length);
}
}
}
catch(e){
}
return "UTF-8";
};
JSONRpcClient.async_requests=[];
JSONRpcClient.async_inflight={};
JSONRpcClient.async_responses=[];
JSONRpcClient.async_timeout=null;
JSONRpcClient.num_req_active=0;
JSONRpcClient._async_handler=function(){
var res,req;
JSONRpcClient.async_timeout=null;
while(JSONRpcClient.async_responses.length>0){
res=JSONRpcClient.async_responses.shift();
if(res.canceled){
continue;
}
if(res.profile){
res.profile.dispatch=new Date();
}
try{
res.cb(res.result,res.ex,res.profile);
}
catch(e){
JSONRpcClient.toplevel_ex_handler(e);
}
}
while(JSONRpcClient.async_requests.length>0&&JSONRpcClient.num_req_active<JSONRpcClient.max_req_active){
req=JSONRpcClient.async_requests.shift();
if(req.canceled){
continue;
}
JSONRpcClient._sendRequest(req.client,req);
}
};
JSONRpcClient.kick_async=function(){
if(!JSONRpcClient.async_timeout){
JSONRpcClient.async_timeout=setTimeout(JSONRpcClient._async_handler,0);
}
};
JSONRpcClient.cancelRequest=function(_38){
if(JSONRpcClient.async_inflight[_38]){
JSONRpcClient.async_inflight[_38].canceled=true;
return true;
}
var i;
for(i in JSONRpcClient.async_requests){
if(JSONRpcClient.async_requests[i].requestId==_38){
JSONRpcClient.async_requests[i].canceled=true;
return true;
}
}
for(i in JSONRpcClient.async_responses){
if(JSONRpcClient.async_responses[i].requestId==_38){
JSONRpcClient.async_responses[i].canceled=true;
return true;
}
}
return false;
};
JSONRpcClient._makeRequest=function(_39,_3a,_3b,_3c,cb){
var req={};
req.client=_39;
req.requestId=JSONRpcClient.requestId++;
var obj="{id:"+req.requestId+",method:";
if((_3c)&&(_3c>0)){
obj+="\".obj["+_3c+"]."+_3a+"\"";
}else{
obj+="\""+_3a+"\"";
}
if(cb){
req.cb=cb;
}
if(JSONRpcClient.profile_async){
req.profile={submit:new Date()};
}
var j=toJSON(_3b);
obj+=",params:"+j.json;
if(j.fixups){
obj+=",fixups:"+toJSON(j.fixups).json;
}
req.data=obj+"}";
return req;
};
JSONRpcClient._sendRequest=function(_3d,req){
var _3e;
if(req.profile){
req.profile.start=new Date();
}
_3e=JSONRpcClient.poolGetHTTPRequest();
JSONRpcClient.num_req_active++;
_3e.open("POST",_3d.serverURL,!!req.cb,_3d.user,_3d.pass);
try{
_3e.setRequestHeader("Content-type","text/plain");
}
catch(e){
}
if(req.cb){
_3e.onreadystatechange=function(){
var res;
if(_3e.readyState==4){
_3e.onreadystatechange=function(){
};
res={cb:req.cb,result:null,ex:null};
if(req.profile){
res.profile=req.profile;
res.profile.end=new Date();
}else{
res.profile=false;
}
try{
res.result=_3d._handleResponse(_3e);
}
catch(e){
res.ex=e;
}
if(!JSONRpcClient.async_inflight[req.requestId].canceled){
JSONRpcClient.async_responses.push(res);
}
delete JSONRpcClient.async_inflight[req.requestId];
JSONRpcClient.kick_async();
}
};
}else{
_3e.onreadystatechange=function(){
};
}
JSONRpcClient.async_inflight[req.requestId]=req;
try{
_3e.send(req.data);
}
catch(e){
JSONRpcClient.poolReturnHTTPRequest(_3e);
JSONRpcClient.num_req_active--;
throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"});
}
if(!req.cb){
delete JSONRpcClient.async_inflight[req.requestId];
return _3d._handleResponse(_3e);
}
return null;
};
JSONRpcClient.prototype._handleResponse=function(_3f){
if(!this.charset){
this.charset=JSONRpcClient._getCharsetFromHeaders(_3f);
}
var _40,_41,_42;
try{
_40=_3f.status;
_41=_3f.statusText;
_42=_3f.responseText;
}
catch(e){
JSONRpcClient.poolReturnHTTPRequest(_3f);
JSONRpcClient.num_req_active--;
JSONRpcClient.kick_async();
throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"});
}
JSONRpcClient.poolReturnHTTPRequest(_3f);
JSONRpcClient.num_req_active--;
if(_40!=200){
throw new JSONRpcClient.Exception({code:_40,message:_41});
}
return this.unmarshallResponse(_42);
};
JSONRpcClient.prototype.unmarshallResponse=function(_43){
function _44(obj,_45){
function _46(ob,_47){
for(var i=0,j=_47.length;i<j;i++){
ob=ob[_47[i]];
}
return ob;
};
function _48(ob,_49,_4a){
var j=_49.length-1;
for(var i=0;i<j;i++){
ob=ob[_49[i]];
}
ob[_49[j]]=_4a;
};
for(var i=0,j=_45.length;i<j;i++){
_48(obj,_45[i][0],_46(obj,_45[i][1]));
}
};
function _4b(obj){
var _4c,foo,num,i,_4d;
if(obj&&typeof obj==="object"){
_4c=obj.hasOwnProperty("javaClass");
foo=_4c?obj.javaClass==="java.util.Date":obj.hasOwnProperty("time");
num=0;
if(!_4c&&foo){
for(i in obj){
if(obj.hasOwnProperty(i)){
num++;
}
}
}
if(_4c&&foo||foo&&num===1){
_4d=new Date(obj.time);
return _4d;
}else{
for(i in obj){
if(obj.hasOwnProperty(i)){
obj[i]=_4b(obj[i]);
}
}
return obj;
}
}else{
return obj;
}
};
var obj;
try{
eval("obj = "+_43);
}
catch(e){
throw new JSONRpcClient.Exception({code:550,message:"error parsing result"});
}
if(obj.error){
throw new JSONRpcClient.Exception(obj.error);
}
var r=obj.result;
var i,tmp;
if(r){
if(r.objectID&&r.JSONRPCType=="CallableReference"){
return this.createCallableProxy(r.objectID,r.javaClass);
}else{
r=JSONRpcClient.extractCallableReferences(this,JSONRpcClient.transformDates?_4b(r):r);
if(obj.fixups){
_44(r,obj.fixups);
}
}
}
return r;
};
JSONRpcClient.extractCallableReferences=function(_4e,_4f){
var i,tmp,_50;
for(i in _4f){
if(typeof (_4f[i])=="object"){
tmp=JSONRpcClient.makeCallableReference(_4e,_4f[i]);
if(tmp){
_4f[i]=tmp;
}else{
tmp=JSONRpcClient.extractCallableReferences(_4e,_4f[i]);
_4f[i]=tmp;
}
}
if(typeof (i)=="object"){
tmp=JSONRpcClient.makeCallableReference(_4e,i);
if(tmp){
_50=_4f[i];
delete _4f[i];
_4f[tmp]=_50;
}else{
tmp=JSONRpcClient.extractCallableReferences(_4e,i);
_50=_4f[i];
delete _4f[i];
_4f[tmp]=_50;
}
}
}
return _4f;
};
JSONRpcClient.makeCallableReference=function(_51,_52){
if(_52&&_52.objectID&&_52.javaClass&&_52.JSONRPCType=="CallableReference"){
return _51.createCallableProxy(_52.objectID,_52.javaClass);
}
return null;
};
JSONRpcClient.http_spare=[];
JSONRpcClient.http_max_spare=8;
JSONRpcClient.poolGetHTTPRequest=function(){
var _53=JSONRpcClient.http_spare.pop();
if(_53){
return _53;
}
return JSONRpcClient.getHTTPRequest();
};
JSONRpcClient.poolReturnHTTPRequest=function(_54){
if(JSONRpcClient.http_spare.length>=JSONRpcClient.http_max_spare){
delete _54;
}else{
JSONRpcClient.http_spare.push(_54);
}
};
JSONRpcClient.msxmlNames=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","Microsoft.XMLHTTP"];
JSONRpcClient.getHTTPRequest=function(){
try{
JSONRpcClient.httpObjectName="XMLHttpRequest";
return new XMLHttpRequest();
}
catch(e){
}
for(var i=0;i<JSONRpcClient.msxmlNames.length;i++){
try{
JSONRpcClient.httpObjectName=JSONRpcClient.msxmlNames[i];
return new ActiveXObject(JSONRpcClient.msxmlNames[i]);
}
catch(e){
}
}
JSONRpcClient.httpObjectName=null;
throw new JSONRpcClient.Exception({code:0,message:"Can't create XMLHttpRequest object"});
};

