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)
| 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) |
no test coverage detected