Example usage for org.springframework.core.annotation AnnotationUtils isAnnotationDeclaredLocally

List of usage examples for org.springframework.core.annotation AnnotationUtils isAnnotationDeclaredLocally

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotationUtils isAnnotationDeclaredLocally.

Prototype

public static boolean isAnnotationDeclaredLocally(Class<? extends Annotation> annotationType, Class<?> clazz) 

Source Link

Document

Determine whether an annotation of the specified annotationType is declared locally (i.e.

Usage

From source file:com.epam.ta.reportportal.ws.validation.JaskonRequiredPropertiesValidator.java

@Override
public boolean supports(Class<?> clazz) {
    return AnnotationUtils.isAnnotationDeclaredLocally(JsonInclude.class, clazz);
}

From source file:com.epam.ta.reportportal.ws.validation.JaskonRequiredPropertiesValidator.java

@Override
public void validate(Object object, Errors errors) {
    for (Field field : collectFields(object.getClass())) {
        if (AnnotationUtils.isAnnotationDeclaredLocally(JsonInclude.class, field.getType())) {
            try {
                Object innerObject = Accessible.on(object).field(field).getValue();
                if (null != innerObject) {
                    errors.pushNestedPath(field.getName());
                    validate(innerObject, errors);
                }/*from w  w w.  j a  v  a2s  . c  o  m*/
            } catch (Exception e) {
                LOGGER.error("JaskonRequiredPropertiesValidator error: " + e.getMessage(), e);
                // do nothing
            }

        }
        if (field.isAnnotationPresent(JsonProperty.class)
                && field.getAnnotation(JsonProperty.class).required()) {
            String errorCode = new StringBuilder("NotNull.").append(field.getName()).toString();
            ValidationUtils.rejectIfEmpty(errors, field.getName(), errorCode, new Object[] { errorCode });
        }
    }
    if (errors.getNestedPath() != null && errors.getNestedPath().length() != 0) {
        errors.popNestedPath();
    }
}

From source file:com.github.philippn.springremotingautoconfigure.server.annotation.HttpInvokerServiceExporterRegistrar.java

@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    for (String beanName : registry.getBeanDefinitionNames()) {
        BeanDefinition definition = registry.getBeanDefinition(beanName);
        if (definition.getBeanClassName() != null) {
            try {
                Class<?> resolvedClass = ClassUtils.forName(definition.getBeanClassName(), null);
                Class<?>[] beanInterfaces = resolvedClass.getInterfaces();
                for (Class<?> clazz : beanInterfaces) {
                    if (AnnotationUtils.isAnnotationDeclaredLocally(RemoteExport.class, clazz)) {
                        setupExport(clazz, beanName, registry);
                    }/*from w  w  w.  j  a  v a  2 s .  c  o  m*/
                }
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException("Unable to inspect class " + definition.getBeanClassName()
                        + " for @RemoteExport annotations");
            }
        }
    }
}

From source file:flex.contrib.factories.config.FlexAnnotationBeanPostProcessor.java

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (AnnotationUtils.isAnnotationDeclaredLocally(RemotingDestination.class, bean.getClass())) {
        FlexUtils.createRemotingDestination(bean, beanName);
    }/*www.  j a v  a  2 s .  co m*/
    return bean;
}

From source file:ei.ne.ke.cassandra.cql3.EntitySpecificationUtils.java

/**
 * If exactly one field is annotated with @EmbeddedId or the class is
 * annotated with @IdClass, we consider the entity a compound entity (= the
 * table has a compound key).  Otherwise if exactly one field is annotated
 * with @Id, we consider the entity a simple entity (= the table has a
 * primary key)./*from  ww w .jav  a  2s  . co  m*/
 *
 * @param entityClazz
 * @return what type of entity the annotated class is (simple or compound).
 */
public static <T> SupportedEntityType inspectEntityClass(Class<T> entityClazz) {
    Preconditions.checkNotNull(entityClazz);
    boolean idClass = AnnotationUtils.isAnnotationDeclaredLocally(IdClass.class, entityClazz);
    Field id = findPrimaryKeyField(entityClazz);
    Field embeddedId = findCompoundKeyField(entityClazz);
    if (idClass) {
        if (embeddedId != null) {
            throw new IllegalStateException("@IdClass and @EmbeddedId are mutually exclusive.");
        }
        return SupportedEntityType.COMPOUND_IDCLASS;
    }
    if (id != null && embeddedId != null) {
        throw new IllegalStateException("@Id and @EmbeddedId are mutually exclusive");
    } else if (id == null && embeddedId == null) {
        throw new IllegalStateException("Entity needs at least one of @Id, @EmbeddedId, or @IdClass");
    } else if (id != null) {
        return SupportedEntityType.SIMPLE;
    } else if (embeddedId != null) {
        /*
         * If the field is annotated with @EmbeddedId, then the type of the
         * field must have been annotated with @Embeddable.
         */
        Class<?> embeddedType = embeddedId.getType();
        boolean annotatedWithEmbeddable = false;
        for (Annotation annotation : embeddedType.getDeclaredAnnotations()) {
            if (annotation.annotationType().equals(javax.persistence.Embeddable.class)) {
                annotatedWithEmbeddable = true;
                break;
            }
        }
        if (!annotatedWithEmbeddable) {
            throw new IllegalStateException("Embedded entity isn't annotated with @Embeddable.");
        }
        return SupportedEntityType.COMPOUND;
    } else {
        return SupportedEntityType.NONE;
    }
}

From source file:flex.contrib.utils.FlexUtils.java

/**
* Checks if the bean has a remoting destination annotation declares either locally or using a proxy bean.
*
* @param bean the bean for which to check if it has a remoting destination annotation declared
* @return true if the bean has a remoting destination annotation declared
*///from  w w w.  j  a va  2 s .c o m
public static boolean hasRemotingDestinationAnnotation(Object bean) {
    return (AnnotationUtils.isAnnotationDeclaredLocally(flex.contrib.stereotypes.RemotingDestination.class,
            bean.getClass()))
            || (AopUtils.isAopProxy(bean) && AnnotationUtils.isAnnotationDeclaredLocally(
                    flex.contrib.stereotypes.RemotingDestination.class, AopUtils.getTargetClass(bean)));
}

From source file:org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.java

/**
 * Determine if the specified include {@link TypeFilter} is supported by the index.
 * @param filter the filter to check/*from   w  w w. j  a v  a 2s .co m*/
 * @return whether the index supports this include filter
 * @since 5.0
 * @see #extractStereotype(TypeFilter)
 */
private boolean indexSupportsIncludeFilter(TypeFilter filter) {
    if (filter instanceof AnnotationTypeFilter) {
        Class<? extends Annotation> annotation = ((AnnotationTypeFilter) filter).getAnnotationType();
        return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotation)
                || annotation.getName().startsWith("javax."));
    }
    if (filter instanceof AssignableTypeFilter) {
        Class<?> target = ((AssignableTypeFilter) filter).getTargetType();
        return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target);
    }
    return false;
}