Example usage for java.lang.reflect AnnotatedElement getAnnotation

List of usage examples for java.lang.reflect AnnotatedElement getAnnotation

Introduction

In this page you can find the example usage for java.lang.reflect AnnotatedElement getAnnotation.

Prototype

<T extends Annotation> T getAnnotation(Class<T> annotationClass);

Source Link

Document

Returns this element's annotation for the specified type if such an annotation is present, else null.

Usage

From source file:com.gradecak.alfresco.mvc.aop.TransactionalAdvice.java

private AlfrescoTransaction parseAnnotation(AnnotatedElement ae) {
    AlfrescoTransaction ann = ae.getAnnotation(AlfrescoTransaction.class);
    if (ann == null) {
        for (Annotation metaAnn : ae.getAnnotations()) {
            ann = metaAnn.annotationType().getAnnotation(AlfrescoTransaction.class);
            if (ann != null) {
                break;
            }/*from w  w  w  .j  a  va  2 s. c o  m*/
        }
    }
    if (ann != null) {
        return parseAnnotation(ann);
    } else {
        return null;
    }
}

From source file:com.sf.ddao.ops.UpdateSqlOperation.java

public void init(AnnotatedElement element, Annotation annotation) {
    Update updateAnnotation = element.getAnnotation(Update.class);
    init(element, updateAnnotation.value());
}

From source file:com.sf.ddao.ops.SelectSqlOperation.java

public void init(AnnotatedElement element, Annotation annotation) {
    Select selectSql = element.getAnnotation(Select.class);
    init(element, selectSql.value());//from  w  ww.j  a v a 2 s  .  c  om
}

From source file:com.adobe.acs.commons.models.injectors.impl.I18nInjector.java

private String getI18nKey(String name, AnnotatedElement annotatedElement) {

    I18N annotation = annotatedElement.getAnnotation(I18N.class);
    String annotationKey = annotation.value();

    if (StringUtils.isNotEmpty(annotationKey)) {
        return annotationKey;
    }/* w  w  w.  j a  va2s  .  co m*/

    return name;
}

From source file:com.springinpractice.ch14.kite.interceptor.AnnotationGuardListSource.java

private List<Guard> parseAnnotation(AnnotatedElement elem) {
    assert (elem != null);
    return parseAnnotation(elem.getAnnotation(GuardedBy.class));
}

From source file:com.sf.ddao.shards.ops.MultiShardSelectSqlOperation.java

@Override
public void init(AnnotatedElement element, Annotation annotation) {
    MultiShardSelect multiShardSelect = element.getAnnotation(MultiShardSelect.class);
    resultMerger = injector.getInstance(multiShardSelect.resultMerger());
    super.init(element, multiShardSelect.value());
}

From source file:com.sf.ddao.ops.SelectThenInsertSqlOperation.java

@Override
public void init(AnnotatedElement element, Annotation annotation) {
    SelectThenInsert selectThenInsert = element.getAnnotation(SelectThenInsert.class);
    String sql[] = selectThenInsert.value();
    if (sql.length != 2) {
        throw new InitializerException(
                SelectThenInsert.class.getSimpleName() + " annotation has to have 2 sql statments, but got:"
                        + Arrays.toString(sql) + ", for method " + element);
    }/*from w w w. java2  s  .c o m*/
    try {
        selectSqlOp.init(element, sql[0]);
        super.init(element, sql[1]);
    } catch (Exception e) {
        throw new InitializerException(
                "Failed to setup sql operations " + Arrays.toString(sql) + " for method " + element, e);
    }
}

From source file:com.tojc.ormlite.android.annotation.info.ContentUriInfo.java

public ContentUriInfo(AnnotatedElement element) {
    DefaultContentUri contentUri = element.getAnnotation(DefaultContentUri.class);
    String authority = null;//from  www  .j  a  v  a  2  s.  com
    String path = null;
    if (contentUri != null) {
        authority = contentUri.authority();
        path = contentUri.path();
    }

    if (element instanceof Class<?>) {
        Class<?> clazz = (Class<?>) element;
        if (StringUtils.isEmpty(authority)) {
            authority = clazz.getPackage().getName();
        }
        if (StringUtils.isEmpty(path)) {
            // TODO use DataBase annotation
            path = clazz.getSimpleName().toLowerCase();
        }
    }

    initialize(authority, path);
}

From source file:com.haulmont.cuba.core.sys.PersistentEntitiesMetadataLoader.java

@Override
protected void initMetaProperty(MetaClass metaClass, MetaProperty metaProperty) {
    super.initMetaProperty(metaClass, metaProperty);

    if (metaProperty.getRange() == null || !metaProperty.getRange().isClass())
        return;/*from w  w  w .  ja  va 2s  .  com*/

    AnnotatedElement annotatedElement = metaProperty.getAnnotatedElement();

    OnDelete onDelete = annotatedElement.getAnnotation(OnDelete.class);
    if (onDelete != null) {
        Map<String, Object> metaAnnotations = metaClass.getAnnotations();

        MetaProperty[] properties = (MetaProperty[]) metaAnnotations.get(OnDelete.class.getName());
        properties = (MetaProperty[]) ArrayUtils.add(properties, metaProperty);
        metaAnnotations.put(OnDelete.class.getName(), properties);
    }

    OnDeleteInverse onDeleteInverse = annotatedElement.getAnnotation(OnDeleteInverse.class);
    if (onDeleteInverse != null) {
        Map<String, Object> metaAnnotations = metaProperty.getRange().asClass().getAnnotations();

        MetaProperty[] properties = (MetaProperty[]) metaAnnotations.get(OnDeleteInverse.class.getName());
        properties = (MetaProperty[]) ArrayUtils.add(properties, metaProperty);
        metaAnnotations.put(OnDeleteInverse.class.getName(), properties);
    }
}

From source file:com.tojc.ormlite.android.annotation.info.ContentMimeTypeVndInfo.java

public ContentMimeTypeVndInfo(AnnotatedElement element) {
    DefaultContentMimeTypeVnd contentMimeTypeVnd = element.getAnnotation(DefaultContentMimeTypeVnd.class);
    String name = null;/*from  w w  w  .j a va2s  . com*/
    String type = null;
    if (contentMimeTypeVnd != null) {
        name = contentMimeTypeVnd.name();
        type = contentMimeTypeVnd.type();
    }

    if (element instanceof Class<?>) {
        Class<?> clazz = (Class<?>) element;
        if (StringUtils.isEmpty(name)) {
            name = clazz.getPackage().getName() + PROVIDER_SUFFIX;
        }

        if (StringUtils.isEmpty(type)) {
            type = clazz.getSimpleName().toLowerCase();
        }
    }

    initialize(name, type);
}