use of org.springframework.beans.PropertyValue in project ignite by apache.
the class IgniteSpringHelperImpl method prepareSpringContext.
/**
* Prepares Spring context.
*
* @param excludedProps Properties to be excluded.
* @return application context.
*/
private static GenericApplicationContext prepareSpringContext(final String... excludedProps) {
GenericApplicationContext springCtx = new GenericApplicationContext();
if (excludedProps.length > 0) {
final List<String> excludedPropsList = Arrays.asList(excludedProps);
BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() {
/**
* @param def Registered BeanDefinition.
* @throws BeansException in case of errors.
*/
private void processNested(BeanDefinition def) throws BeansException {
Iterator<PropertyValue> iterVals = def.getPropertyValues().getPropertyValueList().iterator();
while (iterVals.hasNext()) {
PropertyValue val = iterVals.next();
if (excludedPropsList.contains(val.getName())) {
iterVals.remove();
continue;
}
if (val.getValue() instanceof Iterable) {
Iterator iterNested = ((Iterable) val.getValue()).iterator();
while (iterNested.hasNext()) {
Object item = iterNested.next();
if (item instanceof BeanDefinitionHolder) {
BeanDefinitionHolder h = (BeanDefinitionHolder) item;
try {
if (h.getBeanDefinition().getBeanClassName() != null)
Class.forName(h.getBeanDefinition().getBeanClassName());
processNested(h.getBeanDefinition());
} catch (ClassNotFoundException ignored) {
iterNested.remove();
}
}
}
}
}
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
for (String beanName : beanFactory.getBeanDefinitionNames()) {
try {
BeanDefinition def = beanFactory.getBeanDefinition(beanName);
if (def.getBeanClassName() != null)
Class.forName(def.getBeanClassName());
processNested(def);
} catch (ClassNotFoundException ignored) {
((BeanDefinitionRegistry) beanFactory).removeBeanDefinition(beanName);
}
}
}
};
springCtx.addBeanFactoryPostProcessor(postProc);
}
return springCtx;
}
Aggregations