Example usage for org.springframework.beans MutablePropertyValues getPropertyValue

List of usage examples for org.springframework.beans MutablePropertyValues getPropertyValue

Introduction

In this page you can find the example usage for org.springframework.beans MutablePropertyValues getPropertyValue.

Prototype

@Override
    @Nullable
    public PropertyValue getPropertyValue(String propertyName) 

Source Link

Usage

From source file:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java

@SuppressWarnings("unchecked")
protected ManagedSet<Object> initSetPropertyValue(final String beanName, final String propertyName,
        final MutablePropertyValues propertyValues) {
    ManagedSet<Object> valueSet;
    PropertyValue propertyValue = propertyValues.getPropertyValue(propertyName);
    if (propertyValue == null) {
        LOGGER.trace("[{}] Property {} on {} not defined yet - initializing new managed set", this.beanName,
                beanName, propertyName);
        valueSet = new ManagedSet<>();
        propertyValue = new PropertyValue(propertyName, valueSet);
        propertyValues.addPropertyValue(propertyValue);
    } else if (propertyValue.getValue() instanceof ManagedList<?>) {
        LOGGER.trace("[{}] Property {} on {} already has a set value - amending", this.beanName, beanName,
                propertyName);// w  ww  . ja  v  a 2s  .c o m
        valueSet = (ManagedSet<Object>) propertyValue.getValue();
    } else {
        LOGGER.debug(
                "[{}] Property {} on {} already defined with value {} - overriding with set value based on properties",
                this.beanName, beanName, propertyName, propertyValue.getValue());
        valueSet = new ManagedSet<>();
        propertyValue = new PropertyValue(propertyName, valueSet);
        propertyValues.addPropertyValue(propertyValue);
    }
    return valueSet;
}

From source file:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java

@SuppressWarnings("unchecked")
protected ManagedList<Object> initListPropertyValue(final String beanName, final String propertyName,
        final MutablePropertyValues propertyValues) {
    ManagedList<Object> valueList;
    PropertyValue propertyValue = propertyValues.getPropertyValue(propertyName);
    if (propertyValue == null) {
        LOGGER.trace("[{}] Property {} on {} not defined yet - initializing new managed list", this.beanName,
                beanName, propertyName);
        valueList = new ManagedList<>();
        propertyValue = new PropertyValue(propertyName, valueList);
        propertyValues.addPropertyValue(propertyValue);
    } else if (propertyValue.getValue() instanceof ManagedList<?>) {
        LOGGER.trace("[{}] Property {} on {} already has a list value - amending", this.beanName, beanName,
                propertyName);//from w  ww. j  a va2s. com
        valueList = (ManagedList<Object>) propertyValue.getValue();
    } else {
        LOGGER.debug(
                "[{}] Property {} on {} already defined with value {} - overriding with list value based on properties",
                this.beanName, beanName, propertyName, propertyValue.getValue());
        valueList = new ManagedList<>();
        propertyValue = new PropertyValue(propertyName, valueList);
        propertyValues.addPropertyValue(propertyValue);
    }
    return valueList;
}

From source file:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java

@SuppressWarnings("unchecked")
protected ManagedMap<Object, Object> initMapPropertyValue(final String beanName, final String propertyName,
        final MutablePropertyValues propertyValues) {
    ManagedMap<Object, Object> valueMap;
    PropertyValue propertyValue = propertyValues.getPropertyValue(propertyName);
    if (propertyValue == null) {
        LOGGER.trace("[{}] Property {} on {} not defined yet - initializing new managed map", this.beanName,
                beanName, propertyName);
        valueMap = new ManagedMap<>();
        propertyValue = new PropertyValue(propertyName, valueMap);
        propertyValues.addPropertyValue(propertyValue);
    } else if (propertyValue.getValue() instanceof ManagedMap<?, ?>) {
        LOGGER.trace("[{}] Property {} on {} already has a map value - amending", this.beanName, beanName,
                propertyName);// www  .j a  v  a2  s.c o m
        valueMap = (ManagedMap<Object, Object>) propertyValue.getValue();
    } else {
        LOGGER.debug(
                "[{}] Property {} on {} already defined with value {} - overriding with map value based on properties",
                this.beanName, beanName, propertyName, propertyValue.getValue());
        valueMap = new ManagedMap<>();
        propertyValue = new PropertyValue(propertyName, valueMap);
        propertyValues.addPropertyValue(propertyValue);
    }
    return valueMap;
}

