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

项目:lams    文件:RequiredAnnotationBeanPostProcessor.java   
@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;
}
项目:lams    文件:InjectionMetadata.java   
/**
 * Either this or {@link #getResourceToInject} needs to be overridden.
 */
protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable {
    if (this.isField) {
        Field field = (Field) this.member;
        ReflectionUtils.makeAccessible(field);
        field.set(target, getResourceToInject(target, requestingBeanName));
    }
    else {
        if (checkPropertySkipping(pvs)) {
            return;
        }
        try {
            Method method = (Method) this.member;
            ReflectionUtils.makeAccessible(method);
            method.invoke(target, getResourceToInject(target, requestingBeanName));
        }
        catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        }
    }
}
项目:lams    文件:AbstractAutowireCapableBeanFactory.java   
/**
 * 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.");
            }
        }
    }
}
项目:lams    文件:BeanComponentDefinition.java   
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
    List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
    List<BeanReference> references = new ArrayList<BeanReference>();
    PropertyValues propertyValues = beanDefinition.getPropertyValues();
    for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
        PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
        Object value = propertyValue.getValue();
        if (value instanceof BeanDefinitionHolder) {
            innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
        }
        else if (value instanceof BeanDefinition) {
            innerBeans.add((BeanDefinition) value);
        }
        else if (value instanceof BeanReference) {
            references.add((BeanReference) value);
        }
    }
    this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
    this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
项目:jetcache    文件:CreateCacheAnnotationBeanPostProcessor.java   
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    clear(metadata, pvs);
                }
                try {
                    metadata = buildAutowiringMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for autowiring metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:dubbo-spring-boot-autoconfig    文件:DubboReferenceInjector.java   
private InjectionMetadata findReferenceMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildReferenceMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for reference metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:spring4-understanding    文件:CommonAnnotationBeanPostProcessor.java   
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildResourceMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                }
                catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for resource metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:spring4-understanding    文件:PersistenceAnnotationBeanPostProcessor.java   
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildPersistenceMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                }
                catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for persistence metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:spring4-understanding    文件:WebRequestDataBinderTests.java   
/**
 * Must contain: forname=Tony surname=Blair age=50
 */
protected void doTestTony(PropertyValues pvs) throws Exception {
    assertTrue("Contains 3", pvs.getPropertyValues().length == 3);
    assertTrue("Contains forname", pvs.contains("forname"));
    assertTrue("Contains surname", pvs.contains("surname"));
    assertTrue("Contains age", pvs.contains("age"));
    assertTrue("Doesn't contain tory", !pvs.contains("tory"));

    PropertyValue[] pvArray = pvs.getPropertyValues();
    Map<String, String> m = new HashMap<String, String>();
    m.put("forname", "Tony");
    m.put("surname", "Blair");
    m.put("age", "50");
    for (PropertyValue pv : pvArray) {
        Object val = m.get(pv.getName());
        assertTrue("Can't have unexpected value", val != null);
        assertTrue("Val i string", val instanceof String);
        assertTrue("val matches expected", val.equals(pv.getValue()));
        m.remove(pv.getName());
    }
    assertTrue("Map size is 0", m.size() == 0);
}
项目:spring4-understanding    文件:ServletRequestDataBinderTests.java   
/**
 * Must contain: forname=Tony surname=Blair age=50
 */
