Skip to content

Commit ad9049e

Browse files
committed
Polishing
1 parent b913578 commit ad9049e

File tree

5 files changed

+44
-36
lines changed

5 files changed

+44
-36
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java

Lines changed: 19 additions & 19 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.
@@ -22,7 +22,7 @@
2222

2323
/**
2424
* Simple interface for bean definition readers.
25-
* Specifies load methods with Resource parameters.
25+
* Specifies load methods with Resource and String location parameters.
2626
*
2727
* <p>Concrete bean definition readers can of course add additional
2828
* load and register methods for bean definitions, specific to
@@ -45,23 +45,23 @@ public interface BeanDefinitionReader {
4545
*/
4646
BeanDefinitionRegistry getRegistry();
4747

48-
/**
49-
* Return the resource loader to use for resource locations.
50-
* Can be checked for the <b>ResourcePatternResolver</b> interface and cast
51-
* accordingly, for loading multiple resources for a given resource pattern.
52-
* <p>Null suggests that absolute resource loading is not available
53-
* for this bean definition reader.
54-
* <p>This is mainly meant to be used for importing further resources
55-
* from within a bean definition resource, for example via the "import"
56-
* tag in XML bean definitions. It is recommended, however, to apply
57-
* such imports relative to the defining resource; only explicit full
58-
* resource locations will trigger absolute resource loading.
59-
* <p>There is also a {@code loadBeanDefinitions(String)} method available,
60-
* for loading bean definitions from a resource location (or location pattern).
61-
* This is a convenience to avoid explicit ResourceLoader handling.
62-
* @see #loadBeanDefinitions(String)
63-
* @see org.springframework.core.io.support.ResourcePatternResolver
64-
*/
48+
/**
49+
* Return the resource loader to use for resource locations.
50+
* Can be checked for the <b>ResourcePatternResolver</b> interface and cast
51+
* accordingly, for loading multiple resources for a given resource pattern.
52+
* <p>Null suggests that absolute resource loading is not available
53+
* for this bean definition reader.
54+
* <p>This is mainly meant to be used for importing further resources
55+
* from within a bean definition resource, for example via the "import"
56+
* tag in XML bean definitions. It is recommended, however, to apply
57+
* such imports relative to the defining resource; only explicit full
58+
* resource locations will trigger absolute resource loading.
59+
* <p>There is also a {@code loadBeanDefinitions(String)} method available,
60+
* for loading bean definitions from a resource location (or location pattern).
61+
* This is a convenience to avoid explicit ResourceLoader handling.
62+
* @see #loadBeanDefinitions(String)
63+
* @see org.springframework.core.io.support.ResourcePatternResolver
64+
*/
6565
ResourceLoader getResourceLoader();
6666

6767
/**

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected void doRegisterBeanDefinitions(Element root) {
133133
// then ultimately reset this.delegate back to its original (parent) reference.
134134
// this behavior emulates a stack of delegates without actually necessitating one.
135135
BeanDefinitionParserDelegate parent = this.delegate;
136-
this.delegate = createHelper(this.readerContext, root, parent);
136+
this.delegate = createDelegate(this.readerContext, root, parent);
137137

138138
preProcessXml(root);
139139
parseBeanDefinitions(root, this.delegate);
@@ -142,14 +142,24 @@ protected void doRegisterBeanDefinitions(Element root) {
142142
this.delegate = parent;
143143
}
144144

145-
protected BeanDefinitionParserDelegate createHelper(
145+
protected BeanDefinitionParserDelegate createDelegate(
146146
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
147147

148-
BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext, environment);
149-
delegate.initDefaults(root, parentDelegate);
148+
BeanDefinitionParserDelegate delegate = createHelper(readerContext, root, parentDelegate);
149+
if (delegate == null) {
150+
delegate = new BeanDefinitionParserDelegate(readerContext, this.environment);
151+
delegate.initDefaults(root, parentDelegate);
152+
}
150153
return delegate;
151154
}
152155

156+
@Deprecated
157+
protected BeanDefinitionParserDelegate createHelper(
158+
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
159+
160+
return null;
161+
}
162+
153163
/**
154164
* Return the descriptor for the XML resource that this parser works on.
155165
*/

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ private void processMemberClasses(AnnotationMetadata metadata) throws IOExceptio
287287
private void processPropertySource(AnnotationAttributes propertySource) throws IOException {
288288
String name = propertySource.getString("name");
289289
String[] locations = propertySource.getStringArray("value");
290-
int nLocations = locations.length;
291-
if (nLocations == 0) {
290+
int locationCount = locations.length;
291+
if (locationCount == 0) {
292292
throw new IllegalArgumentException("At least one @PropertySource(value) location is required");
293293
}
294-
for (int i = 0; i < nLocations; i++) {
294+
for (int i = 0; i < locationCount; i++) {
295295
locations[i] = this.environment.resolveRequiredPlaceholders(locations[i]);
296296
}
297297
ClassLoader classLoader = this.resourceLoader.getClassLoader();
@@ -301,7 +301,7 @@ private void processPropertySource(AnnotationAttributes propertySource) throws I
301301
}
302302
}
303303
else {
304-
if (nLocations == 1) {
304+
if (locationCount == 1) {
305305
this.propertySources.push(new ResourcePropertySource(name, locations[0], classLoader));
306306
}
307307
else {

spring-context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java

Lines changed: 5 additions & 7 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.
@@ -45,10 +45,9 @@ public class GenericXmlApplicationContext extends GenericApplicationContext {
4545

4646
/**
4747
* Create a new GenericXmlApplicationContext that needs to be
48-
* {@linkplain #load loaded} and then manually {@link #refresh refreshed}.
48+
* {@link #load loaded} and then manually {@link #refresh refreshed}.
4949
*/
5050
public GenericXmlApplicationContext() {
51-
reader.setEnvironment(this.getEnvironment());
5251
}
5352

5453
/**
@@ -91,14 +90,13 @@ public void setValidating(boolean validating) {
9190
}
9291

9392
/**
94-
* {@inheritDoc}
95-
* <p>Delegates the given environment to underlying {@link XmlBeanDefinitionReader}.
96-
* Should be called before any call to {@link #load}.
93+
* Delegates the given environment to underlying {@link XmlBeanDefinitionReader}.
94+
* Should be called before any call to {@code #load}.
9795
*/
9896
@Override
9997
public void setEnvironment(ConfigurableEnvironment environment) {
10098
super.setEnvironment(environment);
101-
this.reader.setEnvironment(this.getEnvironment());
99+
this.reader.setEnvironment(getEnvironment());
102100
}
103101

104102
/**

spring-core/src/main/java/org/springframework/core/MethodParameter.java

Lines changed: 2 additions & 2 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.
@@ -179,7 +179,7 @@ private AnnotatedElement getAnnotatedElement() {
179179
/**
180180
* Return the class that declares the underlying Method or Constructor.
181181
*/
182-
public Class getDeclaringClass() {
182+
public Class<?> getDeclaringClass() {
183183
return getMember().getDeclaringClass();
184184
}
185185

0 commit comments

Comments
 (0)