List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:de.taimos.dvalin.jaxrs.swagger.SwaggerScanner.java
@Override public Set<Class<?>> classes() { Set<Class<?>> classes = new HashSet<>(); for (Class<?> clz : this.annotationProvider.getClasses()) { if (!this.hasAnnotation(clz, Provider.class) && clz.isAnnotationPresent(Path.class)) { classes.add(clz);//from ww w . j a v a 2s . c o m } } return classes; }
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
private void collectTableUpdatesAnnotations(SparseArray<List<String>> versionUpdates, Class<?> clazz) { if (clazz.isAnnotationPresent(ModelUpdate.class)) { addUpdateIfNeeded(versionUpdates, clazz.getAnnotation(ModelUpdate.class)); } else if (clazz.isAnnotationPresent(ModelUpdates.class)) { ModelUpdates updates = clazz.getAnnotation(ModelUpdates.class); for (ModelUpdate update : updates.value()) { addUpdateIfNeeded(versionUpdates, update); }/*from ww w. j a v a 2 s .co m*/ } }
From source file:nl.knaw.dans.common.lang.search.bean.GenericSearchBeanConverter.java
@SuppressWarnings("unchecked") public IndexDocument toIndexDocument(Object searchBean) throws SearchBeanConverterException, SearchBeanException { Class sbClass = searchBean.getClass(); if (!sbClass.isAnnotationPresent(SearchBean.class)) throw new ObjectIsNotASearchBeanException(sbClass.toString()); SimpleIndexDocument indexDocument = new SimpleIndexDocument(SearchBeanUtil.getDefaultIndex(sbClass)); for (java.lang.reflect.Field classField : ClassUtil.getAllFields(sbClass).values()) { if (classField.isAnnotationPresent(SearchField.class)) { SearchField sbField = classField.getAnnotation(SearchField.class); String fieldName = sbField.name(); boolean isRequired = sbField.required(); Class<? extends SearchFieldConverter<?>> converter = sbField.converter(); String propName = classField.getName(); String getMethodName = "get" + StringUtils.capitalize(propName); addFieldToDocument(searchBean, indexDocument, getMethodName, fieldName, isRequired, converter); if (classField.isAnnotationPresent(CopyField.class)) { for (Annotation annot : classField.getAnnotations()) { if (annot instanceof CopyField) { CopyField sbCopyField = (CopyField) annot; fieldName = sbCopyField.name(); isRequired = sbCopyField.required(); getMethodName = "get" + StringUtils.capitalize(propName) + StringUtils.capitalize(sbCopyField.getterPostfix()); converter = sbCopyField.converter(); addFieldToDocument(searchBean, indexDocument, getMethodName, fieldName, isRequired, converter); }//w w w . ja v a 2 s .com } } } } if (indexDocument.getIndex() != null) { if (indexDocument.getFields().getByFieldName(indexDocument.getIndex().getPrimaryKey()) == null) throw new PrimaryKeyMissingException("Primary key not set to search bean object."); } return indexDocument; }
From source file:com.impetus.kundera.metadata.processor.SuperColumnFamilyProcessor.java
@Override public final void process(Class<?> clazz, EntityMetadata metadata) { if (!clazz.isAnnotationPresent(SuperColumnFamily.class)) { return;/*from w ww . j ava2s . c o m*/ } LOG.debug("Processing @Entity " + clazz.getName() + " for SuperColumnFamily."); metadata.setType(EntityMetadata.Type.SUPER_COLUMN_FAMILY); // check for SuperColumnFamily annotation. SuperColumnFamily scf = clazz.getAnnotation(SuperColumnFamily.class); // set columnFamily metadata.setColumnFamilyName(scf.family()); // set keyspace String keyspace = scf.keyspace().length() != 0 ? scf.keyspace() : em.getKeyspace(); metadata.setKeyspaceName(keyspace); // scan for fields for (Field f : clazz.getDeclaredFields()) { // if @Id if (f.isAnnotationPresent(Id.class)) { LOG.debug(f.getName() + " => Id"); metadata.setIdProperty(f); populateIdAccessorMethods(metadata, clazz, f); } // if @SuperColumn else if (f.isAnnotationPresent(SuperColumn.class)) { SuperColumn sc = f.getAnnotation(SuperColumn.class); String superColumnName = sc.column(); String columnName = getValidJPAColumnName(clazz, f); if (null == columnName) { continue; } LOG.debug(f.getName() + " => Column:" + columnName + ", SuperColumn:" + superColumnName); EntityMetadata.SuperColumn superColumn = metadata.getSuperColumn(superColumnName); if (null == superColumn) { superColumn = metadata.new SuperColumn(superColumnName); } superColumn.addColumn(columnName, f); metadata.addSuperColumn(superColumnName, superColumn); } } }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
private static boolean isByRef(Class<?> param, Annotation[] annotations) { // if parameter has ByValue annotation, it is ByValueParameter if (containsAnnotation(annotations, ByValueParameter.class)) return false; // if this is primitive or wrapper type, it is ByValueParameter if (param.isPrimitive() || param.equals(String.class) || Primitives.allWrapperTypes().contains(param)) return false; // if this is enum, it is ByValueParameter if (param.isEnum()) return false; // if parameter class has ByValueParameter annotation, it is ByValueParameter if (param.isAnnotationPresent(ByValueParameter.class)) return false; // otherwise it is ByRefParameter return true;// w ww . jav a 2s .c om }
From source file:org.develspot.data.orientdb.mapping.BasicOrientPersistentEntity.java
public BasicOrientPersistentEntity(TypeInformation<T> information) { super(information); Class<T> rawType = information.getType(); //default/*from ww w . j av a2 s . c om*/ this.vertexType = rawType.getSimpleName(); //check if annotation is present if (rawType.isAnnotationPresent(VertexType.class)) { VertexType annotation = rawType.getAnnotation(VertexType.class); if (!annotation.value().isEmpty()) { this.vertexType = annotation.value(); } } }
From source file:ofc4j.OFC.java
private void doAlias(Class<?> c) { if (c.isAnnotationPresent(Alias.class)) { converter.alias(c.getAnnotation(Alias.class).value(), c); }// www . j a v a2 s . c o m for (Field f : c.getDeclaredFields()) { if (f.isAnnotationPresent(Alias.class)) { converter.aliasField(f.getAnnotation(Alias.class).value(), c, f.getName()); } } }
From source file:com.lonepulse.robozombie.executor.ConfigurationService.java
/** * {@inheritDoc}/* w w w . ja v a 2 s . co 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:ofc4j.OFC.java
private void doRegisterConverter(Class<?> c) { if (c.isAnnotationPresent(Converter.class)) { Class<? extends ConverterMatcher> clazz = c.getAnnotation(Converter.class).value(); try {/* w w w .j a va2 s . co m*/ if (SingleValueConverter.class.isAssignableFrom(clazz)) { converter.registerConverter((SingleValueConverter) clazz.newInstance()); } else { converter .registerConverter((com.thoughtworks.xstream.converters.Converter) clazz.newInstance()); } } catch (Exception e) { e.printStackTrace(); } } }
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 w w .j a va 2 s . 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; }