//>>built
define("dojox/rpc/Service",["dojo","dojox","dojo/AdapterRegistry","dojo/_base/url"],function(e,g){e.declare("dojox.rpc.Service",null,{constructor:function(a,b){function c(f){f._baseUrl=new e._Url(e.isBrowser?location.href:e.config.baseUrl,k||".")+"";d._smd=f;for(var l in d._smd.services){f=l.split(".");for(var m=d,n=0;n<f.length-1;n++)m=m[f[n]]||(m[f[n]]={});m[f[f.length-1]]=d._generateService(l,d._smd.services[l])}}var d=this;if(a)if(e.isString(a)||a instanceof e._Url){var k=a instanceof e._Url?
a+"":a;var h=e._getText(k);if(h)c(e.fromJson(h));else throw Error("Unable to load SMD from "+a);}else c(a);this._options=b?b:{};this._requestId=0},_generateService:function(a,b){if(this[a])throw Error("WARNING: "+a+" already exists for service. Unable to generate function");b.name=a;var c=e.hitch(this,"_executeMethod",b),d=g.rpc.transportRegistry.match(b.transport||this._smd.transport);d.getExecutor&&(c=d.getExecutor(c,b,this));d=b.returns||(b._schema={});d._service=c;c.servicePath="/"+a+"/";c._schema=
d;c.id=g.rpc.Service._nextId++;return c},_getRequest:function(a,b){var c=this._smd,d,k=g.rpc.envelopeRegistry.match(a.envelope||c.envelope||"NONE"),h=(a.parameters||[]).concat(c.parameters||[]);if(k.namedParams){if(1==b.length&&e.isObject(b[0]))b=b[0];else{var f={};for(d=0;d<a.parameters.length;d++)"undefined"==typeof b[d]&&a.parameters[d].optional||(f[a.parameters[d].name]=b[d]);b=f}if(a.strictParameters||c.strictParameters)for(d in b){f=!1;for(var l=0;l<h.length;l++)h[l].name==d&&(f=!0);f||delete b[d]}for(d=
0;d<h.length;d++)if(f=h[d],!f.optional&&f.name&&!b[f.name])if(f["default"])b[f.name]=f["default"];else if(!(f.name in b))throw Error("Required parameter "+f.name+" was omitted");}else h&&h[0]&&h[0].name&&1==b.length&&e.isObject(b[0])&&(b=!1===k.namedParams?g.rpc.toOrdered(h,b):b[0]);e.isObject(this._options)&&(b=e.mixin(b,this._options));d=a._schema||a.returns;h=k.serialize.apply(this,[c,a,b]);h._envDef=k;return e.mixin(h,{sync:this._options.sync||g.rpc._sync,contentType:a.contentType||c.contentType||
h.contentType,headers:a.headers||c.headers||h.headers||{},target:h.target||g.rpc.getTarget(c,a),transport:a.transport||c.transport||h.transport,envelope:a.envelope||c.envelope||h.envelope,timeout:a.timeout||c.timeout,callbackParamName:a.callbackParamName||c.callbackParamName,rpcObjectParamName:a.rpcObjectParamName||c.rpcObjectParamName,schema:d,handleAs:h.handleAs||"auto",preventCache:a.preventCache||c.preventCache,frameDoc:this._options.frameDoc||void 0})},_executeMethod:function(a){var b=[],c;for(c=
1;c<arguments.length;c++)b.push(arguments[c]);var d=this._getRequest(a,b);b=g.rpc.transportRegistry.match(d.transport).fire(d);b.addBoth(function(k){return d._envDef.deserialize.call(this,k)});return b}});g.rpc.getTarget=function(a,b){var c=a._baseUrl;a.target&&(c=new e._Url(c,a.target)+"");b.target&&(c=new e._Url(c,b.target)+"");return c};g.rpc.toOrdered=function(a,b){if(e.isArray(b))return b;for(var c=[],d=0;d<a.length;d++)c.push(b[a[d].name]);return c};g.rpc.transportRegistry=new e.AdapterRegistry(!0);
g.rpc.envelopeRegistry=new e.AdapterRegistry(!0);g.rpc.envelopeRegistry.register("URL",function(a){return"URL"==a},{serialize:function(a,b,c){return{data:e.objectToQuery(c),transport:"POST"}},deserialize:function(a){return a},namedParams:!0});g.rpc.envelopeRegistry.register("JSON",function(a){return"JSON"==a},{serialize:function(a,b,c){return{data:e.toJson(c),handleAs:"json",contentType:"application/json"}},deserialize:function(a){return a}});g.rpc.envelopeRegistry.register("PATH",function(a){return"PATH"==
a},{serialize:function(a,b,c){var d;a=g.rpc.getTarget(a,b);if(e.isArray(c))for(d=0;d<c.length;d++)a+="/"+c[d];else for(d in c)a+="/"+d+"/"+c[d];return{data:"",target:a}},deserialize:function(a){return a}});g.rpc.transportRegistry.register("POST",function(a){return"POST"==a},{fire:function(a){a.url=a.target;a.postData=a.data;return e.rawXhrPost(a)}});g.rpc.transportRegistry.register("GET",function(a){return"GET"==a},{fire:function(a){a.url=a.target+(a.data?"?"+(a.rpcObjectParamName?a.rpcObjectParamName+
"\x3d":"")+a.data:"");return e.xhrGet(a)}});g.rpc.transportRegistry.register("JSONP",function(a){return"JSONP"==a},{fire:function(a){a.url=a.target+(-1==a.target.indexOf("?")?"?":"\x26")+(a.rpcObjectParamName?a.rpcObjectParamName+"\x3d":"")+a.data;a.callbackParamName=a.callbackParamName||"callback";return e.io.script.get(a)}});g.rpc.Service._nextId=1;e._contentHandlers.auto=function(a){var b=e._contentHandlers,c=a.getResponseHeader("Content-Type");return c?c.match(/\/.*json/)?b.json(a):c.match(/\/javascript/)?
b.javascript(a):c.match(/\/xml/)?b.xml(a):b.text(a):b.text(a)};return g.rpc.Service});