use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class WebDataBinder method checkFieldDefaults.
/**
* Check the given property values for field defaults,
* i.e. for fields that start with the field default prefix.
* <p>The existence of a field defaults indicates that the specified
* value should be used if the field is otherwise not present.
* @param mpvs the property values to be bound (can be modified)
* @see #getFieldDefaultPrefix
*/
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
if (getFieldDefaultPrefix() != null) {
String fieldDefaultPrefix = getFieldDefaultPrefix();
PropertyValue[] pvArray = mpvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
if (pv.getName().startsWith(fieldDefaultPrefix)) {
String field = pv.getName().substring(fieldDefaultPrefix.length());
if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
mpvs.add(field, pv.getValue());
}
mpvs.removePropertyValue(pv);
}
}
}
}
use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method doTestTony.
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
assertTrue("Contains 3", pvs.getPropertyValues().length == 3);
assertTrue("Contains forname", pvs.contains("forname"));
assertTrue("Contains surname", pvs.contains("surname"));
assertTrue("Contains age", pvs.contains("age"));
assertTrue("Doesn't contain tory", !pvs.contains("tory"));
PropertyValue[] pvArray = pvs.getPropertyValues();
Map<String, String> m = new HashMap<>();
m.put("forname", "Tony");
m.put("surname", "Blair");
m.put("age", "50");
for (PropertyValue pv : pvArray) {
Object val = m.get(pv.getName());
assertTrue("Can't have unexpected value", val != null);
assertTrue("Val i string", val instanceof String);
assertTrue("val matches expected", val.equals(pv.getValue()));
m.remove(pv.getName());
}
assertTrue("Map size is 0", m.size() == 0);
}
use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class ViewResolverTests method testBeanNameViewResolver.
@Test
public void testBeanNameViewResolver() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
MutablePropertyValues pvs1 = new MutablePropertyValues();
pvs1.addPropertyValue(new PropertyValue("url", "/example1.jsp"));
wac.registerSingleton("example1", InternalResourceView.class, pvs1);
MutablePropertyValues pvs2 = new MutablePropertyValues();
pvs2.addPropertyValue(new PropertyValue("url", "/example2.jsp"));
wac.registerSingleton("example2", JstlView.class, pvs2);
BeanNameViewResolver vr = new BeanNameViewResolver();
vr.setApplicationContext(wac);
wac.refresh();
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", InternalResourceView.class, view.getClass());
assertEquals("Correct URL", "/example1.jsp", ((InternalResourceView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "/example2.jsp", ((JstlView) view).getUrl());
}
use of org.springframework.beans.PropertyValue in project grails-core by grails.
the class DefaultRuntimeSpringConfiguration method registerBeanDefinitionsWithRegistry.
private void registerBeanDefinitionsWithRegistry(BeanDefinitionRegistry registry) {
for (Object key : beanDefinitions.keySet()) {
BeanDefinition bd = beanDefinitions.get(key);
if (LOG.isDebugEnabled()) {
LOG.debug("[RuntimeConfiguration] Registering bean [" + key + "]");
if (LOG.isTraceEnabled()) {
PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues();
for (PropertyValue pv : pvs) {
LOG.trace("[RuntimeConfiguration] With property [" + pv.getName() + "] set to [" + pv.getValue() + "]");
}
}
}
final String beanName = key.toString();
registry.registerBeanDefinition(beanName, bd);
}
}
use of org.springframework.beans.PropertyValue in project grails-core by grails.
the class DefaultRuntimeSpringConfiguration method registerBeanConfigsWithRegistry.
private void registerBeanConfigsWithRegistry(BeanDefinitionRegistry registry) {
for (BeanConfiguration bc : beanConfigs.values()) {
String beanName = bc.getName();
if (LOG.isDebugEnabled()) {
LOG.debug("[RuntimeConfiguration] Registering bean [" + beanName + "]");
if (LOG.isTraceEnabled()) {
PropertyValue[] pvs = bc.getBeanDefinition().getPropertyValues().getPropertyValues();
for (PropertyValue pv : pvs) {
LOG.trace("[RuntimeConfiguration] With property [" + pv.getName() + "] set to [" + pv.getValue() + "]");
}
}
}
registry.registerBeanDefinition(beanName, bc.getBeanDefinition());
}
}
Aggregations