Exemplo n.º 1
0
  @Override
  public boolean serve(Path path, HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    String scope = desc.getName();

    resp.setContentType("text/javascript");
    PrintWriter printer = resp.getWriter();

    //
    printer.println("HTMLElement.prototype." + scope + "=function(){");
    printer.println("var capture=this;");
    printer.println("return {");

    //
    Iterator<Map.Entry<String, ControllerMethod>> entryIterator = table.entrySet().iterator();
    while (entryIterator.hasNext()) {
      Map.Entry<String, ControllerMethod> entry = entryIterator.next();

      printer.println(entry.getKey() + ":function(){");
      printer.println("return capture.foo(\"" + entry.getValue().getId() + "\");");
      printer.println("}");

      if (entryIterator.hasNext()) {
        printer.println(",");
      }
    }

    //
    printer.println("};");
    printer.println("};");

    //
    return true;
  }
Exemplo n.º 2
0
  public ApplicationAsset(ApplicationDescriptor desc) {
    //
    Map<String, ControllerMethod> table = new HashMap<String, ControllerMethod>();
    for (ControllerMethod cm : desc.getControllerMethods()) {
      Ajax ajax = cm.getMethod().getAnnotation(Ajax.class);
      if (ajax != null) {
        table.put(cm.getName(), cm);
      }
    }

    //
    this.desc = desc;
    this.table = table;
  }