Java Code Examples for org.springframework.beans.PropertyAccessor#getPropertyValue()

The following examples show how to use org.springframework.beans.PropertyAccessor#getPropertyValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceInitializationUtil.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Handle Spring-initialization of resoures produced by the UIMA framework.
 */
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());
  }
}
 
Example 2
Source File: CompositeBinder.java    From jdal with Apache License 2.0 6 votes vote down vote up
public void autobind(Object view) {
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(getModel());
	PropertyAccessor  viewPropertyAccessor = new DirectFieldAccessor(view);
	// iterate on model properties
	for (PropertyDescriptor pd : bw.getPropertyDescriptors()) {
		String propertyName = pd.getName();
		if ( !ignoredProperties.contains(propertyName) && viewPropertyAccessor.isReadableProperty(propertyName)) {
			Object control = viewPropertyAccessor.getPropertyValue(propertyName);
			if (control != null) {
				if (log.isDebugEnabled()) 
					log.debug("Found control: " + control.getClass().getSimpleName() + 
							" for property: " + propertyName);
				bind(control, propertyName);
			}
		}
	}
}
 
Example 3
Source File: JpaUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize collection
 * @param em
 * @param entity
 * @param a
 * @param i
 */
@SuppressWarnings("rawtypes")
private static void intializeCollection(EntityManager em, Object entity, Object attached, 
		Attribute a, int depth) {
	PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(attached);
	Collection c = (Collection) accessor.getPropertyValue(a.getName());
	
	for (Object o : c)
		initialize(em, o, depth -1);
	
	PropertyAccessorFactory.forDirectFieldAccess(entity).setPropertyValue(a.getName(), c);
}
 
Example 4
Source File: JpaDao.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Test if entity is New
 * @param entity
 * @return true if entity is new, ie not detached
 */
@SuppressWarnings("unchecked")
protected boolean isNew(T entity) {
	SingularAttribute<?, ?> id = getIdAttribute(entity.getClass());
	// try field
	PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(entity);
	PK key = (PK) pa.getPropertyValue(id.getName());
	if (key == null)
		key = (PK) PropertyAccessorFactory.forBeanPropertyAccess(entity).getPropertyValue(id.getName());
	
	
	return key == null || !exists(key, entity.getClass());
}