List of usage examples for org.springframework.core.annotation AnnotationUtils getValue
@Nullable public static Object getValue(@Nullable Annotation annotation, @Nullable String attributeName)
From source file:ch.rasc.extclassgenerator.validation.AbstractValidation.java
public static void addValidationToModel(ModelBean model, ModelFieldBean modelFieldBean, Annotation fieldAnnotation, IncludeValidation includeValidation) { String annotationClassName = fieldAnnotation.annotationType().getName(); if (includeValidation == IncludeValidation.BUILTIN || includeValidation == IncludeValidation.ALL) { if (annotationClassName.equals("javax.validation.constraints.NotNull") || annotationClassName.equals("org.hibernate.validator.constraints.NotEmpty")) { model.addValidation(new PresenceValidation(modelFieldBean.getName())); } else if (annotationClassName.equals("javax.validation.constraints.Size") || annotationClassName.equals("org.hibernate.validator.constraints.Length")) { Integer min = (Integer) AnnotationUtils.getValue(fieldAnnotation, "min"); Integer max = (Integer) AnnotationUtils.getValue(fieldAnnotation, "max"); model.addValidation(new LengthValidation(modelFieldBean.getName(), min, max)); } else if (annotationClassName.equals("javax.validation.constraints.Pattern")) { String regexp = (String) AnnotationUtils.getValue(fieldAnnotation, "regexp"); model.addValidation(new FormatValidation(modelFieldBean.getName(), regexp)); } else if (annotationClassName.equals("org.hibernate.validator.constraints.Email")) { model.addValidation(new EmailValidation(modelFieldBean.getName())); }//from w ww . j av a 2 s . c om } if (includeValidation == IncludeValidation.ALL) { if (annotationClassName.equals("javax.validation.constraints.DecimalMax")) { String value = (String) AnnotationUtils.getValue(fieldAnnotation); model.addValidation(new RangeValidation(modelFieldBean.getName(), null, new BigDecimal(value))); } else if (annotationClassName.equals("javax.validation.constraints.DecimalMin")) { String value = (String) AnnotationUtils.getValue(fieldAnnotation); model.addValidation(new RangeValidation(modelFieldBean.getName(), new BigDecimal(value), null)); } else if (annotationClassName.equals("javax.validation.constraints.Digits")) { Integer integer = (Integer) AnnotationUtils.getValue(fieldAnnotation, "integer"); Integer fraction = (Integer) AnnotationUtils.getValue(fieldAnnotation, "fraction"); model.addValidation(new DigitsValidation(modelFieldBean.getName(), integer, fraction)); } else if (annotationClassName.equals("javax.validation.constraints.Future")) { model.addValidation(new FutureValidation(modelFieldBean.getName())); } else if (annotationClassName.equals("javax.validation.constraints.Max")) { Long value = (Long) AnnotationUtils.getValue(fieldAnnotation); model.addValidation(new RangeValidation(modelFieldBean.getName(), null, value)); } else if (annotationClassName.equals("javax.validation.constraints.Min")) { Long value = (Long) AnnotationUtils.getValue(fieldAnnotation); model.addValidation(new RangeValidation(modelFieldBean.getName(), value, null)); } else if (annotationClassName.equals("javax.validation.constraints.Past")) { model.addValidation(new PastValidation(modelFieldBean.getName())); } else if (annotationClassName.equals("org.hibernate.validator.constraints.CreditCardNumber")) { model.addValidation(new CreditCardNumberValidation(modelFieldBean.getName())); } else if (annotationClassName.equals("org.hibernate.validator.constraints.NotBlank")) { model.addValidation(new NotBlankValidation(modelFieldBean.getName())); } else if (annotationClassName.equals("org.hibernate.validator.constraints.Range")) { Long min = (Long) AnnotationUtils.getValue(fieldAnnotation, "min"); Long max = (Long) AnnotationUtils.getValue(fieldAnnotation, "max"); model.addValidation(new RangeValidation(modelFieldBean.getName(), min, max)); } } }
From source file:com.ocs.dynamo.utils.ClassUtils.java
/** * Get the value of a field in an annotation * // w ww.j av a2 s . c o m * @param field * The field with annotations * @param annotionType * The name of the annotation type to find * @param attributeName * The name of the attribute on the annotation type to find the value * @return the value of the field of the annotation or null when not found */ @SuppressWarnings("unchecked") public static <T extends Annotation, R> R getAnnotationAttributeValue(Field field, Class<T> annotationClass, String attributeName) { R result = null; Annotation annotation = getAnnotationOnField(field, annotationClass); if (annotation != null) { result = (R) AnnotationUtils.getValue(annotation, attributeName); } return result; }
From source file:ch.ralscha.extdirectspring.util.ParameterInfo.java
public ParameterInfo(Class<?> clazz, Method method, int paramIndex) { MethodParameter methodParam = new MethodParameter(method, paramIndex); methodParam.initParameterNameDiscovery(discoverer); GenericTypeResolver.resolveParameterType(methodParam, clazz); this.name = methodParam.getParameterName(); this.typeDescriptor = new TypeDescriptor(methodParam); Class<?> paramType = methodParam.getParameterType(); javaUtilOptional = paramType.getName().equals("java.util.Optional"); this.supportedParameter = SupportedParameters.isSupported(typeDescriptor.getObjectType()); Annotation[] paramAnnotations = methodParam.getParameterAnnotations(); for (Annotation paramAnn : paramAnnotations) { this.hasRequestParamAnnotation = false; this.hasMetadataParamAnnotation = false; this.hasRequestHeaderAnnotation = false; this.hasCookieValueAnnotation = false; this.hasAuthenticationPrincipalAnnotation = null; if (RequestParam.class.isInstance(paramAnn)) { RequestParam requestParam = (RequestParam) paramAnn; if (StringUtils.hasText(requestParam.value())) { this.name = requestParam.value(); }/*from ww w . ja v a2s .c o m*/ this.required = requestParam.required(); this.defaultValue = ValueConstants.DEFAULT_NONE.equals(requestParam.defaultValue()) ? null : requestParam.defaultValue(); this.hasRequestParamAnnotation = true; break; } else if (MetadataParam.class.isInstance(paramAnn)) { MetadataParam metadataParam = (MetadataParam) paramAnn; if (StringUtils.hasText(metadataParam.value())) { this.name = metadataParam.value(); } this.required = metadataParam.required(); this.defaultValue = ValueConstants.DEFAULT_NONE.equals(metadataParam.defaultValue()) ? null : metadataParam.defaultValue(); this.hasMetadataParamAnnotation = true; break; } else if (RequestHeader.class.isInstance(paramAnn)) { RequestHeader requestHeader = (RequestHeader) paramAnn; if (StringUtils.hasText(requestHeader.value())) { this.name = requestHeader.value(); } this.required = requestHeader.required(); this.defaultValue = ValueConstants.DEFAULT_NONE.equals(requestHeader.defaultValue()) ? null : requestHeader.defaultValue(); this.hasRequestHeaderAnnotation = true; break; } else if (CookieValue.class.isInstance(paramAnn)) { CookieValue cookieValue = (CookieValue) paramAnn; if (StringUtils.hasText(cookieValue.value())) { this.name = cookieValue.value(); } this.required = cookieValue.required(); this.defaultValue = ValueConstants.DEFAULT_NONE.equals(cookieValue.defaultValue()) ? null : cookieValue.defaultValue(); this.hasCookieValueAnnotation = true; break; } else if (paramAnn.annotationType().getName() .equals("org.springframework.security.web.bind.annotation.AuthenticationPrincipal") || paramAnn.annotationType().getName() .equals("org.springframework.security.core.annotation.AuthenticationPrincipal")) { hasAuthenticationPrincipalAnnotation = (Boolean) AnnotationUtils.getValue(paramAnn, "errorOnInvalidType"); } } }
From source file:org.synyx.hades.dao.query.QueryMethod.java
/** * Returns the countQuery string declared in a {@link Query} annotation or * {@literal null} if neither the annotation found nor the attribute was * specified./* w ww.ja v a 2 s.c o m*/ * * @return */ String getCountQuery() { String countQuery = (String) AnnotationUtils.getValue(getQueryAnnotation(), "countQuery"); return StringUtils.hasText(countQuery) ? countQuery : null; }
From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java
/** * @return value of {@link Facet#limit()} */// w w w.j a v a 2s.com public Integer getFacetLimit() { return (Integer) AnnotationUtils.getValue(getFacetAnnotation(), "limit"); }
From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java
/** * @return value of {@link Facet#minCount()} *//*from w w w. j a v a 2 s .c o m*/ public Integer getFacetMinCount() { return (Integer) AnnotationUtils.getValue(getFacetAnnotation(), "minCount"); }
From source file:org.synyx.hades.dao.query.QueryMethod.java
/** * Returns whether we should clear automatically for modifying queries. * // w w w. j a v a2 s . c o m * @return */ private boolean getClearAutomatically() { return (Boolean) AnnotationUtils.getValue(method.getAnnotation(Modifying.class), "clearAutomatically"); }
From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java
/** * @return value of {@link com.frank.search.solr.repository.Query#delete()} * @since 1.2/*from w w w . java 2s.c o m*/ */ public boolean isDeleteQuery() { if (hasQueryAnnotation()) { return ((Boolean) AnnotationUtils.getValue(getQueryAnnotation(), "delete")).booleanValue(); } return false; }
From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java
private String getAnnotationValueAsStringOrNullIfBlank(Annotation annotation, String attributeName) { String value = (String) AnnotationUtils.getValue(annotation, attributeName); return StringUtils.hasText(value) ? value : null; }
From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java
private Integer getAnnotationValueAsIntOrNullIfNegative(Annotation annotation, String attributeName) { Integer timeAllowed = (Integer) AnnotationUtils.getValue(annotation, attributeName); if (timeAllowed != null && timeAllowed.intValue() > 0) { return timeAllowed; }//from w ww. ja v a 2 s. c om return null; }