Java Code Examples for org.springframework.beans.PropertyValues#contains()

The following examples show how to use org.springframework.beans.PropertyValues#contains() . 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
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example 2
/**
 * Perform a dependency check that all properties exposed have been set,
 * if desired. Dependency checks can be objects (collaborating beans),
 * simple (primitives and String), or all (both).
 * @param beanName the name of the bean
 * @param mbd the merged bean definition the bean was created with
 * @param pds the relevant property descriptors for the target bean
 * @param pvs the property values to be applied to the bean
 * @see #isExcludedFromDependencyCheck(java.beans.PropertyDescriptor)
 */
protected void checkDependencies(
		String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, @Nullable PropertyValues pvs)
		throws UnsatisfiedDependencyException {

	int dependencyCheck = mbd.getDependencyCheck();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && (pvs == null || !pvs.contains(pd.getName()))) {
			boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType());
			boolean unsatisfied = (dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_ALL) ||
					(isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
					(!isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
			if (unsatisfied) {
				throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(),
						"Set this property value or disable dependency checking for this bean.");
			}
		}
	}
}
 
Example 3
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example 4
/**
 * Perform a dependency check that all properties exposed have been set,
 * if desired. Dependency checks can be objects (collaborating beans),
 * simple (primitives and String), or all (both).
 * @param beanName the name of the bean
 * @param mbd the merged bean definition the bean was created with
 * @param pds the relevant property descriptors for the target bean
 * @param pvs the property values to be applied to the bean
 * @see #isExcludedFromDependencyCheck(java.beans.PropertyDescriptor)
 */
protected void checkDependencies(
		String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, @Nullable PropertyValues pvs)
		throws UnsatisfiedDependencyException {

	int dependencyCheck = mbd.getDependencyCheck();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && (pvs == null || !pvs.contains(pd.getName()))) {
			boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType());
			boolean unsatisfied = (dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_ALL) ||
					(isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
					(!isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
			if (unsatisfied) {
				throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(),
						"Set this property value or disable dependency checking for this bean.");
			}
		}
	}
}
 
Example 5
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<String>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example 6
/**
 * Perform a dependency check that all properties exposed have been set,
 * if desired. Dependency checks can be objects (collaborating beans),
 * simple (primitives and String), or all (both).
 * @param beanName the name of the bean
 * @param mbd the merged bean definition the bean was created with
 * @param pds the relevant property descriptors for the target bean
 * @param pvs the property values to be applied to the bean
 * @see #isExcludedFromDependencyCheck(java.beans.PropertyDescriptor)
 */
protected void checkDependencies(
		String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, PropertyValues pvs)
		throws UnsatisfiedDependencyException {

	int dependencyCheck = mbd.getDependencyCheck();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !pvs.contains(pd.getName())) {
			boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType());
			boolean unsatisfied = (dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_ALL) ||
					(isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
					(!isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
			if (unsatisfied) {
				throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(),
						"Set this property value or disable dependency checking for this bean.");
			}
		}
	}
}
 
Example 7
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
		throws BeansException {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<String>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example 8
/**
 * Perform a dependency check that all properties exposed have been set,
 * if desired. Dependency checks can be objects (collaborating beans),
 * simple (primitives and String), or all (both).
 * @param beanName the name of the bean
 * @param mbd the merged bean definition the bean was created with
 * @param pds the relevant property descriptors for the target bean
 * @param pvs the property values to be applied to the bean
 * @see #isExcludedFromDependencyCheck(PropertyDescriptor)
 */
protected void checkDependencies(
		String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, PropertyValues pvs)
		throws UnsatisfiedDependencyException {

	int dependencyCheck = mbd.getDependencyCheck();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !pvs.contains(pd.getName())) {
			boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType());
			boolean unsatisfied = (dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_ALL) ||
					(isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
					(!isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
			if (unsatisfied) {
				throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(),
						"Set this property value or disable dependency checking for this bean.");
			}
		}
	}
}
 
