MCPcopy Create free account
hub / github.com/directwebremoting/dwr / getMethodJS

Method getMethodJS

etc/future/scanner/DefaultRemoter.java:315–363  ·  view source on GitHub ↗

Generates Javascript for a given Java method @param scriptName Name of the Javascript file, without ".js" suffix @param method Target method @return Javascript implementing the DWR call for the target method

(String scriptName, Method method)

Source from the content-addressed store, hash-verified

313 * @return Javascript implementing the DWR call for the target method
314 */
315 protected String getMethodJS(String scriptName, Method method)
316 {
317 StringBuffer buffer = new StringBuffer();
318
319 String methodName = method.getName();
320 Class<?>[] paramTypes = method.getParameterTypes();
321
322 // Create the sdoc comment
323 buffer.append("/**\n");
324 for (int j = 0; j < paramTypes.length; j++)
325 {
326 if (!LocalUtil.isServletClass(paramTypes[j]))
327 {
328 buffer.append(" * @param {" + paramTypes[j] + "} p" + j + " a param\n");
329 }
330 }
331 buffer.append(" * @param {function|Object} callback callback function or options object\n");
332 buffer.append(" */\n");
333
334 // Create the function definition
335 buffer.append(scriptName + '.' + methodName + " = function(");
336 for (int j = 0; j < paramTypes.length; j++)
337 {
338 if (!LocalUtil.isServletClass(paramTypes[j]))
339 {
340 buffer.append("p" + j + ", ");
341 }
342 }
343 buffer.append("callback) {\n");
344
345 // The method body calls into engine.js
346 String executeFunctionName = EnginePrivate.getExecuteFunctionName();
347 buffer.append(" return " + executeFunctionName + "(" + scriptName + "._path, '" + scriptName + "', '" + methodName + "\', ");
348 for (int j = 0; j < paramTypes.length; j++)
349 {
350 if (LocalUtil.isServletClass(paramTypes[j]))
351 {
352 buffer.append("false, ");
353 }
354 else
355 {
356 buffer.append("p" + j + ", ");
357 }
358 }
359 buffer.append("callback);\n");
360 buffer.append("};\n\n");
361
362 return buffer.toString();
363 }
364
365 /* (non-Javadoc)
366 * @see org.directwebremoting.Remoter#execute(org.directwebremoting.Calls)

Callers 1

Calls 5

isServletClassMethod · 0.95
getParameterTypesMethod · 0.80
getNameMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected