本文整理了Java中org.springframework.beans.PropertyValue.getValue()
方法的一些代码示例,展示了PropertyValue.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PropertyValue.getValue()
方法的具体详情如下:
包路径:org.springframework.beans.PropertyValue
类名称:PropertyValue
方法名:getValue
[英]Return the value of the property.
Note that type conversion will not have occurred here. It is the responsibility of the BeanWrapper implementation to perform type conversion.
[中]返回属性的值。
请注意,这里不会发生类型转换。BeanRapper实现负责执行类型转换。
代码示例来源:origin: spring-projects/spring-framework
/**
* Get the raw property value, if any.
* @param propertyName the name to search for
* @return the raw property value, or {@code null} if none found
* @since 4.0
* @see #getPropertyValue(String)
* @see PropertyValue#getValue()
*/
@Nullable
public Object get(String propertyName) {
PropertyValue pv = getPropertyValue(propertyName);
return (pv != null ? pv.getValue() : null);
}
代码示例来源:origin: spring-projects/spring-framework
protected void visitPropertyValues(MutablePropertyValues pvs) {
PropertyValue[] pvArray = pvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
Object newVal = resolveValue(pv.getValue());
if (!ObjectUtils.nullSafeEquals(newVal, pv.getValue())) {
pvs.add(pv.getName(), newVal);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void setPropertyValue(PropertyValue pv) throws BeansException {
setPropertyValue(pv.getName(), pv.getValue());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new BeanComponentDefinition for the given bean.
* @param beanDefinitionHolder the BeanDefinitionHolder encapsulating
* the bean definition as well as the name of the bean
*/
public BeanComponentDefinition(BeanDefinitionHolder beanDefinitionHolder) {
super(beanDefinitionHolder);
List<BeanDefinition> innerBeans = new ArrayList<>();
List<BeanReference> references = new ArrayList<>();
PropertyValues propertyValues = beanDefinitionHolder.getBeanDefinition().getPropertyValues();
for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
Object value = propertyValue.getValue();
if (value instanceof BeanDefinitionHolder) {
innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
}
else if (value instanceof BeanDefinition) {
innerBeans.add((BeanDefinition) value);
}
else if (value instanceof BeanReference) {
references.add((BeanReference) value);
}
}
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]);
this.beanReferences = references.toArray(new BeanReference[0]);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Merges the value of the supplied 'new' {@link PropertyValue} with that of
* the current {@link PropertyValue} if merging is supported and enabled.
* @see Mergeable
*/
private PropertyValue mergeIfRequired(PropertyValue newPv, PropertyValue currentPv) {
Object value = newPv.getValue();
if (value instanceof Mergeable) {
Mergeable mergeable = (Mergeable) value;
if (mergeable.isMergeEnabled()) {
Object merged = mergeable.merge(currentPv.getValue());
return new PropertyValue(newPv.getName(), merged);
}
}
return newPv;
}
代码示例来源:origin: jenkinsci/jenkins
public Object getPropertyValue(String name) {
return getBeanDefinition()
.getPropertyValues()
.getPropertyValue(name)
.getValue();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Copy constructor.
* @param original the PropertyValue to copy (never {@code null})
*/
public PropertyValue(PropertyValue original) {
Assert.notNull(original, "Original must not be null");
this.name = original.getName();
this.value = original.getValue();
this.optional = original.isOptional();
this.converted = original.converted;
this.convertedValue = original.convertedValue;
this.conversionNecessary = original.conversionNecessary;
this.resolvedTokens = original.resolvedTokens;
setSource(original.getSource());
copyAttributesFrom(original);
}
代码示例来源:origin: spring-projects/spring-framework
private void assertPropertyValue(BeanDefinition beanDefinition, String propertyName, Object expectedValue) {
assertEquals("Property '" + propertyName + "' incorrect",
expectedValue, beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue());
}
代码示例来源:origin: spring-projects/spring-framework
private void assertBeanPropertyValueOf(String propertyName, String expected, DefaultListableBeanFactory factory) {
BeanDefinition bean = factory.getBeanDefinition(expected);
PropertyValue value = bean.getPropertyValues().getPropertyValue(propertyName);
assertThat(value, is(notNullValue()));
assertThat(value.getValue().toString(), is(expected));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* 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) {
String fieldDefaultPrefix = getFieldDefaultPrefix();
if (fieldDefaultPrefix != null) {
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);
}
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void streamContainsPropertyValue() {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("foo", "bar");
assertThat(pvs.stream(), notNullValue());
assertThat(pvs.stream().count(), is(1L));
assertThat(pvs.stream().anyMatch(pv -> "foo".equals(pv.getName()) && "bar".equals(pv.getValue())), is(true));
assertThat(pvs.stream().anyMatch(pv -> "bar".equals(pv.getName()) && "foo".equals(pv.getValue())), is(false));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testMultipleValuesForParameter() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
String[] original = new String[] {"Tony", "Rod"};
request.addParameter("forname", original);
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
assertTrue("Found 1 parameter", pvs.getPropertyValues().length == 1);
assertTrue("Found array value", pvs.getPropertyValue("forname").getValue() instanceof String[]);
String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
assertEquals("Correct values", Arrays.asList(values), Arrays.asList(original));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testMultipleValuesForParameter() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
String[] original = new String[] {"Tony", "Rod"};
request.addParameter("forname", original);
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
assertTrue("Found 1 parameter", pvs.getPropertyValues().length == 1);
assertTrue("Found array value", pvs.getPropertyValue("forname").getValue() instanceof String[]);
String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
assertEquals("Correct values", Arrays.asList(values), Arrays.asList(original));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void iteratorContainsPropertyValue() {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("foo", "bar");
Iterator<PropertyValue> it = pvs.iterator();
assertTrue(it.hasNext());
PropertyValue pv = it.next();
assertEquals("foo", pv.getName());
assertEquals("bar", pv.getValue());
try {
it.remove();
fail("Should have thrown UnsupportedOperationException");
}
catch (UnsupportedOperationException ex) {
// expected
}
assertFalse(it.hasNext());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* 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[] ps = pvs.getPropertyValues();
Map<String, String> m = new HashMap<>();
m.put("forname", "Tony");
m.put("surname", "Blair");
m.put("age", "50");
for (int i = 0; i < ps.length; i++) {
Object val = m.get(ps[i].getName());
assertTrue("Can't have unexpected value", val != null);
assertTrue("Val i string", val instanceof String);
assertTrue("val matches expected", val.equals(ps[i].getValue()));
m.remove(ps[i].getName());
}
assertTrue("Map size is 0", m.size() == 0);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* 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);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) {
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[] ps = pvs.getPropertyValues();
Map<String, String> m = new HashMap<>();
m.put("forname", "Tony");
m.put("surname", "Blair");
m.put("age", "50");
for (int i = 0; i < ps.length; i++) {
Object val = m.get(ps[i].getName());
assertTrue("Can't have unexpected value", val != null);
assertTrue("Val i string", val instanceof String);
assertTrue("val matches expected", val.equals(ps[i].getValue()));
m.remove(ps[i].getName());
}
assertTrue("Map size is 0", m.size() == 0);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testValid() {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("forname", "Tony"));
pvs.addPropertyValue(new PropertyValue("surname", "Blair"));
pvs.addPropertyValue(new PropertyValue("age", "50"));
doTestTony(pvs);
MutablePropertyValues deepCopy = new MutablePropertyValues(pvs);
doTestTony(deepCopy);
deepCopy.setPropertyValueAt(new PropertyValue("name", "Gordon"), 0);
doTestTony(pvs);
assertEquals("Gordon", deepCopy.getPropertyValue("name").getValue());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetAnonymousInnerBeanFromScope() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("outerBean");
assertFalse(AopUtils.isAopProxy(bean));
assertTrue(AopUtils.isCglibProxy(bean.getSpouse()));
BeanDefinition beanDef = this.beanFactory.getBeanDefinition("outerBean");
BeanDefinitionHolder innerBeanDef =
(BeanDefinitionHolder) beanDef.getPropertyValues().getPropertyValue("spouse").getValue();
String name = innerBeanDef.getBeanName();
MockHttpServletRequest request = new MockHttpServletRequest();
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
try {
assertNull(request.getAttribute("scopedTarget." + name));
assertEquals("scoped", bean.getSpouse().getName());
assertNotNull(request.getAttribute("scopedTarget." + name));
assertEquals(TestBean.class, request.getAttribute("scopedTarget." + name).getClass());
assertEquals("scoped", ((TestBean) request.getAttribute("scopedTarget." + name)).getName());
}
finally {
RequestContextHolder.setRequestAttributes(null);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void beanEventReceived() throws Exception {
ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
assertEquals(1, componentDefinition1.getBeanDefinitions().length);
BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0];
assertEquals(new TypedStringValue("Rob Harrop"),
beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
assertEquals(1, componentDefinition1.getBeanReferences().length);
assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName());
assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length);
BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0];
assertEquals(new TypedStringValue("ACME"),
innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
assertTrue(componentDefinition1.getSource() instanceof Element);
ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2");
assertTrue(componentDefinition2 instanceof BeanComponentDefinition);
assertEquals(1, componentDefinition1.getBeanDefinitions().length);
BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0];
assertEquals(new TypedStringValue("Juergen Hoeller"),
beanDefinition2.getPropertyValues().getPropertyValue("name").getValue());
assertEquals(0, componentDefinition2.getBeanReferences().length);
assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length);
BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0];
assertEquals(new TypedStringValue("Eva Schallmeiner"),
innerBd2.getPropertyValues().getPropertyValue("name").getValue());
assertTrue(componentDefinition2.getSource() instanceof Element);
}
内容来源于网络,如有侵权,请联系作者删除!