List of usage examples for org.springframework.beans PropertyValues getPropertyValue
@Nullable PropertyValue getPropertyValue(String propertyName);
From source file:com.trenako.web.infrastructure.ServletRequestPathVariablesPropertyValuesTests.java
@Test public void shouldFillPropertyValues() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/trenako-web/rs/brand/ACME"); PropertyValues pvs = new ServletRequestPathVariablesPropertyValues(request); assertNotNull(pvs);//from w w w . jav a2s.co m assertEquals(1, pvs.getPropertyValues().length); assertEquals("ACME", pvs.getPropertyValue("brand").getValue()); }
From source file:org.devefx.httpmapper.spring.mapper.MapperScannerConfigurer.java
private String updatePropertyValue(String propertyName, PropertyValues values) { PropertyValue property = values.getPropertyValue(propertyName); if (property == null) { return null; }//from w w w . jav a 2s. c om 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(); } return null; }
From source file:com.helpinput.spring.refresher.SessiontRefresher.java
@Override public void refresh(ApplicationContext context, Map<Class<?>, ScanedType> scanedClasses) { boolean needRefreshSessionFactory = false; for (Entry<Class<?>, ScanedType> entry : scanedClasses.entrySet()) { if (entry.getValue().getValue() > ScanedType.SAME.getValue() && entry.getKey().getAnnotation(Entity.class) != null) { needRefreshSessionFactory = true; break; }//w w w . j av a 2 s . com } if (needRefreshSessionFactory) { DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) ((AbstractApplicationContext) context) .getBeanFactory(); //testUserManager(dlbf); final String sessionFactory = "sessionFactory"; final String annotatedClasses = "annotatedClasses"; final String setSessionFactory = "setSessionFactory"; BeanDefinition oldSessionFactoryDef = dlbf.getBeanDefinition(sessionFactory); if (oldSessionFactoryDef != null) { dlbf.removeBeanDefinition(sessionFactory); MutablePropertyValues propertyValues = oldSessionFactoryDef.getPropertyValues(); PropertyValue oldPropertyValue = propertyValues.getPropertyValue(annotatedClasses); propertyValues.removePropertyValue(annotatedClasses); BeanDefinition newSessionFactoryDef = BeanDefinitionBuilder .rootBeanDefinition(oldSessionFactoryDef.getBeanClassName()).getBeanDefinition(); List<PropertyValue> propertyValueList = newSessionFactoryDef.getPropertyValues() .getPropertyValueList(); propertyValueList.addAll(propertyValues.getPropertyValueList()); propertyValueList.add(new PropertyValue(annotatedClasses, getManageList(dlbf, oldPropertyValue))); dlbf.registerBeanDefinition(sessionFactory, newSessionFactoryDef); SessionFactory sessionFactoryImpl = (SessionFactory) dlbf.getBean(sessionFactory); String[] beanNames = dlbf.getBeanDefinitionNames(); for (String beanName : beanNames) { BeanDefinition beanDefinition = dlbf.getBeanDefinition(beanName); PropertyValues pValues = beanDefinition.getPropertyValues(); if (pValues.getPropertyValue(sessionFactory) != null) { Object theBean = dlbf.getBean(beanName); Method method = Utils.findMethod(theBean, setSessionFactory, sessionFactoryImpl); if (method != null) Utils.InvokedMethod(theBean, method, sessionFactoryImpl); } } } } }
From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenter.java
@SuppressWarnings("unchecked") private Properties getPropertiesFactoryBeanProperties(BeanDefinition beanDefinition) { PropertyValues propertyValues = beanDefinition.getPropertyValues(); if (propertyValues.contains("location")) { return loadPropertiesForLocation(propertyValues.getPropertyValue("location").getValue()); } else if (propertyValues.contains("locations")) { return loadPropertiesForLocations(propertyValues.getPropertyValue("locations").getValue()); } else if (propertyValues.contains("properties")) { Object value = propertyValues.getPropertyValue("properties").getValue(); if (value instanceof BeanDefinitionHolder) { return extractProperties((BeanDefinitionHolder) value); } else {//from w w w.java2s . c o m return convert((Map<String, String>) value); } } throw new IllegalArgumentException( "Unable to process PropertiesFactoryBean; doesn't contain either 'locations' or 'properties' property"); }
From source file:com.comstar.mars.env.EnvMapperScannerConfigurer.java
private String updatePropertyValue(String propertyName, PropertyValues values) { PropertyValue property = values.getPropertyValue(propertyName); if (property == null) { return null; }/*from w w w . ja v a 2 s. co m*/ 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; } }
From source file:org.jdal.aop.SerializableReference.java
private Object readResolve() throws ObjectStreamException { if (beanFactory == null) { log.error("Can't not deserialize reference without bean factory"); return null; }// w w w . j av a 2s . com if (useMemoryCache) { Object ret = serializedObjects.remove(this.id); if (ret != null) { if (log.isDebugEnabled()) log.debug("Removed a serialized reference. serialized objects size [" + serializedObjects.size() + "]"); return getSerializableProxy(ret); } } if (targetBeanName != null) { if (log.isDebugEnabled()) log.debug("Resolving serializable object to bean name [" + targetBeanName + "]"); return getSerializableProxy(); } if (log.isDebugEnabled()) log.debug("Resolving serializable object for [" + descriptor.getDependencyName() + "]"); Field field = descriptor.getField(); // Check bean definition BeanDefinition rbd = beanFactory.getBeanDefinition(beanName); PropertyValues pvs = rbd.getPropertyValues(); if (pvs.contains(field.getName())) { Object value = pvs.getPropertyValue(field.getName()); if (value instanceof BeanReference) { // cache the bean name this.targetBeanName = ((BeanReference) value).getBeanName(); return getSerializableProxy(); } } // Check Autowired try { Object bean = beanFactory.resolveDependency(descriptor, beanName); if (bean != null) return getSerializableProxy(bean); } catch (BeansException be) { // dependency not found. } // Check Resource annotation if (field.isAnnotationPresent(Resource.class)) { Resource r = field.getAnnotation(Resource.class); String name = StringUtils.isEmpty(r.name()) ? descriptor.getField().getName() : r.name(); if (beanFactory.containsBean(name)) { this.targetBeanName = name; return getSerializableProxy(); } } // Try with depend beans. String[] dependentBeans = beanFactory.getDependenciesForBean(beanName); List<String> candidates = new ArrayList<String>(); for (String name : dependentBeans) { if (beanFactory.isTypeMatch(name, descriptor.getDependencyType())) ; candidates.add(name); } if (candidates.size() == 1) return getSerializableProxy(beanFactory.getBean(candidates.get(0))); if (candidates.size() > 1) { for (PropertyValue pv : pvs.getPropertyValues()) { if (pv.getValue() instanceof BeanReference) { BeanReference br = (BeanReference) pv.getValue(); if (candidates.contains(br.getBeanName())) return getSerializableProxy(beanFactory.getBean(br.getBeanName())); } } } log.error("Cant not resolve serializable reference wiht candidates " + candidates.toArray()); return null; }
From source file:org.kuali.rice.krad.datadictionary.DataDictionary.java
/** * Returns a property value for the bean with the given name from the dictionary. * * @param beanName id or name for the bean definition * @param propertyName name of the property to retrieve, must be a valid property configured on * the bean definition//from ww w . j a v a 2s . co m * @return Object property value for property */ public Object getDictionaryBeanProperty(String beanName, String propertyName) { Object bean = ddBeans.getSingleton(beanName); if (bean != null) { return ObjectPropertyUtils.getPropertyValue(bean, propertyName); } BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName); if (beanDefinition == null) { throw new RuntimeException("Unable to get bean for bean name: " + beanName); } PropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(propertyName)) { PropertyValue propertyValue = pvs.getPropertyValue(propertyName); Object value; if (propertyValue.isConverted()) { value = propertyValue.getConvertedValue(); } else if (propertyValue.getValue() instanceof String) { String unconvertedValue = (String) propertyValue.getValue(); Scope scope = ddBeans.getRegisteredScope(beanDefinition.getScope()); BeanExpressionContext beanExpressionContext = new BeanExpressionContext(ddBeans, scope); value = ddBeans.getBeanExpressionResolver().evaluate(unconvertedValue, beanExpressionContext); } else { value = propertyValue.getValue(); } return value; } return null; }
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 */// ww w .j a va 2 s . c om 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.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java
/** * Insert the bean we have built into the target (typically the parent bean). * * <p>This is the most complex case because the bean can have an aribtrary type. * // w ww .j a va 2s.co m * @param oldName The identifying the bean (typically element name). */ public void insertBeanInTarget(String oldName) { logger.debug("insert " + bean.getBeanDefinition().getBeanClassName() + " -> " + target.getBeanClassName()); assertTargetPresent(); String beanClass = bean.getBeanDefinition().getBeanClassName(); PropertyValues sourceProperties = bean.getRawBeanDefinition().getPropertyValues(); String newName = bestGuessName(targetConfig, oldName, target.getBeanClassName()); MutablePropertyValues targetProperties = target.getPropertyValues(); PropertyValue pv = targetProperties.getPropertyValue(newName); Object oldValue = null == pv ? null : pv.getValue(); if (!targetConfig.isIgnored(oldName)) { if (targetConfig.isCollection(oldName) || beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName())) { if (null == oldValue) { if (beanClass.equals(ChildMapEntryDefinitionParser.KeyValuePair.class.getName()) || beanClass.equals(MapEntryCombiner.class.getName()) || beanClass.equals(MapFactoryBean.class.getName())) { // a collection of maps requires an extra intermediate object that does the // lazy combination/caching of maps when first used BeanDefinitionBuilder combiner = BeanDefinitionBuilder .rootBeanDefinition(MapCombiner.class); targetProperties.addPropertyValue(newName, combiner.getBeanDefinition()); MutablePropertyValues combinerProperties = combiner.getBeanDefinition().getPropertyValues(); oldValue = new ManagedList(); pv = new PropertyValue(MapCombiner.LIST, oldValue); combinerProperties.addPropertyValue(pv); } else { oldValue = new ManagedList(); pv = new PropertyValue(newName, oldValue); targetProperties.addPropertyValue(pv); } } List list = retrieveList(oldValue); if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass)) { list.add(new ManagedMap()); retrieveMap(list.get(list.size() - 1)).put( sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(), sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue()); } else if (beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName())) { list.add(sourceProperties.getPropertyValue(ChildListEntryDefinitionParser.VALUE).getValue()); } else { list.add(bean.getBeanDefinition()); } } else { // not a collection if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass)) { if (null == pv || null == oldValue) { pv = new PropertyValue(newName, new ManagedMap()); targetProperties.addPropertyValue(pv); } retrieveMap(pv.getValue()).put( sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(), sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue()); } else { targetProperties.addPropertyValue(newName, bean.getBeanDefinition()); } } } }
From source file:org.springframework.springfaces.mvc.bind.ReverseDataBinderTest.java
private void doTestReverseBindWithDefaultValues(boolean dontSkip, boolean noConstructor) throws Exception { Sample target = noConstructor ? new SampleWithoutDefaultConstructor("") : new Sample(); target.setIntegerValue(new Integer(123)); DataBinder dataBinder = new DataBinder(target); ReverseDataBinder reverseDataBinder = new ReverseDataBinder(dataBinder); if (dontSkip) { // Only set when skipped to test default is true reverseDataBinder.setSkipDefaultValues(false); }/* w ww.ja v a 2s . co m*/ PropertyValues result = reverseDataBinder.reverseBind(); boolean fullBindExpected = dontSkip || noConstructor; assertThat(result.getPropertyValues().length, is(equalTo(fullBindExpected ? 2 : 1))); assertThat(result.getPropertyValue("integerValue").getValue(), is(equalTo((Object) "123"))); if (fullBindExpected) { assertThat(result.getPropertyValue("stringValue").getValue(), is(equalTo((Object) "default"))); } }