Java Code Examples for org.springframework.beans.PropertyAccessorFactory#forDirectFieldAccess()

The following examples show how to use org.springframework.beans.PropertyAccessorFactory#forDirectFieldAccess() . 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: DefaultRetryTemplateConverterTest.java    From distributed-lock with MIT License 6 votes vote down vote up
private void assertRetryTemplateConstruction(final RetryTemplate retryTemplate, final long timeout, final long backOff) {
  final var wrapper = PropertyAccessorFactory.forDirectFieldAccess(retryTemplate);

  assertThat(wrapper.getPropertyValue("retryPolicy")).isInstanceOf(CompositeRetryPolicy.class);
  assertThat((RetryPolicy[]) wrapper.getPropertyValue("retryPolicy.policies"))
    .hasSize(2)
    .anyMatch(policy1 -> {
      if (policy1 instanceof TimeoutRetryPolicy) {
        final var timeoutRetryPolicy = (TimeoutRetryPolicy) policy1;
        assertThat(timeoutRetryPolicy.getTimeout()).isEqualTo(timeout);
        return true;
      }
      return false;
    })
    .anyMatch(policy2 -> {
      if (policy2 instanceof SimpleRetryPolicy) {
        final var simpleRetryPolicy = (SimpleRetryPolicy) policy2;
        assertThat(simpleRetryPolicy.getMaxAttempts()).isEqualTo(Integer.MAX_VALUE);
        return true;
      }
      return false;
    });

  assertThat(wrapper.getPropertyValue("backOffPolicy")).isInstanceOf(FixedBackOffPolicy.class);
  assertThat(((FixedBackOffPolicy) wrapper.getPropertyValue("backOffPolicy")).getBackOffPeriod()).isEqualTo(backOff);
}
 
Example 2
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 3
Source File: DirectFieldBindingResult.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new DirectFieldAccessor for the underlying target object.
 * @see #getTarget()
 */
protected ConfigurablePropertyAccessor createDirectFieldAccessor() {
	if (this.target == null) {
		throw new IllegalStateException("Cannot access fields on null target instance '" + getObjectName() + "'");
	}
	return PropertyAccessorFactory.forDirectFieldAccess(this.target);
}
 
Example 4
Source File: DirectFieldBindingResult.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new DirectFieldAccessor for the underlying target object.
 * @see #getTarget()
 */
protected ConfigurablePropertyAccessor createDirectFieldAccessor() {
	if (this.target == null) {
		throw new IllegalStateException("Cannot access fields on null target instance '" + getObjectName() + "'");
	}
	return PropertyAccessorFactory.forDirectFieldAccess(this.target);
}
 
Example 5
Source File: GoogleDirectoryUserRolesProvider.java    From fiat with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 6
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 7
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());
}
 
Example 8
Source File: DirectFieldBindingResult.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DirectFieldAccessor for the underlying target object.
 * @see #getTarget()
 */
protected ConfigurablePropertyAccessor createDirectFieldAccessor() {
	Assert.state(this.target != null, "Cannot access fields on null target instance '" + getObjectName() + "'!");
	return PropertyAccessorFactory.forDirectFieldAccess(this.target);
}
 
Example 9
Source File: DirectFieldBindingResult.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new DirectFieldAccessor for the underlying target object.
 * @see #getTarget()
 */
protected ConfigurablePropertyAccessor createDirectFieldAccessor() {
	Assert.state(this.target != null, "Cannot access fields on null target instance '" + getObjectName() + "'!");
	return PropertyAccessorFactory.forDirectFieldAccess(this.target);
}
 
Example 10
Source File: ConfigableBeanMapper.java    From onetwo with Apache License 2.0 4 votes vote down vote up
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
	ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(obj);
	accessor.setAutoGrowNestedPaths(true);
	return accessor;
}
 
Example 11
Source File: SpringUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static ConfigurablePropertyAccessor newPropertyAccessor(Object obj, boolean directFieldAccess){
	ConfigurablePropertyAccessor bw = directFieldAccess?PropertyAccessorFactory.forDirectFieldAccess(obj):PropertyAccessorFactory.forBeanPropertyAccess(obj);
	bw.setAutoGrowNestedPaths(true);
	return bw;
}