Java Code Examples for org.springframework.beans.ConfigurablePropertyAccessor#setPropertyValue()

The following examples show how to use org.springframework.beans.ConfigurablePropertyAccessor#setPropertyValue() . 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: ContentCheckConstraintValidator.java    From onetwo with 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 File: BeanPropertiesMapper.java    From onetwo with 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 3
Source File: ConfigableBeanMapper.java    From onetwo with 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 4
Source File: AuthorizationServerConfiguration.java    From onetwo with 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;
}