protected void doTestTony(PropertyValues pvs) throws Exception {
    assertTrue("Contains 3", pvs.getPropertyValues().length == 3);
    assertTrue("Contains forname", pvs.contains("forname"));
    assertTrue("Contains surname", pvs.contains("surname"));
    assertTrue("Contains age", pvs.contains("age"));
    assertTrue("Doesn't contain tory", !pvs.contains("tory"));

    PropertyValue[] ps = pvs.getPropertyValues();
    Map<String, String> m = new HashMap<String, String>();
    m.put("forname", "Tony");
    m.put("surname", "Blair");
    m.put("age", "50");
    for (int i = 0; i < ps.length; i++) {
        Object val = m.get(ps[i].getName());
        assertTrue("Can't have unexpected value", val != null);
        assertTrue("Val i string", val instanceof String);
        assertTrue("val matches expected", val.equals(ps[i].getValue()));
        m.remove(ps[i].getName());
    }
    assertTrue("Map size is 0", m.size() == 0);
}
项目:spring4-understanding    文件:JcaListenerContainerParser.java   
@Override
protected RootBeanDefinition createContainer(Element containerEle, Element listenerEle, ParserContext parserContext,
        PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {

    RootBeanDefinition containerDef = new RootBeanDefinition();
    containerDef.setSource(parserContext.extractSource(containerEle));
    containerDef.setBeanClassName("org.springframework.jms.listener.endpoint.JmsMessageEndpointManager");
    containerDef.getPropertyValues().addPropertyValues(specificContainerProperties);

    RootBeanDefinition configDef = new RootBeanDefinition();
    configDef.setSource(parserContext.extractSource(containerEle));
    configDef.setBeanClassName("org.springframework.jms.listener.endpoint.JmsActivationSpecConfig");
    configDef.getPropertyValues().addPropertyValues(commonContainerProperties);
    parseListenerConfiguration(listenerEle, parserContext, configDef.getPropertyValues());

    containerDef.getPropertyValues().add("activationSpecConfig", configDef);

    return containerDef;
}
项目:spring4-understanding    文件:JmsListenerContainerParser.java   
@Override
protected RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext,
        PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {

    RootBeanDefinition factoryDef = new RootBeanDefinition();

    String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE);
    String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE);
    if (!"".equals(containerClass)) {
        return null; // Not supported
    }
    else if ("".equals(containerType) || containerType.startsWith("default")) {
        factoryDef.setBeanClassName("org.springframework.jms.config.DefaultJmsListenerContainerFactory");
    }
    else if (containerType.startsWith("simple")) {
        factoryDef.setBeanClassName("org.springframework.jms.config.SimpleJmsListenerContainerFactory");
    }

    factoryDef.getPropertyValues().addPropertyValues(commonContainerProperties);
    factoryDef.getPropertyValues().addPropertyValues(specificContainerProperties);

    return factoryDef;
}
项目:spring4-understanding    文件:RequiredAnnotationBeanPostProcessor.java   
@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;
}
项目:spring4-understanding    文件:AutowiredAnnotationBeanPostProcessor.java   
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildAutowiringMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                }
                catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for autowiring metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:spring4-understanding    文件:InjectionMetadata.java   
/**
 * Either this or {@link #getResourceToInject} needs to be overridden.
 */
protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable {
    if (this.isField) {
        Field field = (Field) this.member;
        ReflectionUtils.makeAccessible(field);
        field.set(target, getResourceToInject(target, requestingBeanName));
    }
    else {
        if (checkPropertySkipping(pvs)) {
            return;
        }
        try {
            Method method = (Method) this.member;
            ReflectionUtils.makeAccessible(method);
            method.invoke(target, getResourceToInject(target, requestingBeanName));
        }
        catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        }
    }
}
项目:spring4-understanding    文件:AbstractAutowireCapableBeanFactory.java   
/**
 * 
 * ִ��һ�������Լ�飬�������ع�������ѱ�����
 * <p>
 * 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.");
            }
        }
    }
}
项目:spring4-understanding    文件:BeanComponentDefinition.java   
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
    List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
    List<BeanReference> references = new ArrayList<BeanReference>();
    PropertyValues propertyValues = beanDefinition.getPropertyValues();
    for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
        PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
        Object value = propertyValue.getValue();
        if (value instanceof BeanDefinitionHolder) {
            innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
        }
        else if (value instanceof BeanDefinition) {
            innerBeans.add((BeanDefinition) value);
        }
        else if (value instanceof BeanReference) {
            references.add((BeanReference) value);
        }
    }
    this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
    this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PropertiesConfigurationFactory.java   
private void doBindPropertiesToTarget() throws BindException {
    RelaxedDataBinder dataBinder = (this.targetName != null
            ? new RelaxedDataBinder(this.target, this.targetName)
            : new RelaxedDataBinder(this.target));
    if (this.validator != null) {
        dataBinder.setValidator(this.validator);
    }
    if (this.conversionService != null) {
        dataBinder.setConversionService(this.conversionService);
    }
    dataBinder.setIgnoreNestedProperties(this.ignoreNestedProperties);
    dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
    dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);
    customizeBinder(dataBinder);
    Iterable<String> relaxedTargetNames = getRelaxedTargetNames();
    Set<String> names = getNames(relaxedTargetNames);
    PropertyValues propertyValues = getPropertyValues(names, relaxedTargetNames);
    dataBinder.bind(propertyValues);
    if (this.validator != null) {
        validate(dataBinder);
    }
}
项目:zebra    文件:ZebraMapperScannerConfigurer.java   
private String updatePropertyValue(String propertyName, PropertyValues values) {
    PropertyValue property = values.getPropertyValue(propertyName);

    if (property == null) {
        return null;
    }

    Object value = property.getValue();

    if (value == null) {
        return null;
    } else if (value instanceof String) {
        return value.toString();
    } else if (value instanceof TypedStringValue) {
        return ((TypedStringValue) value).getValue();
    } else {
        return null;
    }
}
项目:spring    文件:CommonAnnotationBeanPostProcessor.java   
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildResourceMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                }
                catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for resource metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:spring    文件:RequiredAnnotationBeanPostProcessor.java   
@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;
}
项目:spring    文件:AutowiredAnnotationBeanPostProcessor.java   
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildAutowiringMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                }
                catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for autowiring metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:spring    文件:InjectionMetadata.java   
/**
 * Either this or {@link #getResourceToInject} needs to be overridden.
 */
protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable {
    if (this.isField) {
        Field field = (Field) this.member;
        ReflectionUtils.makeAccessible(field);
        field.set(target, getResourceToInject(target, requestingBeanName));
    }
    else {
        if (checkPropertySkipping(pvs)) {
            return;
        }
        try {
            Method method = (Method) this.member;
            ReflectionUtils.makeAccessible(method);
            method.invoke(target, getResourceToInject(target, requestingBeanName));
        }
        catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        }
    }
}
项目:spring    文件:AbstractAutowireCapableBeanFactory.java   
/**
 * 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.");
            }
        }
    }
}
项目:spring    文件:BeanComponentDefinition.java   
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
    List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
    List<BeanReference> references = new ArrayList<BeanReference>();
    PropertyValues propertyValues = beanDefinition.getPropertyValues();
    for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
        PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
        Object value = propertyValue.getValue();
        if (value instanceof BeanDefinitionHolder) {
            innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
        }
        else if (value instanceof BeanDefinition) {
            innerBeans.add((BeanDefinition) value);
        }
        else if (value instanceof BeanReference) {
            references.add((BeanReference) value);
        }
    }
    this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
    this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
项目:easyrec_major    文件:ConfigurationHelper.java   
/**
 * Same as getValues(), but property keys are prefixed with the specified prefix.
 *
 * @param propertyKeyPrefix
 *
 */
public PropertyValues getValues(String propertyKeyPrefix) {
    if (propertyKeyPrefix == null) {
        propertyKeyPrefix = "";
    } else {
        propertyKeyPrefix += ".";
    }
    MutablePropertyValues props = new MutablePropertyValues();
    for (String propertyName : getParameterNames()) {
        String strVal = getParameterStringValue(propertyName);
        if (strVal != null) {
            props.addPropertyValue(propertyKeyPrefix + propertyName, strVal);
        }
    }
    return props;
}
项目:rabbitframework    文件:MapperScannerConfigurer.java   
private String updatePropertyValue(String propertyName,
        PropertyValues values) {
    PropertyValue property = values.getPropertyValue(propertyName);

    if (property == null) {
        return null;
    }

    Object value = property.getValue();

    if (value == null) {
        return null;
    } else if (value instanceof String) {
        return value.toString();
    } else if (value instanceof TypedStringValue) {
        return ((TypedStringValue) value).getValue();
    } else {
        return null;
    }
}
项目:spring-boot-concourse    文件:PropertiesConfigurationFactory.java   
private void doBindPropertiesToTarget() throws BindException {
    RelaxedDataBinder dataBinder = (this.targetName != null
            ? new RelaxedDataBinder(this.target, this.targetName)
            : new RelaxedDataBinder(this.target));
    if (this.validator != null) {
        dataBinder.setValidator(this.validator);
    }
    if (this.conversionService != null) {
        dataBinder.setConversionService(this.conversionService);
    }
    dataBinder.setIgnoreNestedProperties(this.ignoreNestedProperties);
    dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
    dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);
    customizeBinder(dataBinder);
    Iterable<String> relaxedTargetNames = getRelaxedTargetNames();
    Set<String> names = getNames(relaxedTargetNames);
    PropertyValues propertyValues = getPropertyValues(names, relaxedTargetNames);
    dataBinder.bind(propertyValues);
    if (this.validator != null) {
        validate(dataBinder);
    }
}
项目:elastic-config    文件:AutowiredAnnotationResoved.java   
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility
    // with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildAutowiringMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName()
                            + "] for autowiring metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
