Example usage for java.lang Class isAnnotationPresent

List of usage examples for java.lang Class isAnnotationPresent

Introduction

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

Prototype

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

Source Link

Usage

From source file:org.apache.marmotta.commons.sesame.facading.util.FacadeUtils.java

public static <C extends Annotation, D> C getFacadeAnnotation(Class<D> clazz, Class<C> annotation) {
    if (clazz.isAnnotationPresent(annotation)) {
        return clazz.getAnnotation(annotation);
    } else {//from  w w  w . j a  va2s  .c om
        for (final Class<?> iface : clazz.getInterfaces()) {
            if (iface.isAnnotationPresent(annotation)) {
                return iface.getAnnotation(annotation);
            }
        }
        if (clazz.getSuperclass() != null) {
            return getFacadeAnnotation(clazz.getSuperclass(), annotation);
        }
        return null;
    }

}

From source file:net.ymate.platform.plugin.Plugins.java

/**
 * @param clazz ?// w w  w  . java 2  s.  c  o m
 * @return clazz?
 * @throws Exception ??
 */
public static IPluginFactory createFactory(Class<? extends IPluginFactory> clazz) throws Exception {
    IPluginFactory _factory = ClassUtils.impl(clazz, IPluginFactory.class);
    if (_factory != null) {
        if (clazz.isAnnotationPresent(PluginFactory.class)) {
            _factory.init(loadConfig(clazz));
        }
    }
    return _factory;
}

From source file:com.crosstreelabs.junited.elasticsearch.ElasticsearchRule.java

protected static List<ElasticSetup> getAnnotations(final Description description) {
    Class<?> testClass = description.getTestClass();
    String methodName = description.getMethodName();

    List<ElasticSetup> result = new ArrayList<>();
    if (testClass.isAnnotationPresent(ElasticSetup.class)) {
        result.add(testClass.getAnnotation(ElasticSetup.class));
    }/*from   w  w  w  .j a  v  a2s .  c  om*/
    if (testClass.isAnnotationPresent(ElasticSetups.class)) {
        result.addAll(Arrays.asList(testClass.getAnnotation(ElasticSetups.class).value()));
    }
    if (methodName == null) {
        return result;
    }

    try {
        Method method = testClass.getDeclaredMethod(methodName);
        if (method.isAnnotationPresent(ElasticSetup.class)) {
            result.add(method.getAnnotation(ElasticSetup.class));
        }
        if (method.isAnnotationPresent(ElasticSetups.class)) {
            result.addAll(Arrays.asList(method.getAnnotation(ElasticSetups.class).value()));
        }
    } catch (NoSuchMethodException | SecurityException ex) {
    }
    return result;
}

From source file:org.apache.marmotta.commons.sesame.facading.util.FacadeUtils.java

/**
 * Check whether a type is a {@link Facade}, i.e. the type or one of its superinterfaces has the
 * {@link Facade} annotation./*from   w  w w  .  j a v a  2  s  . c o m*/
 * 
 * @param <C>
 * @param clazz
 * @return
 */
public static <C> boolean isFacadeAnnotationPresent(Class<C> clazz, Class<? extends Annotation> annotation) {
    if (clazz.isAnnotationPresent(annotation)) {
        return true;
    } else {
        for (final Class<?> iface : clazz.getInterfaces()) {
            if (iface.isAnnotationPresent(annotation)) {
                return true;
            }
        }
        if (clazz.getSuperclass() != null) {
            return isFacadeAnnotationPresent(clazz.getSuperclass(), annotation);
        }
        return false;
    }
}

From source file:org.lightjason.agentspeak.common.CCommon.java

/**
 * filter of a class to use it as action
 *
 * @param p_class class for checking//w  w  w.  j a v  a2s  .co m
 * @return boolean flag of check result
 */
private static Pair<Boolean, IAgentAction.EAccess> isActionClass(final Class<?> p_class) {
    if (!p_class.isAnnotationPresent(IAgentAction.class))
        return new ImmutablePair<>(false, IAgentAction.EAccess.BLACKLIST);

    final IAgentAction l_annotation = p_class.getAnnotation(IAgentAction.class);
    return new ImmutablePair<>((l_annotation.classes().length == 0) || (Arrays
            .stream(p_class.getAnnotation(IAgentAction.class).classes()).parallel().anyMatch(p_class::equals)),
            l_annotation.access());
}

From source file:com.sqewd.open.dal.services.EntitySchema.java

