List of usage examples for java.lang.reflect Field getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:com.haulmont.chile.jpa.loader.JPAAnnotationsLoader.java
@Override protected Class getFieldTypeAccordingAnnotations(Field field) { OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class); OneToMany oneToManyAnnotation = field.getAnnotation(OneToMany.class); ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class); ManyToMany manyToManyAnnotation = field.getAnnotation(ManyToMany.class); Class result = null;// ww w.j a va2s. com if (oneToOneAnnotation != null) { result = oneToOneAnnotation.targetEntity(); } else if (oneToManyAnnotation != null) { result = oneToManyAnnotation.targetEntity(); } else if (manyToOneAnnotation != null) { result = manyToOneAnnotation.targetEntity(); } else if (manyToManyAnnotation != null) { result = manyToManyAnnotation.targetEntity(); } return result; }
From source file:org.jboss.spring.support.SpringInjectionSupport.java
protected Object inject(Object target) throws Exception { log.debug("Invoking Spring injection: " + target.getClass().getName()); Method[] methods = getAllMethods(target); for (Method m : methods) { Spring spring = m.getAnnotation(Spring.class); if (spring != null) { if (isSetterMethod(m)) { injectToMethod(target, m, spring); } else { log.warn("Spring annotation only allowed on setter methods."); }// w w w . j a v a 2s . c o m } } Field[] fields = getAllFields(target); for (Field f : fields) { Spring spring = f.getAnnotation(Spring.class); if (spring != null) { injectToField(target, f, spring); } } return target; }
From source file:com.thinkbiganalytics.annotations.AnnotationFieldNameResolver.java
/** * create the object describing the Field annotation setting the name based upon the class hierarchy * * @param clazz the class to inspect/*from w w w . j a v a 2 s . c o m*/ * @param names the list of names already parsed. this will be the list the newly parsed field is added to * @param field the field to parse for the annotation matching the {@link #annotation} supplied * @return the object describing the annotation * @see #stackAsString() for the naming strategy on hierachy names */ public AnnotatedFieldProperty addFieldProperty(Class clazz, List<AnnotatedFieldProperty> names, Field field) { AnnotatedFieldProperty annotatedFieldProperty = new AnnotatedFieldProperty(); annotatedFieldProperty.setAnnotation(field.getAnnotation(annotation)); annotatedFieldProperty.setName(stackAsString() + field.getName()); annotatedFieldProperty.setField(field); annotatedFieldProperty.setDescription(getFieldPropertyDescription(field)); names.add(annotatedFieldProperty); afterFieldNameAdded(clazz, stackAsString(), names, field); return annotatedFieldProperty; }
From source file:es.caib.sgtsic.utils.ejb.AbstractService.java
private Class<?> getTargetEntity(Field f) { if (f.getAnnotation(OneToMany.class) != null) { return f.getAnnotation(OneToMany.class).targetEntity(); }// ww w . ja v a2 s . co m if (f.getAnnotation(ManyToMany.class) != null) { return f.getAnnotation(ManyToMany.class).targetEntity(); } if (f.getAnnotation(OneToOne.class) != null) { return f.getAnnotation(OneToOne.class).targetEntity(); } return null; }
From source file:es.caib.sgtsic.utils.ejb.AbstractService.java
private String getMapping(Field f) { if (f.getAnnotation(OneToMany.class) != null) { return f.getAnnotation(OneToMany.class).mappedBy(); }//from w w w .j a va 2 s . co m if (f.getAnnotation(ManyToMany.class) != null) { return f.getAnnotation(ManyToMany.class).mappedBy(); } if (f.getAnnotation(OneToOne.class) != null) { return f.getAnnotation(OneToOne.class).mappedBy(); } return ""; }
From source file:org.ff4j.spring.autowire.AutowiredFF4JBeanPostProcessor.java
private void autoWiredFeature(Object bean, Field field) { // Find the required and name parameters FF4JFeature annFeature = field.getAnnotation(FF4JFeature.class); String annValue = annFeature.value(); String featureName = field.getName(); if (annValue != null && !"".equals(annValue)) { featureName = annValue;/*from w w w . j av a 2s .c o m*/ } Feature feature = readFeature(field, featureName, annFeature.required()); if (feature != null) { if (Feature.class.isAssignableFrom(field.getType())) { injectValue(field, bean, featureName, feature); } else if (Boolean.class.isAssignableFrom(field.getType())) { injectValue(field, bean, featureName, new Boolean(feature.isEnable())); } else if (boolean.class.isAssignableFrom(field.getType())) { injectValue(field, bean, featureName, feature.isEnable()); } else { throw new IllegalArgumentException("Field annotated with @FF4JFeature" + " must inherit from org.ff4j.Feature or be boolean " + field.getType() + " [class=" + bean.getClass().getName() + ", field=" + field.getName() + "]"); } } }
From source file:de.lightful.testflux.drools.DroolsRuleTestListener.java
private boolean canAcceptKnowledgeBase(Field declaredField) { if (declaredField.getAnnotation(NoInjection.class) != null) { return false; }/*w w w .j a v a 2s . c o m*/ if (declaredField.getAnnotation(Inject.class) == null) { return false; } final Class<?> fieldType = declaredField.getType(); if (fieldType.isAssignableFrom(KnowledgeBase.class)) { return true; } return false; }
From source file:stormy.pythian.core.description.OutputStreamDescriptionFactory.java
@SuppressWarnings("unchecked") public List<OutputStreamDescription> createOutputStreamDescriptions(Class<?> componentClass) { List<OutputStreamDescription> descriptions = new ArrayList<>(); Set<Field> fields = getAllFields(componentClass, withAnnotation(OutputStream.class)); for (Field field : fields) { if (field.getType() != Stream.class) { throw new IllegalArgumentException(OutputStream.class + " can only be applied to " + Stream.class); }/*from w w w .j a va 2s .c om*/ OutputStream annotation = field.getAnnotation(OutputStream.class); OutputStreamDescription description = createOutputStreamDescription(componentClass, annotation); descriptions.add(description); } return descriptions; }
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
private void collectFieldUpdatesAnnotations(SparseArray<List<String>> versionUpdates, Class<?> clazz) { for (Field field : clazz.getFields()) { if (field.isAnnotationPresent(ModelUpdate.class)) { addUpdateIfNeeded(versionUpdates, field.getAnnotation(ModelUpdate.class)); } else if (field.isAnnotationPresent(ModelUpdates.class)) { ModelUpdates updates = field.getAnnotation(ModelUpdates.class); for (ModelUpdate update : updates.value()) { addUpdateIfNeeded(versionUpdates, update); }//w w w . j a va 2 s . com } } }
From source file:de.micromata.genome.util.runtime.config.AbstractLocalSettingsConfigModel.java
/** * Reset fiel to default.//from ww w . jav a 2 s . c om * * @param fieldName the field name */ protected void resetFielToDefault(String fieldName) { Field f = PrivateBeanUtils.findField(getClass(), fieldName); Validate.notNull(f); ALocalSettingsPath ap = f.getAnnotation(ALocalSettingsPath.class); PrivateBeanUtils.writeField(this, f, ap.defaultValue()); }