Example 9
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
		throws BeansException {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<String>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example 10
Source Project: spring-analysis-note   File: InjectionMetadata.java    License: MIT License 5 votes vote down vote up
/**
 * Check whether this injector's property needs to be skipped due to
 * an explicit property value having been specified. Also marks the
 * affected property as processed for other processors to ignore it.
 */
protected boolean checkPropertySkipping(@Nullable PropertyValues pvs) {
	Boolean skip = this.skip;
	if (skip != null) {
		return skip;
	}
	if (pvs == null) {
		this.skip = false;
		return false;
	}
	synchronized (pvs) {
		skip = this.skip;
		if (skip != null) {
			return skip;
		}
		if (this.pd != null) {
			if (pvs.contains(this.pd.getName())) {
				// Explicit value provided as part of the bean definition.
				this.skip = true;
				return true;
			}
			else if (pvs instanceof MutablePropertyValues) {
				((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
			}
		}
		this.skip = false;
		return false;
	}
}
 
Example 11
/**
 * Return an array of non-simple bean properties that are unsatisfied.
 * These are probably unsatisfied references to other beans in the
 * factory. Does not include simple properties like primitives or Strings.
 * @param mbd the merged bean definition the bean was created with
 * @param bw the BeanWrapper the bean was created with
 * @return an array of bean property names
 * @see org.springframework.beans.BeanUtils#isSimpleProperty
 */
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
	Set<String> result = new TreeSet<>();
	PropertyValues pvs = mbd.getPropertyValues();
	PropertyDescriptor[] pds = bw.getPropertyDescriptors();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
				!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
			result.add(pd.getName());
		}
	}
	return StringUtils.toStringArray(result);
}
 
Example 12
/**
 * Check whether this injector's property needs to be skipped due to
 * an explicit property value having been specified. Also marks the
 * affected property as processed for other processors to ignore it.
 */
protected boolean checkPropertySkipping(@Nullable PropertyValues pvs) {
	Boolean skip = this.skip;
	if (skip != null) {
		return skip;
	}
	if (pvs == null) {
		this.skip = false;
		return false;
	}
	synchronized (pvs) {
		skip = this.skip;
		if (skip != null) {
			return skip;
		}
		if (this.pd != null) {
			if (pvs.contains(this.pd.getName())) {
				// Explicit value provided as part of the bean definition.
				this.skip = true;
				return true;
			}
			else if (pvs instanceof MutablePropertyValues) {
				((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
			}
		}
		this.skip = false;
		return false;
	}
}
 
Example 13
/**
 * Return an array of non-simple bean properties that are unsatisfied.
 * These are probably unsatisfied references to other beans in the
 * factory. Does not include simple properties like primitives or Strings.
 * @param mbd the merged bean definition the bean was created with
 * @param bw the BeanWrapper the bean was created with
 * @return an array of bean property names
 * @see org.springframework.beans.BeanUtils#isSimpleProperty
 */
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
	Set<String> result = new TreeSet<>();
	PropertyValues pvs = mbd.getPropertyValues();
	PropertyDescriptor[] pds = bw.getPropertyDescriptors();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
				!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
			result.add(pd.getName());
		}
	}
	return StringUtils.toStringArray(result);
}
 
Example 14
/**
 * Check whether this injector's property needs to be skipped due to
 * an explicit property value having been specified. Also marks the
 * affected property as processed for other processors to ignore it.
 */
protected boolean checkPropertySkipping(PropertyValues pvs) {
	if (this.skip != null) {
		return this.skip;
	}
	if (pvs == null) {
		this.skip = false;
		return false;
	}
	synchronized (pvs) {
		if (this.skip != null) {
			return this.skip;
		}
		if (this.pd != null) {
			if (pvs.contains(this.pd.getName())) {
				// Explicit value provided as part of the bean definition.
				this.skip = true;
				return true;
			}
			else if (pvs instanceof MutablePropertyValues) {
				((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
			}
		}
		this.skip = false;
		return false;
	}
}
 
Example 15
/**
 * Return an array of non-simple bean properties that are unsatisfied.
 * These are probably unsatisfied references to other beans in the
 * factory. Does not include simple properties like primitives or Strings.
 * @param mbd the merged bean definition the bean was created with
 * @param bw the BeanWrapper the bean was created with
 * @return an array of bean property names
 * @see org.springframework.beans.BeanUtils#isSimpleProperty
 */
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
	Set<String> result = new TreeSet<String>();
	PropertyValues pvs = mbd.getPropertyValues();
	PropertyDescriptor[] pds = bw.getPropertyDescriptors();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
				!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
			result.add(pd.getName());
		}
	}
	return StringUtils.toStringArray(result);
}
 
Example 16
Source Project: blog_demos   File: InjectionMetadata.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether this injector's property needs to be skipped due to
 * an explicit property value having been specified. Also marks the
 * affected property as processed for other processors to ignore it.
 */
