org.springframework.beans.MutablePropertyValues#removePropertyValue ( )源码实例Demo

下面列出了org.springframework.beans.MutablePropertyValues#removePropertyValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AlgoTrader   文件: GrailsDataBinder.java
/**
 * This overrides the method from WebDataBinder to allow for nested checkbox handling, so property paths such as
 * a._b will result in the boolean b on object a getting set to false.
 */
@Override
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
	if (getFieldMarkerPrefix() == null) {
		return;
	}

	String fieldMarkerPrefix = getFieldMarkerPrefix();
	PropertyValue[] pvArray = mpvs.getPropertyValues();
	for (PropertyValue pv : pvArray) {
		// start of variation from superclass method
		if (propertyStartsWithFieldMarkerPrefix(pv, fieldMarkerPrefix)) {
			String field = stripFieldMarkerPrefix(pv.getName(), fieldMarkerPrefix);
			// end of variation from superclass method
			if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
				Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
				mpvs.add(field, getEmptyValue(field, fieldType));
			}
			mpvs.removePropertyValue(pv);
		}
	}
}
 
源代码2 项目: spring-analysis-note   文件: WebDataBinder.java
/**
 * Check the given property values for field markers,
 * i.e. for fields that start with the field marker prefix.
 * <p>The existence of a field marker indicates that the specified
 * field existed in the form. If the property values do not contain
 * a corresponding field value, the field will be considered as empty
 * and will be reset appropriately.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldMarkerPrefix
 * @see #getEmptyValue(String, Class)
 */
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
	String fieldMarkerPrefix = getFieldMarkerPrefix();
	if (fieldMarkerPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldMarkerPrefix)) {
				String field = pv.getName().substring(fieldMarkerPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
					mpvs.add(field, getEmptyValue(field, fieldType));
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
源代码3 项目: java-technology-stack   文件: WebDataBinder.java
/**
 * Check the given property values for field defaults,
 * i.e. for fields that start with the field default prefix.
 * <p>The existence of a field defaults indicates that the specified
 * value should be used if the field is otherwise not present.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldDefaultPrefix
 */
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
	String fieldDefaultPrefix = getFieldDefaultPrefix();
	if (fieldDefaultPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldDefaultPrefix)) {
				String field = pv.getName().substring(fieldDefaultPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					mpvs.add(field, pv.getValue());
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
源代码4 项目: java-technology-stack   文件: WebDataBinder.java
/**
 * Check the given property values for field markers,
 * i.e. for fields that start with the field marker prefix.
 * <p>The existence of a field marker indicates that the specified
 * field existed in the form. If the property values do not contain
 * a corresponding field value, the field will be considered as empty
 * and will be reset appropriately.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldMarkerPrefix
 * @see #getEmptyValue(String, Class)
 */
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
	String fieldMarkerPrefix = getFieldMarkerPrefix();
	if (fieldMarkerPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldMarkerPrefix)) {
				String field = pv.getName().substring(fieldMarkerPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
					mpvs.add(field, getEmptyValue(field, fieldType));
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
源代码5 项目: lams   文件: SpringBeanJobFactory.java
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = super.createJobInstance(bundle);
	if (isEligibleForPropertyPopulation(job)) {
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
		pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
		if (this.ignoredUnknownProperties != null) {
			for (String propName : this.ignoredUnknownProperties) {
				if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
					pvs.removePropertyValue(propName);
				}
			}
			bw.setPropertyValues(pvs);
		}
		else {
			bw.setPropertyValues(pvs, true);
		}
	}
	return job;
}
 
源代码6 项目: lams   文件: WebDataBinder.java
/**
 * Check the given property values for field defaults,
 * i.e. for fields that start with the field default prefix.
 * <p>The existence of a field defaults indicates that the specified
 * value should be used if the field is otherwise not present.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldDefaultPrefix
 */
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
	String fieldDefaultPrefix = getFieldDefaultPrefix();
	if (fieldDefaultPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldDefaultPrefix)) {
				String field = pv.getName().substring(fieldDefaultPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					mpvs.add(field, pv.getValue());
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
源代码7 项目: lams   文件: WebDataBinder.java
/**
 * Check the given property values for field markers,
 * i.e. for fields that start with the field marker prefix.
 * <p>The existence of a field marker indicates that the specified
 * field existed in the form. If the property values do not contain
 * a corresponding field value, the field will be considered as empty
 * and will be reset appropriately.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldMarkerPrefix
 * @see #getEmptyValue(String, Class)
 */
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
	String fieldMarkerPrefix = getFieldMarkerPrefix();
	if (fieldMarkerPrefix != null) {
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldMarkerPrefix)) {
				String field = pv.getName().substring(fieldMarkerPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
					mpvs.add(field, getEmptyValue(field, fieldType));
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
源代码8 项目: rice   文件: DictionaryBeanFactoryPostProcessor.java
/**
 * Iterates through the properties defined for the bean definition and invokes helper methods to process
 * the property value
 *
 * @param beanDefinition bean definition whose properties will be processed
 * @param nestedBeanStack stack of beans which contain the given bean
 */
protected void processBeanProperties(BeanDefinition beanDefinition, Stack<BeanDefinitionHolder> nestedBeanStack) {
    // iterate through properties and check for any configured message keys within the value
    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    PropertyValue[] pvArray = pvs.getPropertyValues();
    for (PropertyValue pv : pvArray) {
        Object newPropertyValue = null;
        if (isStringValue(pv.getValue())) {
            newPropertyValue = processStringPropertyValue(pv.getName(), getString(pv.getValue()), nestedBeanStack);
        } else {
            newPropertyValue = visitPropertyValue(pv.getName(), pv.getValue(), nestedBeanStack);
        }

        pvs.removePropertyValue(pv.getName());
        pvs.addPropertyValue(pv.getName(), newPropertyValue);
    }
}
 
源代码9 项目: spring4-understanding   文件: WebDataBinder.java
/**
 * Check the given property values for field defaults,
 * i.e. for fields that start with the field default prefix.
 * <p>The existence of a field defaults indicates that the specified
 * value should be used if the field is otherwise not present.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldDefaultPrefix
 */
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
	if (getFieldDefaultPrefix() != null) {
		String fieldDefaultPrefix = getFieldDefaultPrefix();
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldDefaultPrefix)) {
				String field = pv.getName().substring(fieldDefaultPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					mpvs.add(field, pv.getValue());
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
源代码10 项目: spring4-understanding   文件: WebDataBinder.java
/**
 * Check the given property values for field markers,
 * i.e. for fields that start with the field marker prefix.
 * <p>The existence of a field marker indicates that the specified
 * field existed in the form. If the property values do not contain
 * a corresponding field value, the field will be considered as empty
 * and will be reset appropriately.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getFieldMarkerPrefix
 * @see #getEmptyValue(String, Class)
 */
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
	if (getFieldMarkerPrefix() != null) {
		String fieldMarkerPrefix = getFieldMarkerPrefix();
		PropertyValue[] pvArray = mpvs.getPropertyValues();
		for (PropertyValue pv : pvArray) {
			if (pv.getName().startsWith(fieldMarkerPrefix)) {
				String field = pv.getName().substring(fieldMarkerPrefix.length());
				if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
					Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
					mpvs.add(field, getEmptyValue(field, fieldType));
				}
				mpvs.removePropertyValue(pv);
			}
		}
	}
}
 
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = super.createJobInstance(bundle);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
	if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
		pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
		if (this.ignoredUnknownProperties != null) {
			for (String propName : this.ignoredUnknownProperties) {
				if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
					pvs.removePropertyValue(propName);
				}
			}
			bw.setPropertyValues(pvs);
		}
		else {
			bw.setPropertyValues(pvs, true);
		}
	}
	return job;
}
 
