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

项目:onetwo    文件:BeanPropertiesMapper.java   
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);
        }
    }
}
项目:winlet    文件:WinletDefaultFormattingConversionService.java   
/**
 * 判断对象属性是否有格式可以应用。调用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);
}
项目:winlet    文件:WinletDefaultFormattingConversionService.java   
/**
 * 如果有格式可应用则应用
 * 
 * @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();
}
项目: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);
    }
    return this.directFieldAccessor;
}
项目: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;
}
项目:spring4-understanding    文件: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;
}
项目:spring4-understanding    文件: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;
}
项目:my-spring-cache-redis    文件: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);
    }
    return this.directFieldAccessor;
}
项目:my-spring-cache-redis    文件: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;
}
项目:spring    文件: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;
}
项目:spring    文件: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;
}
项目:dachs    文件:EclipseLinkEntityEventListener.java   
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;
}
项目: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);
    }
}
项目:class-guard    文件: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);
    }
    return this.directFieldAccessor;
}
项目:class-guard    文件: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;
}
项目:spring-mvc-toolkit    文件:Html5InputTag.java   
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;
}
项目: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);
}
项目:lams    文件:DataBinder.java   
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
    return getInternalBindingResult().getPropertyAccessor();
}
项目:spring4-understanding    文件: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);
}
项目:spring4-understanding    文件:DataBinder.java   
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
    return getInternalBindingResult().getPropertyAccessor();
}
项目:my-spring-cache-redis    文件: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);
}
项目:my-spring-cache-redis    文件:DataBinder.java   
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
    return getInternalBindingResult().getPropertyAccessor();
}
项目:spring    文件: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);
}
项目:spring    文件:DataBinder.java   
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
    return getInternalBindingResult().getPropertyAccessor();
}
项目:dachs    文件:EclipseLinkEntityEventListener.java   
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;
}
项目:onetwo    文件:BeanPropertiesMapper.java   
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
    ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forBeanPropertyAccess(obj);
    accessor.setAutoGrowNestedPaths(true);
    return accessor;
}
项目:onetwo    文件:BeanPropertiesMapper.java   
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
    ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(obj);
    accessor.setAutoGrowNestedPaths(true);
    return accessor;
}
项目: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;
}
项目:AlgoTrader    文件:GrailsDataBinder.java   
private boolean isNullAndWritableProperty(ConfigurablePropertyAccessor accessor, String propertyName) {
    return accessor.isWritableProperty(propertyName) && (accessor.isReadableProperty(propertyName) && accessor.getPropertyValue(propertyName) == null);
}
项目:class-guard    文件: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);
}
项目:class-guard    文件:DataBinder.java   
/**
 * Return the underlying PropertyAccessor of this binder's BindingResult.
 */
protected ConfigurablePropertyAccessor getPropertyAccessor() {
    return getInternalBindingResult().getPropertyAccessor();
}
项目: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();
项目:spring4-understanding    文件: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();
项目:my-spring-cache-redis    文件: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();
项目:spring    文件: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();
项目:class-guard    文件: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();
项目:onetwo    文件:BeanPropertiesMapper.java   
abstract public ConfigurablePropertyAccessor createAccessor(Object obj);