org.springframework.beans.PropertyAccessorFactory#forDirectFieldAccess ( )源码实例Demo

下面列出了org.springframework.beans.PropertyAccessorFactory#forDirectFieldAccess ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
}
 
源代码2 项目: uima-uimafit   文件: ResourceInitializationUtil.java
/**
 * 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());
  }
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码5 项目: fiat   文件: 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();
}
 
源代码6 项目: jdal   文件: JpaUtils.java
/**
 * 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);
}
 
源代码7 项目: jdal   文件: JpaDao.java
/**
 * 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());
}
 
源代码8 项目: lams   文件: DirectFieldBindingResult.java
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码10 项目: onetwo   文件: ConfigableBeanMapper.java
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
	ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(obj);
	accessor.setAutoGrowNestedPaths(true);
	return accessor;
}
 
源代码11 项目: onetwo   文件: SpringUtils.java
public static ConfigurablePropertyAccessor newPropertyAccessor(Object obj, boolean directFieldAccess){
	ConfigurablePropertyAccessor bw = directFieldAccess?PropertyAccessorFactory.forDirectFieldAccess(obj):PropertyAccessorFactory.forBeanPropertyAccess(obj);
	bw.setAutoGrowNestedPaths(true);
	return bw;
}