本文整理汇总了Java中org.springframework.beans.ConfigurablePropertyAccessor类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurablePropertyAccessor类的具体用法?Java ConfigurablePropertyAccessor怎么用?Java ConfigurablePropertyAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurablePropertyAccessor类属于org.springframework.beans包,在下文中一共展示了ConfigurablePropertyAccessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToObject
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
public void mapToObject(Object obj) {
Assert.notEmpty(config);
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);
}
}
}
示例2: canFormat
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
/**
* 判断对象属性是否有格式可以应用。调用format()前必须先调用canFormat()
*
* @param obj
* @param prop
* @return
*/
public static boolean canFormat(ConfigurablePropertyAccessor bw,
Object obj, String prop) {
String key = obj.getClass().getName() + "_" + prop;
if (!cache.containsKey(key)) {
cache.put(key, false);
TypeDescriptor td = bw.getPropertyTypeDescriptor(prop);
if (td != null) {
WinletDefaultFormattingConversionService wcs = get();
if (wcs != null
&& wcs.hasFmtAnnotation(td)
&& wcs.canConvert(td,
TypeDescriptor.valueOf(String.class)))
cache.put(key, true);
}
}
return cache.get(key);
}
示例3: format
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
/**
* 如果有格式可应用则应用
*
* @param bw
* @param obj
* @param prop
* @return
*/
public static String format(ConfigurablePropertyAccessor bw, Object obj,
String prop) {
String key = obj.getClass().getName() + "_" + prop;
if (!cache.containsKey(key))
canFormat(bw, obj, prop);
Object val = bw.getPropertyValue(prop);
if (val == null)
return null;
if (val.getClass().isArray())
return null;
if (!cache.get(key))
return val.toString();
TypeDescriptor td = bw.getPropertyTypeDescriptor(prop);
val = get().convert(val, td, TypeDescriptor.valueOf(String.class));
return val == null ? null : val.toString();
}
示例4: getPropertyAccessor
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
/**
* 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);
}
return this.directFieldAccessor;
}
示例5: getPropertyAccessor
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
/**
* 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;
}
示例6: getPropertyAccessor
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
/**
* 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;
}
示例7: handleModification
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
private List<PropertyChange<?>> handleModification(DescriptorEvent event)
{
final Class<?> objectClass = event.getSource().getClass();
final WriteObjectQuery writeObjectQuery = (WriteObjectQuery)event.getQuery();
final ObjectChangeSet changeset = writeObjectQuery.getObjectChangeSet();
final ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(event.getObject());
final List<ChangeRecord> changes = changeset != null ? changeset.getChanges() : extractManually(writeObjectQuery, fieldFilter);
final List<PropertyChange<?>> propChanges = new ArrayList<PropertyChange<?>>();
for (ChangeRecord change : changes)
{
final String attrName = change.getAttribute();
final Object newValue = accessor.getPropertyValue(attrName);
final Object oldValue = change.getOldValue();
final Class<?> attrType = accessor.getPropertyType(attrName);
final Field field = ReflectionUtils.findField(objectClass, change.getAttribute());
if (fieldFilter != null && !fieldFilter.test(field))
{
continue;
}
entityUtil.extractSingle(field, attrName, attrType, oldValue, newValue, propChanges);
}
return propChanges;
}
示例8: setPropertyValue
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
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);
}
}
示例9: getBean
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
protected Object getBean(String beanName, Map<String, Object> model) {
Object bean;
if (model != null) {
bean = model.get(beanName);
} else {
ConfigurablePropertyAccessor bw = PropertyAccessorFactory.forDirectFieldAccess(getRequestContext());
HttpServletRequest request = (HttpServletRequest) bw.getPropertyValue("request");
bean = request.getAttribute(beanName);
}
return bean;
}
示例10: createDirectFieldAccessor
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
/**
* 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);
}
示例11: getPropertyAccessor
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
/**
* Return the underlying PropertyAccessor of this binder's BindingResult.
*/
protected ConfigurablePropertyAccessor getPropertyAccessor() {
return getInternalBindingResult().getPropertyAccessor();
}
示例12: extractManually
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
private List<ChangeRecord> extractManually(WriteObjectQuery writeObjectQuery, Predicate<Field> filter)
{
final Object oldObj = writeObjectQuery.getBackupClone();
final Object newObj = writeObjectQuery.getObject();
final ConfigurablePropertyAccessor accessorOld = PropertyAccessorFactory.forDirectFieldAccess(oldObj);
final ConfigurablePropertyAccessor accessorNew = PropertyAccessorFactory.forDirectFieldAccess(newObj);
final BeanWrapper beanAccessor = PropertyAccessorFactory.forBeanPropertyAccess(newObj);
final List<ChangeRecord> retVal = new LinkedList<>();
for (PropertyDescriptor desc : beanAccessor.getPropertyDescriptors())
{
final String propName = desc.getName();
if (accessorNew.isReadableProperty(propName))
{
final Field field = ReflectionUtils.findField(oldObj.getClass(), propName);
if (filter == null || filter.test(field))
{
final Object newPropValue = accessorNew.getPropertyValue(propName);
final Object oldPropValue = accessorOld.getPropertyValue(propName);
if (! Objects.equals(newPropValue, oldPropValue))
{
final ChangeRecord c = new ChangeRecord()
{
@Override
public ObjectChangeSet getOwner()
{
return null;
}
@Override
public Object getOldValue()
{
return oldPropValue;
}
@Override
public String getAttribute()
{
return propName;
}
};
retVal.add(c);
}
}
}
}
return retVal;
}
示例13: createAccessor
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forBeanPropertyAccess(obj);
accessor.setAutoGrowNestedPaths(true);
return accessor;
}
示例14: newPropertyAccessor
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
public static ConfigurablePropertyAccessor newPropertyAccessor(Object obj, boolean directFieldAccess){
ConfigurablePropertyAccessor bw = directFieldAccess?PropertyAccessorFactory.forDirectFieldAccess(obj):PropertyAccessorFactory.forBeanPropertyAccess(obj);
bw.setAutoGrowNestedPaths(true);
return bw;
}
示例15: isNullAndWritableProperty
import org.springframework.beans.ConfigurablePropertyAccessor; //导入依赖的package包/类
private boolean isNullAndWritableProperty(ConfigurablePropertyAccessor accessor, String propertyName) {
return accessor.isWritableProperty(propertyName) && (accessor.isReadableProperty(propertyName) && accessor.getPropertyValue(propertyName) == null);
}