From source file:cn.guoyukun.spring.SpeedUpSpringProcessor.java

private boolean needRemove(String beanName, BeanDefinition beanDefinition) {

    if (ArrayUtils.isNotEmpty(removedBeanNames)) {
        for (String removedBeanName : removedBeanNames) {
            if (beanName.equals(removedBeanName)) {
                return true;
            }/*from  w w  w .j  av a 2 s. co m*/
            if (beanDefinition.getBeanClassName().equals(removedBeanName)) {
                return true;
            }
        }
    }

    if (this.removedBeanProperties != null) {
        Set<String[]> propertiesSet = removedBeanProperties.get(beanName);
        if (propertiesSet != null) {
            Iterator<String[]> iter = propertiesSet.iterator();
            MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

            while (iter.hasNext()) {
                String[] properties = iter.next();
                if (properties.length == 1) {

                    //
                    propertyValues.removePropertyValue(properties[0]);

                    //?????
                    if (this.replaceBeanProperties != null) {
                        String key = beanName + "@" + properties[0];
                        if (this.replaceBeanProperties.containsKey(key)) {
                            propertyValues.add(properties[0], this.replaceBeanProperties.get(key));
                        }
                    }
                } else {
                    PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]);
                    if (propertyValue != null) {
                        Object nextValue = propertyValue.getValue();
                        //???  + Map
                        if (nextValue instanceof ManagedMap) {

                            TypedStringValue typedStringValue = new TypedStringValue(properties[1]);
                            ((ManagedMap) nextValue).remove(typedStringValue);

                            //?????
                            if (this.replaceBeanProperties != null) {
                                String key = beanName + "@" + properties[0] + "@" + properties[1];
                                if (this.replaceBeanProperties.containsKey(key)) {
                                    ((ManagedMap) nextValue).put(properties[1],
                                            this.replaceBeanProperties.get(key));
                                }
                            }
                        }
                    }
                }
            }

        }
    }

    String className = beanDefinition.getBeanClassName();

    //spring data jpa
    if (className.equals("cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepositoryFactoryBean")
            || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) {
        PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues()
                .getPropertyValue("repositoryInterface");
        if (repositoryInterfaceValue != null) {
            className = repositoryInterfaceValue.getValue().toString();
        }
    }

    if (ArrayUtils.isEmpty(this.removedClassPatterns)) {
        return false;
    }

    if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) {
        for (String includeClassPattern : includeClassPatterns) {
            if (className.matches(includeClassPattern)) {
                return false;
            }
        }
    }

    for (String removedClassPattern : removedClassPatterns) {
        if (className.matches(removedClassPattern)) {
            return true;
        }
    }

    return false;
}

From source file:com.luna.common.spring.SpeedUpSpringProcessor.java

private boolean needRemove(String beanName, BeanDefinition beanDefinition) {

    if (ArrayUtils.isNotEmpty(removedBeanNames)) {
        for (String removedBeanName : removedBeanNames) {
            if (beanName.equals(removedBeanName)) {
                return true;
            }/*www  . j  a v a2 s  .  c  o m*/
            if (beanDefinition.getBeanClassName().equals(removedBeanName)) {
                return true;
            }
        }
    }

    if (this.removedBeanProperties != null) {
        Set<String[]> propertiesSet = removedBeanProperties.get(beanName);
        if (propertiesSet != null) {
            Iterator<String[]> iter = propertiesSet.iterator();
            MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

            while (iter.hasNext()) {
                String[] properties = iter.next();
                if (properties.length == 1) {

                    //
                    propertyValues.removePropertyValue(properties[0]);

                    //?????
                    if (this.replaceBeanProperties != null) {
                        String key = beanName + "@" + properties[0];
                        if (this.replaceBeanProperties.containsKey(key)) {
                            propertyValues.add(properties[0], this.replaceBeanProperties.get(key));
                        }
                    }
                } else {
                    PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]);
                    if (propertyValue != null) {
                        Object nextValue = propertyValue.getValue();
                        //???  + Map
                        if (nextValue instanceof ManagedMap) {

                            TypedStringValue typedStringValue = new TypedStringValue(properties[1]);
                            ((ManagedMap) nextValue).remove(typedStringValue);

                            //?????
                            if (this.replaceBeanProperties != null) {
                                String key = beanName + "@" + properties[0] + "@" + properties[1];
                                if (this.replaceBeanProperties.containsKey(key)) {
                                    ((ManagedMap) nextValue).put(properties[1],
                                            this.replaceBeanProperties.get(key));
                                }
                            }
                        }
                    }
                }
            }

        }
    }

    String className = beanDefinition.getBeanClassName();

    //spring data jpa
    if (className.equals("com.luna.common.repository.support.SimpleBaseRepositoryFactoryBean")
            || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) {
        PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues()
                .getPropertyValue("repositoryInterface");
        if (repositoryInterfaceValue != null) {
            className = repositoryInterfaceValue.getValue().toString();
        }
    }

    if (ArrayUtils.isEmpty(this.removedClassPatterns)) {
        return false;
    }

    if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) {
        for (String includeClassPattern : includeClassPatterns) {
            if (className.matches(includeClassPattern)) {
                return false;
            }
        }
    }

    for (String removedClassPattern : removedClassPatterns) {
        if (className.matches(removedClassPattern)) {
            return true;
        }
    }

    return false;
}

