Example usage for java.lang.reflect Field isAnnotationPresent

List of usage examples for java.lang.reflect Field isAnnotationPresent

Introduction

In this page you can find the example usage for java.lang.reflect Field isAnnotationPresent.

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:tv.arte.resteventapi.core.presentation.decoration.RestEventApiDecorationProvider.java

/**
 * Retrieve a decoration context related to a given bean
 * /*from ww w .  ja v  a 2s.  com*/
 * @param bean A given bean
 * @return A map with field names as keys and appropriate objects as values
 */
public static Map<String, ?> getBeanDecorationContext(final Object bean) {
    Map<String, Object> decorationContext = new LinkedHashMap<String, Object>();

    //Construct Hateoas self referencing link
    if (hrefedBeansControllerMethodMapping.containsKey(bean.getClass())) {
        Method method = hrefedBeansControllerMethodMapping.get(bean.getClass());
        final Map<String, Object> paramValue = new LinkedHashMap<String, Object>();

        ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
            public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {

                String hrefedValue = field.getAnnotation(HrefedParamField.class).value();

                if (StringUtils.isBlank(hrefedValue)) {
                    hrefedValue = field.getName();
                }

                Object fieldValue = null;
                try {
                    fieldValue = PropertyUtils.getProperty(bean, field.getName());
                } catch (Exception e) {
                    throw new RestEventApiRuntimeException("Unable to access the bean property value.");
                }
                if (fieldValue != null) {
                    paramValue.put(hrefedValue, fieldValue);
                }
            }
        }, new FieldFilter() {
            public boolean matches(Field field) {
                return field.isAnnotationPresent(HrefedParamField.class);
            }
        });

        decorationContext.put(HATEOAS_HREF_KEY, RestEventApiControllerLinkBuilder
                .linkTo(method.getDeclaringClass(), method, paramValue, conversionService));
    }

    return decorationContext;
}

From source file:com.cassius.spring.assembly.test.common.process.MakeObjectProcessor.java

/**
 * Need process before.// w ww.j a  v  a2s .c  o  m
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessBefore(Object instance, Field field) {
    return field.isAnnotationPresent(MakeObject.class) && !field.getType().isPrimitive();
}

From source file:com.cassius.spring.assembly.test.common.process.SpringBeanProcessor.java

/**
 * Need process before./*from w ww.  j av  a  2s. c  o m*/
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessBefore(Object instance, Field field) {
    return field.isAnnotationPresent(SpringBean.class);
}

From source file:com.cassius.spring.assembly.test.common.process.SpringMockProcessor.java

/**
 * Need process before./*from w w w.j av a2s  .  co  m*/
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessBefore(Object instance, Field field) {
    return field.isAnnotationPresent(SpringMock.class);
}

From source file:com.cassius.spring.assembly.test.common.process.SpringMockProcessor.java

/**
 * Need process after.//from   w  w w  . j a va2s .c o  m
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessAfter(Object instance, Field field) {
    return field.isAnnotationPresent(SpringMock.class);
}

From source file:com.cassius.spring.assembly.test.common.process.MockObjectProcessor.java

/**
 * Need process before./* w w  w  . j a  va 2  s.  co m*/
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessBefore(Object instance, Field field) {
    return field.isAnnotationPresent(MockObject.class);
}

From source file:com.cassius.spring.assembly.test.common.process.MockObjectProcessor.java

/**
 * Need process after.//from  w w  w  . j ava 2 s  . c  o m
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessAfter(Object instance, Field field) {
    return field.isAnnotationPresent(MockObject.class);
}

From source file:com.cassius.spring.assembly.test.common.process.MockOnBeanProcessor.java

/**
 * Need process before./*from   w ww  .  j  a  va2  s .  c o  m*/
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessBefore(Object instance, Field field) {
    return field.isAnnotationPresent(MockOnBean.class);
}

From source file:com.cassius.spring.assembly.test.common.process.MockOnBeanProcessor.java

/**
 * Need process after.//from   ww w  .  j a  v a2 s. com
 *
 * @param instance the instance
 * @param field the field
 * @return the boolean
 */
@Override
protected boolean needProcessAfter(Object instance, Field field) {
    return field.isAnnotationPresent(MockOnBean.class);
}

From source file:com.cognifide.qa.bb.aem.ui.DialogFieldProvider.java

/**
 * PageObjectInjectorListener calls this method to check if the provider is able to handle currently
 * injected field./*ww w.  j av a  2s.  co m*/
 * <p>
 * DialogFieldProvider handles fields decorated with DialogField annotation.
 */
@Override
public boolean accepts(Field field) {
    return field.isAnnotationPresent(DialogField.class);
}