List of usage examples for org.springframework.beans.factory.support ManagedProperties ManagedProperties
ManagedProperties
From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenter.java
private Properties extractOriginalValue(ConfigurableListableBeanFactory beanFactory, PropertyValue originalProperty) { if (originalProperty == null) { return new ManagedProperties(); }// w w w. j ava 2s . c o m Object value = originalProperty.getValue(); if (value instanceof Properties) { return (Properties) value; } else if (value instanceof BeanDefinitionHolder) { return extractProperties((BeanDefinitionHolder) value); } else if (value instanceof BeanReference) { return extractProperties((BeanReference) value, beanFactory); } else if (value instanceof TypedStringValue) { return extractProperties((TypedStringValue) value); } throw new IllegalStateException(String.format("Unable to process property '%s' of type %s", originalProperty.getName(), value.getClass().getName())); }
From source file:jeeves.server.overrides.AddPropertyUpdater.java
@SuppressWarnings("unchecked") @Override//w w w. jav a2 s .com protected void doUpdate(ConfigurableListableBeanFactory beanFactory, BeanDefinition bean, Object value) { Log.debug(Log.JEEVES, "Adding new value " + value + " to property: " + propertyName + " on " + beanName); PropertyValue propertyValue = bean.getPropertyValues().getPropertyValue(propertyName); if (propertyValue == null) { final String beanClassName = bean.getBeanClassName(); try { final Class<?> aClass = Class.forName(beanClassName); final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(aClass); for (PropertyDescriptor descriptor : propertyDescriptors) { if (propertyName.equals(descriptor.getName())) { final Class<?> collectionType = descriptor.getWriteMethod().getParameterTypes()[0]; if (List.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedList<Object>()); } else if (Set.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedSet<Object>()); } else if (Map.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedMap<Object, Object>()); } else if (Properties.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedProperties()); } else if (Array.class.isAssignableFrom(collectionType)) { throw new IllegalArgumentException("Array collections not currently supported"); } else if (Collection.class.isAssignableFrom(collectionType)) { propertyValue = new PropertyValue(propertyName, new ManagedList<Object>()); } else { throw new IllegalArgumentException( collectionType + " is not a supported type for adding new values"); } break; } } if (propertyValue == null) { throw new IllegalArgumentException("Unable to find the collection type for property: " + propertyName + " on bean " + beanName); } bean.getPropertyValues().addPropertyValue(propertyValue); } catch (ClassNotFoundException e) { throw new AssertionError(e); } } Object originalValue = propertyValue.getValue(); if (originalValue instanceof Collection) { Collection<Object> coll = (Collection<Object>) originalValue; coll.add(value); } else { throw new IllegalArgumentException(originalValue + " is not a collection as expected"); } }
From source file:com.wavemaker.runtime.data.cloudfoundry.CloudFoundryDataServiceBeanFactoryPostProcessor.java
/** * @param beanFactory/*from w ww . j a v a 2s . com*/ */ private void processHibernateProperties(DefaultListableBeanFactory beanFactory) { String[] sessionFactoryBeanNames = beanFactory .getBeanNamesForType(ConfigurationAndSessionFactoryBean.class); for (String sfBean : sessionFactoryBeanNames) { BeanDefinition beanDefinition = getBeanDefinition(beanFactory, sfBean); if (sfBean.contains(DataServiceConstants.AUX_BEAN_SUFFIX)) { beanDefinition.setLazyInit(false); } else { beanDefinition.setLazyInit(true); } MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); PropertyValue hibernateProperties = propertyValues.getPropertyValue("hibernateProperties"); ManagedProperties hibernatePropsPropertyValue = null; if (hibernateProperties != null) { Object value = hibernateProperties.getValue(); if (value instanceof ManagedProperties) { hibernatePropsPropertyValue = (ManagedProperties) hibernateProperties.getValue(); TypedStringValue dialect = (TypedStringValue) hibernatePropsPropertyValue .get(new TypedStringValue(DataServiceConstants.HIBERNATE_DIALECT_PROPERTY)); if (dialect != null && dialect .equals(new TypedStringValue("com.wavemaker.runtime.data.dialect.MySQLDialect"))) { hibernatePropsPropertyValue.put( new TypedStringValue(DataServiceConstants.HIBERNATE_DIALECT_PROPERTY), new TypedStringValue("org.hibernate.dialect.MySQLDialect")); } } } else { hibernatePropsPropertyValue = new ManagedProperties(); } } }
From source file:org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.java
/** * Parse a props element./* www .ja va2 s . c o m*/ */ public Properties parsePropsElement(Element propsEle) { ManagedProperties props = new ManagedProperties(); props.setSource(extractSource(propsEle)); props.setMergeEnabled(parseMergeAttribute(propsEle)); List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT); for (Element propEle : propEles) { String key = propEle.getAttribute(KEY_ATTRIBUTE); // Trim the text value to avoid unwanted whitespace // caused by typical XML formatting. String value = DomUtils.getTextValue(propEle).trim(); TypedStringValue keyHolder = new TypedStringValue(key); keyHolder.setSource(extractSource(propEle)); TypedStringValue valueHolder = new TypedStringValue(value); valueHolder.setSource(extractSource(propEle)); props.put(keyHolder, valueHolder); } return props; }