Here are the examples of the java api org.springframework.beans.PropertyValue taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
55 Examples
19
View Source File : WebDataBinder.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Check the given property values for field markers,
* i.e. for fields that start with the field marker prefix.
* <p>The existence of a field marker indicates that the specified
* field existed in the form. If the property values do not contain
* a corresponding field value, the field will be considered as empty
* and will be reset appropriately.
* @param mpvs the property values to be bound (can be modified)
* @see #getFieldMarkerPrefix
* @see #getEmptyValue(String, Clreplaced)
*/
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
String fieldMarkerPrefix = getFieldMarkerPrefix();
if (fieldMarkerPrefix != null) {
PropertyValue[] pvArray = mpvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
if (pv.getName().startsWith(fieldMarkerPrefix)) {
String field = pv.getName().substring(fieldMarkerPrefix.length());
if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
Clreplaced<?> fieldType = getPropertyAccessor().getPropertyType(field);
mpvs.add(field, getEmptyValue(field, fieldType));
}
mpvs.removePropertyValue(pv);
}
}
}
}
19
View Source File : WebDataBinder.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* 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);
}
}
}
}
19
View Source File : JdbcNamespaceIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
private void replacedertBeanPropertyValueOf(String propertyName, String expected, DefaultListableBeanFactory factory) {
BeanDefinition bean = factory.getBeanDefinition(expected);
PropertyValue value = bean.getPropertyValues().getPropertyValue(propertyName);
replacedertThat(value, is(notNullValue()));
replacedertThat(value.getValue().toString(), is(expected));
}
19
View Source File : MetadataAttachmentTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void propertyMetadata() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3");
PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("name");
replacedertEquals("Harrop", pv.getAttribute("surname"));
}
19
View Source File : PropertyOverrideConfigurer.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Apply the given property value to the corresponding bean.
*/
protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
BeanDefinition bd = factory.getBeanDefinition(beanName);
BeanDefinition bdToUse = bd;
while (bd != null) {
bdToUse = bd;
bd = bd.getOriginatingBeanDefinition();
}
PropertyValue pv = new PropertyValue(property, value);
pv.setOptional(this.ignoreInvalidKeys);
bdToUse.getPropertyValues().addPropertyValue(pv);
}
19
View Source File : BeanDefinitionVisitor.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
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);
}
}
}
19
View Source File : JdbcNamespaceIntegrationTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
private void replacedertBeanPropertyValueOf(String propertyName, String expected, DefaultListableBeanFactory factory) {
BeanDefinition bean = factory.getBeanDefinition(expected);
PropertyValue value = bean.getPropertyValues().getPropertyValue(propertyName);
replacedertThat(value).isNotNull();
replacedertThat(value.getValue().toString()).isEqualTo(expected);
}
19
View Source File : ConfigurationBeanDefinitionHelper.java
License : MIT License
Project Creator : SabreOSS
License : MIT License
Project Creator : SabreOSS
/**
* Add to the bean definition an indicator which says the definition is a conf4j configuration.
*
* @param beanDefinition bean definition
* @param configurationIndicator configuration indicator
* @throws NullPointerException when {@code beanDefinition} is {@code null}.
*/
public static void addConf4jConfigurationIndicator(BeanDefinition beanDefinition, ConfigurationIndicator configurationIndicator) {
PropertyValue conf4jConfigurationIndicator = new PropertyValue(CONF4J_CONFIGURATION_INDICATOR, configurationIndicator);
conf4jConfigurationIndicator.setOptional(true);
beanDefinition.getPropertyValues().addPropertyValue(conf4jConfigurationIndicator);
}
19
View Source File : WebDataBinder.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Check the given property values for field markers,
* i.e. for fields that start with the field marker prefix.
* <p>The existence of a field marker indicates that the specified
* field existed in the form. If the property values do not contain
* a corresponding field value, the field will be considered as empty
* and will be reset appropriately.
* @param mpvs the property values to be bound (can be modified)
* @see #getFieldMarkerPrefix
* @see #getEmptyValue(String, Clreplaced)
*/
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
if (getFieldMarkerPrefix() != null) {
String fieldMarkerPrefix = getFieldMarkerPrefix();
PropertyValue[] pvArray = mpvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
if (pv.getName().startsWith(fieldMarkerPrefix)) {
String field = pv.getName().substring(fieldMarkerPrefix.length());
if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
Clreplaced<?> fieldType = getPropertyAccessor().getPropertyType(field);
mpvs.add(field, getEmptyValue(field, fieldType));
}
mpvs.removePropertyValue(pv);
}
}
}
}
19
View Source File : WebDataBinder.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* 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);
}
}
}
}
19
View Source File : PropertyOverrideConfigurer.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Apply the given property value to the corresponding bean.
*/
protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
BeanDefinition bd = factory.getBeanDefinition(beanName);
while (bd.getOriginatingBeanDefinition() != null) {
bd = bd.getOriginatingBeanDefinition();
}
PropertyValue pv = new PropertyValue(property, value);
pv.setOptional(this.ignoreInvalidKeys);
bd.getPropertyValues().addPropertyValue(pv);
}
19
View Source File : PropertySourcesPropertyValues.java
License : Apache License 2.0
Project Creator : finleytianhe
License : Apache License 2.0
Project Creator : finleytianhe
private PropertyValue putIfAbsent(String propertyName, Object value, PropertySource<?> source) {
if (value != null && !this.propertyValues.containsKey(propertyName)) {
PropertySource<?> collectionOwner = this.collectionOwners.putIfAbsent(COLLECTION_PROPERTY.matcher(propertyName).replaceAll("[]"), source);
if (collectionOwner == null || collectionOwner == source) {
PropertyValue propertyValue = new OriginCapablePropertyValue(propertyName, value, propertyName, source);
this.propertyValues.put(propertyName, propertyValue);
return propertyValue;
}
}
return null;
}
19
View Source File : PropertySourcesPropertyValues.java
License : Apache License 2.0
Project Creator : finleytianhe
License : Apache License 2.0
Project Creator : finleytianhe
@Override
public PropertyValue getPropertyValue(String propertyName) {
PropertyValue propertyValue = this.propertyValues.get(propertyName);
if (propertyValue != null) {
return propertyValue;
}
for (PropertySource<?> source : this.propertySources) {
Object value = source.getProperty(propertyName);
propertyValue = putIfAbsent(propertyName, value, source);
if (propertyValue != null) {
return propertyValue;
}
}
return null;
}
19
View Source File : OriginCapablePropertyValue.java
License : Apache License 2.0
Project Creator : finleytianhe
License : Apache License 2.0
Project Creator : finleytianhe
public static PropertyOrigin getOrigin(PropertyValue propertyValue) {
if (propertyValue instanceof OriginCapablePropertyValue) {
return ((OriginCapablePropertyValue) propertyValue).getOrigin();
}
return new OriginCapablePropertyValue(propertyValue).getOrigin();
}
19
View Source File : MandatoryImporterDependencyFactory.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
private String[] getInterfaces(PropertyValue pv) {
if (pv == null)
return new String[0];
Object value = pv.getValue();
if (value instanceof Collection) {
Collection collection = (Collection) value;
String[] strs = new String[collection.size()];
int index = 0;
for (Object obj : collection) {
if (value instanceof TypedStringValue) {
strs[index] = ((TypedStringValue) value).getValue();
} else {
strs[index] = value.toString();
}
index++;
}
return strs;
} else {
return new String[] { value.toString() };
}
}
19
View Source File : MandatoryImporterDependencyFactory.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
private String getString(PropertyValue pv) {
if (pv == null)
return "";
Object value = pv.getValue();
if (value == null) {
return "";
}
if (value instanceof TypedStringValue) {
return ((TypedStringValue) value).getValue();
}
return value.toString();
}
19
View Source File : MetadataUtils.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
static Object getValue(PropertyValue pv) {
// return (pv.isConverted() ? pv.getConvertedValue() : pv.getValue());
return pv.getValue();
}
19
View Source File : AbstractAutowireCapableBeanFactory.java
License : Apache License 2.0
Project Creator : DerekYRC
License : Apache License 2.0
Project Creator : DerekYRC
/**
* 为bean填充属性
*
* @param bean
* @param beanDefinition
*/
protected void applyPropertyValues(String beanName, Object bean, BeanDefinition beanDefinition) {
try {
for (PropertyValue propertyValue : beanDefinition.getPropertyValues().getPropertyValues()) {
String name = propertyValue.getName();
Object value = propertyValue.getValue();
if (value instanceof BeanReference) {
// beanA依赖beanB,先实例化beanB
BeanReference beanReference = (BeanReference) value;
value = getBean(beanReference.getBeanName());
} else {
// 类型转换
Clreplaced<?> sourceType = value.getClreplaced();
Clreplaced<?> targetType = (Clreplaced<?>) TypeUtil.getFieldType(bean.getClreplaced(), name);
ConversionService conversionService = getConversionService();
if (conversionService != null) {
if (conversionService.canConvert(sourceType, targetType)) {
value = conversionService.convert(value, targetType);
}
}
}
// 通过反射设置属性
BeanUtil.setFieldValue(bean, name, value);
}
} catch (Exception ex) {
throw new BeansException("Error setting property values for bean: " + beanName, ex);
}
}
19
View Source File : BeanExtenderUnitTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
/**
* Helper method to generate a mocked property value
*/
private PropertyValue generateMockedPropertyValue(String name, String value) {
PropertyValue result = mock(PropertyValue.clreplaced);
doReturn(name).when(result).getName();
doReturn(value).when(result).getValue();
return result;
}
19
View Source File : BeanExtender.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
/**
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
ParameterCheck.mandatory("beanName", beanName);
ParameterCheck.mandatory("extendingBeanName", extendingBeanName);
// check for bean name
if (!beanFactory.containsBean(beanName)) {
throw new NoSuchBeanDefinitionException("Can't find bean '" + beanName + "' to be extended.");
}
// check for extending bean
if (!beanFactory.containsBean(extendingBeanName)) {
throw new NoSuchBeanDefinitionException("Can't find bean '" + extendingBeanName + "' that is going to extend original bean definition.");
}
// get the bean definitions
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
BeanDefinition extendingBeanDefinition = beanFactory.getBeanDefinition(extendingBeanName);
// update clreplaced
if (StringUtils.isNotBlank(extendingBeanDefinition.getBeanClreplacedName()) && !beanDefinition.getBeanClreplacedName().equals(extendingBeanDefinition.getBeanClreplacedName())) {
beanDefinition.setBeanClreplacedName(extendingBeanDefinition.getBeanClreplacedName());
}
// update properties
MutablePropertyValues properties = beanDefinition.getPropertyValues();
MutablePropertyValues extendingProperties = extendingBeanDefinition.getPropertyValues();
for (PropertyValue propertyValue : extendingProperties.getPropertyValueList()) {
properties.add(propertyValue.getName(), propertyValue.getValue());
}
}
18
View Source File : MapperScannerConfigurer.java
License : Apache License 2.0
Project Creator : xuminwlt
License : Apache License 2.0
Project Creator : xuminwlt
private String updatePropertyValue(String propertyName, PropertyValues values) {
PropertyValue property = values.getPropertyValue(propertyName);
if (property == null) {
return null;
}
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;
}
}
18
View Source File : MetadataAttachmentTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void propertyMetadata() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3");
PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("name");
replacedertThat(pv.getAttribute("surname")).isEqualTo("Harrop");
}
18
View Source File : BeanComponentDefinition.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
List<BeanReference> references = new ArrayList<BeanReference>();
PropertyValues propertyValues = beanDefinition.getPropertyValues();
for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
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[innerBeans.size()]);
this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
18
View Source File : PropertySourcesPropertyValues.java
License : Apache License 2.0
Project Creator : finleytianhe
License : Apache License 2.0
Project Creator : finleytianhe
@Override
public PropertyValues changesSince(PropertyValues old) {
MutablePropertyValues changes = new MutablePropertyValues();
// for each property value in the new set
for (PropertyValue newValue : getPropertyValues()) {
// if there wasn't an old one, add it
PropertyValue oldValue = old.getPropertyValue(newValue.getName());
if (oldValue == null || !oldValue.equals(newValue)) {
changes.addPropertyValue(newValue);
}
}
return changes;
}
18
View Source File : MetadataUtils.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
static List<BeanProperty> getBeanProperties(BeanDefinition definition) {
List<BeanProperty> temp;
List<PropertyValue> pvs = definition.getPropertyValues().getPropertyValueList();
if (pvs.isEmpty()) {
return Collections.<BeanProperty>emptyList();
} else {
temp = new ArrayList<BeanProperty>(pvs.size());
}
for (PropertyValue propertyValue : pvs) {
temp.add(new SimpleBeanProperty(propertyValue));
}
return Collections.unmodifiableList(temp);
}
18
View Source File : ComponentMetadataFactory.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
private static void processBeanDefinition(BeanDefinition definition, Collection<ComponentMetadata> to) {
to.add(buildMetadata(null, definition));
// start with constructors
ConstructorArgumentValues cavs = definition.getConstructorArgumentValues();
// generic values
List<ValueHolder> genericValues = cavs.getGenericArgumentValues();
for (ValueHolder valueHolder : genericValues) {
Object value = MetadataUtils.getValue(valueHolder);
if (value instanceof BeanMetadataElement) {
processBeanMetadata((BeanMetadataElement) value, to);
}
}
// indexed ones
Map<Integer, ValueHolder> indexedValues = cavs.getIndexedArgumentValues();
for (ValueHolder valueHolder : indexedValues.values()) {
Object value = MetadataUtils.getValue(valueHolder);
if (value instanceof BeanMetadataElement) {
processBeanMetadata((BeanMetadataElement) value, to);
}
}
// now property values
PropertyValues pvs = definition.getPropertyValues();
for (PropertyValue pv : pvs.getPropertyValues()) {
Object value = MetadataUtils.getValue(pv);
if (value instanceof BeanMetadataElement) {
processBeanMetadata((BeanMetadataElement) value, to);
}
}
}
18
View Source File : AbstractAutowireCapableBeanFactory.java
License : Apache License 2.0
Project Creator : DerekYRC
License : Apache License 2.0
Project Creator : DerekYRC
/**
* 在设置bean属性之前,允许BeanPostProcessor修改属性值
*
* @param beanName
* @param bean
* @param beanDefinition
*/
protected void applyBeanPostProcessorsBeforeApplyingPropertyValues(String beanName, Object bean, BeanDefinition beanDefinition) {
for (BeanPostProcessor beanPostProcessor : getBeanPostProcessors()) {
if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
PropertyValues pvs = ((InstantiationAwareBeanPostProcessor) beanPostProcessor).postProcessPropertyValues(beanDefinition.getPropertyValues(), bean, beanName);
if (pvs != null) {
for (PropertyValue propertyValue : pvs.getPropertyValues()) {
beanDefinition.getPropertyValues().addPropertyValue(propertyValue);
}
}
}
}
}
18
View Source File : BeanExtenderUnitTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
/**
* given that new property values have been set on the extending bean ensure that they
* are correctly set on the original bean.
*/
@Test
public void beanPropertyValuesSet() {
// === given ===
// set the bean names
beanExtender.setBeanName(BEAN_NAME);
beanExtender.setExtendingBeanName(EXTENDING_BEAN_NAME);
// both beans are available in the bean factory
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_NAME);
doReturn(true).when(mockedBeanFactory).containsBean(EXTENDING_BEAN_NAME);
// return the mocked bean definitions
doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_NAME);
doReturn(mockedExtendingBeanDefinition).when(mockedBeanFactory).getBeanDefinition(EXTENDING_BEAN_NAME);
// bean clreplaced names
doReturn("a").when(mockedBeanDefinition).getBeanClreplacedName();
doReturn(null).when(mockedExtendingBeanDefinition).getBeanClreplacedName();
PropertyValue mockedPropertyValueOne = generateMockedPropertyValue("one", "1");
PropertyValue mockedPropertyValueTwo = generateMockedPropertyValue("two", "2");
List<PropertyValue> list = new ArrayList<PropertyValue>(2);
list.add(mockedPropertyValueOne);
list.add(mockedPropertyValueTwo);
doReturn(list).when(mockedPropertyValuesExtendingBean).getPropertyValueList();
// === when ===
beanExtender.postProcessBeanFactory(mockedBeanFactory);
// === then ===
// expect the clreplaced name to be set on the bean
verify(mockedBeanDefinition, never()).setBeanClreplacedName(anyString());
verify(mockedPropertyValuesBean, times(1)).add("one", "1");
verify(mockedPropertyValuesBean, times(1)).add("two", "2");
}
17
View Source File : ServletRequestDataBinderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
replacedertTrue("Contains 3", pvs.getPropertyValues().length == 3);
replacedertTrue("Contains forname", pvs.contains("forname"));
replacedertTrue("Contains surname", pvs.contains("surname"));
replacedertTrue("Contains age", pvs.contains("age"));
replacedertTrue("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());
replacedertTrue("Can't have unexpected value", val != null);
replacedertTrue("Val i string", val instanceof String);
replacedertTrue("val matches expected", val.equals(ps[i].getValue()));
m.remove(ps[i].getName());
}
replacedertTrue("Map size is 0", m.size() == 0);
}
17
View Source File : DataBinder.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Check the given property values against the allowed fields,
* removing values for fields that are not allowed.
* @param mpvs the property values to be bound (can be modified)
* @see #getAllowedFields
* @see #isAllowed(String)
*/
protected void checkAllowedFields(MutablePropertyValues mpvs) {
PropertyValue[] pvs = mpvs.getPropertyValues();
for (PropertyValue pv : pvs) {
String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
if (!isAllowed(field)) {
mpvs.removePropertyValue(pv);
getBindingResult().recordSuppressedField(field);
if (logger.isDebugEnabled()) {
logger.debug("Field [" + field + "] has been removed from PropertyValues " + "and will not be bound, because it has not been found in the list of allowed fields");
}
}
}
}
17
View Source File : ServletRequestDataBinderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
replacedertThat(pvs.getPropertyValues().length == 3).as("Contains 3").isTrue();
replacedertThat(pvs.contains("forname")).as("Contains forname").isTrue();
replacedertThat(pvs.contains("surname")).as("Contains surname").isTrue();
replacedertThat(pvs.contains("age")).as("Contains age").isTrue();
boolean condition1 = !pvs.contains("tory");
replacedertThat(condition1).as("Doesn't contain tory").isTrue();
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());
replacedertThat(val != null).as("Can't have unexpected value").isTrue();
boolean condition = val instanceof String;
replacedertThat(condition).as("Val i string").isTrue();
replacedertThat(val.equals(ps[i].getValue())).as("val matches expected").isTrue();
m.remove(ps[i].getName());
}
replacedertThat(m.size() == 0).as("Map size is 0").isTrue();
}
17
View Source File : ServletRequestDataBinderTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
replacedertTrue("Contains 3", pvs.getPropertyValues().length == 3);
replacedertTrue("Contains forname", pvs.contains("forname"));
replacedertTrue("Contains surname", pvs.contains("surname"));
replacedertTrue("Contains age", pvs.contains("age"));
replacedertTrue("Doesn't contain tory", !pvs.contains("tory"));
PropertyValue[] ps = pvs.getPropertyValues();
Map<String, String> m = new HashMap<String, String>();
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());
replacedertTrue("Can't have unexpected value", val != null);
replacedertTrue("Val i string", val instanceof String);
replacedertTrue("val matches expected", val.equals(ps[i].getValue()));
m.remove(ps[i].getName());
}
replacedertTrue("Map size is 0", m.size() == 0);
}
17
View Source File : SpringValueDefinitionProcessor.java
License : Apache License 2.0
Project Creator : garyxiong123
License : Apache License 2.0
Project Creator : garyxiong123
private void processPropertyValues(BeanDefinitionRegistry beanRegistry) {
if (!PROPERTY_VALUES_PROCESSED_BEAN_FACTORIES.add(beanRegistry)) {
// already initialized
return;
}
if (!beanName2SpringValueDefinitions.containsKey(beanRegistry)) {
beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.<String, SpringValueDefinition>create());
}
Multimap<String, SpringValueDefinition> springValueDefinitions = beanName2SpringValueDefinitions.get(beanRegistry);
String[] beanNames = beanRegistry.getBeanDefinitionNames();
for (String beanName : beanNames) {
BeanDefinition beanDefinition = beanRegistry.getBeanDefinition(beanName);
MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
List<PropertyValue> propertyValues = mutablePropertyValues.getPropertyValueList();
for (PropertyValue propertyValue : propertyValues) {
Object value = propertyValue.getValue();
if (!(value instanceof TypedStringValue)) {
continue;
}
String placeholder = ((TypedStringValue) value).getValue();
Set<String> keys = placeholderHelper.extractPlaceholderKeys(placeholder);
if (keys.isEmpty()) {
continue;
}
for (String key : keys) {
springValueDefinitions.put(beanName, new SpringValueDefinition(key, placeholder, propertyValue.getName()));
}
}
}
}
17
View Source File : ComponentSubElementTest.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
public void testpropertyValueNested() throws Exception {
AbstractBeanDefinition def = (AbstractBeanDefinition) context.getBeanDefinition("propertyValueNested");
replacedertEquals(Socket.clreplaced.getName(), def.getBeanClreplacedName());
PropertyValue nested = def.getPropertyValues().getPropertyValue("sendBufferSize");
replacedertTrue(nested.getValue() instanceof BeanDefinitionHolder);
}
17
View Source File : MetadataUtils.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
static Object getValue(PropertyValues pvs, String name) {
if (pvs.contains(name)) {
PropertyValue pv = pvs.getPropertyValue(name);
// return (pv.isConverted() ? pv.getConvertedValue() : pv.getValue());
return pv.getValue();
}
return null;
}
17
View Source File : PropertyPlaceholderConfigurer.java
License : Apache License 2.0
Project Creator : DerekYRC
License : Apache License 2.0
Project Creator : DerekYRC
private void resolvePropertyValues(BeanDefinition beanDefinition, Properties properties) {
PropertyValues propertyValues = beanDefinition.getPropertyValues();
for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
Object value = propertyValue.getValue();
if (value instanceof String) {
value = resolvePlaceholder((String) value, properties);
propertyValues.addPropertyValue(new PropertyValue(propertyValue.getName(), value));
}
}
}
17
View Source File : LegacyConfigPostProcessor.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
/**
* Given a bean name (replacedumed to implement {@link org.springframework.core.io.support.PropertiesLoaderSupport})
* checks whether it already references the <code>global-properties</code> bean. If not, 'upgrades' the bean by
* appending all additional resources it mentions in its <code>locations</code> property to
* <code>globalPropertyLocations</code>, except for those resources mentioned in <code>newLocations</code>. A
* reference to <code>global-properties</code> will then be added and the resource list in
* <code>newLocations<code> will then become the new <code>locations</code> list for the bean.
*
* @param beanFactory
* the bean factory
* @param globalPropertyLocations
* the list of global property locations to be appended to
* @param beanName
* the bean name
* @param newLocations
* the new locations to be set on the bean
* @return the mutable property values
*/
@SuppressWarnings("unchecked")
private MutablePropertyValues processLocations(ConfigurableListableBeanFactory beanFactory, Collection<Object> globalPropertyLocations, String beanName, String[] newLocations) {
// Get the bean an check its existing properties value
MutablePropertyValues beanProperties = beanFactory.getBeanDefinition(beanName).getPropertyValues();
PropertyValue pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES);
Object value;
// If the properties value already references the global-properties bean, we have nothing else to do. Otherwise,
// we have to 'upgrade' the bean definition.
if (pv == null || (value = pv.getValue()) == null || !(value instanceof BeanReference) || ((BeanReference) value).getBeanName().equals(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES)) {
// Convert the array of new locations to a managed list of type string values, so that it is
// compatible with a bean definition
Collection<Object> newLocationList = new ManagedList(newLocations.length);
if (newLocations != null && newLocations.length > 0) {
for (String preserveLocation : newLocations) {
newLocationList.add(new TypedStringValue(preserveLocation));
}
}
// If there is currently a locations list, process it
pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
if (pv != null && (value = pv.getValue()) != null && value instanceof Collection) {
Collection<Object> locations = (Collection<Object>) value;
// Compute the set of locations that need to be added to globalPropertyLocations (preserving order) and
// warn about each
Set<Object> addedLocations = new LinkedHashSet<Object>(locations);
addedLocations.removeAll(globalPropertyLocations);
addedLocations.removeAll(newLocationList);
for (Object location : addedLocations) {
LegacyConfigPostProcessor.logger.warn("Legacy configuration detected: adding " + (location instanceof TypedStringValue ? ((TypedStringValue) location).getValue() : location.toString()) + " to global-properties definition");
globalPropertyLocations.add(location);
}
}
// Ensure the bean now references global-properties
beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES, new RuntimeBeanReference(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES));
// Ensure the new location list is now set on the bean
if (newLocationList.size() > 0) {
beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS, newLocationList);
} else {
beanProperties.removePropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
}
}
return beanProperties;
}
16
View Source File : ComponentSubElementTest.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
public void testPropertyInline() throws Exception {
AbstractBeanDefinition def = (AbstractBeanDefinition) context.getBeanDefinition("propertyValueInline");
replacedertEquals(Socket.clreplaced.getName(), def.getBeanClreplacedName());
MutablePropertyValues propertyValues = def.getPropertyValues();
PropertyValue propertyValue = propertyValues.getPropertyValue("keepAlive");
replacedertNotNull(propertyValue);
replacedertTrue(propertyValue.getValue() instanceof BeanMetadataElement);
}
15
View Source File : DataBinder.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Check the given property values against the required fields,
* generating missing field errors where appropriate.
* @param mpvs the property values to be bound (can be modified)
* @see #getRequiredFields
* @see #getBindingErrorProcessor
* @see BindingErrorProcessor#processMissingFieldError
*/
protected void checkRequiredFields(MutablePropertyValues mpvs) {
String[] requiredFields = getRequiredFields();
if (!ObjectUtils.isEmpty(requiredFields)) {
Map<String, PropertyValue> propertyValues = new HashMap<>();
PropertyValue[] pvs = mpvs.getPropertyValues();
for (PropertyValue pv : pvs) {
String canonicalName = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
propertyValues.put(canonicalName, pv);
}
for (String field : requiredFields) {
PropertyValue pv = propertyValues.get(field);
boolean empty = (pv == null || pv.getValue() == null);
if (!empty) {
if (pv.getValue() instanceof String) {
empty = !StringUtils.hasText((String) pv.getValue());
} else if (pv.getValue() instanceof String[]) {
String[] values = (String[]) pv.getValue();
empty = (values.length == 0 || !StringUtils.hasText(values[0]));
}
}
if (empty) {
// Use bind error processor to create FieldError.
getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult());
// Remove property from property values to bind:
// It has already caused a field error with a rejected value.
if (pv != null) {
mpvs.removePropertyValue(pv);
propertyValues.remove(field);
}
}
}
}
}
15
View Source File : MapperScannerConfigurerBeanDefinitionRegistryPostProcessor.java
License : Apache License 2.0
Project Creator : smart-cloud
License : Apache License 2.0
Project Creator : smart-cloud
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
// 处理Mapper interface与启动类不在同一包名下时无法注入IOC容器的问题
String mapperScannerConfigurerBeanName = MapperScannerConfigurer.clreplaced.getName();
if (!registry.containsBeanDefinition(mapperScannerConfigurerBeanName)) {
return;
}
BeanDefinition beanDefinition = registry.getBeanDefinition(mapperScannerConfigurerBeanName);
MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
PropertyValue existedPropertyValue = mutablePropertyValues.getPropertyValue(mapperPropertyName);
Set<String> packages = new HashSet<>(2);
packages.add(String.valueOf(existedPropertyValue.getValue()));
String[] componentScans = PackageConfig.getBasePackages();
for (String componentScan : componentScans) {
packages.add(componentScan);
}
// 将componentScan指定的包名也加入到mapper的扫描范围
beanDefinition.getPropertyValues().add(mapperPropertyName, StringUtils.collectionToCommaDelimitedString(packages));
}
15
View Source File : SnakeToCamelRequestDataBinder.java
License : MIT License
Project Creator : lynnlovemin
License : MIT License
Project Creator : lynnlovemin
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
super.addBindValues(mpvs, request);
// 处理JsonProperty注释的对象
Clreplaced<?> targetClreplaced = getTarget().getClreplaced();
Field[] fields = targetClreplaced.getDeclaredFields();
for (Field field : fields) {
JsonProperty jsonPropertyAnnotation = field.getAnnotation(JsonProperty.clreplaced);
if (jsonPropertyAnnotation != null && mpvs.contains(jsonPropertyAnnotation.value())) {
if (!mpvs.contains(field.getName())) {
mpvs.add(field.getName(), mpvs.getPropertyValue(jsonPropertyAnnotation.value()).getValue());
}
}
}
List<PropertyValue> covertValues = new ArrayList<PropertyValue>();
for (PropertyValue propertyValue : mpvs.getPropertyValueList()) {
if (propertyValue.getName().contains("_")) {
String camelName = SnakeToCamelRequestParameterUtil.convertSnakeToCamel(propertyValue.getName());
if (!mpvs.contains(camelName)) {
covertValues.add(new PropertyValue(camelName, propertyValue.getValue()));
}
}
}
mpvs.getPropertyValueList().addAll(covertValues);
}
15
View Source File : DataBinder.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Check the given property values against the required fields,
* generating missing field errors where appropriate.
* @param mpvs the property values to be bound (can be modified)
* @see #getRequiredFields
* @see #getBindingErrorProcessor
* @see BindingErrorProcessor#processMissingFieldError
*/
protected void checkRequiredFields(MutablePropertyValues mpvs) {
String[] requiredFields = getRequiredFields();
if (!ObjectUtils.isEmpty(requiredFields)) {
Map<String, PropertyValue> propertyValues = new HashMap<String, PropertyValue>();
PropertyValue[] pvs = mpvs.getPropertyValues();
for (PropertyValue pv : pvs) {
String canonicalName = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
propertyValues.put(canonicalName, pv);
}
for (String field : requiredFields) {
PropertyValue pv = propertyValues.get(field);
boolean empty = (pv == null || pv.getValue() == null);
if (!empty) {
if (pv.getValue() instanceof String) {
empty = !StringUtils.hasText((String) pv.getValue());
} else if (pv.getValue() instanceof String[]) {
String[] values = (String[]) pv.getValue();
empty = (values.length == 0 || !StringUtils.hasText(values[0]));
}
}
if (empty) {
// Use bind error processor to create FieldError.
getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult());
// Remove property from property values to bind:
// It has already caused a field error with a rejected value.
if (pv != null) {
mpvs.removePropertyValue(pv);
propertyValues.remove(field);
}
}
}
}
}
15
View Source File : LegacyConfigPostProcessor.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco
/*
* (non-Javadoc)
* @see
* org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.
* beans.factory.config.ConfigurableListableBeanFactory)
*/
@SuppressWarnings("unchecked")
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
try {
// Look up the global-properties bean and its locations list
MutablePropertyValues globalProperties = beanFactory.getBeanDefinition(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES).getPropertyValues();
PropertyValue pv = globalProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
Collection<Object> globalPropertyLocations;
Object value;
// Use the locations list if there is one, otherwise replacedociate a new empty list
if (pv != null && (value = pv.getValue()) != null && value instanceof Collection) {
globalPropertyLocations = (Collection<Object>) value;
} else {
globalPropertyLocations = new ManagedList(10);
globalProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS, globalPropertyLocations);
}
// Move location paths added to repository-properties
MutablePropertyValues repositoryProperties = processLocations(beanFactory, globalPropertyLocations, LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES, new String[] { "clreplacedpath:alfresco/version.properties" });
// Fix up additional properties to enforce correct order of precedence
repositoryProperties.addPropertyValue("ignoreUnresolvablePlaceholders", Boolean.TRUE);
repositoryProperties.addPropertyValue("localOverride", Boolean.FALSE);
repositoryProperties.addPropertyValue("valueSeparator", null);
repositoryProperties.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_NEVER");
// Move location paths added to hibernateConfigProperties
MutablePropertyValues hibernateProperties = processLocations(beanFactory, globalPropertyLocations, LegacyConfigPostProcessor.BEAN_NAME_HIBERNATE_PROPERTIES, new String[] { "clreplacedpath:alfresco/domain/hibernate-cfg.properties", "clreplacedpath*:alfresco/enterprise/cache/hibernate-cfg.properties" });
// Fix up additional properties to enforce correct order of precedence
hibernateProperties.addPropertyValue("localOverride", Boolean.TRUE);
// Because Spring gets all post processors in one shot, the bean may already have been created. Let's try to
// fix it up!
PropertyPlaceholderConfigurer repositoryConfigurer = (PropertyPlaceholderConfigurer) beanFactory.getSingleton(LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES);
if (repositoryConfigurer != null) {
// Reset locations list
repositoryConfigurer.setLocations(null);
// Invalidate cached merged bean definitions
((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES, beanFactory.getBeanDefinition(LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES));
// Reconfigure the bean according to its new definition
beanFactory.configureBean(repositoryConfigurer, LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES);
}
} catch (NoSuchBeanDefinitionException e) {
// Ignore and continue
}
}
14
View Source File : WebRequestDataBinderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
replacedertTrue("Contains 3", pvs.getPropertyValues().length == 3);
replacedertTrue("Contains forname", pvs.contains("forname"));
replacedertTrue("Contains surname", pvs.contains("surname"));
replacedertTrue("Contains age", pvs.contains("age"));
replacedertTrue("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());
replacedertTrue("Can't have unexpected value", val != null);
replacedertTrue("Val i string", val instanceof String);
replacedertTrue("val matches expected", val.equals(pv.getValue()));
m.remove(pv.getName());
}
replacedertTrue("Map size is 0", m.size() == 0);
}
14
View Source File : WebRequestDataBinderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
replacedertThat(pvs.getPropertyValues().length == 3).as("Contains 3").isTrue();
replacedertThat(pvs.contains("forname")).as("Contains forname").isTrue();
replacedertThat(pvs.contains("surname")).as("Contains surname").isTrue();
replacedertThat(pvs.contains("age")).as("Contains age").isTrue();
boolean condition1 = !pvs.contains("tory");
replacedertThat(condition1).as("Doesn't contain tory").isTrue();
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());
replacedertThat(val != null).as("Can't have unexpected value").isTrue();
boolean condition = val instanceof String;
replacedertThat(condition).as("Val i string").isTrue();
replacedertThat(val.equals(pv.getValue())).as("val matches expected").isTrue();
m.remove(pv.getName());
}
replacedertThat(m.size() == 0).as("Map size is 0").isTrue();
}
14
View Source File : WebRequestDataBinderTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
replacedertTrue("Contains 3", pvs.getPropertyValues().length == 3);
replacedertTrue("Contains forname", pvs.contains("forname"));
replacedertTrue("Contains surname", pvs.contains("surname"));
replacedertTrue("Contains age", pvs.contains("age"));
replacedertTrue("Doesn't contain tory", !pvs.contains("tory"));
PropertyValue[] pvArray = pvs.getPropertyValues();
Map<String, String> m = new HashMap<String, String>();
m.put("forname", "Tony");
m.put("surname", "Blair");
m.put("age", "50");
for (PropertyValue pv : pvArray) {
Object val = m.get(pv.getName());
replacedertTrue("Can't have unexpected value", val != null);
replacedertTrue("Val i string", val instanceof String);
replacedertTrue("val matches expected", val.equals(pv.getValue()));
m.remove(pv.getName());
}
replacedertTrue("Map size is 0", m.size() == 0);
}
13
View Source File : BlueprintParser.java
License : Apache License 2.0
Project Creator : eclipse
License : Apache License 2.0
Project Creator : eclipse
private void parsePropertyElement(Element ele, BeanDefinition bd) {
String propertyName = ele.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
if (!StringUtils.hasLength(propertyName)) {
error("Tag 'property' must have a 'name' attribute", ele);
return;
}
this.parseState.push(new PropertyEntry(propertyName));
try {
if (bd.getPropertyValues().contains(propertyName)) {
error("Multiple 'property' definitions for property '" + propertyName + "'", ele);
return;
}
Object val = parsePropertyValue(ele, bd, propertyName);
PropertyValue pv = new PropertyValue(propertyName, val);
pv.setSource(parserContext.extractSource(ele));
bd.getPropertyValues().addPropertyValue(pv);
} finally {
this.parseState.pop();
}
}
12
View Source File : AbstractListenerContainerParser.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext, MutablePropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {
RootBeanDefinition listenerDef = new RootBeanDefinition();
listenerDef.setSource(parserContext.extractSource(listenerEle));
listenerDef.setBeanClreplacedName("org.springframework.jms.listener.adapter.MessageListenerAdapter");
String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
if (!StringUtils.hasText(ref)) {
parserContext.getReaderContext().error("Listener 'ref' attribute contains empty value.", listenerEle);
} else {
listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
}
if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
String method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
if (!StringUtils.hasText(method)) {
parserContext.getReaderContext().error("Listener 'method' attribute contains empty value.", listenerEle);
}
listenerDef.getPropertyValues().add("defaultListenerMethod", method);
}
PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
if (messageConverterPv != null) {
listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
}
BeanDefinition containerDef = createContainer(containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
containerDef.getPropertyValues().add("messageListener", listenerDef);
if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
Boolean pubSubDomain = (Boolean) commonContainerProperties.get("replyPubSubDomain");
if (pubSubDomain == null) {
pubSubDomain = false;
}
listenerDef.getPropertyValues().add(pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
PropertyValue destinationResolver = containerDef.getPropertyValues().getPropertyValue("destinationResolver");
if (destinationResolver != null) {
listenerDef.getPropertyValues().addPropertyValue(destinationResolver);
}
}
String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
// If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
if (!StringUtils.hasText(containerBeanName)) {
containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
}
// Register the listener and fire event
parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
12
View Source File : AbstractListenerContainerParser.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {
RootBeanDefinition listenerDef = new RootBeanDefinition();
listenerDef.setSource(parserContext.extractSource(listenerEle));
listenerDef.setBeanClreplacedName("org.springframework.jms.listener.adapter.MessageListenerAdapter");
String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
if (!StringUtils.hasText(ref)) {
parserContext.getReaderContext().error("Listener 'ref' attribute contains empty value.", listenerEle);
} else {
listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
}
String method = null;
if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
if (!StringUtils.hasText(method)) {
parserContext.getReaderContext().error("Listener 'method' attribute contains empty value.", listenerEle);
}
}
listenerDef.getPropertyValues().add("defaultListenerMethod", method);
PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
if (messageConverterPv != null) {
listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
}
BeanDefinition containerDef = createContainer(containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
containerDef.getPropertyValues().add("messageListener", listenerDef);
if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
Boolean pubSubDomain = (Boolean) commonContainerProperties.getPropertyValue("replyPubSubDomain").getValue();
listenerDef.getPropertyValues().add(pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
if (containerDef.getPropertyValues().contains("destinationResolver")) {
listenerDef.getPropertyValues().add("destinationResolver", containerDef.getPropertyValues().getPropertyValue("destinationResolver").getValue());
}
}
String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
// If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
if (!StringUtils.hasText(containerBeanName)) {
containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
}
// Register the listener and fire event
parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
10
View Source File : ScriptFactoryPostProcessor.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Create a config interface for the given bean definition, defining setter
* methods for the defined property values as well as an init method and
* a destroy method (if defined).
* <p>This implementation creates the interface via CGLIB's InterfaceMaker,
* determining the property types from the given interfaces (as far as possible).
* @param bd the bean definition (property values etc) to create a
* config interface for
* @param interfaces the interfaces to check against (might define
* getters corresponding to the setters we're supposed to generate)
* @return the config interface
* @see org.springframework.cglib.proxy.InterfaceMaker
* @see org.springframework.beans.BeanUtils#findPropertyType
*/
protected Clreplaced<?> createConfigInterface(BeanDefinition bd, @Nullable Clreplaced<?>[] interfaces) {
InterfaceMaker maker = new InterfaceMaker();
PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues();
for (PropertyValue pv : pvs) {
String propertyName = pv.getName();
Clreplaced<?> propertyType = BeanUtils.findPropertyType(propertyName, interfaces);
String setterName = "set" + StringUtils.capitalize(propertyName);
Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] { Type.getType(propertyType) });
maker.add(signature, new Type[0]);
}
if (bd.getInitMethodName() != null) {
Signature signature = new Signature(bd.getInitMethodName(), Type.VOID_TYPE, new Type[0]);
maker.add(signature, new Type[0]);
}
if (StringUtils.hasText(bd.getDestroyMethodName())) {
Signature signature = new Signature(bd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]);
maker.add(signature, new Type[0]);
}
return maker.create();
}
See More Examples