Ejemplo n.º 1
0
 private void checkResourceClassSetters(final MethodList methodList, final boolean encodedFlag) {
   for (AnnotatedMethod method :
       methodList
           .withoutMetaAnnotation(HttpMethod.class)
           .withoutAnnotation(Path.class)
           .hasNumParams(1)
           .hasReturnType(void.class)
           .nameStartsWith("set")) {
     Parameter p =
         Parameter.create(
             handlerClass,
             method.getMethod().getDeclaringClass(),
             encodedFlag || method.isAnnotationPresent(Encoded.class),
             method.getParameterTypes()[0],
             method.getGenericParameterTypes()[0],
             method.getAnnotations());
     if (null != p) {
       ResourceMethodValidator.validateParameter(
           p,
           method.getMethod(),
           method.getMethod().toGenericString(),
           "1",
           InvocableValidator.isSingleton(handlerClass));
     }
   }
 }
Ejemplo n.º 2
0
  private Resource.Builder doCreateResourceBuilder() {
    if (!disableValidation) {
      checkForNonPublicMethodIssues();
    }

    final Class<?> annotatedResourceClass = ModelHelper.getAnnotatedResourceClass(handlerClass);
    final Path rPathAnnotation = annotatedResourceClass.getAnnotation(Path.class);

    final boolean keepEncodedParams = (null != annotatedResourceClass.getAnnotation(Encoded.class));

    final List<MediaType> defaultConsumedTypes =
        extractMediaTypes(annotatedResourceClass.getAnnotation(Consumes.class));
    final List<MediaType> defaultProducedTypes =
        extractMediaTypes(annotatedResourceClass.getAnnotation(Produces.class));
    final Collection<Class<? extends Annotation>> defaultNameBindings =
        ReflectionHelper.getAnnotationTypes(annotatedResourceClass, NameBinding.class);

    final MethodList methodList = new MethodList(handlerClass);

    checkResourceClassSetters(methodList, keepEncodedParams);
    checkResourceClassFields(keepEncodedParams, InvocableValidator.isSingleton(handlerClass));

    Resource.Builder resourceBuilder;

    if (null != rPathAnnotation) {
      resourceBuilder = Resource.builder(rPathAnnotation.value());
    } else {
      resourceBuilder = Resource.builder();
    }

    boolean extended = false;
    if (handlerClass.isAnnotationPresent(ExtendedResource.class)) {
      resourceBuilder.extended(true);
      extended = true;
    }

    resourceBuilder.name(handlerClass.getName());

    addResourceMethods(
        resourceBuilder,
        methodList,
        keepEncodedParams,
        defaultConsumedTypes,
        defaultProducedTypes,
        defaultNameBindings,
        extended);
    addSubResourceMethods(
        resourceBuilder,
        methodList,
        keepEncodedParams,
        defaultConsumedTypes,
        defaultProducedTypes,
        defaultNameBindings,
        extended);
    addSubResourceLocators(resourceBuilder, methodList, keepEncodedParams, extended);

    if (LOGGER.isLoggable(Level.FINEST)) {
      LOGGER.finest(
          LocalizationMessages.NEW_AR_CREATED_BY_INTROSPECTION_MODELER(resourceBuilder.toString()));
    }

    return resourceBuilder;
  }