源代码12 项目: spring-analysis-note   文件: DataBinder.java
/**
 * Check the given property values against the allowed fields,
 * removing values for fields that are not allowed.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getAllowedFields
 * @see #isAllowed(String)
 */
protected void checkAllowedFields(MutablePropertyValues mpvs) {
	PropertyValue[] pvs = mpvs.getPropertyValues();
	for (PropertyValue pv : pvs) {
		String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
		if (!isAllowed(field)) {
			mpvs.removePropertyValue(pv);
			getBindingResult().recordSuppressedField(field);
			if (logger.isDebugEnabled()) {
				logger.debug("Field [" + field + "] has been removed from PropertyValues " +
						"and will not be bound, because it has not been found in the list of allowed fields");
			}
		}
	}
}
 
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = (this.applicationContext != null ?
			this.applicationContext.getAutowireCapableBeanFactory().createBean(
					bundle.getJobDetail().getJobClass(), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false) :
			super.createJobInstance(bundle));

	if (isEligibleForPropertyPopulation(job)) {
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
		pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
		if (this.ignoredUnknownProperties != null) {
			for (String propName : this.ignoredUnknownProperties) {
				if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
					pvs.removePropertyValue(propName);
				}
			}
			bw.setPropertyValues(pvs);
		}
		else {
			bw.setPropertyValues(pvs, true);
		}
	}

	return job;
}
 
