use of org.springframework.beans.factory.config.BeanDefinitionHolder in project dubbo by alibaba.
the class DubboBeanDefinitionParser method parseArguments.
@SuppressWarnings("unchecked")
private static void parseArguments(String id, NodeList nodeList, RootBeanDefinition beanDefinition, ParserContext parserContext) {
if (nodeList == null) {
return;
}
ManagedList arguments = null;
for (int i = 0; i < nodeList.getLength(); i++) {
if (!(nodeList.item(i) instanceof Element)) {
continue;
}
Element element = (Element) nodeList.item(i);
if ("argument".equals(element.getNodeName()) || "argument".equals(element.getLocalName())) {
String argumentIndex = resolveAttribute(element, "index", parserContext);
if (arguments == null) {
arguments = new ManagedList();
}
BeanDefinition argumentBeanDefinition = parse(element, parserContext, ArgumentConfig.class, false);
String name = id + "." + argumentIndex;
BeanDefinitionHolder argumentBeanDefinitionHolder = new BeanDefinitionHolder(argumentBeanDefinition, name);
arguments.add(argumentBeanDefinitionHolder);
}
}
if (arguments != null) {
beanDefinition.getPropertyValues().addPropertyValue("arguments", arguments);
}
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder 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;
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project leopard by tanhaichao.
the class OptionScanner method doScan.
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
for (BeanDefinitionHolder holder : beanDefinitions) {
GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
String id = getValue(definition);
if (StringUtils.isEmpty(id)) {
id = holder.getBeanName();
}
String className = holder.getBeanDefinition().getBeanClassName();
// logger.info("holder:" + holder.getBeanName() + " className:" + className);
OptionData.load(id, className);
definition.getPropertyValues().add("innerClassName", definition.getBeanClassName());
definition.setBeanClass(OptionFactoryBean.class);
}
return beanDefinitions;
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project leopard by tanhaichao.
the class RegisterComponentUtil method registerComponent.
public static BeanDefinition registerComponent(ParserContext parserContext, BeanDefinitionBuilder builder, String id) {
BeanDefinition definition = builder.getBeanDefinition();
if (!parserContext.isNested()) {
String[] aliases = new String[0];
BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
parserContext.registerComponent(componentDefinition);
}
return definition;
}
Aggregations