use of org.springframework.beans.factory.config.BeanDefinitionVisitor in project com.revolsys.open by revolsys.
the class BeanConfigurrer method processPlaceholderAttributes.
protected void processPlaceholderAttributes(final ConfigurableListableBeanFactory beanFactory, final String beanName, final Map<String, Object> attributes) throws BeansException {
final StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver("${", "}", this.ignoreUnresolvablePlaceholders, null, attributes);
final BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
// locations.
if (!(beanName.equals(this.beanName) && beanFactory.equals(this.applicationContext))) {
final BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
try {
visitor.visitBeanDefinition(bd);
} catch (final BeanDefinitionStoreException ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanName, ex.getMessage());
}
}
// NEW in Spring 2.5: resolve placeholders in alias target names and aliases
// as well.
beanFactory.resolveAliases(valueResolver);
}
use of org.springframework.beans.factory.config.BeanDefinitionVisitor in project com.revolsys.open by revolsys.
the class BeanConfigurrer method processPlaceholderAttributes.
protected void processPlaceholderAttributes(final ConfigurableListableBeanFactory beanFactory, final Map<String, Object> attributes) throws BeansException {
final Map<String, Object> attributeMap = new LinkedHashMap<>();
for (final Entry<String, Object> entry : attributes.entrySet()) {
final String key = entry.getKey();
final Object value = entry.getValue();
if (!(value instanceof BeanReference)) {
attributeMap.put(key, value);
}
}
final StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver("${", "}", this.ignoreUnresolvablePlaceholders, null, attributeMap);
final BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
final String[] beanNames = beanFactory.getBeanDefinitionNames();
for (int i = 0; i < beanNames.length; i++) {
// locations.
if (!(beanNames[i].equals(this.beanName) && beanFactory.equals(this.applicationContext))) {
final BeanDefinition bd = beanFactory.getBeanDefinition(beanNames[i]);
try {
visitor.visitBeanDefinition(bd);
} catch (final BeanDefinitionStoreException ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage());
}
}
}
// NEW in Spring 2.5: resolve placeholders in alias target names and aliases
// as well.
beanFactory.resolveAliases(valueResolver);
}
use of org.springframework.beans.factory.config.BeanDefinitionVisitor in project ff4j by ff4j.
the class FF4jPropertiesPlaceHolderConfigurer method postProcessBeanFactory.
/**
* {@inheritDoc}
*/
public final void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) {
try {
// 1) Retrieve properties from ff4j
BeanDefinitionVisitor visitor = new PropertiesPlaceHolderBeanDefinitionVisitor(ff4j);
// 2) Inject property & features value
String[] beanNames = beanFactory.getBeanDefinitionNames();
for (int i = 0; i < beanNames.length; i++) {
if (beanNames[i].equals(beanName)) {
continue;
}
BeanDefinition bd = beanFactory.getBeanDefinition(beanNames[i]);
try {
visitor.visitBeanDefinition(bd);
} catch (BeanDefinitionStoreException ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage());
}
}
} catch (Exception e) {
LOGGER.error("Cannot handle placeholding through ff4j : ", e);
throw new BeanInitializationException("An error occured during substition", e);
}
}
use of org.springframework.beans.factory.config.BeanDefinitionVisitor in project grails-core by grails.
the class GrailsPlaceholderConfigurer method doProcessProperties.
@Override
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver) {
BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver) {
@Override
protected void visitMap(Map<?, ?> mapVal) {
if (mapVal instanceof Config)
return;
super.visitMap(mapVal);
}
};
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
for (String curName : beanNames) {
// to avoid failing on unresolvable placeholders in properties file locations.
if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName);
try {
visitor.visitBeanDefinition(bd);
} catch (Exception ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage(), ex);
}
}
}
// New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
beanFactoryToProcess.resolveAliases(valueResolver);
// New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);
}
Aggregations