List of usage examples for org.springframework.beans PropertyValue PropertyValue
public PropertyValue(PropertyValue original, @Nullable Object newValue)
From source file:org.jdbcluster.dao.Dao.java
/** * creates new instance of a Dao using given Dao class * @param daoClass class of Object to create * @return created dao instance//from w w w. ja v a2s . c o m */ public static Object newInstance(Class<?> daoClass) { Object dao = JDBClusterUtil.createClassObject(daoClass); //get property of DAO and initial value from jdbcluster.dao.conf.xml HashMap<String, String> hm; synchronized (classToPropsMap) { hm = classToPropsMap.get(daoClass); if (hm == null) hm = putCacheMap(daoClass); } BeanWrapper beanWrapper = new BeanWrapperImpl(); beanWrapper.setWrappedInstance(dao); for (String prop : hm.keySet()) { String value = hm.get(prop); //get property of DAO Class<?> propClass = beanWrapper.getPropertyType(prop); //convert to Type if necessary Object o = beanWrapper.convertIfNecessary(value, propClass); //set the value of the predefined property read from jdbcluster.dao.conf.xml beanWrapper.setPropertyValue(new PropertyValue(prop, o)); } return dao; }
From source file:net.sourceforge.jabm.spring.PropertyOverrideWithReferencesConfigurer.java
@Override protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value) {/*from ww w . j a v a 2 s . c o m*/ if (value != null && value.length() > 0 && !(value.charAt(0) == '&')) { super.applyPropertyValue(factory, beanName, property, value); } else { BeanDefinition bd = factory.getBeanDefinition(beanName); while (bd.getOriginatingBeanDefinition() != null) { bd = bd.getOriginatingBeanDefinition(); } Object referencedValue = new RuntimeBeanReference(value.substring(1)); PropertyValue pv = new PropertyValue(property, referencedValue); pv.setOptional(false); bd.getPropertyValues().addPropertyValue(pv); } }
From source file:org.jdal.util.BeanUtils.java
/** * Get PropertyValues from Object/*from ww w.j a va2 s . c o m*/ * @param obj Object to get PropertyValues * @return the property values */ public static PropertyValue[] getPropertyValues(Object obj) { PropertyDescriptor[] pds = getPropertyDescriptors(obj.getClass()); ArrayList<PropertyValue> pvs = new ArrayList<PropertyValue>(); List<String> excludedProperties = Arrays.asList(EXCLUDED_PROPERTIES); for (int i = 0; i < pds.length; i++) { Object value = null; String name = pds[i].getName(); if (!excludedProperties.contains(name)) { try { value = pds[i].getReadMethod().invoke(obj, (Object[]) null); } catch (IllegalAccessException e) { log.error("Error reading property name: " + name, e); } catch (IllegalArgumentException e) { log.error("Error reading property name: " + name, e); } catch (InvocationTargetException e) { log.error("Error reading property name: " + name, e); } pvs.add(new PropertyValue(name, value)); } } return (PropertyValue[]) pvs.toArray(new PropertyValue[pvs.size()]); }
From source file:org.springmodules.cache.config.AnnotationsParserTests.java
public void testConfigureCachingInterceptor() { MutablePropertyValues propertyValues = new MutablePropertyValues(); parser.configureCachingInterceptor(propertyValues, registry); Class targetClass = AnnotationCachingAttributeSource.class; String beanName = targetClass.getName(); AbstractBeanDefinition definition = (AbstractBeanDefinition) registry.getBeanDefinition(beanName); ConfigAssert.assertBeanDefinitionWrapsClass(definition, targetClass); PropertyValue expected = new PropertyValue("cachingAttributeSource", new RuntimeBeanReference(beanName)); ConfigAssert.assertPropertyIsPresent(propertyValues, expected); }
From source file:org.browsexml.timesheetjob.web.SimpleWebApplicationContext.java
public void refresh() throws BeansException { MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("commandClass", "org.springframework.beans.TestBean")); pvs.addPropertyValue(new PropertyValue("formView", "form")); //registerSingleton("/form.do", HoursWorkedFormController.class, pvs); //registerSingleton("/locale.do", LocaleChecker.class); //registerPrototype("/throwaway.do", TestThrowawayController.class); addMessage("test", Locale.ENGLISH, "test message"); addMessage("test", Locale.CANADA, "Canadian & test message"); addMessage("testArgs", Locale.ENGLISH, "test {0} message {1}"); addMessage("testArgsFormat", Locale.ENGLISH, "test {0} message {1,number,#.##} X"); registerSingleton(UiApplicationContextUtils.THEME_SOURCE_BEAN_NAME, DummyThemeSource.class); super.refresh(); }
From source file:org.intellij.plugins.ui.EditableListTableModel.java
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { PropertyValue propValue = new PropertyValue(columns[columnIndex].property, aValue); new BeanWrapperImpl(getRows().get(rowIndex)).setPropertyValue(propValue); }
From source file:com.easyshop.datasource.MyBatisBeanFactoryPostProcessor.java
/** * @param beanFactory//from ww w. j a v a 2s .c o m * @throws BeansException * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) */ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { BeanDefinition bd = beanFactory.getBeanDefinition(sqlSessionFactoryBeanName); MutablePropertyValues propertyValues = bd.getPropertyValues(); PropertyValue propertyValue = propertyValues.getPropertyValue("mapperLocations"); Object value = propertyValue.getValue(); ManagedList<TypedStringValue> locations = new ManagedList<TypedStringValue>(); for (String location : mapperLocations) { locations.add(new TypedStringValue(location)); log.info(" SQL Mapper :{} " + location); } if (value == null) { PropertyValue newValue = new PropertyValue(propertyValue, locations); propertyValues.addPropertyValue(newValue); } else if (value instanceof String) { locations.add(new TypedStringValue((String) value)); PropertyValue newValue = new PropertyValue(propertyValue, locations); propertyValues.addPropertyValue(newValue); } else if (value instanceof ManagedList) { ((ManagedList) value).addAll(locations); } else if (value instanceof TypedStringValue) { locations.add((TypedStringValue) value); PropertyValue newValue = new PropertyValue(propertyValue, locations); propertyValues.addPropertyValue(newValue); } }
From source file:com.bt.aloha.spring.BeanFactoryPostProcessorBase.java
protected void injectBeanIfDefined(ConfigurableListableBeanFactory beanFactory, String targetBeanName, String propertyName, Class<?> beanClassToInject) { String[] beanNamesForInjection = beanFactory.getBeanNamesForType(beanClassToInject); if (beanNamesForInjection != null && beanNamesForInjection.length > 0) { log.debug(String.format("Injecting bean %s into property %s of bean %s", beanClassToInject.getName(), propertyName, targetBeanName)); if (beanNamesForInjection.length > 1) log.debug(String.format("Multiple beans of type %s found, injecting only the first one into %s", beanClassToInject.getName(), targetBeanName)); PropertyValue propertyValue = new PropertyValue(propertyName, new RuntimeBeanReference(beanNamesForInjection[0])); BeanDefinition beanDefinition = beanFactory.getBeanDefinition(targetBeanName); beanDefinition.getPropertyValues().addPropertyValue(propertyValue); } else//w ww.j av a 2s . co m log.info(String.format("Property %s not set for bean %s", propertyName, targetBeanName)); }
From source file:org.jdal.util.BeanUtils.java
/** * Copy a property, avoid Execeptions// ww w . ja va 2 s.co m * @param source source bean * @param dest destination bean * @param propertyName the propertyName * */ public static void copyProperty(Object source, Object dest, String propertyName) { BeanWrapper wrapper = new BeanWrapperImpl(source); PropertyValue pv = new PropertyValue(propertyName, wrapper.getPropertyValue(propertyName)); wrapper.setPropertyValue(pv); }
From source file:org.robotframework.remoteapplications.server.PropertyParser.java
private PropertyValue createPropertyValue(int index) { String propertyAsString = getPropertyAsString(index); String[] propertyAr = propertyAsString.split(NAME_VALUE_SEPARATOR_CHAR); return new PropertyValue(propertyAr[0], propertyAr[1]); }