Java Code Examples for org.springframework.beans.ConfigurablePropertyAccessor

The following examples show how to use org.springframework.beans.ConfigurablePropertyAccessor. These examples are extracted from open source projects. 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 Project: onetwo   Source File: ContentCheckConstraintValidator.java    License: Apache License 2.0 6 votes vote down vote up
@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;
	}
 
Example 2
Source Project: spring-analysis-note   Source File: DirectFieldBindingResult.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source Project: spring-analysis-note   Source File: DirectFieldBindingResult.java    License: 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 Project: spring-analysis-note   Source File: BeanPropertyBindingResult.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source Project: java-technology-stack   Source File: DirectFieldBindingResult.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source Project: java-technology-stack   Source File: DirectFieldBindingResult.java    License: 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 7
Source Project: java-technology-stack   Source File: BeanPropertyBindingResult.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
/**
 * 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;
}
 
Example 9
/**
 * 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;
}
 
Example 10
/**
 * 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;
}
 
Example 11
/**
 * 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;
}
 
Example 12
Source Project: onetwo   Source File: BeanPropertiesMapper.java    License: Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}
 
Example 13
Source Project: onetwo   Source File: BeanPropertiesMapper.java    License: Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 14
Source Project: onetwo   Source File: ConfigableBeanMapper.java    License: Apache License 2.0 5 votes vote down vote up
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);
			}
		}
	}
 
Example 15
Source Project: onetwo   Source File: ConfigableBeanMapper.java    License: Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 16
Source Project: onetwo   Source File: PropsTargeterEnhancer.java    License: Apache License 2.0 5 votes vote down vote up
@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();
	}
 
Example 17
Source Project: onetwo   Source File: AuthorizationServerConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 18
Source Project: spring-analysis-note   Source File: DataBinder.java    License: MIT License 4 votes vote down vote up
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
Example 19
Source Project: java-technology-stack   Source File: DataBinder.java    License: MIT License 4 votes vote down vote up
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
Example 20
/**
 * 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 21
Source Project: lams   Source File: DataBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
Example 22
/**
 * 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 23
Source Project: spring4-understanding   Source File: DataBinder.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
	return getInternalBindingResult().getPropertyAccessor();
}
 
Example 24
Source Project: onetwo   Source File: ConfigableBeanMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
	ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forBeanPropertyAccess(obj);
	accessor.setAutoGrowNestedPaths(true);
	return accessor;
}
 
Example 25
Source Project: onetwo   Source File: ConfigableBeanMapper.java    License: 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 26
Source Project: onetwo   Source File: SpringUtils.java    License: 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;
}
 
Example 27
Source Project: AlgoTrader   Source File: GrailsDataBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
private boolean isNullAndWritableProperty(ConfigurablePropertyAccessor accessor, String propertyName) {
	return accessor.isWritableProperty(propertyName) && (accessor.isReadableProperty(propertyName) && accessor.getPropertyValue(propertyName) == null);
}
 
Example 28
/**
 * 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();
 
Example 29
/**
 * 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();
 
Example 30
/**
 * 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();