Example usage for java.lang Class getAnnotation

List of usage examples for java.lang Class getAnnotation

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<A> annotationClass) 

Source Link

Usage

From source file:com.dbs.sdwt.jpa.JpaUniqueUtil.java

private List<String> validateCompositeUniqueConstraints(Identifiable<?> entity) {
    Class<?> entityClass = getClassWithoutInitializingProxy(entity);
    Table table = entityClass.getAnnotation(Table.class);
    if (table == null) {
        return emptyList();
    }/*from   ww w.  jav  a 2 s  . c  o m*/
    List<String> errors = newArrayList();
    for (UniqueConstraint uniqueConstraint : table.uniqueConstraints()) {
        if (!checkCompositeUniqueConstraint(entity, entityClass, uniqueConstraint)) {
            errors.add(compositeUniqueConstraintErrorCode(entity, uniqueConstraint));
        }
    }
    return errors;
}

From source file:com.joyveb.dbpimpl.cass.prepare.mapping.BasicCassandraPersistentEntity.java

/**
 * Creates a new {@link BasicCassandraPersistentEntity} with the given {@link TypeInformation}. Will default the table
 * name to the entities simple type name.
 * /* ww  w.  j  a  v  a 2 s  .  co m*/
 * @param typeInformation
 */
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation) {

    super(typeInformation, CassandraPersistentPropertyComparator.INSTANCE);

    this.parser = new SpelExpressionParser();
    this.context = new StandardEvaluationContext();

    Class<?> rawType = typeInformation.getType();
    String fallback = rawType.getSimpleName().toLowerCase();

    if (rawType.isAnnotationPresent(Table.class)) {
        Table d = rawType.getAnnotation(Table.class);
        this.table = StringUtils.hasText(d.name()) ? d.name() : fallback;
    } else {
        this.table = fallback;
    }
}

From source file:io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerAspect.java

private CircuitBreaker getBackendMonitoredAnnotation(ProceedingJoinPoint proceedingJoinPoint) {
    if (logger.isDebugEnabled()) {
        logger.debug("circuitBreaker parameter is null");
    }/*  w  ww  .ja  v  a2s. c o  m*/
    CircuitBreaker circuitBreaker = null;
    Class<?> targetClass = proceedingJoinPoint.getTarget().getClass();
    if (targetClass.isAnnotationPresent(CircuitBreaker.class)) {
        circuitBreaker = targetClass.getAnnotation(CircuitBreaker.class);
        if (circuitBreaker == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("TargetClass has no annotation 'CircuitBreaker'");
            }
            circuitBreaker = targetClass.getDeclaredAnnotation(CircuitBreaker.class);
            if (circuitBreaker == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("TargetClass has no declared annotation 'CircuitBreaker'");
                }
            }
        }
    }
    return circuitBreaker;
}

From source file:de.micromata.mgc.javafx.ControllerService.java

public <W extends Node, C> Pair<W, C> loadControl(Class<C> controlToLoad, Class<W> widget) {
    String file;//  w w  w  .  ja v a  2 s. c  o  m
    FXMLFile fxml = controlToLoad.getAnnotation(FXMLFile.class);
    if (fxml != null) {
        file = fxml.file();
    } else {
        file = "/fxml/" + controlToLoad.getSimpleName() + ".fxml";

    }
    Pair<W, C> load = loadScene(file, widget, controlToLoad);

    return load;
}

From source file:org.geoserver.wps.jts.SpringBeanProcessFactory.java

@Override
protected DescribeProcess getProcessDescription(Name name) {
    Class c = classMap.get(name.getLocalPart());
    if (c == null) {
        return null;
    } else {/*from ww  w  .j  a v a2  s .co m*/
        return (DescribeProcess) c.getAnnotation(DescribeProcess.class);
    }
}

From source file:edu.utah.further.core.util.context.EnumAliasService.java

/**
 * Set the static enum alias map field.//from   w  w w .j a va 2s .  c  om
 * <p>
 * Warning: do not call this method outside this class. It is meant to be called by
 * Spring when instantiating the singleton instance of this bean.
 */
