org.springframework.beans.factory.xml.XmlReaderContext Java Examples

The following examples show how to use org.springframework.beans.factory.xml.XmlReaderContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComponentScanBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
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.valueOf(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);
}
 
Example #2
Source File: ComponentScanBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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.valueOf(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);
}
 
Example #3
Source File: GroovyBeanDefinitionReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example #4
Source File: ScriptBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Resolves the script source from either the '{@code script-source}' attribute or
 * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and
 * returns {@code null} if neither or both of these values are specified.
 */
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
	boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
	if (hasScriptSource && !elements.isEmpty()) {
		readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
		return null;
	}
	else if (hasScriptSource) {
		return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	}
	else if (!elements.isEmpty()) {
		Element inlineElement = elements.get(0);
		return "inline:" + DomUtils.getTextValue(inlineElement);
	}
	else {
		readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
		return null;
	}
}
 
Example #5
Source File: ScriptBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the script source from either the '{@code script-source}' attribute or
 * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and
 * returns {@code null} if neither or both of these values are specified.
 */
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
	boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
	if (hasScriptSource && !elements.isEmpty()) {
		readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
		return null;
	}
	else if (hasScriptSource) {
		return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	}
	else if (!elements.isEmpty()) {
		Element inlineElement = elements.get(0);
		return "inline:" + DomUtils.getTextValue(inlineElement);
	}
	else {
		readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
		return null;
	}
}
 
Example #6
Source File: GroovyBeanDefinitionReader.java    From java-technology-stack with MIT License 6 votes vote down vote up
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example #7
Source File: ComponentScanBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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.valueOf(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);
}
 
Example #8
Source File: ScriptBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Resolves the script source from either the '{@code script-source}' attribute or
 * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and
 * returns {@code null} if neither or both of these values are specified.
 */
@Nullable
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
	boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
	if (hasScriptSource && !elements.isEmpty()) {
		readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
		return null;
	}
	else if (hasScriptSource) {
		return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	}
	else if (!elements.isEmpty()) {
		Element inlineElement = elements.get(0);
		return "inline:" + DomUtils.getTextValue(inlineElement);
	}
	else {
		readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
		return null;
	}
}
 
Example #9
Source File: GroovyBeanDefinitionReader.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example #10
Source File: GroovyBeanDefinitionReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
	XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
		"Groovy"));
	BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
	boolean decorating = (this.currentBeanDefinition != null);
	if (!decorating) {
		this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(namespace);
	}
	return new GroovyDynamicElementReader(namespace, this.namespaces, delegate, this.currentBeanDefinition, decorating) {
		@Override
		protected void afterInvocation() {
			if (!this.decorating) {
				currentBeanDefinition = null;
			}
		}
	};
}
 
Example #11
Source File: ComponentScanBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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.valueOf(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);
}
 
Example #12
Source File: ScriptBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Resolves the script source from either the '{@code script-source}' attribute or
 * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and
 * returns {@code null} if neither or both of these values are specified.
 */
@Nullable
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
	boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
	if (hasScriptSource && !elements.isEmpty()) {
		readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
		return null;
	}
	else if (hasScriptSource) {
		return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	}
	else if (!elements.isEmpty()) {
		Element inlineElement = elements.get(0);
		return "inline:" + DomUtils.getTextValue(inlineElement);
	}
	else {
		readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
		return null;
	}
}
 
Example #13
Source File: CustomBeanDefinitionParser.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Parse bean like a real bean definition.
 * @param ele element
 * @param parserContext parserContext
 * @param builder builder
 */
protected void parseBeanDefinition(Element ele, ParserContext parserContext, BeanDefinitionBuilder builder) {	
	BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
	AbstractBeanDefinition bd = builder.getRawBeanDefinition();
	XmlReaderContext reader =  parserContext.getReaderContext();
	
	try {
		delegate.parseBeanDefinitionAttributes(ele, beanName, null , bd);
		bd.setDescription(DomUtils.getChildElementValueByTagName(ele, "description"));

		delegate.parseMetaElements(ele, bd);
		delegate.parseLookupOverrideSubElements(ele, bd.getMethodOverrides());
		delegate.parseReplacedMethodSubElements(ele, bd.getMethodOverrides());

		delegate.parseConstructorArgElements(ele, bd);
		delegate.parsePropertyElements(ele, bd);
		delegate.parseQualifierElements(ele, bd);

	}
	catch (NoClassDefFoundError err) {
		reader.error("Class that bean class [" + this.beanClass + "] depends on not found", ele, err);
	}
	catch (Throwable ex) {
		reader.error("Unexpected failure during bean definition parsing", ele, ex);
	}
	
}
 
