Esempio n. 1
0
  /**
   * Loads the specified entity parameter according to the method signature override.
   *
   * @param signatureOverride The signature override.
   * @return The resource entity parameter.
   */
  protected ResourceEntityParameter loadEntityParameter(ResourceMethodSignature signatureOverride) {
    try {
      Class<?> entityType = signatureOverride.input();
      if (entityType != ResourceMethodSignature.NONE.class) {
        AnnotationProcessorEnvironment env = net.sf.jelly.apt.Context.getCurrentEnvironment();
        TypeDeclaration type = env.getTypeDeclaration(entityType.getName());
        return new ResourceEntityParameter(type, env.getTypeUtils().getDeclaredType(type));
      }
    } catch (MirroredTypeException e) {
      DecoratedTypeMirror typeMirror =
          (DecoratedTypeMirror) TypeMirrorDecorator.decorate(e.getTypeMirror());
      if (typeMirror.isDeclared()) {
        if (typeMirror.isInstanceOf(ResourceMethodSignature.class.getName() + ".NONE")) {
          return null;
        } else {
          return new ResourceEntityParameter(
              ((DeclaredType) typeMirror).getDeclaration(), typeMirror);
        }
      } else {
        throw new ValidationException(
            getPosition(), "Illegal input type (must be a declared type): " + typeMirror);
      }
    }

    return null;
  }
Esempio n. 2
0
  /**
   * Loads the explicit output payload.
   *
   * @param signatureOverride The method signature override.
   * @return The output payload (explicit in the signature override.
   */
  protected ResourceRepresentationMetadata loadOutputPayload(
      ResourceMethodSignature signatureOverride) {
    DecoratedTypeMirror returnType = (DecoratedTypeMirror) getReturnType();

    try {
      Class<?> outputType = signatureOverride.output();
      if (outputType != ResourceMethodSignature.NONE.class) {
        AnnotationProcessorEnvironment env = net.sf.jelly.apt.Context.getCurrentEnvironment();
        TypeDeclaration type = env.getTypeDeclaration(outputType.getName());
        return new ResourceRepresentationMetadata(
            env.getTypeUtils().getDeclaredType(type), returnType.getDocValue());
      }
    } catch (MirroredTypeException e) {
      DecoratedTypeMirror typeMirror =
          (DecoratedTypeMirror) TypeMirrorDecorator.decorate(e.getTypeMirror());
      if (typeMirror.isDeclared()) {
        if (typeMirror.isInstanceOf(ResourceMethodSignature.class.getName() + ".NONE")) {
          return null;
        }
        return new ResourceRepresentationMetadata(typeMirror, returnType.getDocValue());
      } else {
        throw new ValidationException(
            getPosition(), "Illegal output type (must be a declared type): " + typeMirror);
      }
    }

    return null;
  }
Esempio n. 3
0
  /**
   * Loads the overridden resource parameter values.
   *
   * @param signatureOverride The signature override.
   * @return The explicit resource parameters.
   */
  protected List<ResourceParameter> loadResourceParameters(
      ResourceMethodSignature signatureOverride) {
    HashMap<String, String> paramComments = parseParamComments(getJavaDoc());

    ArrayList<ResourceParameter> params = new ArrayList<ResourceParameter>();
    for (CookieParam cookieParam : signatureOverride.cookieParams()) {
      params.add(
          new ExplicitResourceParameter(
              this,
              paramComments.get(cookieParam.value()),
              cookieParam.value(),
              ResourceParameterType.COOKIE));
    }
    for (MatrixParam matrixParam : signatureOverride.matrixParams()) {
      params.add(
          new ExplicitResourceParameter(
              this,
              paramComments.get(matrixParam.value()),
              matrixParam.value(),
              ResourceParameterType.MATRIX));
    }
    for (QueryParam queryParam : signatureOverride.queryParams()) {
      params.add(
          new ExplicitResourceParameter(
              this,
              paramComments.get(queryParam.value()),
              queryParam.value(),
              ResourceParameterType.QUERY));
    }
    for (PathParam pathParam : signatureOverride.pathParams()) {
      params.add(
          new ExplicitResourceParameter(
              this,
              paramComments.get(pathParam.value()),
              pathParam.value(),
              ResourceParameterType.PATH));
    }
    for (HeaderParam headerParam : signatureOverride.headerParams()) {
      params.add(
          new ExplicitResourceParameter(
              this,
              paramComments.get(headerParam.value()),
              headerParam.value(),
              ResourceParameterType.HEADER));
    }
    for (FormParam formParam : signatureOverride.formParams()) {
      params.add(
          new ExplicitResourceParameter(
              this,
              paramComments.get(formParam.value()),
              formParam.value(),
              ResourceParameterType.FORM));
    }

    return params;
  }