Skip to content

Commit f473392

Browse files
committed
Polishing
1 parent 1e2b8ab commit f473392

File tree

7 files changed

+72
-69
lines changed

7 files changed

+72
-69
lines changed

spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java

Lines changed: 3 additions & 3 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-2016 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.
@@ -112,9 +112,9 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
112112
* Add a new BeanFactoryPostProcessor that will get applied to the internal
113113
* bean factory of this application context on refresh, before any of the
114114
* bean definitions get evaluated. To be invoked during context configuration.
115-
* @param beanFactoryPostProcessor the factory processor to register
115+
* @param postProcessor the factory processor to register
116116
*/
117-
void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor);
117+
void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor);
118118

119119
/**
120120
* Add a new ApplicationListener that will be notified on context events

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -53,6 +53,7 @@
5353
import org.springframework.context.ApplicationEventPublisherAware;
5454
import org.springframework.context.ApplicationListener;
5555
import org.springframework.context.ConfigurableApplicationContext;
56+
import org.springframework.context.EmbeddedValueResolverAware;
5657
import org.springframework.context.EnvironmentAware;
5758
import org.springframework.context.HierarchicalMessageSource;
5859
import org.springframework.context.LifecycleProcessor;
@@ -404,8 +405,9 @@ public void setParent(ApplicationContext parent) {
404405
}
405406
}
406407

407-
public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor) {
408-
this.beanFactoryPostProcessors.add(beanFactoryPostProcessor);
408+
public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor) {
409+
Assert.notNull(postProcessor, "BeanFactoryPostProcessor must not be null");
410+
this.beanFactoryPostProcessors.add(postProcessor);
409411
}
410412

411413

@@ -418,6 +420,7 @@ public List<BeanFactoryPostProcessor> getBeanFactoryPostProcessors() {
418420
}
419421

420422
public void addApplicationListener(ApplicationListener<?> listener) {
423+
Assert.notNull(listener, "ApplicationListener must not be null");
421424
if (this.applicationEventMulticaster != null) {
422425
this.applicationEventMulticaster.addApplicationListener(listener);
423426
}
@@ -560,11 +563,12 @@ protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
560563

561564
// Configure the bean factory with context callbacks.
562565
beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this));
566+
beanFactory.ignoreDependencyInterface(EnvironmentAware.class);
567+
beanFactory.ignoreDependencyInterface(EmbeddedValueResolverAware.class);
563568
beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class);
564569
beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class);
565570
beanFactory.ignoreDependencyInterface(MessageSourceAware.class);
566571
beanFactory.ignoreDependencyInterface(ApplicationContextAware.class);
567-
beanFactory.ignoreDependencyInterface(EnvironmentAware.class);
568572

569573
// BeanFactory interface not registered as resolvable type in a plain factory.
570574
// MessageSource registered (and found for autowiring) as a bean.

spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -27,15 +27,16 @@ public interface ConverterRegistry {
2727

2828
/**
2929
* Add a plain converter to this registry.
30-
* The convertible sourceType/targetType pair is derived from the Converter's parameterized types.
30+
* The convertible source/target type pair is derived from the Converter's parameterized types.
3131
* @throws IllegalArgumentException if the parameterized types could not be resolved
3232
*/
3333
void addConverter(Converter<?, ?> converter);
3434