项目:mybatis-spring-1.2.2    文件:MapperScannerConfigurer.java   
private String updatePropertyValue(String propertyName, PropertyValues values) {
  PropertyValue property = values.getPropertyValue(propertyName);

  if (property == null) {
    return null;
  }

  Object value = property.getValue();

  if (value == null) {
    return null;
  } else if (value instanceof String) {
    return value.toString();
  } else if (value instanceof TypedStringValue) {
    return ((TypedStringValue) value).getValue();
  } else {
    return null;
  }
}
项目:kc-rice    文件:ViewModelUtils.java   
/**
 * Helper method for getting the string value of a property from a {@link PropertyValues}
 *
 * @param propertyValues property values instance to pull from
 * @param propertyName name of property whose value should be retrieved
 * @return String value for property or null if property was not found
 */
public static String getStringValFromPVs(PropertyValues propertyValues, String propertyName) {
    String propertyValue = null;

    if ((propertyValues != null) && propertyValues.contains(propertyName)) {
        Object pvValue = propertyValues.getPropertyValue(propertyName).getValue();
        if (pvValue instanceof TypedStringValue) {
            TypedStringValue typedStringValue = (TypedStringValue) pvValue;
            propertyValue = typedStringValue.getValue();
        } else if (pvValue instanceof String) {
            propertyValue = (String) pvValue;
        }
    }

    return propertyValue;
}
项目:kc-rice    文件:UifDictionaryIndex.java   
/**
 * Performs additional indexing based on the view type associated with the view instance. The
 * {@code ViewTypeService} associated with the view type name on the instance is invoked to retrieve
 * the parameter key/value pairs from the configured property values, which are then used to build up an index
 * used to key the entry
 *
 * @param propertyValues - property values configured on the view bean definition
 * @param id - id (or bean name if id was not set) for the view
 */
protected void indexViewForType(PropertyValues propertyValues, String id) {
    String viewTypeName = ViewModelUtils.getStringValFromPVs(propertyValues, "viewTypeName");
    if (StringUtils.isBlank(viewTypeName)) {
        return;
    }

    UifConstants.ViewType viewType = ViewType.valueOf(viewTypeName);

    ViewTypeService typeService = KRADServiceLocatorWeb.getViewService().getViewTypeService(viewType);
    if (typeService == null) {
        // don't do any further indexing
        return;
    }

    // invoke type service to retrieve it parameter name/value pairs
    Map<String, String> typeParameters = typeService.getParametersFromViewConfiguration(propertyValues);

    // build the index string from the parameters
    String index = buildTypeIndex(typeParameters);

    // get the index for the type and add the view entry
    ViewTypeDictionaryIndex typeIndex = getTypeIndex(viewType);

    typeIndex.put(index, id);
}
项目:kc-rice    文件:MaintenanceViewTypeServiceImpl.java   
/**
 * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromViewConfiguration(org.springframework.beans.PropertyValues)
 */
public Map<String, String> getParametersFromViewConfiguration(PropertyValues propertyValues) {
    Map<String, String> parameters = new HashMap<String, String>();

    String viewName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.VIEW_NAME);
    String dataObjectClassName = ViewModelUtils.getStringValFromPVs(propertyValues,
            UifParameters.DATA_OBJECT_CLASS_NAME);
    String docTypeName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.DOC_TYPE_NAME);

    if (!StringUtils.isEmpty(docTypeName)) {
        parameters.put(UifParameters.DOC_TYPE_NAME, docTypeName);
    } else if (!StringUtils.isEmpty(dataObjectClassName)) {
        parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName);
    } else {
        throw new IllegalArgumentException("Document type name or bo class not given!");
    }

    parameters.put(UifParameters.VIEW_NAME, viewName);

    return parameters;
}
项目:ccshop    文件:ArgumentsResolver.java   
private Object convertIfDomainClass(WebRequest webRequest, PropertyValues pvs, Class<?> paramType, String prefix) {
//      // 如果参数是Domain Class,则看看是否有ID,有就根据ID读取数据
//      if (Persistable.class.isAssignableFrom(paramType)) {
//          PropertyValue idValue = pvs.getPropertyValue("id");
//          if (null != idValue) {
//              String idString = (String) idValue.getValue();
//              if (StringUtils.isNotEmpty(idString)) {
//                  WebDataBinder binder = new WebDataBinder(null, prefix + separator + "id");
//                  if (webBindingInitializer != null) {
//                      webBindingInitializer.initBinder(binder, webRequest);
//                  }
//                  return binder.convertIfNecessary(idString, paramType);
//              }
//          }
//      }
        return null;
    }
