List of usage examples for java.lang.annotation Annotation equals
boolean equals(Object obj);
From source file:gov.nih.nci.caarray.validation.UniqueConstraintValidator.java
private boolean declaresConstraint(Class<?> entityClass) { Annotation[] annotations = entityClass.getDeclaredAnnotations(); for (Annotation a : annotations) { if (a.equals(uniqueConstraint)) { return true; } else if (UniqueConstraints.class.equals(a.annotationType())) { UniqueConstraints ucs = (UniqueConstraints) a; return ArrayUtils.contains(ucs.constraints(), uniqueConstraint); }//from w w w. j a va 2 s .c om } return false; }
From source file:org.guicerecipes.spring.support.AutowiredMemberProvider.java
/** * Returns a new filter on the given member to respect the use of {@link Qualifier} annotations or annotations annotated with {@link Qualifier} *//* www. j av a 2 s .c o m*/ protected Predicate<Binding> createQualifierFilter(Member member, Annotation[] parameterAnnotations) { if (member instanceof AnnotatedElement) { AnnotatedElement annotatedElement = (AnnotatedElement) member; final Qualifier qualifier = annotatedElement.getAnnotation(Qualifier.class); if (qualifier != null) { final String expectedValue = qualifier.value(); final boolean notEmptyValue = Strings.isNotEmpty(expectedValue); return new Predicate<Binding>() { public boolean matches(Binding binding) { String value = annotationName(binding); // we cannot use @Qualified as a binding annotation // so we can't test for just a @Qualified binding with no text // so lets just test for a non-empty string if (notEmptyValue) { return Comparators.equal(expectedValue, value); } else { return Strings.isNotEmpty(value); } } @Override public String toString() { return "@Autowired @Qualifier(" + expectedValue + ")"; } }; } // lets iterate through all of the annotations looking for a qualifier Set<Annotation> qualifiedAnnotations = Sets.newHashSet(); Annotation[] annotations = annotatedElement.getAnnotations(); for (Annotation annotation : annotations) { if (isQualified(annotation)) { qualifiedAnnotations.add(annotation); } } if (parameterAnnotations != null) { for (Annotation annotation : parameterAnnotations) { if (isQualified(annotation)) { qualifiedAnnotations.add(annotation); } } } int size = qualifiedAnnotations.size(); if (size == 1) { final Annotation annotation = Iterables.getOnlyElement(qualifiedAnnotations); return new Predicate<Binding>() { public boolean matches(Binding binding) { Annotation actualAnnotation = binding.getKey().getAnnotation(); return (actualAnnotation != null) && actualAnnotation.equals(annotation); } @Override public String toString() { return "@Autowired " + annotation; } }; } else if (size > 0) { throw new ProvisionException("Too many qualified annotations " + qualifiedAnnotations + " when trying to inject " + member); } } return new Predicate<Binding>() { public boolean matches(Binding binding) { return true; } @Override public String toString() { return "@Autowired"; } }; }
From source file:org.guiceyfruit.spring.support.AutowiredMemberProvider.java
/** * Returns a new filter on the given member to respect the use of {@link Qualifier} annotations or * annotations annotated with {@link Qualifier} *//*from w ww.j a va 2 s . c om*/ protected Predicate<Binding> createQualifierFilter(Member member, Annotation[] parameterAnnotations) { if (member instanceof AnnotatedElement) { AnnotatedElement annotatedElement = (AnnotatedElement) member; final Qualifier qualifier = annotatedElement.getAnnotation(Qualifier.class); if (qualifier != null) { final String expectedValue = qualifier.value(); final boolean notEmptyValue = Strings.isNotEmpty(expectedValue); return new Predicate<Binding>() { public boolean matches(Binding binding) { String value = annotationName(binding); // we cannot use @Qualified as a binding annotation // so we can't test for just a @Qualified binding with no text // so lets just test for a non-empty string if (notEmptyValue) { return Comparators.equal(expectedValue, value); } else { return Strings.isNotEmpty(value); } } @Override public String toString() { return "@Autowired @Qualifier(" + expectedValue + ")"; } }; } // lets iterate through all of the annotations looking for a qualifier Set<Annotation> qualifiedAnnotations = Sets.newHashSet(); Annotation[] annotations = annotatedElement.getAnnotations(); for (Annotation annotation : annotations) { if (isQualified(annotation)) { qualifiedAnnotations.add(annotation); } } if (parameterAnnotations != null) { for (Annotation annotation : parameterAnnotations) { if (isQualified(annotation)) { qualifiedAnnotations.add(annotation); } } } int size = qualifiedAnnotations.size(); if (size == 1) { final Annotation annotation = Iterables.getOnlyElement(qualifiedAnnotations); return new Predicate<Binding>() { public boolean matches(Binding binding) { Annotation actualAnnotation = binding.getKey().getAnnotation(); return actualAnnotation != null && actualAnnotation.equals(annotation); } @Override public String toString() { return "@Autowired " + annotation; } }; } else if (size > 0) { throw new ProvisionException("Too many qualified annotations " + qualifiedAnnotations + " when trying to inject " + member); } } return new Predicate<Binding>() { public boolean matches(Binding binding) { return true; } @Override public String toString() { return "@Autowired"; } }; }
From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java
private boolean hasMatchingAnnotation(final PropertyDescriptor ppropertyDescription, final boolean useField, final ConstraintDescriptor<?> constraint) throws UnableToCompleteException { final Annotation expectedAnnotation = constraint.getAnnotation(); final Class<? extends Annotation> expectedAnnotationClass = expectedAnnotation.annotationType(); if (expectedAnnotation .equals(this.getAnnotation(ppropertyDescription, useField, expectedAnnotationClass))) { return true; }/*from w ww . jav a 2 s .c om*/ return this.hasMatchingAnnotation(expectedAnnotation, this.getAnnotations(ppropertyDescription, useField)); }
From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java
private boolean hasMatchingAnnotation(final ConstraintDescriptor<?> constraint) throws UnableToCompleteException { final Annotation expectedAnnotation = constraint.getAnnotation(); final Class<? extends Annotation> expectedAnnotationClass = expectedAnnotation.annotationType(); if (expectedAnnotation.equals(this.beanHelper.getClazz().getAnnotation(expectedAnnotationClass))) { return true; }/*w ww .j ava2s . c om*/ // See spec section 2.2. Applying multiple constraints of the same type final Annotation[] annotations = this.beanHelper.getClazz().getAnnotations(); return this.hasMatchingAnnotation(expectedAnnotation, annotations); }
From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java
private boolean hasMatchingAnnotation(final Annotation expectedAnnotation, final Annotation[] annotations) throws UnableToCompleteException { // See spec section 2.2. Applying multiple constraints of the same type for (final Annotation annotation : annotations) { // annotations not annotated by @Constraint if (annotation.annotationType().getAnnotation(Constraint.class) == null) { try { // value element has a return type of an array of constraint // annotations final Method valueMethod = annotation.annotationType().getMethod("value"); final Class<?> valueType = valueMethod.getReturnType(); if (valueType.isArray() && Annotation.class.isAssignableFrom(valueType.getComponentType())) { if (Modifier.isAbstract(valueMethod.getModifiers())) { // handle edge case where interface is marked "abstract" valueMethod.setAccessible(true); }// w w w . j av a 2s . c o m final Annotation[] valueAnnotions = (Annotation[]) valueMethod.invoke(annotation); for (final Annotation annotation2 : valueAnnotions) { if (expectedAnnotation.equals(annotation2)) { return true; } } } } catch (final NoSuchMethodException ignore) { // NOPMD // Expected Case. } catch (final Exception e) { throw error(this.logger, e); } } } return false; }