Пример #1
0
  protected String getRemoteServiceRelativePath() {
    RemoteServiceRelativePath moduleRelativeURL =
        serviceIntf.getAnnotation(RemoteServiceRelativePath.class);
    if (moduleRelativeURL != null) {
      return "\"" + moduleRelativeURL.value() + "\"";
    }

    return null;
  }
Пример #2
0
  @Override
  protected void generate() throws UnableToCompleteException {

    if (source.isInterface() == null) {
      getLogger().log(ERROR, "Type is not an interface.");
      throw new UnableToCompleteException();
    }

    locator = new JsonEncoderDecoderInstanceLocator(context, getLogger());

    this.XML_CALLBACK_TYPE = find(XmlCallback.class, getLogger(), context);
    this.METHOD_CALLBACK_TYPE = find(MethodCallback.class, getLogger(), context);
    this.TEXT_CALLBACK_TYPE = find(TextCallback.class, getLogger(), context);
    this.JSON_CALLBACK_TYPE = find(JsonCallback.class, getLogger(), context);
    this.OVERLAY_CALLBACK_TYPE = find(OverlayCallback.class, getLogger(), context);
    this.DOCUMENT_TYPE = find(Document.class, getLogger(), context);
    this.METHOD_TYPE = find(Method.class, getLogger(), context);
    this.STRING_TYPE = find(String.class, getLogger(), context);
    this.JSON_VALUE_TYPE = find(JSONValue.class, getLogger(), context);
    this.OVERLAY_VALUE_TYPE = find(JavaScriptObject.class, getLogger(), context);
    this.OVERLAY_ARRAY_TYPES = new HashSet<JClassType>();
    this.OVERLAY_ARRAY_TYPES.add(find(JsArray.class, getLogger(), context));
    this.OVERLAY_ARRAY_TYPES.add(find(JsArrayBoolean.class, getLogger(), context));
    this.OVERLAY_ARRAY_TYPES.add(find(JsArrayInteger.class, getLogger(), context));
    this.OVERLAY_ARRAY_TYPES.add(find(JsArrayNumber.class, getLogger(), context));
    this.OVERLAY_ARRAY_TYPES.add(find(JsArrayString.class, getLogger(), context));
    this.QUERY_PARAM_LIST_TYPES = new HashSet<JClassType>();
    this.QUERY_PARAM_LIST_TYPES.add(find(List.class, getLogger(), context));
    this.QUERY_PARAM_LIST_TYPES.add(find(Set.class, getLogger(), context));
    this.REST_SERVICE_TYPE = find(RestService.class, getLogger(), context);

    String path = null;
    Path pathAnnotation = source.getAnnotation(Path.class);
    if (pathAnnotation != null) {
      path = pathAnnotation.value();
    }

    RemoteServiceRelativePath relativePath = source.getAnnotation(RemoteServiceRelativePath.class);
    if (relativePath != null) {
      path = relativePath.value();
    }

    p("private " + RESOURCE_CLASS + " resource = null;");
    p();

    p("public void setResource(" + RESOURCE_CLASS + " resource) {").i(1);
    {
      p("this.resource = resource;");
    }
    i(-1).p("}");

    p("public " + RESOURCE_CLASS + " getResource() {").i(1);
    {
      p("if (this.resource == null) {").i(1);
      if (path == null) {
        p("this.resource = new " + RESOURCE_CLASS + "(" + DEFAULTS_CLASS + ".getServiceRoot());");
      } else {
        p(
            "this.resource = new "
                + RESOURCE_CLASS
                + "("
                + DEFAULTS_CLASS
                + ".getServiceRoot()).resolve("
                + quote(path)
                + ");");
      }
      i(-1).p("}");
      p("return this.resource;");
    }
    i(-1).p("}");

    Options options = source.getAnnotation(Options.class);
    if (options != null && options.dispatcher() != Dispatcher.class) {
      p(
          "private "
              + DISPATCHER_CLASS
              + " dispatcher = "
              + options.dispatcher().getName()
              + ".INSTANCE;");
    } else {
      p("private " + DISPATCHER_CLASS + " dispatcher = null;");
    }

    p();
    p("public void setDispatcher(" + DISPATCHER_CLASS + " dispatcher) {").i(1);
    {
      p("this.dispatcher = dispatcher;");
    }
    i(-1).p("}");

    p();
    p("public " + DISPATCHER_CLASS + " getDispatcher() {").i(1);
    {
      p("return this.dispatcher;");
    }
    i(-1).p("}");

    for (JMethod method : source.getInheritableMethods()) {
      JClassType iface = method.getReturnType().isInterface();
      if (iface != null && REST_SERVICE_TYPE.isAssignableFrom(iface))
        writeSubresourceLocatorImpl(method);
      else writeMethodImpl(method);
    }
  }