Skip to content

Commit e3c83bb

Browse files
committed
Minor javadoc and source layout polishing
1 parent 9ffbee3 commit e3c83bb

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionDocumentReader.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
1616

1717
package org.springframework.beans.factory.xml;
1818

19+
import org.w3c.dom.Document;
20+
1921
import org.springframework.beans.factory.BeanDefinitionStoreException;
2022
import org.springframework.core.env.Environment;
2123

22-
import org.w3c.dom.Document;
23-
2424
/**
2525
* SPI for parsing an XML document that contains Spring bean definitions.
2626
* Used by XmlBeanDefinitionReader for actually parsing a DOM document.
@@ -38,20 +38,21 @@
3838
public interface BeanDefinitionDocumentReader {
3939

4040
/**
41-
* Read bean definitions from the given DOM document,
42-
* and register them with the given bean factory.
41+
* Set the Environment to use when reading bean definitions.
42+
* <p>Used for evaluating profile information to determine whether a
43+
* {@code <beans/>} document/element should be included or ignored.
44+
*/
45+
void setEnvironment(Environment environment);
46+
47+
/**
48+
* Read bean definitions from the given DOM document and
49+
* register them with the registry in the given reader context.
4350
* @param doc the DOM document
44-
* @param readerContext the current context of the reader. Includes the resource being parsed
51+
* @param readerContext the current context of the reader
52+
* (includes the target registry and the resource being parsed)
4553
* @throws BeanDefinitionStoreException in case of parsing errors
4654
*/
4755
void registerBeanDefinitions(Document doc, XmlReaderContext readerContext)
4856
throws BeanDefinitionStoreException;
4957

50-
/**
51-
* Set the Environment to use when reading bean definitions. Used for evaluating
52-
* profile information to determine whether a {@code <beans/>} document/element should
53-
* be included or omitted.
54-
*/
55-
void setEnvironment(Environment environment);
56-
5758
}

spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,16 +72,15 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
7272

7373
public static final String RESOURCE_ATTRIBUTE = "resource";
7474

75-
/** @see org.springframework.context.annotation.Profile */
7675
public static final String PROFILE_ATTRIBUTE = "profile";
7776

7877

7978
protected final Log logger = LogFactory.getLog(getClass());
8079

81-
private XmlReaderContext readerContext;
82-
8380
private Environment environment;
8481

82+
private XmlReaderContext readerContext;
83+
8584
private BeanDefinitionParserDelegate delegate;
8685

8786

@@ -104,13 +103,12 @@ public void setEnvironment(Environment environment) {
104103
*/
105104
public void registerBeanDefinitions(Document doc, XmlReaderContext readerContext) {
106105
this.readerContext = readerContext;
107-
108106
logger.debug("Loading bean definitions");
109107
Element root = doc.getDocumentElement();
110-
111108
doRegisterBeanDefinitions(root);
112109
}
113110

111+
114112
/**
115113
* Register each bean definition within the given root {@code <beans/>} element.
116114
* @throws IllegalStateException if {@code <beans profile="..."} attribute is present
@@ -120,21 +118,22 @@ public void registerBeanDefinitions(Document doc, XmlReaderContext readerContext
120118
protected void doRegisterBeanDefinitions(Element root) {
121119
String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE);
122120
if (StringUtils.hasText(profileSpec)) {
123-
Assert.state(this.environment != null, "environment property must not be null");
124-
String[] specifiedProfiles = StringUtils.tokenizeToStringArray(profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
121+
Assert.state(this.environment != null, "Environment must be set for evaluating profiles");
122+
String[] specifiedProfiles = StringUtils.tokenizeToStringArray(
123+
profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
125124
if (!this.environment.acceptsProfiles(specifiedProfiles)) {
126125
return;
127126
}
128127
}
129128

130-
// any nested <beans> elements will cause recursion in this method. In
129+
// Any nested <beans> elements will cause recursion in this method. In
131130
// order to propagate and preserve <beans> default-* attributes correctly,
132131
// keep track of the current (parent) delegate, which may be null. Create
133132
// the new (child) delegate with a reference to the parent for fallback purposes,
134133
// then ultimately reset this.delegate back to its original (parent) reference.
135134
// this behavior emulates a stack of delegates without actually necessitating one.
136135
BeanDefinitionParserDelegate parent = this.delegate;
137-
this.delegate = createHelper(readerContext, root, parent);
136+
this.delegate = createHelper(this.readerContext, root, parent);
138137

139138
preProcessXml(root);
140139
parseBeanDefinitions(root, this.delegate);
@@ -143,7 +142,9 @@ protected void doRegisterBeanDefinitions(Element root) {
143142
this.delegate = parent;
144143
}
145144

146-
protected BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
145+
protected BeanDefinitionParserDelegate createHelper(
146+
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
147+
147148
BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext, environment);
148149
delegate.initDefaults(root, parentDelegate);
149150
return delegate;

0 commit comments

Comments
 (0)