use of org.springframework.beans.factory.support.AbstractBeanDefinition in project qi4j-sdk by Qi4j.
the class Qi4jServiceBeanDefinitionParser method parse.
@Override
public final BeanDefinition parse(Element anElement, ParserContext aParserContext) {
String serviceId = anElement.getAttribute(SERVICE_ID);
// Service factory bean
BeanDefinitionBuilder builder = rootBeanDefinition(ServiceFactoryBean.class);
builder.addConstructorArgReference(BEAN_ID_QI4J_APPLICATION);
builder.addConstructorArgValue(serviceId);
AbstractBeanDefinition definition = builder.getBeanDefinition();
// Register service factory bean
BeanDefinitionRegistry definitionRegistry = aParserContext.getRegistry();
definitionRegistry.registerBeanDefinition(serviceId, definition);
return definition;
}
use of org.springframework.beans.factory.support.AbstractBeanDefinition in project cxf by apache.
the class AbstractFactoryBeanDefinitionParser method doParse.
@Override
protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
Class<?> factoryClass = getFactoryClass();
BeanDefinitionBuilder factoryBean = bean;
if (!FactoryBean.class.isAssignableFrom(factoryClass)) {
factoryBean = BeanDefinitionBuilder.rootBeanDefinition(getFactoryClass());
}
NamedNodeMap atts = element.getAttributes();
boolean createdFromAPI = false;
boolean setBus = false;
for (int i = 0; i < atts.getLength(); i++) {
Attr node = (Attr) atts.item(i);
String val = node.getValue();
String pre = node.getPrefix();
String name = node.getLocalName();
if ("createdFromAPI".equals(name)) {
factoryBean.setAbstract(true);
bean.setAbstract(true);
createdFromAPI = true;
} else if ("abstract".equals(name)) {
factoryBean.setAbstract(true);
bean.setAbstract(true);
} else if ("depends-on".equals(name)) {
factoryBean.addDependsOn(val);
bean.addDependsOn(val);
} else if (!"id".equals(name) && !"name".equals(name) && isAttribute(pre, name)) {
if ("bus".equals(name)) {
setBus = true;
if (!val.startsWith("#")) {
// bus attributes always need to be a reference
val = "#" + val;
}
}
mapAttribute(factoryBean, element, name, val);
}
}
if (!setBus) {
addBusWiringAttribute(factoryBean, BusWiringType.PROPERTY);
}
Node node = element.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String name = node.getLocalName();
mapElement(ctx, factoryBean, (Element) node, name);
}
node = node.getNextSibling();
}
String id = getIdOrName(element);
BeanDefinition container = ctx.getContainingBeanDefinition();
boolean noFactory = false;
if (StringUtils.isEmpty(id)) {
if (container == null) {
id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), ctx.getRegistry(), false);
} else {
id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), ctx.getRegistry(), true);
noFactory = true;
// inner bean, no need for the factory to be public at all
}
}
if (createdFromAPI) {
id = id + getSuffix();
}
if (FactoryBean.class.isAssignableFrom(getFactoryClass())) {
if (!noFactory) {
AbstractBeanDefinition def = factoryBean.getRawBeanDefinition().cloneBeanDefinition();
def.setBeanClass(getRawFactoryClass());
def.setAbstract(factoriesAreAbstract);
def.setLazyInit(true);
ctx.getRegistry().registerBeanDefinition(id + getFactoryIdSuffix(), def);
}
bean.getBeanDefinition().setAttribute("id", id);
} else {
String factoryId = id + getFactoryIdSuffix();
ctx.getRegistry().registerBeanDefinition(factoryId, factoryBean.getBeanDefinition());
bean.getRawBeanDefinition().setAttribute("id", id);
bean.getRawBeanDefinition().setFactoryBeanName(factoryId);
bean.getRawBeanDefinition().setFactoryMethodName("create");
}
if (getDestroyMethod() != null) {
bean.setDestroyMethodName(getDestroyMethod());
}
}
use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterParser method potentiallyCreateMappingContext.
public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext, BeanDefinition conversionsDefinition, String converterId) {
String ctxRef = element.getAttribute("mapping-context-ref");
if (StringUtils.hasText(ctxRef)) {
return ctxRef;
}
BeanComponentDefinitionBuilder componentDefinitionBuilder = new BeanComponentDefinitionBuilder(element, parserContext);
BeanDefinitionBuilder mappingContextBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoMappingContext.class);
Set<String> classesToAdd = getInititalEntityClasses(element);
if (classesToAdd != null) {
mappingContextBuilder.addPropertyValue("initialEntitySet", classesToAdd);
}
if (conversionsDefinition != null) {
AbstractBeanDefinition simpleTypesDefinition = new GenericBeanDefinition();
simpleTypesDefinition.setFactoryBeanName("customConversions");
simpleTypesDefinition.setFactoryMethodName("getSimpleTypeHolder");
mappingContextBuilder.addPropertyValue("simpleTypeHolder", simpleTypesDefinition);
}
parseFieldNamingStrategy(element, parserContext.getReaderContext(), mappingContextBuilder);
ctxRef = converterId == null || DEFAULT_CONVERTER_BEAN_NAME.equals(converterId) ? MAPPING_CONTEXT_BEAN_NAME : converterId + "." + MAPPING_CONTEXT_BEAN_NAME;
parserContext.registerBeanComponent(componentDefinitionBuilder.getComponent(mappingContextBuilder, ctxRef));
return ctxRef;
}
use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-data-mongodb by spring-projects.
the class MongoTemplateParser method parseInternal.
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanComponentDefinitionBuilder helper = new BeanComponentDefinitionBuilder(element, parserContext);
String converterRef = element.getAttribute("converter-ref");
String dbFactoryRef = element.getAttribute("db-factory-ref");
BeanDefinitionBuilder mongoTemplateBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoTemplate.class);
setPropertyValue(mongoTemplateBuilder, element, "write-concern", "writeConcern");
if (StringUtils.hasText(dbFactoryRef)) {
mongoTemplateBuilder.addConstructorArgReference(dbFactoryRef);
} else {
mongoTemplateBuilder.addConstructorArgReference(BeanNames.DB_FACTORY_BEAN_NAME);
}
if (StringUtils.hasText(converterRef)) {
mongoTemplateBuilder.addConstructorArgReference(converterRef);
}
BeanDefinitionBuilder writeConcernPropertyEditorBuilder = getWriteConcernPropertyEditorBuilder();
BeanComponentDefinition component = helper.getComponent(writeConcernPropertyEditorBuilder);
parserContext.registerBeanComponent(component);
return (AbstractBeanDefinition) helper.getComponentIdButFallback(mongoTemplateBuilder, BeanNames.MONGO_TEMPLATE_BEAN_NAME).getBeanDefinition();
}
Aggregations