源代码14 项目: java-technology-stack   文件: DataBinder.java
/**
 * Check the given property values against the allowed fields,
 * removing values for fields that are not allowed.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getAllowedFields
 * @see #isAllowed(String)
 */
protected void checkAllowedFields(MutablePropertyValues mpvs) {
	PropertyValue[] pvs = mpvs.getPropertyValues();
	for (PropertyValue pv : pvs) {
		String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
		if (!isAllowed(field)) {
			mpvs.removePropertyValue(pv);
			getBindingResult().recordSuppressedField(field);
			if (logger.isDebugEnabled()) {
				logger.debug("Field [" + field + "] has been removed from PropertyValues " +
						"and will not be bound, because it has not been found in the list of allowed fields");
			}
		}
	}
}
 
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = (this.applicationContext != null ?
			this.applicationContext.getAutowireCapableBeanFactory().createBean(
					bundle.getJobDetail().getJobClass(), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false) :
			super.createJobInstance(bundle));

	if (isEligibleForPropertyPopulation(job)) {
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
		pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
		if (this.ignoredUnknownProperties != null) {
			for (String propName : this.ignoredUnknownProperties) {
				if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
					pvs.removePropertyValue(propName);
				}
			}
			bw.setPropertyValues(pvs);
		}
		else {
			bw.setPropertyValues(pvs, true);
		}
	}

	return job;
}
 
源代码16 项目: lams   文件: DataBinder.java
/**
 * Check the given property values against the allowed fields,
 * removing values for fields that are not allowed.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getAllowedFields
 * @see #isAllowed(String)
 */
protected void checkAllowedFields(MutablePropertyValues mpvs) {
	PropertyValue[] pvs = mpvs.getPropertyValues();
	for (PropertyValue pv : pvs) {
		String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
		if (!isAllowed(field)) {
			mpvs.removePropertyValue(pv);
			getBindingResult().recordSuppressedField(field);
			if (logger.isDebugEnabled()) {
				logger.debug("Field [" + field + "] has been removed from PropertyValues " +
						"and will not be bound, because it has not been found in the list of allowed fields");
			}
		}
	}
}
 
源代码17 项目: AlgoTrader   文件: GrailsDataBinder.java
private void filterNestedParameterMaps(MutablePropertyValues mpvs) {
	for (PropertyValue pv : mpvs.getPropertyValues()) {
		final Object value = pv.getValue();
		if (isNotCandidateForBinding(value)) {
			mpvs.removePropertyValue(pv);
		}
	}
}
 