protected boolean checkPropertySkipping(PropertyValues pvs) {
	if (this.skip != null) {
		return this.skip;
	}
	if (pvs == null) {
		this.skip = false;
		return false;
	}
	synchronized (pvs) {
		if (this.skip != null) {
			return this.skip;
		}
		if (this.pd != null) {
			if (pvs.contains(this.pd.getName())) {
				// Explicit value provided as part of the bean definition.
				this.skip = true;
				return true;
			}
			else if (pvs instanceof MutablePropertyValues) {
				((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
			}
		}
		this.skip = false;
		return false;
	}
}
 
Example 17
/**
 * Return an array of non-simple bean properties that are unsatisfied.
 * These are probably unsatisfied references to other beans in the
 * factory. Does not include simple properties like primitives or Strings.
 * @param mbd the merged bean definition the bean was created with
 * @param bw the BeanWrapper the bean was created with
 * @return an array of bean property names
 * @see BeanUtils#isSimpleProperty
 */
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
	Set<String> result = new TreeSet<String>();
	PropertyValues pvs = mbd.getPropertyValues();
	PropertyDescriptor[] pds = bw.getPropertyDescriptors();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
				!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
			result.add(pd.getName());
		}
	}
	return StringUtils.toStringArray(result);
}
 
Example 18
/**
 * Check whether this injector's property needs to be skipped due to
 * an explicit property value having been specified. Also marks the
 * affected property as processed for other processors to ignore it.
 */
protected boolean checkPropertySkipping(PropertyValues pvs) {
	if (this.skip != null) {
		return this.skip;
	}
	if (pvs == null) {
		this.skip = false;
		return false;
	}
	synchronized (pvs) {
		if (this.skip != null) {
			return this.skip;
		}
		if (this.pd != null) {
			if (pvs.contains(this.pd.getName())) {
				// Explicit value provided as part of the bean definition.
				this.skip = true;
				return true;
			}
			else if (pvs instanceof MutablePropertyValues) {
				((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
			}
		}
		this.skip = false;
		return false;
	}
}
 
Example 19
/**
	 * Return an array of non-simple bean properties that are unsatisfied.
	 * These are probably unsatisfied references to other beans in the
	 * factory. Does not include simple properties like primitives or Strings.
	 * @param mbd the merged bean definition the bean was created with
	 * @param bw the BeanWrapper the bean was created with
	 * @return an array of bean property names
	 * @see org.springframework.beans.BeanUtils#isSimpleProperty
	 */
	protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
		Set<String> result = new TreeSet<String>();
		PropertyValues pvs = mbd.getPropertyValues();
		PropertyDescriptor[] pds = bw.getPropertyDescriptors();
		for (PropertyDescriptor pd : pds) {
//			��ȡ����дֵ�ķ���������
			if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
					!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
				
				result.add(pd.getName());
			}
		}
		return StringUtils.toStringArray(result);
	}
 
Example 20
/**
 * Returns a property value for the bean with the given name from the dictionary.
 *
 * @param beanName id or name for the bean definition
 * @param propertyName name of the property to retrieve, must be a valid property configured on
 * the bean definition
 * @return Object property value for property
 */
public Object getDictionaryBeanProperty(String beanName, String propertyName) {
    Object bean = ddBeans.getSingleton(beanName);
    if (bean != null) {
        return ObjectPropertyUtils.getPropertyValue(bean, propertyName);
    }

    BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName);

    if (beanDefinition == null) {
        throw new RuntimeException("Unable to get bean for bean name: " + beanName);
    }

    PropertyValues pvs = beanDefinition.getPropertyValues();
    if (pvs.contains(propertyName)) {
        PropertyValue propertyValue = pvs.getPropertyValue(propertyName);

        Object value;
        if (propertyValue.isConverted()) {
            value = propertyValue.getConvertedValue();
        } else if (propertyValue.getValue() instanceof String) {
            String unconvertedValue = (String) propertyValue.getValue();
            Scope scope = ddBeans.getRegisteredScope(beanDefinition.getScope());
            BeanExpressionContext beanExpressionContext = new BeanExpressionContext(ddBeans, scope);

            value = ddBeans.getBeanExpressionResolver().evaluate(unconvertedValue, beanExpressionContext);
        } else {
            value = propertyValue.getValue();
        }

        return value;
    }

    return null;
}