3535
/**
3636
* Add a plain converter to this registry.
37-
* The convertible sourceType/targetType pair is specified explicitly.
38-
* Allows for a Converter to be reused for multiple distinct pairs without having to create a Converter class for each pair.
37+
* The convertible source/target type pair is specified explicitly.
38+
* <p>Allows for a Converter to be reused for multiple distinct pairs without
39+
* having to create a Converter class for each pair.
3940
* @since 3.1
4041
*/
4142
void addConverter(Class<?> sourceType, Class<?> targetType, Converter<?, ?> converter);
@@ -47,13 +48,13 @@ public interface ConverterRegistry {
4748

4849
/**
4950
* Add a ranged converter factory to this registry.
50-
* The convertible sourceType/rangeType pair is derived from the ConverterFactory's parameterized types.
51-
* @throws IllegalArgumentException if the parameterized types could not be resolved.
51+
* The convertible source/target type pair is derived from the ConverterFactory's parameterized types.
52+
* @throws IllegalArgumentException if the parameterized types could not be resolved
5253
*/
53-
void addConverterFactory(ConverterFactory<?, ?> converterFactory);
54+
void addConverterFactory(ConverterFactory<?, ?> factory);
5455

5556
/**
56-
* Remove any converters from sourceType to targetType.
57+
* Remove any converters from {@code sourceType} to {@code targetType}.
5758
* @param sourceType the source type
5859
* @param targetType the target type
5960
*/

spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ public class GenericConversionService implements ConfigurableConversionService {
8181

8282
public void addConverter(Converter<?, ?> converter) {
8383
GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converter, Converter.class);
84-
Assert.notNull(typeInfo, "Unable to the determine sourceType <S> and targetType " +
85-
"<T> which your Converter<S, T> converts between; declare these generic types.");
84+
if (typeInfo == null) {
85+
throw new IllegalArgumentException("Unable to determine source type <S> and target type <T> for your " +
86+
"Converter [" + converter.getClass().getName() + "]; does the class parameterize those types?");
87+
}
8688
addConverter(new ConverterAdapter(converter, typeInfo));
8789
}
8890

@@ -96,14 +98,13 @@ public void addConverter(GenericConverter converter) {
9698
invalidateCache();
9799
}
98100

99-
public void addConverterFactory(ConverterFactory<?, ?> converterFactory) {
100-
GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converterFactory, ConverterFactory.class);
101+
public void addConverterFactory(ConverterFactory<?, ?> factory) {
102+
GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(factory, ConverterFactory.class);
101103
if (typeInfo == null) {
102-
throw new IllegalArgumentException("Unable to the determine sourceType <S> and " +
103-
"targetRangeType R which your ConverterFactory<S, R> converts between; " +
104-
"declare these generic types.");
104+
throw new IllegalArgumentException("Unable to determine source type <S> and target type <T> for your " +
105+
"ConverterFactory [" + factory.getClass().getName() + "]; does the class parameterize those types?");
105106
}
106-
addConverter(new ConverterFactoryAdapter(converterFactory, typeInfo));
107+
addConverter(new ConverterFactoryAdapter(factory, typeInfo));
107108
}
108109

109110
public void removeConvertible(Class<?> sourceType, Class<?> targetType) {
@@ -129,17 +130,18 @@ public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
129130
}
130131

131132
/**
132-
* Returns true if conversion between the sourceType and targetType can be bypassed.
133-
* More precisely this method will return true if objects of sourceType can be
133+
* Return whether conversion between the sourceType and targetType can be bypassed.
134+
* <p>More precisely, this method will return true if objects of sourceType can be
134135
* converted to the targetType by returning the source object unchanged.
135-
* @param sourceType context about the source type to convert from (may be null if source is null)
136+
* @param sourceType context about the source type to convert from
137+
* (may be {@code null} if source is {@code null})
136138
* @param targetType context about the target type to convert to (required)
137-
* @return true if conversion can be bypassed
138-
* @throws IllegalArgumentException if targetType is null
139+
* @return {@code true} if conversion can be bypassed; {@code false} otherwise
140+
* @throws IllegalArgumentException if targetType is {@code null}
139141
* @since 3.2
140142
*/
141143
public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
142-
Assert.notNull(targetType, "The targetType to convert to cannot be null");
144+
Assert.notNull(targetType, "targetType to convert to cannot be null");
143145
if (sourceType == null) {
144146
return true;
145147
}
@@ -149,18 +151,18 @@ public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor target
149151

150152
@SuppressWarnings("unchecked")
151153
public <T> T convert(Object source, Class<T> targetType) {
152-
Assert.notNull(targetType,"The targetType to convert to cannot be null");
154+
Assert.notNull(targetType, "targetType to convert to cannot be null");
153155
return (T) convert(source, TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetType));
154156
}
155157