源代码18 项目: rice   文件: UifBeanFactoryPostProcessor.java
/**
 * If the bean class is type UifDictionaryBean, iterate through configured property values
 * and check for expressions.
 *
 * @param beanName name of the bean in the factory (only set for top level beans, not nested)
 * @param beanDefinition bean definition to process for expressions
 * @param nestedPropertyName
 * @param expressionGraph
 * @param beanFactory bean factory being processed
 * @param processedBeanNames
 */
protected void processNestedBeanDefinition(String beanName, BeanDefinition beanDefinition,
        String nestedPropertyName, Map<String, String> expressionGraph,
        ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) {
    Class<?> beanClass = getBeanClass(beanDefinition, beanFactory);
    if ((beanClass == null) || !UifDictionaryBean.class.isAssignableFrom(beanClass) || processedBeanNames.contains(
            beanName)) {
        return;
    }

    LOG.debug("Processing bean name '" + beanName + "'");

    Map<String, String> parentExpressionGraph = getExpressionGraphFromParent(beanDefinition.getParentName(),
            beanFactory, processedBeanNames);

    // process expressions on property values
    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    PropertyValue[] pvArray = pvs.getPropertyValues();
    for (PropertyValue pv : pvArray) {
        if (pv.getName().equals(UifPropertyPaths.EXPRESSION_GRAPH)) {
            continue;
        }

        String propertyPath = pv.getName();
        if (StringUtils.isNotBlank(nestedPropertyName)) {
            propertyPath = nestedPropertyName + "." + propertyPath;
        }

        // for reloading, need to remove the property from the previously loaded bean definition
        if (expressionGraph.containsKey(propertyPath)) {
            expressionGraph.remove(propertyPath);
        }

        if (hasExpression(pv.getValue())) {
            // process expression
            String strValue = getStringValue(pv.getValue());
            expressionGraph.put(propertyPath, strValue);

            // remove property value so expression will not cause binding exception
            pvs.removePropertyValue(pv.getName());
        } else {
            // process nested objects
            Object newValue = processPropertyValue(propertyPath, pv.getName(), pv.getValue(), beanDefinition,
                    parentExpressionGraph, expressionGraph, beanFactory, processedBeanNames);

            pvs.removePropertyValue(pv.getName());
            pvs.addPropertyValue(pv.getName(), newValue);
        }

        // removed expression (if exists) from parent map since the property was set on child
        if (parentExpressionGraph.containsKey(pv.getName())) {
            parentExpressionGraph.remove(pv.getName());
        }
    }

    // if nested bean set expression graph to null so it is not inherited from parent definition
    if (StringUtils.isNotBlank(nestedPropertyName)) {
        pvs.addPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH, null);
    }

    // add remaining expressions from parent to expression graph
    for (Map.Entry<String, String> parentExpression : parentExpressionGraph.entrySet()) {
        String expressionPath = parentExpression.getKey();
        if (StringUtils.isNotBlank(nestedPropertyName)) {
            expressionPath = nestedPropertyName + "." + expressionPath;
        }

        if (!expressionGraph.containsKey(expressionPath)) {
            expressionGraph.put(expressionPath, parentExpression.getValue());
        }
    }

    if (StringUtils.isNotBlank(beanName)) {
        processedBeanNames.add(beanName);
    }
}
 
/**
 * Given a bean name (assumed to implement {@link org.springframework.core.io.support.PropertiesLoaderSupport})
 * checks whether it already references the <code>global-properties</code> bean. If not, 'upgrades' the bean by
 * appending all additional resources it mentions in its <code>locations</code> property to
 * <code>globalPropertyLocations</code>, except for those resources mentioned in <code>newLocations</code>. A
 * reference to <code>global-properties</code> will then be added and the resource list in
 * <code>newLocations<code> will then become the new <code>locations</code> list for the bean.
 * 
 * @param beanFactory
 *            the bean factory
 * @param globalPropertyLocations
 *            the list of global property locations to be appended to
 * @param beanName
 *            the bean name
 * @param newLocations
 *            the new locations to be set on the bean
 * @return the mutable property values
 */