项目:contestparser    文件:PropertiesConfigurationFactory.java   
private void doBindPropertiesToTarget() throws BindException {
    RelaxedDataBinder dataBinder = (this.targetName != null
            ? new RelaxedDataBinder(this.target, this.targetName)
            : new RelaxedDataBinder(this.target));
    if (this.validator != null) {
        dataBinder.setValidator(this.validator);
    }
    if (this.conversionService != null) {
        dataBinder.setConversionService(this.conversionService);
    }
    dataBinder.setIgnoreNestedProperties(this.ignoreNestedProperties);
    dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
    dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);
    customizeBinder(dataBinder);
    Set<String> names = getNames();
    PropertyValues propertyValues = getPropertyValues(names);
    dataBinder.bind(propertyValues);
    if (this.validator != null) {
        validate(dataBinder);
    }
}
项目:mybatis-spring-support    文件:ScannerConfigurer.java   
private String updatePropertyValue(String propertyName, PropertyValues values) {
  PropertyValue property = values.getPropertyValue(propertyName);

  if (property == null) {
    return null;
  }

  Object value = property.getValue();

  if (value == null) {
    return null;
  } else if (value instanceof String) {
    return value.toString();
  } else if (value instanceof TypedStringValue) {
    return ((TypedStringValue) value).getValue();
  } else {
    return null;
  }
}
项目:spring-rest-client    文件:SpringRestClientScannerConfigurer.java   
private String updatePropertyValue(String propertyName, PropertyValues values) {
    PropertyValue property = values.getPropertyValue(propertyName);

    if (property == null) {
        return null;
    }

    Object value = property.getValue();

    if (value == null) {
        return null;
    } else if (value instanceof String) {
        return value.toString();
    } else if (value instanceof TypedStringValue) {
        return ((TypedStringValue) value).getValue();
    } else {
        return null;
    }
}
项目:AlgoTrader    文件:GrailsDataBinder.java   
private PropertyValues filterPropertyValues(PropertyValues propertyValues, String prefix) {
    if (prefix == null || prefix.length() == 0)
        return propertyValues;

    PropertyValue[] valueArray = propertyValues.getPropertyValues();
    MutablePropertyValues newValues = new MutablePropertyValues();
    for (PropertyValue propertyValue : valueArray) {
        String name = propertyValue.getName();
        final String prefixWithDot = prefix + PREFIX_SEPERATOR;
        if (name.startsWith(prefixWithDot)) {
            name = name.substring(prefixWithDot.length(), name.length());
            newValues.addPropertyValue(name, propertyValue.getValue());
        }
    }
    return newValues;
}
项目:easyrec-PoC    文件:ConfigurationHelper.java   
/**
 * Same as getValues(), but property keys are prefixed with the specified prefix.
 *
 * @param propertyKeyPrefix
 * @return
 */
public PropertyValues getValues(String propertyKeyPrefix) {
    if (propertyKeyPrefix == null) {
        propertyKeyPrefix = "";
    } else {
        propertyKeyPrefix += ".";
    }
    MutablePropertyValues props = new MutablePropertyValues();
    for (String propertyName : getParameterNames()) {
        String strVal = getParameterStringValue(propertyName);
        if (strVal != null) {
            props.addPropertyValue(propertyKeyPrefix + propertyName, strVal);
        }
    }
    return props;
}
项目:class-guard    文件:WebRequestDataBinderTests.java   
/**
 * Must contain: forname=Tony surname=Blair age=50
 */
protected void doTestTony(PropertyValues pvs) throws Exception {
    assertTrue("Contains 3", pvs.getPropertyValues().length == 3);
    assertTrue("Contains forname", pvs.contains("forname"));
    assertTrue("Contains surname", pvs.contains("surname"));
    assertTrue("Contains age", pvs.contains("age"));
    assertTrue("Doesn't contain tory", !pvs.contains("tory"));

    PropertyValue[] pvArray = pvs.getPropertyValues();
    Map<String, String> m = new HashMap<String, String>();
    m.put("forname", "Tony");
    m.put("surname", "Blair");
    m.put("age", "50");
    for (PropertyValue pv : pvArray) {
        Object val = m.get(pv.getName());
        assertTrue("Can't have unexpected value", val != null);
        assertTrue("Val i string", val instanceof String);
        assertTrue("val matches expected", val.equals(pv.getValue()));
        m.remove(pv.getName());
    }
    assertTrue("Map size is 0", m.size() == 0);
}