From source file:com.cloudy.common.spring.SpeedUpSpringProcessor.java

private boolean needRemove(String beanName, BeanDefinition beanDefinition) {

    if (ArrayUtils.isNotEmpty(removedBeanNames)) {
        for (String removedBeanName : removedBeanNames) {
            if (beanName.equals(removedBeanName)) {
                return true;
            }//from  w  ww .j av a  2s  .  co  m
            if (beanDefinition.getBeanClassName().equals(removedBeanName)) {
                return true;
            }
        }
    }

    if (this.removedBeanProperties != null) {
        Set<String[]> propertiesSet = removedBeanProperties.get(beanName);
        if (propertiesSet != null) {
            Iterator<String[]> iter = propertiesSet.iterator();
            MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

            while (iter.hasNext()) {
                String[] properties = iter.next();
                if (properties.length == 1) {

                    //
                    propertyValues.removePropertyValue(properties[0]);

                    //?????
                    if (this.replaceBeanProperties != null) {
                        String key = beanName + "@" + properties[0];
                        if (this.replaceBeanProperties.containsKey(key)) {
                            propertyValues.add(properties[0], this.replaceBeanProperties.get(key));
                        }
                    }
                } else {
                    PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]);
                    if (propertyValue != null) {
                        Object nextValue = propertyValue.getValue();
                        //???  + Map
                        if (nextValue instanceof ManagedMap) {

                            TypedStringValue typedStringValue = new TypedStringValue(properties[1]);
                            ((ManagedMap) nextValue).remove(typedStringValue);

                            //?????
                            if (this.replaceBeanProperties != null) {
                                String key = beanName + "@" + properties[0] + "@" + properties[1];
                                if (this.replaceBeanProperties.containsKey(key)) {
                                    ((ManagedMap) nextValue).put(properties[1],
                                            this.replaceBeanProperties.get(key));
                                }
                            }
                        }
                    }
                }
            }

        }
    }

    String className = beanDefinition.getBeanClassName();

    //spring data jpa
    if (className.equals("com.ibm.common.repository.support.SimpleBaseRepositoryFactoryBean")
            || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) {
        PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues()
                .getPropertyValue("repositoryInterface");
        if (repositoryInterfaceValue != null) {
            className = repositoryInterfaceValue.getValue().toString();
        }
    }

    if (ArrayUtils.isEmpty(this.removedClassPatterns)) {
        return false;
    }

    if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) {
        for (String includeClassPattern : includeClassPatterns) {
            if (className.matches(includeClassPattern)) {
                return false;
            }
        }
    }

    for (String removedClassPattern : removedClassPatterns) {
        if (className.matches(removedClassPattern)) {
            return true;
        }
    }

    return false;
}

From source file:com.cykj.base.common.spring.SpeedUpSpringProcessor.java