@SuppressWarnings("unchecked")
private MutablePropertyValues processLocations(ConfigurableListableBeanFactory beanFactory,
        Collection<Object> globalPropertyLocations, String beanName, String[] newLocations)
{
    // Get the bean an check its existing properties value
    MutablePropertyValues beanProperties = beanFactory.getBeanDefinition(beanName).getPropertyValues();
    PropertyValue pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES);
    Object value;

    // If the properties value already references the global-properties bean, we have nothing else to do. Otherwise,
    // we have to 'upgrade' the bean definition.
    if (pv == null || (value = pv.getValue()) == null || !(value instanceof BeanReference)
            || ((BeanReference) value).getBeanName().equals(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES))
    {
        // Convert the array of new locations to a managed list of type string values, so that it is
        // compatible with a bean definition
        Collection<Object> newLocationList = new ManagedList(newLocations.length);
        if (newLocations != null && newLocations.length > 0)
        {
            for (String preserveLocation : newLocations)
            {
                newLocationList.add(new TypedStringValue(preserveLocation));
            }
        }

        // If there is currently a locations list, process it
        pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
        if (pv != null && (value = pv.getValue()) != null && value instanceof Collection)
        {
            Collection<Object> locations = (Collection<Object>) value;

            // Compute the set of locations that need to be added to globalPropertyLocations (preserving order) and
            // warn about each
            Set<Object> addedLocations = new LinkedHashSet<Object>(locations);
            addedLocations.removeAll(globalPropertyLocations);
            addedLocations.removeAll(newLocationList);

            for (Object location : addedLocations)
            {
                LegacyConfigPostProcessor.logger.warn("Legacy configuration detected: adding "
                        + (location instanceof TypedStringValue ? ((TypedStringValue) location).getValue()
                                : location.toString()) + " to global-properties definition");
                globalPropertyLocations.add(location);
            }

        }
        // Ensure the bean now references global-properties
        beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES, new RuntimeBeanReference(
                LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES));

        // Ensure the new location list is now set on the bean
        if (newLocationList.size() > 0)
        {
            beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS, newLocationList);
        }
        else
        {
            beanProperties.removePropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
        }
    }
    return beanProperties;
}
 
源代码20 项目: AlgoTrader   文件: GrailsDataBinder.java
@SuppressWarnings("unchecked")
private void bindCollectionAssociation(MutablePropertyValues mpvs, PropertyValue pv) {
	Object v = pv.getValue();

	Collection collection = (Collection) this.bean.getPropertyValue(pv.getName());
	collection.clear();
	final Class associatedType = getReferencedTypeForCollection(pv.getName(), getTarget());
	final boolean isArray = v != null && v.getClass().isArray();
	final PropertyEditor propertyEditor = findCustomEditor(collection.getClass(), pv.getName());
	if (propertyEditor == null) {
		if (isDomainAssociation(associatedType)) {
			if (isArray) {
				Object[] identifiers = (Object[]) v;
				for (Object id : identifiers) {
					if (id != null) {
						associateObjectForId(pv, id, associatedType);
					}
				}
				mpvs.removePropertyValue(pv);
			} else if (v != null && (v instanceof String)) {
				associateObjectForId(pv, v, associatedType);
				mpvs.removePropertyValue(pv);
			}
		} else if (GrailsDomainConfigurationUtil.isBasicType(associatedType)) {
			if (isArray) {
				Object[] values = (Object[]) v;
				List list = collection instanceof List ? (List) collection : null;
				for (int i = 0; i < values.length; i++) {
					Object value = values[i];
					try {
						Object newValue = getTypeConverter().convertIfNecessary(value, associatedType);
						if (list != null) {
							if (i > list.size() - 1) {
								list.add(i, newValue);
							} else {
								list.set(i, newValue);
							}
						} else {
							collection.add(newValue);
						}
					} catch (TypeMismatchException e) {
						// ignore
					}
				}
			}
		}
	}
}