public static EntitySchema loadSchema(StructEntityReflect enref) throws Exception {
    EntitySchema entity = new EntitySchema();
    Class<?> type = Class.forName(enref.Class);

    entity.name = enref.Entity;// w  ww.  j a  v  a  2 s.  c  o m
    AbstractPersister pers = DataManager.get().getPersister(type);
    entity.persister = pers.getClass().getCanonicalName();
    entity.classname = type.getCanonicalName();

    if (type.isAnnotationPresent(JsonRootName.class)) {
        JsonRootName re = type.getAnnotation(JsonRootName.class);
        entity.jsonname = re.value();
    }

    entity.properties = new ArrayList<PropertySchema>();

    for (StructAttributeReflect attr : enref.Attributes) {
        PropertySchema pdef = PropertySchema.load(type, attr.Field.getName());
        if (pdef != null)
            entity.properties.add(pdef);
    }
    return entity;
}

From source file:xiaofei.library.hermes.util.TypeUtils.java

public static void validateAccessible(Class<?> clazz) throws HermesException {
    if (clazz.isAnnotationPresent(WithinProcess.class)) {
        throw new HermesException(ErrorCodes.CLASS_WITH_PROCESS,
                "Class " + clazz.getName() + " has a WithProcess annotation on it, "
                        + "so it cannot be accessed from outside the process.");
    }//from  ww  w  .  j av a  2  s.  c  o  m
}

From source file:unquietcode.tools.beanmachine.AnnotationUtils.java

/**
 * Determine whether an annotation for the specified <code>annotationType</code> is present
 * on the supplied <code>clazz</code> and is {@link java.lang.annotation.Inherited inherited}
 * i.e., not declared locally for the class).
 * <p>If the supplied <code>clazz</code> is an interface, only the interface itself will be checked.
 * In accordance with standard meta-annotation semantics, the inheritance hierarchy for interfaces
 * will not be traversed. See the {@link java.lang.annotation.Inherited JavaDoc} for the
 * &#064;Inherited meta-annotation for further details regarding annotation inheritance.
 * @param annotationType the Class object corresponding to the annotation type
 * @param clazz the Class object corresponding to the class on which to check for the annotation
 * @return <code>true</code> if an annotation for the specified <code>annotationType</code> is present
 * on the supplied <code>clazz</code> and is {@link java.lang.annotation.Inherited inherited}
 * @see Class#isAnnotationPresent(Class)
 * @see #isAnnotationDeclaredLocally(Class, Class)
 *//*ww w  .  ja va  2 s  .c  o  m*/
public static boolean isAnnotationInherited(Class<? extends Annotation> annotationType, Class<?> clazz) {
    Assert.notNull(annotationType, "Annotation type must not be null");
    Assert.notNull(clazz, "Class must not be null");
    return (clazz.isAnnotationPresent(annotationType) && !isAnnotationDeclaredLocally(annotationType, clazz));
}

From source file:com.weibo.api.motan.core.extension.ExtensionLoader.java

private static <T> boolean isSpiType(Class<T> clz) {
    return clz.isAnnotationPresent(Spi.class);
}

From source file:com.github.valdr.thirdparty.spring.AnnotationUtils.java

/**
 * Determine whether an annotation for the specified {@code annotationType} is present
 * on the supplied {@code clazz} and is {@linkplain java.lang.annotation.Inherited inherited}
 * (i.e., not declared locally for the class).
 * <p>If the supplied {@code clazz} is an interface, only the interface itself will be checked.
 * In accordance with standard meta-annotation semantics, the inheritance hierarchy for interfaces
 * will not be traversed. See the {@linkplain java.lang.annotation.Inherited Javadoc} for the
 * {@code @Inherited} meta-annotation for further details regarding annotation inheritance.
 * @param annotationType the Class object corresponding to the annotation type
 * @param clazz the Class object corresponding to the class on which to check for the annotation
 * @return {@code true} if an annotation for the specified {@code annotationType} is present
 * on the supplied {@code clazz} and is <em>inherited</em>
 * @see Class#isAnnotationPresent(Class)
 * @see #isAnnotationDeclaredLocally(Class, Class)
 *//*from   ww w.j  av a 2s. c o  m*/
public static boolean isAnnotationInherited(Class<? extends Annotation> annotationType, Class<?> clazz) {
    return (clazz.isAnnotationPresent(annotationType) && !isAnnotationDeclaredLocally(annotationType, clazz));
}