类org.springframework.beans.ConfigurablePropertyAccessor源码实例Demo

下面列出了怎么用org.springframework.beans.ConfigurablePropertyAccessor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: onetwo   文件: ContentCheckConstraintValidator.java
@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (StringUtils.isBlank(value)) {
			return true;
		}
		List<String> sentitiveWords = getContentChecker().check(value);
		if (LangUtils.isEmpty(sentitiveWords)) {
			return true;
		}
		ConstraintValidatorContextImpl ctx = (ConstraintValidatorContextImpl)context;
		
		// 这种方法虽然可以动态显示错误信息,但是无法把错误信息放到i18n国际化资源文件里
//		ctx.addExpressionVariable("invalidWords", StringUtils.join(sentitiveWords, ", "));
//		ctx.buildConstraintViolationWithTemplate("${invalidWords}").addConstraintViolation();
		
		Map<String, Object> newAttributes = Maps.newHashMap(ctx.getConstraintDescriptor().getAttributes());
		newAttributes.put("invalidWords", StringUtils.join(sentitiveWords, ", "));
		ConfigurablePropertyAccessor constraintDescriptor = SpringUtils.newPropertyAccessor(ctx.getConstraintDescriptor(), true);
		constraintDescriptor.setPropertyValue("attributes", newAttributes);
		return false;
	}
 
/**
 * Returns the DirectFieldAccessor that this instance uses.
 * Creates a new one if none existed before.
 * @see #createDirectFieldAccessor()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.directFieldAccessor == null) {
		this.directFieldAccessor = createDirectFieldAccessor();
		this.directFieldAccessor.setExtractOldValueForEditor(true);
		this.directFieldAccessor.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
	}
	return this.directFieldAccessor;
}
 
/**
 * 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);
}
 
/**
 * Returns the {@link BeanWrapper} that this instance uses.
 * Creates a new one if none existed before.
 * @see #createBeanWrapper()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.beanWrapper == null) {
		this.beanWrapper = createBeanWrapper();
		this.beanWrapper.setExtractOldValueForEditor(true);
		this.beanWrapper.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
		this.beanWrapper.setAutoGrowCollectionLimit(this.autoGrowCollectionLimit);
	}
	return this.beanWrapper;
}
 
/**
 * Returns the DirectFieldAccessor that this instance uses.
 * Creates a new one if none existed before.
 * @see #createDirectFieldAccessor()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.directFieldAccessor == null) {
		this.directFieldAccessor = createDirectFieldAccessor();
		this.directFieldAccessor.setExtractOldValueForEditor(true);
		this.directFieldAccessor.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
	}
	return this.directFieldAccessor;
}
 
/**
 * 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);
}
 
/**
 * Returns the {@link BeanWrapper} that this instance uses.
 * Creates a new one if none existed before.
 * @see #createBeanWrapper()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.beanWrapper == null) {
		this.beanWrapper = createBeanWrapper();
		this.beanWrapper.setExtractOldValueForEditor(true);
		this.beanWrapper.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
		this.beanWrapper.setAutoGrowCollectionLimit(this.autoGrowCollectionLimit);
	}
	return this.beanWrapper;
}
 
源代码8 项目: lams   文件: DirectFieldBindingResult.java
/**
 * Returns the DirectFieldAccessor that this instance uses.
 * Creates a new one if none existed before.
 * @see #createDirectFieldAccessor()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.directFieldAccessor == null) {
		this.directFieldAccessor = createDirectFieldAccessor();
		this.directFieldAccessor.setExtractOldValueForEditor(true);
		this.directFieldAccessor.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
	}
	return this.directFieldAccessor;
}
 
源代码9 项目: lams   文件: BeanPropertyBindingResult.java
/**
 * Returns the {@link BeanWrapper} that this instance uses.
 * Creates a new one if none existed before.
 * @see #createBeanWrapper()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.beanWrapper == null) {
		this.beanWrapper = createBeanWrapper();
		this.beanWrapper.setExtractOldValueForEditor(true);
		this.beanWrapper.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
		this.beanWrapper.setAutoGrowCollectionLimit(this.autoGrowCollectionLimit);
	}
	return this.beanWrapper;
}
 
/**
 * Returns the DirectFieldAccessor that this instance uses.
 * Creates a new one if none existed before.
 * @see #createDirectFieldAccessor()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.directFieldAccessor == null) {
		this.directFieldAccessor = createDirectFieldAccessor();
		this.directFieldAccessor.setExtractOldValueForEditor(true);
		this.directFieldAccessor.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
	}
	return this.directFieldAccessor;
}
 
/**
 * Returns the {@link BeanWrapper} that this instance uses.
 * Creates a new one if none existed before.
 * @see #createBeanWrapper()
 */
