16
16
17
17
package org .springframework .test .context .support ;
18
18
19
- import java .util .Arrays ;
20
- import java .util .List ;
21
-
22
19
import org .apache .commons .logging .Log ;
23
20
import org .apache .commons .logging .LogFactory ;
24
21
@@ -87,33 +84,36 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
87
84
protected abstract SmartContextLoader getAnnotationConfigLoader ();
88
85
89
86
90
- // SmartContextLoader
87
+ // ContextLoader
91
88
92
- private static void delegateProcessing (SmartContextLoader loader , ContextConfigurationAttributes configAttributes ) {
93
- if (logger .isDebugEnabled ()) {
94
- logger .debug (String .format ("Delegating to %s to process context configuration %s." ,
95
- name (loader ), configAttributes ));
96
- }
97
- loader .processContextConfiguration (configAttributes );
89
+ /**
90
+ * {@code AbstractDelegatingSmartContextLoader} does not support the
91
+ * {@link ContextLoader#processLocations(Class, String...)} method. Call
92
+ * {@link #processContextConfiguration(ContextConfigurationAttributes)} instead.
93
+ * @throws UnsupportedOperationException in this implementation
94
+ */
95
+ @ Override
96
+ public final String [] processLocations (Class <?> clazz , String ... locations ) {
97
+ throw new UnsupportedOperationException (
98
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
99
+ "Call processContextConfiguration(ContextConfigurationAttributes) instead." );
98
100
}
99
101
100
- private static ApplicationContext delegateLoading (SmartContextLoader loader , MergedContextConfiguration mergedConfig )
101
- throws Exception {
102
-
103
- if (logger .isDebugEnabled ()) {
104
- logger .debug (String .format ("Delegating to %s to load context from %s." , name (loader ), mergedConfig ));
105
- }
106
- return loader .loadContext (mergedConfig );
102
+ /**
103
+ * {@code AbstractDelegatingSmartContextLoader} does not support the
104
+ * {@link ContextLoader#loadContext(String...) } method. Call
105
+ * {@link #loadContext(MergedContextConfiguration)} instead.
106
+ * @throws UnsupportedOperationException in this implementation
107
+ */
108
+ @ Override
109
+ public final ApplicationContext loadContext (String ... locations ) throws Exception {
110
+ throw new UnsupportedOperationException (
111
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
112
+ "Call loadContext(MergedContextConfiguration) instead." );
107
113
}
108
114
109
- private boolean supports (SmartContextLoader loader , MergedContextConfiguration mergedConfig ) {
110
- if (loader == getAnnotationConfigLoader ()) {
111
- return (mergedConfig .hasClasses () && !mergedConfig .hasLocations ());
112
- }
113
- else {
114
- return (mergedConfig .hasLocations () && !mergedConfig .hasClasses ());
115
- }
116
- }
115
+
116
+ // SmartContextLoader
117
117
118
118
/**
119
119
* Delegates to candidate {@code SmartContextLoaders} to process the supplied
@@ -232,8 +232,7 @@ else if (configAttributes.hasClasses()) {
232
232
*/
233
233
@ Override
234
234
public ApplicationContext loadContext (MergedContextConfiguration mergedConfig ) throws Exception {
235
- Assert .notNull (mergedConfig , "mergedConfig must not be null" );
236
- List <SmartContextLoader > candidates = Arrays .asList (getXmlLoader (), getAnnotationConfigLoader ());
235
+ Assert .notNull (mergedConfig , "MergedContextConfiguration must not be null" );
237
236
238
237
if (mergedConfig .hasLocations () && mergedConfig .hasClasses ()) {
239
238
throw new IllegalStateException (String .format (
@@ -242,6 +241,7 @@ public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) t
242
241
name (getAnnotationConfigLoader ()), mergedConfig ));
243
242
}
244
243
244
+ SmartContextLoader [] candidates = {getXmlLoader (), getAnnotationConfigLoader ()};
245
245
for (SmartContextLoader loader : candidates ) {
246
246
// Determine if each loader can load a context from the mergedConfig. If it
247
247
// can, let it; otherwise, keep iterating.
@@ -259,41 +259,39 @@ public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) t
259
259
260
260
// else...
261
261
throw new IllegalStateException (String .format (
262
- "Neither %s nor %s was able to load an ApplicationContext from %s." , name ( getXmlLoader ()),
263
- name (getAnnotationConfigLoader ()), mergedConfig ));
262
+ "Neither %s nor %s was able to load an ApplicationContext from %s." ,
263
+ name (getXmlLoader ()), name ( getAnnotationConfigLoader ()), mergedConfig ));
264
264
}
265
265
266
- private static String name (SmartContextLoader loader ) {
267
- return loader .getClass ().getSimpleName ();
266
+
267
+ private static void delegateProcessing (SmartContextLoader loader , ContextConfigurationAttributes configAttributes ) {
268
+ if (logger .isDebugEnabled ()) {
269
+ logger .debug (String .format ("Delegating to %s to process context configuration %s." ,
270
+ name (loader ), configAttributes ));
271
+ }
272
+ loader .processContextConfiguration (configAttributes );
268
273
}
269
274
275
+ private static ApplicationContext delegateLoading (SmartContextLoader loader , MergedContextConfiguration mergedConfig )
276
+ throws Exception {
270
277
271
- // ContextLoader
278
+ if (logger .isDebugEnabled ()) {
279
+ logger .debug (String .format ("Delegating to %s to load context from %s." , name (loader ), mergedConfig ));
280
+ }
281
+ return loader .loadContext (mergedConfig );
282
+ }
272
283
273
- /**
274
- * {@code AbstractDelegatingSmartContextLoader} does not support the
275
- * {@link ContextLoader#processLocations(Class, String...)} method. Call
276
- * {@link #processContextConfiguration(ContextConfigurationAttributes)} instead.
277
- * @throws UnsupportedOperationException in this implementation
278
- */
279
- @ Override
280
- public final String [] processLocations (Class <?> clazz , String ... locations ) {
281
- throw new UnsupportedOperationException (
282
- "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
283
- "Call processContextConfiguration(ContextConfigurationAttributes) instead." );
284
+ private boolean supports (SmartContextLoader loader , MergedContextConfiguration mergedConfig ) {
285
+ if (loader == getAnnotationConfigLoader ()) {
286
+ return (mergedConfig .hasClasses () && !mergedConfig .hasLocations ());
287
+ }
288
+ else {
289
+ return (mergedConfig .hasLocations () && !mergedConfig .hasClasses ());
290
+ }
284
291
}
285
292
286
- /**
287
- * {@code AbstractDelegatingSmartContextLoader} does not support the
288
- * {@link ContextLoader#loadContext(String...) } method. Call
289
- * {@link #loadContext(MergedContextConfiguration)} instead.
290
- * @throws UnsupportedOperationException
291
- */
292
- @ Override
293
- public final ApplicationContext loadContext (String ... locations ) throws Exception {
294
- throw new UnsupportedOperationException (
295
- "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
296
- "Call loadContext(MergedContextConfiguration) instead." );
293
+ private static String name (SmartContextLoader loader ) {
294
+ return loader .getClass ().getSimpleName ();
297
295
}
298
296
299
297
}
0 commit comments