1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
67
67
* not result in an exception.
68
68
*
69
69
* @author Sam Brannen
70
+ * @author Phillip Webb
70
71
* @since 3.2
71
72
* @see SmartContextLoader
72
73
*/
@@ -86,16 +87,13 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
86
87
*/
87
88
protected abstract SmartContextLoader getAnnotationConfigLoader ();
88
89
89
- // --- SmartContextLoader --------------------------------------------------
90
90
91
- private static String name (SmartContextLoader loader ) {
92
- return loader .getClass ().getSimpleName ();
93
- }
91
+ // SmartContextLoader
94
92
95
93
private static void delegateProcessing (SmartContextLoader loader , ContextConfigurationAttributes configAttributes ) {
96
94
if (logger .isDebugEnabled ()) {
97
- logger .debug (String .format ("Delegating to %s to process context configuration %s." , name ( loader ),
98
- configAttributes ));
95
+ logger .debug (String .format ("Delegating to %s to process context configuration %s." ,
96
+ name ( loader ), configAttributes ));
99
97
}
100
98
loader .processContextConfiguration (configAttributes );
101
99
}
@@ -111,10 +109,10 @@ private static ApplicationContext delegateLoading(SmartContextLoader loader, Mer
111
109
112
110
private boolean supports (SmartContextLoader loader , MergedContextConfiguration mergedConfig ) {
113
111
if (loader == getAnnotationConfigLoader ()) {
114
- return mergedConfig .hasClasses () && !mergedConfig .hasLocations ();
112
+ return ( mergedConfig .hasClasses () && !mergedConfig .hasLocations () );
115
113
}
116
114
else {
117
- return mergedConfig .hasLocations () && !mergedConfig .hasClasses ();
115
+ return ( mergedConfig .hasLocations () && !mergedConfig .hasClasses () );
118
116
}
119
117
}
120
118
@@ -152,9 +150,9 @@ private boolean supports(SmartContextLoader loader, MergedContextConfiguration m
152
150
@ Override
153
151
public void processContextConfiguration (final ContextConfigurationAttributes configAttributes ) {
154
152
Assert .notNull (configAttributes , "configAttributes must not be null" );
155
- Assert .isTrue (!(configAttributes .hasLocations () && configAttributes .hasClasses ()), () -> String . format (
156
- "Cannot process locations AND classes for context configuration %s: "
157
- + "configure one or the other, but not both." , configAttributes ));
153
+ Assert .isTrue (!(configAttributes .hasLocations () && configAttributes .hasClasses ()),
154
+ () -> String . format ( "Cannot process locations AND classes for context configuration %s: " +
155
+ "configure one or the other, but not both." , configAttributes ));
158
156
159
157
// If the original locations or classes were not empty, there's no
160
158
// need to bother with default detection checks; just let the
@@ -175,7 +173,7 @@ else if (configAttributes.hasClasses()) {
175
173
if (xmlLoaderDetectedDefaults ) {
176
174
if (logger .isInfoEnabled ()) {
177
175
logger .info (String .format ("%s detected default locations for context configuration %s." ,
178
- name (getXmlLoader ()), configAttributes ));
176
+ name (getXmlLoader ()), configAttributes ));
179
177
}
180
178
}
181
179
@@ -188,9 +186,8 @@ else if (configAttributes.hasClasses()) {
188
186
189
187
if (configAttributes .hasClasses ()) {
190
188
if (logger .isInfoEnabled ()) {
191
- logger .info (String .format (
192
- "%s detected default configuration classes for context configuration %s." ,
193
- name (getAnnotationConfigLoader ()), configAttributes ));
189
+ logger .info (String .format ("%s detected default configuration classes for context configuration %s." ,
190
+ name (getAnnotationConfigLoader ()), configAttributes ));
194
191
}
195
192
}
196
193
@@ -199,12 +196,12 @@ else if (configAttributes.hasClasses()) {
199
196
name (getAnnotationConfigLoader ()), configAttributes ));
200
197
201
198
if (configAttributes .hasLocations () && configAttributes .hasClasses ()) {
202
- String message = String .format (
203
- "Configuration error: both default locations AND default configuration classes "
204
- + "were detected for context configuration %s; configure one or the other, but not both." ,
205
- configAttributes );
206
- logger .error (message );
207
- throw new IllegalStateException (message );
199
+ String msg = String .format (
200
+ "Configuration error: both default locations AND default configuration classes " +
201
+ "were detected for context configuration %s; configure one or the other, but not both." ,
202
+ configAttributes );
203
+ logger .error (msg );
204
+ throw new IllegalStateException (msg );
208
205
}
209
206
}
210
207
}
@@ -235,8 +232,8 @@ public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) t
235
232
List <SmartContextLoader > candidates = Arrays .asList (getXmlLoader (), getAnnotationConfigLoader ());
236
233
237
234
Assert .state (!(mergedConfig .hasLocations () && mergedConfig .hasClasses ()), () -> String .format (
238
- "Neither %s nor %s supports loading an ApplicationContext from %s: "
239
- + "declare either 'locations' or 'classes' but not both." , name (getXmlLoader ()),
235
+ "Neither %s nor %s supports loading an ApplicationContext from %s: " +
236
+ "declare either 'locations' or 'classes' but not both." , name (getXmlLoader ()),
240
237
name (getAnnotationConfigLoader ()), mergedConfig ));
241
238
242
239
for (SmartContextLoader loader : candidates ) {
@@ -256,34 +253,41 @@ public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) t
256
253
257
254
// else...
258
255
throw new IllegalStateException (String .format (
259
- "Neither %s nor %s was able to load an ApplicationContext from %s." , name (getXmlLoader ()),
260
- name (getAnnotationConfigLoader ()), mergedConfig ));
256
+ "Neither %s nor %s was able to load an ApplicationContext from %s." , name (getXmlLoader ()),
257
+ name (getAnnotationConfigLoader ()), mergedConfig ));
261
258
}
262
259
263
- // --- ContextLoader -------------------------------------------------------
260
+ private static String name (SmartContextLoader loader ) {
261
+ return loader .getClass ().getSimpleName ();
262
+ }
263
+
264
+
265
+ // ContextLoader
264
266
265
267
/**
266
268
* {@code AbstractDelegatingSmartContextLoader} does not support the
267
269
* {@link ContextLoader#processLocations(Class, String...)} method. Call
268
270
* {@link #processContextConfiguration(ContextConfigurationAttributes)} instead.
269
- * @throws UnsupportedOperationException
271
+ * @throws UnsupportedOperationException in this implementation
270
272
*/
271
273
@ Override
272
274
public final String [] processLocations (Class <?> clazz , @ Nullable String ... locations ) {
273
- throw new UnsupportedOperationException ("DelegatingSmartContextLoaders do not support the ContextLoader SPI. "
274
- + "Call processContextConfiguration(ContextConfigurationAttributes) instead." );
275
+ throw new UnsupportedOperationException (
276
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
277
+ "Call processContextConfiguration(ContextConfigurationAttributes) instead." );
275
278
}
276
279
277
280
/**
278
281
* {@code AbstractDelegatingSmartContextLoader} does not support the
279
282
* {@link ContextLoader#loadContext(String...) } method. Call
280
283
* {@link #loadContext(MergedContextConfiguration)} instead.
281
- * @throws UnsupportedOperationException
284
+ * @throws UnsupportedOperationException in this implementation
282
285
*/
283
286
@ Override
284
287
public final ApplicationContext loadContext (String ... locations ) throws Exception {
285
- throw new UnsupportedOperationException ("DelegatingSmartContextLoaders do not support the ContextLoader SPI. "
286
- + "Call loadContext(MergedContextConfiguration) instead." );
288
+ throw new UnsupportedOperationException (
289
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
290
+ "Call loadContext(MergedContextConfiguration) instead." );
287
291
}
288
292
289
293
}
0 commit comments