public ComponentModelValidator(Collection<ValueParamProvider> valueParamProviders, MessageBodyWorkers msgBodyWorkers) { validators = new ArrayList<>(); validators.add(new ResourceValidator()); validators.add(new RuntimeResourceModelValidator(msgBodyWorkers)); validators.add(new ResourceMethodValidator(valueParamProviders)); validators.add(new InvocableValidator()); }
private void visitJaxrsResourceMethod(ResourceMethod method) { checkMethod(method); }
private void visitSubResourceLocator(ResourceMethod locator) { checkParameters(locator); checkValueProviders(locator); final Invocable invocable = locator.getInvocable(); if (void.class == invocable.getRawResponseType()) { Errors.fatal(locator, LocalizationMessages.SUBRES_LOC_RETURNS_VOID(invocable.getHandlingMethod())); } // Prevent PARAM_ANNOTATION_SET annotations on a resource locator if (invocable.getHandlingMethod().getAnnotation(Path.class) != null) { checkUnexpectedAnnotations(locator); } }
@Override public void visitResourceMethod(final ResourceMethod method) { switch (method.getType()) { case RESOURCE_METHOD: visitJaxrsResourceMethod(method); break; case SUB_RESOURCE_LOCATOR: visitSubResourceLocator(method); break; } }
private void checkMethod(ResourceMethod method) { checkValueProviders(method); final Invocable invocable = method.getInvocable(); checkParameters(method); if (!isConcreteType(responseType)) { Errors.warning(invocable.getHandlingMethod(), LocalizationMessages.TYPE_OF_METHOD_NOT_RESOLVABLE_TO_CONCRETE_TYPE(responseType, checkUnexpectedAnnotations(method);
private void checkResourceClassFields(final boolean encodedFlag, boolean isInSingleton, Collection<Parameter> injectableParameters) { for (Field field : AccessController.doPrivileged(ReflectionHelper.getDeclaredFieldsPA(handlerClass))) { if (field.getDeclaredAnnotations().length > 0) { Parameter p = Parameter.create( handlerClass, field.getDeclaringClass(), encodedFlag || field.isAnnotationPresent(Encoded.class), field.getType(), field.getGenericType(), field.getAnnotations()); if (null != p) { ResourceMethodValidator.validateParameter(p, field, field.toGenericString(), field.getName(), isInSingleton); // we do not inject entity and unknown parameters into class instance fields and properties. if (p.getSource() != Parameter.Source.ENTITY) { injectableParameters.add(p); } } } } }
private void checkMethod(ResourceMethod method) { checkValueProviders(method); final Invocable invocable = method.getInvocable(); checkParameters(method); if (!isConcreteType(responseType)) { Errors.warning(invocable.getHandlingMethod(), LocalizationMessages.TYPE_OF_METHOD_NOT_RESOLVABLE_TO_CONCRETE_TYPE(responseType,
private void visitSubResourceLocator(ResourceMethod locator) { checkParameters(locator); checkValueProviders(locator); final Invocable invocable = locator.getInvocable(); if (void.class == invocable.getRawResponseType()) { Errors.fatal(locator, LocalizationMessages.SUBRES_LOC_RETURNS_VOID(invocable.getHandlingMethod())); } }
@SuppressWarnings("ChainOfInstanceofChecks") private static boolean isConcreteType(Type t) { if (t instanceof ParameterizedType) { return isConcreteParameterizedType((ParameterizedType) t); } else if (!(t instanceof Class)) { // GenericArrayType, WildcardType, TypeVariable return false; } return true; }
private static boolean isConcreteParameterizedType(ParameterizedType pt) { boolean isConcrete = true; for (Type t : pt.getActualTypeArguments()) { isConcrete &= isConcreteType(t); } return isConcrete; } }
private void checkMethod(ResourceMethod method) { checkValueProviders(method); final Invocable invocable = method.getInvocable(); checkParameters(method); if (!isConcreteType(responseType)) { Errors.warning(invocable.getHandlingMethod(), LocalizationMessages.TYPE_OF_METHOD_NOT_RESOLVABLE_TO_CONCRETE_TYPE(responseType, checkUnexpectedAnnotations(method);
@Override public void visitResourceMethod(final ResourceMethod method) { switch (method.getType()) { case RESOURCE_METHOD: visitJaxrsResourceMethod(method); break; case SUB_RESOURCE_LOCATOR: visitSubResourceLocator(method); break; } }
private void checkResourceClassFields(final boolean encodedFlag, boolean isInSingleton, Collection<Parameter> injectableParameters) { for (Field field : AccessController.doPrivileged(ReflectionHelper.getDeclaredFieldsPA(handlerClass))) { if (field.getDeclaredAnnotations().length > 0) { Parameter p = Parameter.create( handlerClass, field.getDeclaringClass(), encodedFlag || field.isAnnotationPresent(Encoded.class), field.getType(), field.getGenericType(), field.getAnnotations()); if (null != p) { ResourceMethodValidator.validateParameter(p, field, field.toGenericString(), field.getName(), isInSingleton); // we do not inject entity and unknown parameters into class instance fields and properties. if (p.getSource() != Parameter.Source.ENTITY) { injectableParameters.add(p); } } } } }
private void checkMethod(ResourceMethod method) { checkValueProviders(method); final Invocable invocable = method.getInvocable(); checkParameters(method); if (!isConcreteType(responseType)) { Errors.warning(invocable.getHandlingMethod(), LocalizationMessages.TYPE_OF_METHOD_NOT_RESOLVABLE_TO_CONCRETE_TYPE(responseType,
private void visitSubResourceLocator(ResourceMethod locator) { checkParameters(locator); checkValueProviders(locator); final Invocable invocable = locator.getInvocable(); if (void.class == invocable.getRawResponseType()) { Errors.fatal(locator, LocalizationMessages.SUBRES_LOC_RETURNS_VOID(invocable.getHandlingMethod())); } }
@SuppressWarnings("ChainOfInstanceofChecks") private static boolean isConcreteType(Type t) { if (t instanceof ParameterizedType) { return isConcreteParameterizedType((ParameterizedType) t); } else if (!(t instanceof Class)) { // GenericArrayType, WildcardType, TypeVariable return false; } return true; }
private static boolean isConcreteParameterizedType(ParameterizedType pt) { boolean isConcrete = true; for (Type t : pt.getActualTypeArguments()) { isConcrete &= isConcreteType(t); } return isConcrete; } }
private void checkMethod(ResourceMethod method) { checkValueProviders(method); final Invocable invocable = method.getInvocable(); checkParameters(method); if (!isConcreteType(responseType)) { Errors.warning(invocable.getHandlingMethod(), LocalizationMessages.TYPE_OF_METHOD_NOT_RESOLVABLE_TO_CONCRETE_TYPE(responseType, checkUnexpectedAnnotations(method);
@Override public void visitResourceMethod(final ResourceMethod method) { switch (method.getType()) { case RESOURCE_METHOD: visitJaxrsResourceMethod(method); break; case SUB_RESOURCE_LOCATOR: visitSubResourceLocator(method); break; } }
@Override public void visitResourceHandlerConstructor(final HandlerConstructor constructor) { Class<?> resClass = constructor.getConstructor().getDeclaringClass(); boolean isSingleton = isSingleton(resClass); int paramCount = 0; for (Parameter p : constructor.getParameters()) { ResourceMethodValidator.validateParameter(p, constructor.getConstructor(), constructor.getConstructor() .toGenericString(), Integer.toString(++paramCount), isSingleton); } }