Example #14
Source File: AspectJNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	SourceExtractor sourceExtractor = new PassThroughSourceExtractor();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry);
	XmlReaderContext readerContext =
			new XmlReaderContext(null, null, this.readerEventListener, sourceExtractor, reader, null);
	this.parserContext = new ParserContext(readerContext, null);
}
 
Example #15
Source File: LazyClassPathXmlApplicationContext.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected BeanDefinitionParserDelegate createDelegate(
        XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate)
{
    BeanDefinitionParserDelegate delegate = super.createDelegate(readerContext, root, parentDelegate);
    delegate.getDefaults().setLazyInit("true");
    return delegate;
}
 
Example #16
Source File: NoAutoStartClassPathXmlApplicationContext.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected BeanDefinitionParserDelegate createDelegate(
        XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate)
{
    BeanDefinitionParserDelegate delegate = new NoAutoStartBeanDefinitionParserDelegate(readerContext);
    delegate.initDefaults(root);
    return delegate;
}
 
Example #17
Source File: AspectJNamespaceHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	SourceExtractor sourceExtractor = new PassThroughSourceExtractor();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry);
	XmlReaderContext readerContext =
			new XmlReaderContext(null, null, this.readerEventListener, sourceExtractor, reader, null);
	this.parserContext = new ParserContext(readerContext, null);
}
 
Example #18
Source File: XmlNacosPropertySourceBuilder.java    From nacos-spring-project with Apache License 2.0 5 votes vote down vote up
private void initOrigin(NacosPropertySource nacosPropertySource,
		XmlReaderContext xmlReaderContext) {
	// Resource
	Resource resource = xmlReaderContext.getResource();

	nacosPropertySource.setOrigin(resource);
}
 
Example #19
Source File: AspectJNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	SourceExtractor sourceExtractor = new PassThroughSourceExtractor();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry);
	XmlReaderContext readerContext =
			new XmlReaderContext(null, null, this.readerEventListener, sourceExtractor, reader, null);
	this.parserContext = new ParserContext(readerContext, null);
}
 
Example #20
Source File: ComponentScanBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
	return new ClassPathBeanDefinitionScanner(readerContext.getRegistry(), useDefaultFilters,
			readerContext.getEnvironment(), readerContext.getResourceLoader());
}
 
Example #21
Source File: ConfigurationScanBeanDefinitionParser.java    From conf4j with MIT License 4 votes vote down vote up
@Override
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
    // default filters are removed, to avoid necessity of using @Component and related meta-annotations
    return new ConfigurationClassPathBeanDefinitionScanner(readerContext.getRegistry());
}
 
Example #22
Source File: NoAutoStartClassPathXmlApplicationContext.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected NoAutoStartBeanDefinitionParserDelegate(XmlReaderContext readerContext) {
   super(readerContext);
}
 
Example #23
Source File: NacosPropertySourceXmlBeanDefinition.java    From nacos-spring-project with Apache License 2.0 4 votes vote down vote up
void setXmlReaderContext(XmlReaderContext xmlReaderContext) {
	this.xmlReaderContext = xmlReaderContext;
}
 
Example #24
Source File: NacosPropertySourceXmlBeanDefinition.java    From nacos-spring-project with Apache License 2.0 4 votes vote down vote up
public XmlReaderContext getXmlReaderContext() {
	return xmlReaderContext;
}
 
Example #25
Source File: ComponentScanBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
	return new ClassPathBeanDefinitionScanner(readerContext.getRegistry(), useDefaultFilters);
}
 
Example #26
Source File: ComponentScanBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
	return new ClassPathBeanDefinitionScanner(readerContext.getRegistry(), useDefaultFilters,
			readerContext.getEnvironment(), readerContext.getResourceLoader());
}
 
Example #27
Source File: ComponentScanBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
	return new ClassPathBeanDefinitionScanner(readerContext.getRegistry(), useDefaultFilters,
			readerContext.getEnvironment(), readerContext.getResourceLoader());
}