use of org.springframework.beans.factory.config.BeanDefinitionHolder in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScanner method doScan.
/**
* Perform a scan within the specified base packages,
* returning the registered bean definitions.
* <p>This method does <i>not</i> register an annotation config processor
* but rather leaves this up to the caller.
* @param basePackages the packages to check for annotated classes
* @return set of beans registered if any for tooling registration purposes (never {@code null})
*/
protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
Assert.notEmpty(basePackages, "At least one base package must be specified");
Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<>();
for (String basePackage : basePackages) {
Set<BeanDefinition> candidates = findCandidateComponents(basePackage);
for (BeanDefinition candidate : candidates) {
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);
candidate.setScope(scopeMetadata.getScopeName());
String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);
if (candidate instanceof AbstractBeanDefinition) {
postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);
}
if (candidate instanceof AnnotatedBeanDefinition) {
AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);
}
if (checkCandidate(beanName, candidate)) {
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);
definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
beanDefinitions.add(definitionHolder);
registerBeanDefinition(definitionHolder, this.registry);
}
}
}
return beanDefinitions;
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project spring-framework by spring-projects.
the class ComponentScanBeanDefinitionParser method registerComponents.
protected void registerComponents(XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {
Object source = readerContext.extractSource(element);
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
}
// Register annotation config processors, if necessary.
boolean annotationConfig = true;
if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
annotationConfig = Boolean.parseBoolean(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
}
if (annotationConfig) {
Set<BeanDefinitionHolder> processorDefinitions = AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
}
}
readerContext.fireComponentRegistered(compositeDef);
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project spring-framework by spring-projects.
the class AnnotationConfigBeanDefinitionParser method parse.
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Obtain bean definitions for all relevant BeanPostProcessors.
Set<BeanDefinitionHolder> processorDefinitions = AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);
// Register component for the surrounding <context:annotation-config> element.
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
parserContext.pushContainingComponent(compDefinition);
// Nest the concrete beans in the surrounding component.
for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
}
// Finally register the composite component.
parserContext.popAndRegisterContainingComponent();
return null;
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterParser method parseConverter.
@Nullable
public BeanMetadataElement parseConverter(Element element, ParserContext parserContext) {
String converterRef = element.getAttribute("ref");
if (StringUtils.hasText(converterRef)) {
return new RuntimeBeanReference(converterRef);
}
Element beanElement = DomUtils.getChildElementByTagName(element, "bean");
if (beanElement != null) {
BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(beanElement);
beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(beanElement, beanDef);
return beanDef;
}
parserContext.getReaderContext().error("Element <converter> must specify 'ref' or contain a bean definition for the converter", element);
return null;
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project geronimo-xbean by apache.
the class XBeanNamespaceHandler method parseCustomMapElement.
protected Object parseCustomMapElement(MappingMetaData metadata, Element element, String name) {
Map map = new ManagedMap();
Element parent = (Element) element.getParentNode();
String entryName = metadata.getMapEntryName(getLocalName(parent), name);
String keyName = metadata.getMapKeyName(getLocalName(parent), name);
String dups = metadata.getMapDupsMode(getLocalName(parent), name);
boolean flat = metadata.isFlatMap(getLocalName(parent), name);
String defaultKey = metadata.getMapDefaultKey(getLocalName(parent), name);
if (entryName == null)
entryName = "property";
if (keyName == null)
keyName = "key";
if (dups == null)
dups = "replace";
// TODO : support further customizations
// String valueName = "value";
// boolean keyIsAttr = true;
// boolean valueIsAttr = false;
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element childElement = (Element) node;
String localName = childElement.getLocalName();
String uri = childElement.getNamespaceURI();
if (localName == null || localName.equals("xmlns") || localName.startsWith("xmlns:")) {
continue;
}
// attributes from namespace-specific attributes
if (!flat && !isEmpty(uri) && localName.equals(entryName)) {
String key = childElement.getAttribute(keyName);
if (key == null || key.length() == 0) {
key = defaultKey;
}
if (key == null) {
throw new RuntimeException("No key defined for map " + entryName);
}
Object keyValue = getValue(key, null);
Element valueElement = getFirstChildElement(childElement);
Object value;
if (valueElement != null) {
String valueElUri = valueElement.getNamespaceURI();
String valueElLocalName = valueElement.getLocalName();
if (valueElUri == null || valueElUri.equals(SPRING_SCHEMA) || valueElUri.equals(SPRING_SCHEMA_COMPAT) || valueElUri.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
if (BeanDefinitionParserDelegate.BEAN_ELEMENT.equals(valueElLocalName)) {
value = parserContext.getDelegate().parseBeanDefinitionElement(valueElement, null);
} else {
value = parserContext.getDelegate().parsePropertySubElement(valueElement, null);
}
} else {
value = parserContext.getDelegate().parseCustomElement(valueElement);
}
} else {
value = getElementText(childElement);
}
addValueToMap(map, keyValue, value, dups);
} else if (flat && !isEmpty(uri)) {
String key = childElement.getAttribute(keyName);
if (key == null || key.length() == 0) {
key = defaultKey;
}
if (key == null) {
throw new RuntimeException("No key defined for map entry " + entryName);
}
Object keyValue = getValue(key, null);
childElement.removeAttribute(keyName);
BeanDefinitionHolder bdh = parseBeanFromExtensionElement(childElement);
addValueToMap(map, keyValue, bdh, dups);
}
}
}
return map;
}
Aggregations