private boolean needRemove(String beanName, BeanDefinition beanDefinition) {

    if (ArrayUtils.isNotEmpty(removedBeanNames)) {
        for (String removedBeanName : removedBeanNames) {
            if (beanName.equals(removedBeanName)) {
                return true;
            }//from  w w  w . j  a v  a 2s  .c  o m
            if (beanDefinition.getBeanClassName().equals(removedBeanName)) {
                return true;
            }
        }
    }

    if (this.removedBeanProperties != null) {
        Set<String[]> propertiesSet = removedBeanProperties.get(beanName);
        if (propertiesSet != null) {
            Iterator<String[]> iter = propertiesSet.iterator();
            MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

            while (iter.hasNext()) {
                String[] properties = iter.next();
                if (properties.length == 1) {

                    //
                    propertyValues.removePropertyValue(properties[0]);

                    //?????
                    if (this.replaceBeanProperties != null) {
                        String key = beanName + "@" + properties[0];
                        if (this.replaceBeanProperties.containsKey(key)) {
                            propertyValues.add(properties[0], this.replaceBeanProperties.get(key));
                        }
                    }
                } else {
                    PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]);
                    if (propertyValue != null) {
                        Object nextValue = propertyValue.getValue();
                        //???  + Map
                        if (nextValue instanceof ManagedMap) {

                            TypedStringValue typedStringValue = new TypedStringValue(properties[1]);
                            ((ManagedMap) nextValue).remove(typedStringValue);

                            //?????
                            if (this.replaceBeanProperties != null) {
                                String key = beanName + "@" + properties[0] + "@" + properties[1];
                                if (this.replaceBeanProperties.containsKey(key)) {
                                    ((ManagedMap) nextValue).put(properties[1],
                                            this.replaceBeanProperties.get(key));
                                }
                            }
                        }
                    }
                }
            }

        }
    }

    String className = beanDefinition.getBeanClassName();

    //spring data jpa
    if (className.equals("com.sishuok.es.common.repository.support.SimpleBaseRepositoryFactoryBean")
            || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) {
        PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues()
                .getPropertyValue("repositoryInterface");
        if (repositoryInterfaceValue != null) {
            className = repositoryInterfaceValue.getValue().toString();
        }
    }

    if (ArrayUtils.isEmpty(this.removedClassPatterns)) {
        return false;
    }

    if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) {
        for (String includeClassPattern : includeClassPatterns) {
            if (className.matches(includeClassPattern)) {
                return false;
            }
        }
    }

    for (String removedClassPattern : removedClassPatterns) {
        if (className.matches(removedClassPattern)) {
            return true;
        }
    }

    return false;
}

From source file:com.daphne.es.common.spring.SpeedUpSpringProcessor.java

private boolean needRemove(String beanName, BeanDefinition beanDefinition) {

    if (ArrayUtils.isNotEmpty(removedBeanNames)) {
        for (String removedBeanName : removedBeanNames) {
            if (beanName.equals(removedBeanName)) {
                return true;
            }/*from  ww  w  .  ja  va 2  s .  c  om*/
            if (beanDefinition.getBeanClassName().equals(removedBeanName)) {
                return true;
            }
        }
    }

    if (this.removedBeanProperties != null) {
        Set<String[]> propertiesSet = removedBeanProperties.get(beanName);
        if (propertiesSet != null) {
            Iterator<String[]> iter = propertiesSet.iterator();
            MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

            while (iter.hasNext()) {
                String[] properties = iter.next();
                if (properties.length == 1) {

                    //
                    propertyValues.removePropertyValue(properties[0]);

                    //?????
                    if (this.replaceBeanProperties != null) {
                        String key = beanName + "@" + properties[0];
                        if (this.replaceBeanProperties.containsKey(key)) {
                            propertyValues.add(properties[0], this.replaceBeanProperties.get(key));
                        }
                    }
                } else {
                    PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]);
                    if (propertyValue != null) {
                        Object nextValue = propertyValue.getValue();
                        //???  + Map
                        if (nextValue instanceof ManagedMap) {

                            TypedStringValue typedStringValue = new TypedStringValue(properties[1]);
                            ((ManagedMap) nextValue).remove(typedStringValue);

                            //?????
                            if (this.replaceBeanProperties != null) {
                                String key = beanName + "@" + properties[0] + "@" + properties[1];
                                if (this.replaceBeanProperties.containsKey(key)) {
                                    ((ManagedMap) nextValue).put(properties[1],
                                            this.replaceBeanProperties.get(key));
                                }
                            }
                        }
                    }
                }
            }

        }
    }

    String className = beanDefinition.getBeanClassName();

    //spring data jpa
    if (className.equals("com.daphne.es.common.repository.support.SimpleBaseRepositoryFactoryBean")
            || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) {
        PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues()
                .getPropertyValue("repositoryInterface");
        if (repositoryInterfaceValue != null) {
            className = repositoryInterfaceValue.getValue().toString();
        }
    }

    if (ArrayUtils.isEmpty(this.removedClassPatterns)) {
        return false;
    }

    if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) {
        for (String includeClassPattern : includeClassPatterns) {
            if (className.matches(includeClassPattern)) {
                return false;
            }
        }
    }

    for (String removedClassPattern : removedClassPatterns) {
        if (className.matches(removedClassPattern)) {
            return true;
        }
    }

    return false;
}