@SuppressWarnings("unchecked")
private BidiMap<String, Class<? extends Enum<?>>> initializeEnumAliases() {
    final Class<Alias> annotationClass = Alias.class;
    // TODO: move to CollectionUtil as a generic factory method
    final BidiMap<String, Class<? extends Enum<?>>> map = new DualHashBidiMap<>();
    for (final Class<?> annotatedClass : this.getObject()) {
        if (annotatedClass.isEnum()) {
            final String alias = annotatedClass.getAnnotation(annotationClass).value();
            final Class<? extends Enum<?>> otherClass = map.get(alias);
            if (otherClass != null) {
                // This is the second time that we encountered the alias
                // key, signal name collision
                final String errorMessage = "Enum alias collision!!! Both " + otherClass + ", " + annotatedClass
                        + " have the same alias: " + quote(alias) + ". Rename the @"
                        + annotationClass.getSimpleName() + " annotation value one of them.";
                // Log message before throwing, otherwise Spring will
                // show an incomprehensible TargetInvocationException
                // without its cause here.
                log.error(errorMessage);
                throw new ApplicationException(errorMessage);
            }
            map.put(alias, (Class<? extends Enum<?>>) annotatedClass);
        }
    }
    return map;
}

From source file:io.seventyone.mongoutils.MongoServiceImplementation.java

@Override
public MongoCollection<Document> getCollection(Class<?> entityClass) {
    io.seventyone.mongoutils.annotations.MongoCollection annotation;
    annotation = entityClass.getAnnotation(io.seventyone.mongoutils.annotations.MongoCollection.class);

    if (annotation == null) {
        String message = String.format("Annotation '@MongoCollection' not present on class '%s'",
                entityClass.getSimpleName());
        throw new UnsupportedOperationException(message);
    }//from ww w .  ja  va  2 s  . c  om
    String collectionName = annotation.value();
    if (StringUtils.isBlank(collectionName)) {
        collectionName = entityClass.getSimpleName();
    }
    return this.getCollection(annotation.value());
}

From source file:com.lonepulse.robozombie.executor.ConfigurationService.java

/**
 * {@inheritDoc}//ww  w .j a  v a2  s.c o m
 */
@Override
public Configuration register(Class<?> endpointClass) {

    try {

        if (endpointClass.isAnnotationPresent(Config.class)) {

            Configuration configuration = endpointClass.getAnnotation(Config.class).value().newInstance();

            HttpClient httpClient = configuration.httpClient();
            HttpClientDirectory.INSTANCE.bind(endpointClass, httpClient); //currently the only configurable property

            return configuration;
        } else {

            HttpClientDirectory.INSTANCE.bind(endpointClass, HttpClientDirectory.DEFAULT);

            return new Configuration() {
            };
        }
    } catch (Exception e) {

        throw new ConfigurationFailedException(endpointClass, e);
    }
}

From source file:com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementActionConfigTransformer.java

public List<ServiceLevelAgreementActionUiConfigurationItem> discoverActionConfigurations() {

    List<ServiceLevelAgreementActionUiConfigurationItem> rules = new ArrayList<>();
    Set<Class<?>> items = new Reflections("com.thinkbiganalytics")
            .getTypesAnnotatedWith(ServiceLevelAgreementActionConfig.class);
    for (Class c : items) {
        List<FieldRuleProperty> properties = getUiProperties(c);
        ServiceLevelAgreementActionConfig policy = (ServiceLevelAgreementActionConfig) c
                .getAnnotation(ServiceLevelAgreementActionConfig.class);
        ServiceLevelAgreementActionUiConfigurationItem configItem = buildUiModel(policy, c, properties);
        rules.add(configItem);//from  w  ww . j av a2  s . c  o m

    }

    return rules;
}

From source file:com.smbtec.xo.orientdb.impl.OrientDbMetadataFactory.java

@Override
public IndexedPropertyMetadata createIndexedPropertyMetadata(final PropertyMethod propertyMethod) {
    final String name = propertyMethod.getName();
    final Class<?> declaringClass = propertyMethod.getAnnotatedElement().getDeclaringClass();
    Class<? extends Element> type = null;
    if (declaringClass.getAnnotation(Vertex.class) != null) {
        type = com.tinkerpop.blueprints.Vertex.class;
    } else if (declaringClass.getAnnotation(Edge.class) != null) {
        type = com.tinkerpop.blueprints.Edge.class;
    } else {//from  w  w w. j a v a  2 s  . c  o m
        throw new XOException("Property '" + name
                + "' was found with index annotation, but the declaring type is neither a vertex nor an edge.");
    }
    final Indexed indexedAnnotation = propertyMethod.getAnnotation(Indexed.class);
    final boolean unique = indexedAnnotation.unique();
    final Class<?> dataType = propertyMethod.getType();
    return new IndexedPropertyMetadata(name, unique, dataType, type);
}