@Override
public final ConfigurablePropertyAccessor getPropertyAccessor() {
	if (this.beanWrapper == null) {
		this.beanWrapper = createBeanWrapper();
		this.beanWrapper.setExtractOldValueForEditor(true);
		this.beanWrapper.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
		this.beanWrapper.setAutoGrowCollectionLimit(this.autoGrowCollectionLimit);
	}
	return this.beanWrapper;
}
 
源代码12 项目: onetwo   文件: BeanPropertiesMapper.java
public void mapToObject(Object obj) {
	if(config==null || config.isEmpty()){
		return ;
	}
	boolean hasPrefix = StringUtils.isNotBlank(prefix);
	
	ConfigurablePropertyAccessor bw = beanAccessors.createAccessor(obj);
	Enumeration<?> names = config.propertyNames();
	while(names.hasMoreElements()){
		String propertyName = names.nextElement().toString();
		String value = config.getProperty(propertyName);
		if(value==null){
			continue;
		}
		if(StringUtils.isBlank(value) && ignoreBlankString){
			continue;
		}
		if(hasPrefix){
			if(propertyName.startsWith(prefix)){
				propertyName = propertyName.substring(prefix.length());
				setPropertyValue(obj, bw, propertyName, value);
			}
		}else{
			setPropertyValue(obj, bw, propertyName, value);
		}
	}
}
 
源代码13 项目: onetwo   文件: BeanPropertiesMapper.java
protected void setPropertyValue(Object obj, ConfigurablePropertyAccessor bw, String propertyName, Object value){
	if(!bw.isWritableProperty(propertyName)){
		if(!ignoreNotFoundProperty){
			throw new NoSuchElementException("no setter found for property: " + propertyName+", target: " + obj);
		}
		logger.debug("ignore property: {}={} ", propertyName, value);
		return ;
	}
	bw.setPropertyValue(propertyName, value);
	if(logger.isDebugEnabled()){
		logger.debug("set property: {}={} ", propertyName, value);
	}
}
 
源代码14 项目: onetwo   文件: ConfigableBeanMapper.java
public void mapToObject(Object obj) {
		if(config==null || config.isEmpty()){
			return ;
		}
		boolean hasPrefix = StringUtils.isNotBlank(prefix);
		
		ConfigurablePropertyAccessor bw = beanAccessors.createAccessor(obj);
//		Enumeration<?> names = config.propertyNames();
//		while(names.hasMoreElements()){
		for(Entry<String, Object> entry : config.entrySet()){
//			String propertyName = names.nextElement().toString();
//			String value = config.getProperty(propertyName);
			if(entry.getValue()==null){
				continue;
			}
			String propertyName = entry.getKey();
			String text = entry.getValue().toString();
			if(StringUtils.isBlank(text) && ignoreBlankString){
				continue;
			}
			if(hasPrefix){
				if(propertyName.startsWith(prefix)){
					propertyName = propertyName.substring(prefix.length());
					setPropertyValue(obj, bw, propertyName, text);
				}
			}else{
				setPropertyValue(obj, bw, propertyName, text);
			}
		}
	}
 
源代码15 项目: onetwo   文件: ConfigableBeanMapper.java
protected void setPropertyValue(Object obj, ConfigurablePropertyAccessor bw, String propertyName, Object value){
	if(!bw.isWritableProperty(propertyName)){
		if(!ignoreNotFoundProperty){
			throw new NoSuchElementException("no setter found for property: " + propertyName+", target: " + obj);
		}
		logger.debug("ignore property: {}={} ", propertyName, value);
		return ;
	}
	bw.setPropertyValue(propertyName, value);
	if(logger.isDebugEnabled()){
		logger.debug("set property: {}={} ", propertyName, value);
	}
}
 