156158
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
157-
Assert.notNull(targetType,"The targetType to convert to cannot be null");
159+
Assert.notNull(targetType, "targetType to convert to cannot be null");
158160
if (sourceType == null) {
159-
Assert.isTrue(source == null, "The source must be [null] if sourceType == [null]");
160-
return handleResult(sourceType, targetType, convertNullSource(sourceType, targetType));
161+
Assert.isTrue(source == null, "source must be [null] if sourceType == [null]");
162+
return handleResult(null, targetType, convertNullSource(null, targetType));
161163
}
162164
if (source != null && !sourceType.getObjectType().isInstance(source)) {
163-
throw new IllegalArgumentException("The source to convert from must be an instance of " +
165+
throw new IllegalArgumentException("source to convert from must be an instance of " +
164166
sourceType + "; instead it was a " + source.getClass().getName());
165167
}
166168
GenericConverter converter = getConverter(sourceType, targetType);
@@ -198,7 +200,7 @@ public String toString() {
198200

199201
/**
200202
* Template method to convert a null source.
201-
* <p>Default implementation returns {@code null}.
203+
* <p>The default implementation returns {@code null}.
202204
* Subclasses may override to return custom null objects for specific target types.
203205
* @param sourceType the sourceType to convert from
204206
* @param targetType the targetType to convert to
@@ -213,11 +215,10 @@ protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor tar
213215
* First queries this ConversionService's converter cache.
214216
* On a cache miss, then performs an exhaustive search for a matching converter.
215217
* If no converter matches, returns the default converter.
216-
* Subclasses may override.
217218
* @param sourceType the source type to convert from
218219
* @param targetType the target type to convert to
219-
* @return the generic converter that will perform the conversion, or {@code null} if
220-
* no suitable converter was found
220+
* @return the generic converter that will perform the conversion,
221+
* or {@code null} if no suitable converter was found
221222
* @see #getDefaultConverter(TypeDescriptor, TypeDescriptor)
222223
*/
223224
protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
@@ -243,9 +244,8 @@ protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescripto
243244

244245
/**
245246
* Return the default converter if no converter is found for the given sourceType/targetType pair.
246-
* Returns a NO_OP Converter if the sourceType is assignable to the targetType.
247+
* <p>Returns a NO_OP Converter if the sourceType is assignable to the targetType.
247248
* Returns {@code null} otherwise, indicating no suitable converter could be found.
248-
* Subclasses may override.
249249
* @param sourceType the source type to convert from
250250
* @param targetType the target type to convert to
251251
* @return the default generic converter that will perform the conversion

spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -36,6 +36,7 @@
3636
* @author Juergen Hoeller
3737
* @author Sam Brannen
3838
* @since 1.2.6
39+
* @see Resource#getInputStream()
3940
* @see java.io.Reader
4041
* @see java.nio.charset.Charset
4142
*/
@@ -51,7 +52,7 @@ public class EncodedResource {
5152
/**
5253
* Create a new {@code EncodedResource} for the given {@code Resource},
5354
* not specifying an explicit encoding or {@code Charset}.
54-
* @param resource the {@code Resource} to hold; never {@code null}
55+
* @param resource the {@code Resource} to hold (never {@code null})
5556
*/
5657
public EncodedResource(Resource resource) {
5758
this(resource, null, null);
@@ -60,7 +61,7 @@ public EncodedResource(Resource resource) {
6061
/**
6162
* Create a new {@code EncodedResource} for the given {@code Resource},
6263
* using the specified {@code encoding}.
63-
* @param resource the {@code Resource} to hold; never {@code null}
64+
* @param resource the {@code Resource} to hold (never {@code null})
6465
* @param encoding the encoding to use for reading from the resource
6566
*/
6667
public EncodedResource(Resource resource, String encoding) {
@@ -70,7 +71,7 @@ public EncodedResource(Resource resource, String encoding) {
7071
/**
7172
* Create a new {@code EncodedResource} for the given {@code Resource},
7273
* using the specified {@code Charset}.
73-
* @param resource the {@code Resource} to hold; never {@code null}
74+
* @param resource the {@code Resource} to hold (never {@code null})
7475
* @param charset the {@code Charset} to use for reading from the resource
7576
*/
7677
public EncodedResource(Resource resource, Charset charset) {
@@ -85,6 +86,7 @@ private EncodedResource(Resource resource, String encoding, Charset charset) {
8586
this.charset = charset;
8687
}
8788

89+
8890
/**
8991
* Return the {@code Resource} held by this {@code EncodedResource}.
9092
*/
@@ -140,8 +142,8 @@ else if (this.encoding != null) {
140142
}
141143

142144
/**
143-
* Open a {@code java.io.InputStream} for the specified resource, ignoring any
144-
* specified {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}.
145+
* Open an {@code InputStream} for the specified resource, ignoring any specified
146+
* {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}.
145147
* @throws IOException if opening the InputStream failed
146148
* @see #requiresReader()
147149
* @see #getReader()
@@ -152,17 +154,17 @@ public InputStream getInputStream() throws IOException {
152154

153155

154156
@Override
155-
public boolean equals(Object obj) {
156-
if (obj == this) {
157+
public boolean equals(Object other) {
158+
if (this == other) {
157159
return true;
158160
}
159-
if (obj instanceof EncodedResource) {
160-
EncodedResource that = (EncodedResource) obj;
161-
return (this.resource.equals(that.resource) &&
162-
ObjectUtils.nullSafeEquals(this.charset, that.charset) &&
163-
ObjectUtils.nullSafeEquals(this.encoding, that.encoding));
161+
if (!(other instanceof EncodedResource)) {
162+
return false;
164163
}
165-
return false;
164+
EncodedResource otherResource = (EncodedResource) other;
165+
return (this.resource.equals(otherResource.resource) &&
166+
ObjectUtils.nullSafeEquals(this.charset, otherResource.charset) &&
167+
ObjectUtils.nullSafeEquals(this.encoding, otherResource.encoding));
166168
}
167169

168170
@Override
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 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,31 +16,24 @@
1616

1717
package org.springframework.tests;
1818

19-
import static java.lang.String.format;
20-
2119
import org.springframework.core.io.ClassPathResource;
2220

2321
/**
2422
* Convenience utilities for common operations with test resources.
2523
*
2624
* @author Chris Beams
2725
*/
28-
public class TestResourceUtils {
26+
public abstract class TestResourceUtils {
2927

3028
/**
31-
* Loads a {@link ClassPathResource} qualified by the simple name of clazz,
29+
* Load a {@link ClassPathResource} qualified by the simple name of clazz,
3230
* and relative to the package for clazz.
33-
*
3431
* <p>Example: given a clazz 'com.foo.BarTests' and a resourceSuffix of 'context.xml',
3532
* this method will return a ClassPathResource representing com/foo/BarTests-context.xml
36-
*
3733
* <p>Intended for use loading context configuration XML files within JUnit tests.
38-
*
39-
* @param clazz
40-
* @param resourceSuffix
4134
*/
4235
public static ClassPathResource qualifiedResource(Class<?> clazz, String resourceSuffix) {
43-
return new ClassPathResource(format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz);
36+
return new ClassPathResource(String.format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz);
4437
}
4538

4639
}

0 commit comments

Comments
 (0)