📄 dmi.js
字号:
// <code>ServerObjects</code> defined in a given .app.xml file and call methods on them// directly.//// @param appID (string or Object) the appID (.app.xml file to look in) or comprehensive request// object as documented above.// @param className (string) +link{serverObject.className} or +link{serverObject.ID}// @param methodName (string) the name of the method to call on the serverObject// @param [args] (any) The next N-1 params specify arguments to the server-side method.// @param callback (RPCCallback) The callback of the response. If you do not want a callback, you// must specify a <code>null</code> value for this parameter when// using the first signature (documented above).//// @visibility external//<call : function (appID, className, methodName) { // arguments isn't a real array so methods like slice() that we use below don't work on it // - so make a real array var args = []; for (var i = 0; i < arguments.length; i++) args[args.length] = arguments[i]; // two invocation styles: can pass an object literal that is the dmi request or as the // documented above for external consumption var request = {}; if (isc.isAn.Object(appID) && args.length == 1) { // internal signature // appID = { // appID: x, // className: x, // methodName: x, // arguments: [], // callback: x, // requestParams: {} // } // don't modify user object - clone it var requestData = isc.clone(appID); if (requestData.requestParams) { isc.addProperties(request, requestData.requestParams); delete requestData.requestParams; } request.callback = requestData.callback; delete requestData.callback; request.data = requestData; } else { // external style - as in method signature // all following args except last = arguments // lastArg = callback - must be specified, but can be null // request.data = { appID: appID, className: className, methodName: methodName, // the next argument.lenght-1 args are method arguments arguments: args.slice(3, args.length-1) }; // and the last is a callback. request.callback = args[args.length-1] } // force arguments to an array - that's what the server expects args = request.data.arguments; if (!isc.isAn.Array(args)) { if (args == null) args = []; else args = [args]; } request.data.arguments = args; // mark this as a DMI RPC so the server can figure it out request.data.is_ISC_RPC_DMI = true; // expose appID, className, methodName in query string. Useful for looking at timing // output of proxy-based performance testing tools like JMeter where parsing the // request to get this data is a pain. if (this.addMetaDataToQueryString) { if (!request.queryParams) request.queryParams = {}; isc.addProperties(request.queryParams, { dmi_appID: request.data.appID, dmi_class: request.data.className, dmi_method: request.data.methodName }); } isc.RPCManager.sendRequest(request);},//> @groupDef loadDMIStubsTag//// <i>produces:</i> JavaScript// <p>// Creates global bindings for all serverObjects defined in the <code>rpcBindings</code>// section .app.xml file specified by the <code>ID</code> or <code>name</code> attribute of// this tag. Once you've loaded your <code>rpcBindings</code> using this tag, you can call// methods on the <code>ServerObjects</code> defined there directly. For example, you can load// the example.app.xml (located in /shared/app directory of the webRoot of the SDK) like this:// <pre>// <isomorphic:loadDMIStubs ID="example"/>// </pre>// Whereas using +link{DMI.call} you would have had to invoke the <code>getTimeStamp</code>// method like this:// <pre>// DMI.call("example", "GetTimeStampDMI", "getTimeStamp", new Date(), "alert(data)";// </pre>// Having loaded the stubs of the <code>example</code> .app.xml, you can then call// <code>getTimeStamp</code> like this:// <pre>// GetTimeStampDMI.getTimeStamp(new Date(), "alert(data)");// </pre>// or this:// <pre>// GetTimeStamp.getTimeStamp({// arguments: [new Date()],// callback: "alert(data)"// });// </pre>// or this:// <pre>// GetTimeStamp.call({// methodName: "getTimeStamp",// arguments: [new Date()],// callback: "alert(data)"// });// </pre>// As with +link{DMI.call}, the last argument must be the callback - if you don't want a// callback, simply specify <code>null</code> as the callback. The name of the global binding// created will be the same as the +link{ServerObject.ID} or the non-qualified name of the// +link{ServerObject.className} (java namespace, if any, will be stripped).// <p>// <b><u>Tag Attributes:</u></b>// <p>// <b>ID or name</b><br>// <i>value format</i>: String - name of .app.xml file to load (minus the .app.xml extension)<br>// <i>default value</i>: NONE// <p>// This attribute specifies the name of the file that contains the rpcBindings to load.// UI files are located in <code>[webroot]/shared/app</code> by default. This location is// changeable in <code>[webroot]/WEB-INF/classes/server.properties</code> by setting the config// parameter <code>project.apps</code> to the directory where your .app.xml files are located. // We recommend that for prototying, at least, you use the default directory.//// @see DMI//// @visibility external// @requiresModules SCServer// @treeLocation Java Server Reference/SmartClient JSP Tags// @title <isomorphic:loadDMIStubs>//<// template used to generate method bindings. firstArg can be an object literal, in which case// that's passed directly to isc.DMI.call() - otherwise the arguments array is the set of// arguments to pass to the target methodcallTemplate : "(function(){var x = function (firstArg) { " // isCall specifies whether this is a generic call() binding - where the methodName // must be passed in as the first arg or a named call() binding where the methodName // will be encoded into this template +"var isCall = ${isCall};" +"var obj = isc.addProperties({}, this.requestParams);" // copy arguments to array - for some reason we can't call standard array methods on // the arguments object. +"if(isc.isAn.Object(firstArg) && arguments.length == 1){" // for isCall == true, the methodName must be supplied in the obj that is the firstArg, // so setting it to 'firstArg' here is harmless// +"isc.addProperties(obj,{appID:'${appID}',className:'${className}',methodName:'${methodName}',arguments:firstArg.arguments});" +"isc.addProperties(obj,{appID:'${appID}',className:'${className}',methodName:'${methodName}'},firstArg);" +"} else {" +"var args = [];for (var i = 0; i < arguments.length; i++) args[args.length] = arguments[i];" // switch on isCall to treat the first argument either as the method name (isCall == // true) or as part of the arguments array +"isc.addProperties(obj,{appID:'${appID}',className:'${className}',methodName:isCall?firstArg:'${methodName}'," +"arguments:args.slice(isCall ? 1 : 0,args.length-1),callback:args[args.length-1]});" +"}isc.DMI.call(obj);" +"};return x;})()",// returns an object on which you can directly invoke the methods passed in here - those are// plumbed through to isc.DMI.call()bind : function (appID, className, methods, requestParams) { //!OBFUSCATEOK if (!isc.isAn.Array(methods)) methods = [methods]; // this is the class we'll be returning var binding = isc.defineClass(className).addProperties({ requestParams : requestParams }); // bind the special 'call' method that works just like DMI.call(), but with the first // argument being the methodName to call var callArgs = {appID: appID, className: className, methodName: "firstArg", isCall: true}; binding.call = eval(this.callTemplate.evalDynamicString(this, callArgs)); // bind all other named methods. Note that if the user specifies a method named 'call' // then it will clobber the generic call binding above for (var i = 0; i < methods.length; i++) { var bindingArgs = {appID: appID, className: className, methodName: methods[i], isCall: false}; binding[methods[i]] = eval(this.callTemplate.evalDynamicString(this, bindingArgs)); } window[className] = binding; return binding;},makeDMIMethod : function (appID, className, isCall, methodName) { //!OBFUSCATEOK var callArgs = {appID: appID, className: className, isCall: isCall, methodName: isCall ? "firstArg" : methodName}; return eval(this.callTemplate.evalDynamicString(this, callArgs));}});isc.DMI.callBuiltin = isc.DMI.makeDMIMethod("isc_builtin", "builtin", true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -