List of usage examples for java.lang.reflect Field getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:org.cybercat.automation.annotations.AnnotationBuilder.java
@SuppressWarnings("unchecked") private static final void createIntegrationService(Field field, Object targetObject) throws AutomationFrameworkException { Class<IIntegrationService> clazz; try {//from w w w. j a v a 2s .c om clazz = (Class<IIntegrationService>) field.getType(); } catch (Exception e) { throw new AutomationFrameworkException("Unexpected field type :" + field.getType().getSimpleName() + " field name: " + field.getName() + " class: " + targetObject.getClass().getSimpleName() + " Thread ID:" + Thread.currentThread().getId() + " \n\tThis field must be of the type that extends AbstractPageObject class.", e); } try { field.set(targetObject, createIntegrationService(clazz, field.getAnnotation(CCIntegrationService.class))); } catch (Exception e) { throw new AutomationFrameworkException( "Set filed exception. Please, save this log and contact the Cybercat project support." + " field name: " + field.getName() + " class: " + targetObject.getClass().getSimpleName() + " Thread ID:" + Thread.currentThread().getId(), e); } }
From source file:com.github.dactiv.common.utils.ReflectionUtils.java
/** * ?fieldannotationClass//w ww . j ava 2 s .co m * * @param field * field * @param annotationClass * annotationClass * * @return {@link Annotation} */ public static <T extends Annotation> T getAnnotation(Field field, Class annotationClass) { Assert.notNull(field, "field?"); Assert.notNull(annotationClass, "annotationClass?"); field.setAccessible(true); if (field.isAnnotationPresent(annotationClass)) { return (T) field.getAnnotation(annotationClass); } return null; }
From source file:org.jongo.marshall.jackson.JacksonIdFieldSelector.java
private boolean hasJsonProperty(Field f) { JsonProperty annotation = f.getAnnotation(JsonProperty.class); return annotation != null && "_id".equals(annotation.value()); }
From source file:com.github.javarch.support.log.LoggingAnnotationBeanPostProcessor.java
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { LOG.trace("Searching @Logging annotation into {}", beanName); List<Field> fields = FieldAnnotationUtils.findFieldsWithAnnotation(bean.getClass(), Logging.class); for (Field field : fields) { if (field.getAnnotation(Logging.class) != null) { LOG.debug("Bean {} has @Logging annotation. Injecting Logger...", beanName); injectLogger(bean, field);//from ww w . ja va2 s . co m } } return bean; }
From source file:edu.usu.sdl.openstorefront.validation.UniqueRule.java
@Override protected String getValidationRule(Field field) { Unique unique = field.getAnnotation(Unique.class); if (unique != null) { return "Field is required to be unique accord to handler: " + unique.value().getSimpleName(); }/*from w w w . ja v a2 s . c om*/ return "Field is required to be unique accord to handler."; }
From source file:adalid.core.XS1.java
private static CastingField getCastingFieldAnnotation(Field declaringField, Class<?> fieldType) { if (Property.class.isAssignableFrom(fieldType) || Parameter.class.isAssignableFrom(fieldType)) { if (declaringField.isAnnotationPresent(CastingField.class)) { return declaringField.getAnnotation(CastingField.class); }/*from ww w . j a va 2s.com*/ } return null; }
From source file:com.qmetry.qaf.automation.data.DataView.java
Type getType(Field fld) { UiElement map = fld.getAnnotation(UiElement.class); return (null != map) ? map.fieldType() : Type.text; }
From source file:edu.usu.sdl.openstorefront.validation.ForeignKeyRule.java
@Override protected String getValidationRule(Field field) { FK fk = field.getAnnotation(FK.class); if (fk != null) { return "Field is required to be in foreign key: " + fk.value().getSimpleName(); }/*from ww w . j a v a 2 s .c om*/ return "Field is required in foreign key (FK annotation not found)."; }
From source file:io.github.moosbusch.permagon.configuration.controller.spi.AbstractPermagonController.java
@Override public void registerMembers() { Field[] fields = FieldUtils.getAllFields(getClass()); for (Field field : fields) { FXML fxml = field.getAnnotation(FXML.class); if (fxml != null) { String fieldName = field.getName(); Object fieldValue = null; try { field.setAccessible(true); fieldValue = field.get(this); } catch (IllegalArgumentException | IllegalAccessException ex) { Logger.getLogger(AbstractPermagonController.class.getName()).log(Level.SEVERE, null, ex); } finally { if (fieldValue != null) { appCtx.getBeanFactory().registerSingleton(fieldName, fieldValue); }// ww w. j av a 2 s. c o m } } } }
From source file:com.art4ul.jcoon.bean.RestClientAnnotationBeanPostProcessor.java
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { Field[] fields = bean.getClass().getDeclaredFields(); for (Field field : fields) { RestClient restClient = field.getAnnotation(RestClient.class); if (restClient != null) { field.setAccessible(true);//w w w . j a va 2s . c om Object proxyInstance = createProxyInstance(bean.getClass().getClassLoader(), restClient.value(), field.getType()); // TODO: Optimization , do not create new instance for same classes ReflectionUtils.setField(field, bean, proxyInstance); } } return bean; }