From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java

@SuppressWarnings("unchecked")
private void processStructuredProperty(StructuredPropertyEditor structuredEditor, String propertyName,
        Class<?> type, List<String> valueNames, MutablePropertyValues propertyValues) {

    List requiredFields = structuredEditor.getRequiredFields();
    List<String> fields = new ArrayList<String>();
    fields.addAll(requiredFields);//  w  w w . ja v  a 2s. c  o m
    fields.addAll(structuredEditor.getOptionalFields());

    Map<String, String> fieldValues = new HashMap<String, String>();
    try {

        String firstRequiredField = null;
        for (String field : fields) {
            String fullName = propertyName + STRUCTURED_PROPERTY_SEPERATOR + field;

            // don't re-process related properties
            valueNames.remove(fullName);

            if (firstRequiredField != null) {
                continue;
            }

            PropertyValue partialStructValue = propertyValues.getPropertyValue(fullName);
            if (partialStructValue == null) {
                if (requiredFields.contains(field)) {
                    firstRequiredField = field;
                }
            } else {
                fieldValues.put(field, getStringValue(partialStructValue));
            }
        }

        // set to null since it either won't be created because of problem, or will be overwritten
        propertyValues.removePropertyValue(propertyName);

        if (firstRequiredField != null) {
            throw new MissingPropertyException(
                    "Required structured property is missing [" + firstRequiredField + "]");
        }

        try {
            Object value = structuredEditor.assemble(type, fieldValues);
            for (String field : fields) {
                PropertyValue partialStructValue = propertyValues
                        .getPropertyValue(propertyName + STRUCTURED_PROPERTY_SEPERATOR + field);
                if (null != partialStructValue) {
                    partialStructValue.setConvertedValue(getStringValue(partialStructValue));
                }
            }
            propertyValues.addPropertyValue(new PropertyValue(propertyName, value));
        } catch (IllegalArgumentException e) {
            LOG.warn("Unable to parse structured date from request for date [" + propertyName + "]", e);
        }
    } catch (InvalidPropertyException ignored) {
        // ignored
    }
}

From source file:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java

protected void processPropertyValueDefinition(final String beanName, final String propertyDefinitionKey,
        final String value, final BeanDefinition beanDefinition,
        final Consumer<ManagedList<?>> paddedListRegistrator) {
    final String propertyName;

    String definitionKeyRemainder;
    final int nextDot = propertyDefinitionKey.indexOf('.');
    if (nextDot != -1) {
        propertyName = propertyDefinitionKey.substring(0, nextDot);
        definitionKeyRemainder = propertyDefinitionKey.substring(nextDot + 1).toLowerCase(Locale.ENGLISH);
    } else {/*from www . j a  v  a 2s .co  m*/
        propertyName = propertyDefinitionKey.toString();
        definitionKeyRemainder = "";
    }

    final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

    final boolean isList = definitionKeyRemainder.startsWith(PREFIX_LIST);
    final boolean isSet = definitionKeyRemainder.startsWith(PREFIX_LIST);
    final boolean isMap = definitionKeyRemainder.startsWith(PREFIX_MAP);

    if (isList) {
        definitionKeyRemainder = definitionKeyRemainder.substring(PREFIX_LIST.length());
        this.processListPropertyValueDefinition(beanName, propertyName, definitionKeyRemainder, value,
                propertyValues, paddedListRegistrator);
    } else if (isSet) {
        definitionKeyRemainder = definitionKeyRemainder.substring(PREFIX_SET.length());
        this.processSetPropertyValueDefinition(beanName, propertyName, definitionKeyRemainder, value,
                propertyValues);
    } else if (isMap) {
        definitionKeyRemainder = definitionKeyRemainder.substring(PREFIX_MAP.length());
        this.processMapPropertryValueDefinition(beanName, propertyName, definitionKeyRemainder, value,
                propertyValues);
    } else {
        PropertyValue propertyValue = propertyValues.getPropertyValue(propertyName);
        final Object valueToSet = this.getAsValue(beanName, propertyName, definitionKeyRemainder, value);

        if (propertyValue != null && propertyValue.getValue() != null) {
            LOGGER.debug(
                    "[{}] Property {} on {} already defined with value {} - overriding with different value",
                    this.beanName, beanName, propertyName, propertyValue.getValue());
        }
        propertyValue = new PropertyValue(propertyName, valueToSet);
        propertyValues.addPropertyValue(propertyValue);
    }
}