List of usage examples for org.springframework.beans.factory.config TypedStringValue getValue
@Nullable
public String getValue()
From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java
private ElementConfiguration parseBeanObject(Object item) { if (item instanceof TypedStringValue) { TypedStringValue stringValue = (TypedStringValue) item; ElementConfiguration primitiveConfiguration = objectConfigurationFactory .createPrimitiveConfiguration(stringValue.getValue()); return primitiveConfiguration; } else if (item instanceof RuntimeBeanReference) { RuntimeBeanReference runtimeBeanReference = (RuntimeBeanReference) item; // return parseBeanDefinition(runtimeBeanReference.getBeanName()); ReferenceConfiguration reference = objectConfigurationFactory.createReferenceConfiguration(); reference.setReferenceName(runtimeBeanReference.getBeanName()); return reference; } else if (item instanceof BeanDefinitionHolder) { BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) item; return parseBeanDefinition(beanDefinitionHolder.getBeanDefinition()); } else {// w ww . ja v a 2 s . c om throw new IllegalArgumentException("Not supported : item class " + item.getClass().getName()); } }
From source file:org.guiceyfruit.spring.converter.SpringConverter.java
protected void generateBeanDefinition(ModuleGenerator generator, String name, BeanDefinition definition, String className) {/* w ww .j ava 2 s . c o m*/ String shortClassName = addImport(className); ProduceMethod method = generator.startProvides(name, shortClassName); ConstructorArgumentValues constructors = definition.getConstructorArgumentValues(); Map map = constructors.getIndexedArgumentValues(); for (int i = 0, size = map.size(); i < size; i++) { ValueHolder valueHolder = (ValueHolder) map.get(i); if (valueHolder != null) { Object value = valueHolder.getValue(); if (value instanceof TypedStringValue) { TypedStringValue stringValue = (TypedStringValue) value; String text = stringValue.getValue(); System.out.printf("param %s=\"%s\"\n", i, text); String expression = null; String namedParameter = namedParameter(text); if (namedParameter != null) { expression = addParameter(method, "String", namedParameter); } else { expression = "\"" + text + "\""; } method.addConstructorExpression(expression); } else if (value instanceof BeanReference) { BeanReference reference = (BeanReference) value; String beanRef = reference.getBeanName(); // TODO String typeName = "Object"; String expression = addParameter(method, typeName, beanRef); method.addConstructorExpression(expression); } } } MutablePropertyValues propertyValues = definition.getPropertyValues(); PropertyValue[] propertyArray = propertyValues.getPropertyValues(); for (PropertyValue propertyValue : propertyArray) { String property = getSetterMethod(propertyValue); Object value = propertyValue.getConvertedValue(); if (value == null) { value = propertyValue.getValue(); } if (value instanceof BeanReference) { BeanReference reference = (BeanReference) value; String beanRef = reference.getBeanName(); // TODO String typeName = "Object"; String expression = addParameter(method, typeName, beanRef); method.addMethodCall("answer", getSetterMethod(propertyValue), expression); } else if (value instanceof BeanDefinitionHolder) { BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) value; addChildBeanDefinition(generator, method, name, propertyValue, beanDefinitionHolder.getBeanDefinition()); } else if (value instanceof ChildBeanDefinition) { ChildBeanDefinition childBeanDefinition = (ChildBeanDefinition) value; addChildBeanDefinition(generator, method, name, propertyValue, childBeanDefinition); } else { if (value instanceof TypedStringValue) { TypedStringValue stringValue = (TypedStringValue) value; value = stringValue.getValue(); } String valueType = (value == null) ? null : value.getClass().getName(); System.out.printf("property %s=%s of type %s\n", property, value, valueType); String expression; if (value instanceof String) { String text = (String) value; String namedParameter = namedParameter(text); if (namedParameter != null) { expression = addParameter(method, "String", namedParameter); } else { expression = "\"" + value + "\""; } } else if (value == null) { expression = "null"; } else { expression = value.toString(); } method.addMethodCall("answer", getSetterMethod(propertyValue), expression); } } }
From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java
private ObjectConfiguration getEnumObjectConfiguration(TypedStringValue stringValue) { ObjectConfiguration enumObjectConfiguration = objectConfigurationFactory.createObjectConfiguration(); enumObjectConfiguration.setClassName(hashHelper.hashClassName(stringValue.getTargetTypeName())); enumObjectConfiguration.setConstructorArguments(new ArrayList<ElementConfiguration>()); PrimitiveConfiguration enumFieldConfiguration = objectConfigurationFactory .createPrimitiveConfiguration(stringValue.getValue()); enumObjectConfiguration.getConstructorArguments().add(enumFieldConfiguration); return enumObjectConfiguration; }
From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java
public ElementConfiguration parseProperty(Object value) { LOGGER.debug("value : " + value); if (value instanceof TypedStringValue) { TypedStringValue stringValue = (TypedStringValue) value; if (stringValue.getTargetTypeName() != null) { return getEnumObjectConfiguration(stringValue); } else {/*from w w w . j av a 2 s . co m*/ PrimitiveConfiguration primitiveConfiguration = objectConfigurationFactory .createPrimitiveConfiguration(); if (useSPEL(stringValue)) { ExpressionParser parser = new SpelExpressionParser(); String expAsStringWithToken = stringValue.getValue().trim(); String expAsString = expAsStringWithToken.substring(2, expAsStringWithToken.length() - 1) .trim(); LOGGER.trace("This property is a SPEL expression: " + expAsString); // String regex = "systemProperties\\['([^\\s]+)'\\]"; Expression exp = parser.parseExpression(expAsString); StandardEvaluationContext sec = null; if (sec == null) { sec = new StandardEvaluationContext(); sec.addPropertyAccessor(new EnvironmentAccessor()); sec.addPropertyAccessor(new BeanExpressionContextAccessor()); sec.addPropertyAccessor(new BeanFactoryAccessor()); sec.addPropertyAccessor(new MapAccessor()); } primitiveConfiguration.setValue(String.valueOf(exp.getValue())); } else { LOGGER.trace("This property is NOT a SPEL expression: " + stringValue.getValue()); primitiveConfiguration.setValue(stringValue.getValue()); } return primitiveConfiguration; } } else if (value instanceof RuntimeBeanReference) { RuntimeBeanReference beanReference = (RuntimeBeanReference) value; ReferenceConfiguration referenceConfiguration = objectConfigurationFactory .createReferenceConfiguration(); referenceConfiguration.setReferenceName(beanReference.getBeanName()); return referenceConfiguration; } else if (value instanceof ManagedList<?>) { return parseValueList((ManagedList<?>) value); } else if (value instanceof ManagedMap<?, ?>) { return parseValueMap((ManagedMap<?, ?>) value); } else if (value instanceof BeanDefinitionHolder) { BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) value; return parseBeanDefinition(beanDefinitionHolder.getBeanDefinition()); } else { throw new UnsupportedOperationException("The type of property value is not suppported : " + value + " (class : " + value.getClass().getName() + ")"); } }
From source file:org.kuali.rice.krad.datadictionary.DictionaryBeanFactoryPostProcessor.java
/** * Determines whether the given value is of String type and if so returns the string value * * @param value object value to check/* w w w . j av a 2 s .c o m*/ * @return String string value for object or null if object is not a string type */ protected String getString(Object value) { String stringValue = null; if (value instanceof TypedStringValue || (value instanceof String)) { if (value instanceof TypedStringValue) { TypedStringValue typedStringValue = (TypedStringValue) value; stringValue = typedStringValue.getValue(); } else { stringValue = (String) value; } } return stringValue; }
From source file:org.kuali.rice.krad.datadictionary.DictionaryBeanProcessorBase.java
/** * Determines whether the given value is of String type and if so returns the string value * * @param value object value to check/*w w w . j a v a 2s.c o m*/ * @return String string value for object or null if object is not a string type */ protected String getStringValue(Object value) { if (value instanceof TypedStringValue) { TypedStringValue typedStringValue = (TypedStringValue) value; return typedStringValue.getValue(); } else if (value instanceof String) { return (String) value; } return null; }
From source file:org.kuali.rice.krad.datadictionary.uif.UifBeanFactoryPostProcessor.java
/** * Processes the given property name/value pair for complex objects, such as bean definitions or collections, * which if found will be processed for contained property expression values * * @param nestedPropertyName nested path of the property whose value is being processed * @param propertyName name of the property in the bean definition being processed * @param propertyValue value to check/*from ww w.ja v a2s . c o m*/ * @param beanDefinition bean definition the property belongs to * @param parentExpressionGraph map that holds property expressions for the parent bean definition, used for * merging * @param expressionGraph map that holds property expressions for the bean definition being processed * @param beanFactory bean factory that contains the bean definition being processed * @param processedBeanNames set of bean names that have been processed so far * @return new value to set for property */ protected Object processPropertyValue(String nestedPropertyName, String propertyName, Object propertyValue, BeanDefinition beanDefinition, Map<String, String> parentExpressionGraph, Map<String, String> expressionGraph, ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) { boolean clearExpressionsForNull = false; if (propertyValue instanceof TypedStringValue) { TypedStringValue typedStringValue = (TypedStringValue) propertyValue; String value = typedStringValue.getValue(); if (value == null) { clearExpressionsForNull = true; } } else if (propertyValue == null) { clearExpressionsForNull = true; } // if property is object and set to null, clear any parent expressions for the property if (clearExpressionsForNull) { removeExpressionsByPrefix(nestedPropertyName, expressionGraph); removeExpressionsByPrefix(propertyName, parentExpressionGraph); return propertyValue; } // process nested bean definitions if ((propertyValue instanceof BeanDefinition) || (propertyValue instanceof BeanDefinitionHolder)) { String beanName = null; BeanDefinition beanDefinitionValue; if (propertyValue instanceof BeanDefinition) { beanDefinitionValue = (BeanDefinition) propertyValue; } else { beanDefinitionValue = ((BeanDefinitionHolder) propertyValue).getBeanDefinition(); beanName = ((BeanDefinitionHolder) propertyValue).getBeanName(); } // since overriding the entire bean, clear any expressions from parent that start with the bean property removeExpressionsByPrefix(nestedPropertyName, expressionGraph); removeExpressionsByPrefix(propertyName, parentExpressionGraph); processNestedBeanDefinition(beanName, beanDefinitionValue, nestedPropertyName, expressionGraph, beanFactory, processedBeanNames); return propertyValue; } // recurse into collections if (propertyValue instanceof Object[]) { visitArray(nestedPropertyName, parentExpressionGraph, expressionGraph, (Object[]) propertyValue, beanFactory, processedBeanNames); } else if (propertyValue instanceof List) { visitList(nestedPropertyName, propertyName, beanDefinition, parentExpressionGraph, expressionGraph, (List) propertyValue, beanFactory, processedBeanNames); } else if (propertyValue instanceof Set) { visitSet(nestedPropertyName, parentExpressionGraph, expressionGraph, (Set) propertyValue, beanFactory, processedBeanNames); } else if (propertyValue instanceof Map) { visitMap(nestedPropertyName, parentExpressionGraph, expressionGraph, (Map) propertyValue, beanFactory, processedBeanNames); } // others (primitive) just return value as is return propertyValue; }
From source file:org.kuali.rice.krad.uif.util.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 *//* w w w . j a v a2 s. c o m*/ 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; }
From source file:org.kuali.student.common.uif.util.KSUifUtils.java
/** * Determines whether the given value is of String type and if so returns the string value * * @param value - object value to check//from w w w . jav a 2s .c o m * @return String string value for object or null if object is not a string type */ protected static String getStringValue(Object value) { if (value instanceof TypedStringValue) { TypedStringValue typedStringValue = (TypedStringValue) value; return typedStringValue.getValue(); } else if (value instanceof String) { return (String) value; } return null; }
From source file:org.springframework.beans.factory.support.BeanDefinitionValueResolver.java
/** * Given a PropertyValue, return a value, resolving any references to other * beans in the factory if necessary. The value could be: * <li>A BeanDefinition, which leads to the creation of a corresponding * new bean instance. Singleton flags and names of such "inner beans" * are always ignored: Inner beans are anonymous prototypes. * <li>A RuntimeBeanReference, which must be resolved. * <li>A ManagedList. This is a special collection that may contain * RuntimeBeanReferences or Collections that will need to be resolved. * <li>A ManagedSet. May also contain RuntimeBeanReferences or * Collections that will need to be resolved. * <li>A ManagedMap. In this case the value may be a RuntimeBeanReference * or Collection that will need to be resolved. * <li>An ordinary object or <code>null</code>, in which case it's left alone. *///from ww w.j a v a 2s .c o m public Object resolveValueIfNecessary(String argName, Object value) throws BeansException { // We must check each value to see whether it requires a runtime reference // to another bean to be resolved. if (value instanceof BeanDefinitionHolder) { // Resolve BeanDefinitionHolder: contains BeanDefinition with name and aliases. BeanDefinitionHolder bdHolder = (BeanDefinitionHolder) value; return resolveInnerBeanDefinition(argName, bdHolder.getBeanName(), bdHolder.getBeanDefinition()); } else if (value instanceof BeanDefinition) { // Resolve plain BeanDefinition, without contained name: use dummy name. BeanDefinition bd = (BeanDefinition) value; return resolveInnerBeanDefinition(argName, "(inner bean)", bd); } else if (value instanceof RuntimeBeanReference) { RuntimeBeanReference ref = (RuntimeBeanReference) value; return resolveReference(argName, ref); } else if (value instanceof ManagedList) { // May need to resolve contained runtime references. return resolveManagedList(argName, (List) value); } else if (value instanceof ManagedSet) { // May need to resolve contained runtime references. return resolveManagedSet(argName, (Set) value); } else if (value instanceof ManagedMap) { // May need to resolve contained runtime references. return resolveManagedMap(argName, (Map) value); } else if (value instanceof TypedStringValue) { // Convert value to target type here. TypedStringValue typedStringValue = (TypedStringValue) value; try { return this.beanFactory.doTypeConversionIfNecessary(typedStringValue.getValue(), typedStringValue.getTargetType()); } catch (Throwable ex) { // Improve the message by showing the context. throw new BeanCreationException(this.beanDefinition.getResourceDescription(), this.beanName, "Error converting typed String value for " + argName, ex); } } else { // No need to resolve value... return value; } }