List of usage examples for org.springframework.beans PropertyAccessorFactory forDirectFieldAccess
public static ConfigurablePropertyAccessor forDirectFieldAccess(Object target)
From source file:org.web4thejob.util.FieldLocator.java
public static Object getFieldValue(Object object, String fieldName) throws Exception { Object target;/*from www. j av a 2s . com*/ if (AopUtils.isAopProxy(object)) { target = ((Advised) object).getTargetSource().getTarget(); } else { target = object; } return PropertyAccessorFactory.forDirectFieldAccess(target).getPropertyValue(fieldName); }
From source file:org.uimafit.spring.util.ResourceInitializationUtil.java
/** * Handle Spring-initialization of resoures produced by the UIMA framework. *//*from w w w.j a v a 2 s . c om*/ public static Resource initResource(Resource aResource, ApplicationContext aApplicationContext) { AutowireCapableBeanFactory beanFactory = aApplicationContext.getAutowireCapableBeanFactory(); if (aResource instanceof PrimitiveAnalysisEngine_impl) { PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(aResource); // Access the actual AnalysisComponent and initialize it AnalysisComponent analysisComponent = (AnalysisComponent) pa.getPropertyValue("mAnalysisComponent"); initializeBean(beanFactory, analysisComponent, aResource.getMetaData().getName()); pa.setPropertyValue("mAnalysisComponent", analysisComponent); return aResource; } else { return (Resource) beanFactory.initializeBean(aResource, aResource.getMetaData().getName()); } }
From source file:org.web4thejob.model.CalendarEventEntity.java
public CalendarEventEntity(Entity entity, Map<CalendarSettingEnum, Setting> mappings) { this.entity = entity; this.mappings = mappings; this.beanWrapper = PropertyAccessorFactory.forDirectFieldAccess(this.entity); }
From source file:org.dkpro.lab.engine.impl.DefaultLifeCycleManager.java
@Override public void configure(TaskContext aParentContext, Task aTask, Map<String, Object> aConfiguration) { PropertyAccessor paBean = PropertyAccessorFactory.forBeanPropertyAccess(aTask); PropertyAccessor paDirect = PropertyAccessorFactory.forDirectFieldAccess(aTask); for (Entry<String, Object> property : aConfiguration.entrySet()) { String key = property.getKey(); Object value = property.getValue(); // Find all fields that are annotated with a discriminator/property that have // a non-default name and might apply. for (String prop : ParameterUtil.findBeanPropertiesWithName(aTask, key)) { // Try setter - there may be extra logic in the setter if (paBean.isWritableProperty(prop)) { paBean.setPropertyValue(prop, value); }// www. j av a 2s. co m // Otherwise try direct access else if (paDirect.isWritableProperty(prop)) { paDirect.setPropertyValue(prop, value); } } // And try once again for all fields where the name is not explicitly set // Try setter - there may be extra logic in the setter if (paBean.isWritableProperty(key)) { paBean.setPropertyValue(key, value); } // Otherwise try direct access else if (paDirect.isWritableProperty(key)) { paDirect.setPropertyValue(key, value); } } if (aTask instanceof ConfigurationAware) { ((ConfigurationAware) aTask).setConfiguration(aConfiguration); } if (aParentContext != null) { aParentContext.message("Injected parameters into [" + aTask.getType() + "]"); } }
From source file:org.brushingbits.jnap.validation.constraints.AbstractConstraintValidator.java
/** * This method copies all the annotation properties to fields with the same name. * /* w ww.ja v a 2s. c o m*/ * @param constraintAnnotation This constraint annotation. * @see PropertyAccessorFactory */ protected void bindParameters(A constraintAnnotation) { Class<?> annotationClass = constraintAnnotation.getClass(); Method[] methods = annotationClass.getDeclaredMethods(); ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(this); try { for (Method method : methods) { String methodName = method.getName(); if (accessor.isWritableProperty(methodName)) { accessor.setPropertyValue(methodName, method.invoke(constraintAnnotation, ArrayUtils.EMPTY_OBJECT_ARRAY)); } } } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } }
From source file:org.uimafit.spring.SpringContextResourceManager.java
/** * Get a field value from a non-visible field. *///from w w w. j a v a 2s.c o m @SuppressWarnings("unchecked") private static <T> T getFieldValue(Object aObject, String aFieldName) { return (T) PropertyAccessorFactory.forDirectFieldAccess(aObject).getPropertyValue(aFieldName); }
From source file:org.web4thejob.model.CalendarEventEntity.java
@Override public void update(Entity entity) { if (this.entity.equals(entity)) { this.entity = entity; beanWrapper = PropertyAccessorFactory.forDirectFieldAccess(this.entity); } else {//from w w w.j a v a 2s . c om throw new IllegalArgumentException("not the same entity."); } }
From source file:com.javaetmoi.core.mvc.tag.Html5InputTag.java
protected Object getBean(String beanName, Map<String, Object> model) { Object bean;//from w w w.ja v a 2 s. c om if (model != null) { bean = model.get(beanName); } else { ConfigurablePropertyAccessor bw = PropertyAccessorFactory.forDirectFieldAccess(getRequestContext()); HttpServletRequest request = (HttpServletRequest) bw.getPropertyValue("request"); bean = request.getAttribute(beanName); } return bean; }
From source file:com.netflix.spinnaker.fiat.roles.google.GoogleDirectoryUserRolesProvider.java
private Directory getDirectoryService() { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jacksonFactory = new JacksonFactory(); GoogleCredential credential = getGoogleCredential(); PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(credential); accessor.setPropertyValue("serviceAccountUser", config.getAdminUsername()); accessor.setPropertyValue("serviceAccountScopes", SERVICE_ACCOUNT_SCOPES); return new Directory.Builder(httpTransport, jacksonFactory, credential).setApplicationName("Spinnaker-Fiat") .build();/*from w ww . j ava 2s . com*/ }
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Initialize entity attribute/*from w w w.j a v a2 s .c o m*/ * @param em * @param entity * @param a * @param depth */ @SuppressWarnings("rawtypes") private static void intialize(EntityManager em, Object entity, Object attached, Attribute a, int depth) { Object value = PropertyAccessorFactory.forDirectFieldAccess(attached).getPropertyValue(a.getName()); if (!em.getEntityManagerFactory().getPersistenceUnitUtil().isLoaded(value)) { em.refresh(value); } PropertyAccessorFactory.forDirectFieldAccess(entity).setPropertyValue(a.getName(), value); initialize(em, value, depth - 1); }