源代码16 项目: onetwo   文件: PropsTargeterEnhancer.java
@Override
	public <T> T enhanceTargeter(FeignTargetContext<T> ctx) {
		FeignClientFactoryBean factory = ctx.getFeignClientfactory();
		String serviceName = factory.getName();
		if (feignProperties.getServices().containsKey(serviceName)) {
			ServiceProps serviceProp = feignProperties.getServices().get(serviceName);
//			factory.setUrl(serviceProp.getUrl()); // 这里设置太迟了
			ConfigurablePropertyAccessor bw = SpringUtils.newPropertyAccessor(ctx.getHardeCodetarget(), true);
//			bw.setPropertyValue("url", serviceProp.getUrl());
		}
		return ctx.createTargeter();
	}
 
源代码17 项目: onetwo   文件: AuthorizationServerConfiguration.java
@Override
public <O extends ClientCredentialsTokenEndpointFilter> O postProcess(O filter) {
	ConfigurablePropertyAccessor filterAccessor = SpringUtils.newPropertyAccessor(filter, true);
	if(oauth2ExceptionRenderer!=null){
		filterAccessor.setPropertyValue("authenticationEntryPoint.exceptionRenderer", oauth2ExceptionRenderer);
	}
	/*AuthenticationManager origin = (AuthenticationManager)filterAccessor.getPropertyValue("authenticationManager");
	DelegateAuthenticationManager delegate = new DelegateAuthenticationManager(origin);
	filter.setAuthenticationManager(delegate);*/
	if(tokenEndpointFilterInterceptor!=null){
		filter = Proxys.intercept(filter, tokenEndpointFilterInterceptor);
	}
	return filter;
}
 
源代码18 项目: spring-analysis-note   文件: DataBinder.java
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
源代码19 项目: java-technology-stack   文件: DataBinder.java
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
源代码20 项目: 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);
}
 
源代码21 项目: lams   文件: DataBinder.java
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
/**
 * 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);
}
 
源代码23 项目: spring4-understanding   文件: DataBinder.java
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
源代码24 项目: onetwo   文件: ConfigableBeanMapper.java
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
	ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forBeanPropertyAccess(obj);
	accessor.setAutoGrowNestedPaths(true);
	return accessor;
}
 
源代码25 项目: onetwo   文件: ConfigableBeanMapper.java
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
	ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(obj);
	accessor.setAutoGrowNestedPaths(true);
	return accessor;
}
 
源代码26 项目: 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;
}
 
源代码27 项目: AlgoTrader   文件: GrailsDataBinder.java
private boolean isNullAndWritableProperty(ConfigurablePropertyAccessor accessor, String propertyName) {
	return accessor.isWritableProperty(propertyName) && (accessor.isReadableProperty(propertyName) && accessor.getPropertyValue(propertyName) == null);
}
 
/**
 * Provide the PropertyAccessor to work with, according to the
 * concrete strategy of access.
 * <p>Note that a PropertyAccessor used by a BindingResult should
 * always have its "extractOldValueForEditor" flag set to "true"
 * by default, since this is typically possible without side effects
 * for model objects that serve as data binding target.
 * @see ConfigurablePropertyAccessor#setExtractOldValueForEditor
 */
public abstract ConfigurablePropertyAccessor getPropertyAccessor();
 
/**
 * Provide the PropertyAccessor to work with, according to the
 * concrete strategy of access.
 * <p>Note that a PropertyAccessor used by a BindingResult should
 * always have its "extractOldValueForEditor" flag set to "true"
 * by default, since this is typically possible without side effects
 * for model objects that serve as data binding target.
 * @see ConfigurablePropertyAccessor#setExtractOldValueForEditor
 */
public abstract ConfigurablePropertyAccessor getPropertyAccessor();
 
源代码30 项目: lams   文件: AbstractPropertyBindingResult.java
/**
 * Provide the PropertyAccessor to work with, according to the
 * concrete strategy of access.
 * <p>Note that a PropertyAccessor used by a BindingResult should
 * always have its "extractOldValueForEditor" flag set to "true"
 * by default, since this is typically possible without side effects
 * for model objects that serve as data binding target.
 * @see ConfigurablePropertyAccessor#setExtractOldValueForEditor
 */
public abstract ConfigurablePropertyAccessor getPropertyAccessor();
 
 同包方法