|
|
|
@ -35,7 +35,6 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.support.ResourcePatternUtils; |
|
|
|
import org.springframework.core.io.support.ResourcePatternUtils; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
import org.springframework.util.ResourceUtils; |
|
|
|
import org.springframework.util.ResourceUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
@ -77,27 +76,18 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume |
|
|
|
|
|
|
|
|
|
|
|
protected final Log logger = LogFactory.getLog(getClass()); |
|
|
|
protected final Log logger = LogFactory.getLog(getClass()); |
|
|
|
|
|
|
|
|
|
|
|
private Environment environment; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private XmlReaderContext readerContext; |
|
|
|
private XmlReaderContext readerContext; |
|
|
|
|
|
|
|
|
|
|
|
private BeanDefinitionParserDelegate delegate; |
|
|
|
private BeanDefinitionParserDelegate delegate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Deprecated |
|
|
|
* {@inheritDoc} |
|
|
|
|
|
|
|
* <p>Default value is {@code null}; property is required for parsing any |
|
|
|
|
|
|
|
* {@code <beans/>} element with a {@code profile} attribute present. |
|
|
|
|
|
|
|
* @see #doRegisterBeanDefinitions |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setEnvironment(Environment environment) { |
|
|
|
public void setEnvironment(Environment environment) { |
|
|
|
this.environment = environment; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@inheritDoc} |
|
|
|
* This implementation parses bean definitions according to the "spring-beans" XSD |
|
|
|
* <p>This implementation parses bean definitions according to the "spring-beans" XSD |
|
|
|
|
|
|
|
* (or DTD, historically). |
|
|
|
* (or DTD, historically). |
|
|
|
* <p>Opens a DOM Document; then initializes the default settings |
|
|
|
* <p>Opens a DOM Document; then initializes the default settings |
|
|
|
* specified at the {@code <beans/>} level; then parses the contained bean definitions. |
|
|
|
* specified at the {@code <beans/>} level; then parses the contained bean definitions. |
|
|
|
@ -110,12 +100,24 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume |
|
|
|
doRegisterBeanDefinitions(root); |
|
|
|
doRegisterBeanDefinitions(root); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the descriptor for the XML resource that this parser works on. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected final XmlReaderContext getReaderContext() { |
|
|
|
|
|
|
|
return this.readerContext; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor} to pull the |
|
|
|
|
|
|
|
* source metadata from the supplied {@link Element}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected Object extractSource(Element ele) { |
|
|
|
|
|
|
|
return getReaderContext().extractSource(ele); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Register each bean definition within the given root {@code <beans/>} element. |
|
|
|
* Register each bean definition within the given root {@code <beans/>} element. |
|
|
|
* @throws IllegalStateException if {@code <beans profile="..."} attribute is present |
|
|
|
|
|
|
|
* and Environment property has not been set |
|
|
|
|
|
|
|
* @see #setEnvironment |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void doRegisterBeanDefinitions(Element root) { |
|
|
|
protected void doRegisterBeanDefinitions(Element root) { |
|
|
|
// Any nested <beans> elements will cause recursion in this method. In
|
|
|
|
// Any nested <beans> elements will cause recursion in this method. In
|
|
|
|
@ -125,15 +127,14 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume |
|
|
|
// then ultimately reset this.delegate back to its original (parent) reference.
|
|
|
|
// then ultimately reset this.delegate back to its original (parent) reference.
|
|
|
|
// this behavior emulates a stack of delegates without actually necessitating one.
|
|
|
|
// this behavior emulates a stack of delegates without actually necessitating one.
|
|
|
|
BeanDefinitionParserDelegate parent = this.delegate; |
|
|
|
BeanDefinitionParserDelegate parent = this.delegate; |
|
|
|
this.delegate = createDelegate(this.readerContext, root, parent); |
|
|
|
this.delegate = createDelegate(getReaderContext(), root, parent); |
|
|
|
|
|
|
|
|
|
|
|
if (this.delegate.isDefaultNamespace(root)) { |
|
|
|
if (this.delegate.isDefaultNamespace(root)) { |
|
|
|
String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE); |
|
|
|
String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE); |
|
|
|
if (StringUtils.hasText(profileSpec)) { |
|
|
|
if (StringUtils.hasText(profileSpec)) { |
|
|
|
Assert.state(this.environment != null, "Environment must be set for evaluating profiles"); |
|
|
|
|
|
|
|
String[] specifiedProfiles = StringUtils.tokenizeToStringArray( |
|
|
|
String[] specifiedProfiles = StringUtils.tokenizeToStringArray( |
|
|
|
profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS); |
|
|
|
profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS); |
|
|
|
if (!this.environment.acceptsProfiles(specifiedProfiles)) { |
|
|
|
if (!getReaderContext().getEnvironment().acceptsProfiles(specifiedProfiles)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -149,27 +150,11 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume |
|
|
|
protected BeanDefinitionParserDelegate createDelegate( |
|
|
|
protected BeanDefinitionParserDelegate createDelegate( |
|
|
|
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) { |
|
|
|
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) { |
|
|
|
|
|
|
|
|
|
|
|
BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext, this.environment); |
|
|
|
BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext); |
|
|
|
delegate.initDefaults(root, parentDelegate); |
|
|
|
delegate.initDefaults(root, parentDelegate); |
|
|
|
return delegate; |
|
|
|
return delegate; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the descriptor for the XML resource that this parser works on. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected final XmlReaderContext getReaderContext() { |
|
|
|
|
|
|
|
return this.readerContext; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor} to pull the |
|
|
|
|
|
|
|
* source metadata from the supplied {@link Element}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected Object extractSource(Element ele) { |
|
|
|
|
|
|
|
return this.readerContext.extractSource(ele); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Parse the elements at the root level in the document: |
|
|
|
* Parse the elements at the root level in the document: |
|
|
|
* "import", "alias", "bean". |
|
|
|
* "import", "alias", "bean". |
|
|
|
@ -224,7 +209,7 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Resolve system properties: e.g. "${user.dir}"
|
|
|
|
// Resolve system properties: e.g. "${user.dir}"
|
|
|
|
location = environment.resolveRequiredPlaceholders(location); |
|
|
|
location = getReaderContext().getEnvironment().resolveRequiredPlaceholders(location); |
|
|
|
|
|
|
|
|
|
|
|
Set<Resource> actualResources = new LinkedHashSet<Resource>(4); |
|
|
|
Set<Resource> actualResources = new LinkedHashSet<Resource>(4); |
|
|
|
|
|
|
|
|
|
|
|
|