diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionDocumentReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionDocumentReader.java
index ffe9d294d9b..a41138fd36f 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionDocumentReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionDocumentReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,9 @@ public interface BeanDefinitionDocumentReader {
* Set the Environment to use when reading bean definitions.
*
Used for evaluating profile information to determine whether a
* {@code } document/element should be included or ignored.
+ * @deprecated in favor of Environment access via XmlReaderContext
*/
+ @Deprecated
void setEnvironment(Environment environment);
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java
index de4c3e695ed..6be94c1a897 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,6 @@ import org.springframework.beans.factory.support.ManagedSet;
import org.springframework.beans.factory.support.MethodOverrides;
import org.springframework.beans.factory.support.ReplaceOverride;
import org.springframework.core.env.Environment;
-import org.springframework.core.env.StandardEnvironment;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -246,12 +245,12 @@ public class BeanDefinitionParserDelegate {
private final XmlReaderContext readerContext;
+ private final Environment environment;
+
private final DocumentDefaultsDefinition defaults = new DocumentDefaultsDefinition();
private final ParseState parseState = new ParseState();
- private Environment environment;
-
/**
* Stores all used bean names so we can enforce uniqueness on a per
* beans-element basis. Duplicate bean ids/names may not exist within the
@@ -261,26 +260,24 @@ public class BeanDefinitionParserDelegate {
/**
- * Create a new BeanDefinitionParserDelegate associated with the
- * supplied {@link XmlReaderContext} and {@link Environment}.
+ * Create a new BeanDefinitionParserDelegate associated with the supplied
+ * {@link XmlReaderContext}.
+ */
+ public BeanDefinitionParserDelegate(XmlReaderContext readerContext) {
+ this(readerContext, readerContext.getReader().getEnvironment());
+ }
+
+ /**
+ * Create a new BeanDefinitionParserDelegate associated with the supplied
+ * {@link XmlReaderContext}.
*/
public BeanDefinitionParserDelegate(XmlReaderContext readerContext, Environment environment) {
Assert.notNull(readerContext, "XmlReaderContext must not be null");
- Assert.notNull(readerContext, "Environment must not be null");
+ Assert.notNull(environment, "Environment must not be null");
this.readerContext = readerContext;
this.environment = environment;
}
- /**
- * Create a new BeanDefinitionParserDelegate associated with the
- * supplied {@link XmlReaderContext} and a new {@link StandardEnvironment}.
- * @deprecated since Spring 3.1 in favor of
- * {@link #BeanDefinitionParserDelegate(XmlReaderContext, Environment)}
- */
- @Deprecated
- public BeanDefinitionParserDelegate(XmlReaderContext readerContext) {
- this(readerContext, new StandardEnvironment());
- }
/**
* Get the {@link XmlReaderContext} associated with this helper instance.
@@ -326,6 +323,13 @@ public class BeanDefinitionParserDelegate {
}
+ /**
+ * Initialize the default settings assuming a {@code null} parent delegate.
+ */
+ public void initDefaults(Element root) {
+ initDefaults(root, null);
+ }
+
/**
* Initialize the default lazy-init, autowire, dependency check settings,
* init-method, destroy-method and merge settings. Support nested 'beans'
@@ -339,16 +343,6 @@ public class BeanDefinitionParserDelegate {
this.readerContext.fireDefaultsRegistered(this.defaults);
}
- /**
- * Initialize the default settings assuming a {@code null} parent delegate.
- * @deprecated in Spring 3.1 in favor of
- * {@link #initDefaults(Element, BeanDefinitionParserDelegate)}
- */
- @Deprecated
- public void initDefaults(Element root) {
- initDefaults(root, null);
- }
-
/**
* Populate the given DocumentDefaultsDefinition instance with the default lazy-init,
* autowire, dependency check settings, init-method, destroy-method and merge settings.
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java
index 0be926af27e..63bdfc3ec75 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,6 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternUtils;
-import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
@@ -84,19 +83,13 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
private BeanDefinitionParserDelegate delegate;
- /**
- * {@inheritDoc}
- *
Default value is {@code null}; property is required for parsing any
- * {@code } element with a {@code profile} attribute present.
- * @see #doRegisterBeanDefinitions
- */
+ @Deprecated
public void setEnvironment(Environment environment) {
this.environment = environment;
}
/**
- * {@inheritDoc}
- *
This implementation parses bean definitions according to the "spring-beans" XSD
+ * This implementation parses bean definitions according to the "spring-beans" XSD
* (or DTD, historically).
*
Opens a DOM Document; then initializes the default settings
* specified at the {@code } level; then parses the contained bean definitions.
@@ -108,20 +101,35 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
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);
+ }
+
+ private Environment getEnvironment() {
+ return (this.environment != null ? this.environment : getReaderContext().getReader().getEnvironment());
+ }
+
/**
* Register each bean definition within the given root {@code } element.
- * @throws IllegalStateException if {@code actualResources = new LinkedHashSet(4);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
index 16b58500bc1..860799adc81 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -135,6 +135,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
super(registry);
}
+
/**
* Set whether to use XML validation. Default is {@code true}.
* This method switches namespace awareness on if validation is turned off,
@@ -486,9 +487,10 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
* @see #setDocumentReaderClass
* @see BeanDefinitionDocumentReader#registerBeanDefinitions
*/
+ @SuppressWarnings("deprecation")
public int registerBeanDefinitions(Document doc, Resource resource) throws BeanDefinitionStoreException {
BeanDefinitionDocumentReader documentReader = createBeanDefinitionDocumentReader();
- documentReader.setEnvironment(this.getEnvironment());
+ documentReader.setEnvironment(getEnvironment());
int countBefore = getRegistry().getBeanDefinitionCount();
documentReader.registerBeanDefinitions(doc, createReaderContext(resource));
return getRegistry().getBeanDefinitionCount() - countBefore;