| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package edu.sampleu.travel.infrastructure; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.log4j.Logger; |
| 20 | |
import org.springframework.context.ConfigurableApplicationContext; |
| 21 | |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | 0 | public class TravelServiceLocator { |
| 28 | 0 | private static final Logger LOG = Logger.getLogger(TravelServiceLocator.class); |
| 29 | |
|
| 30 | |
private static final String STANDARD_CONTEXT = "classpath:SampleAppBeans.xml"; |
| 31 | |
private static final String TEST_CONTEXT = "classpath:SampleAppBeans-test.xml"; |
| 32 | |
|
| 33 | |
private static ConfigurableApplicationContext appContext; |
| 34 | |
|
| 35 | |
public static synchronized void initialize(boolean test) { |
| 36 | 0 | if (appContext == null) { |
| 37 | |
final String[] resources; |
| 38 | |
|
| 39 | 0 | if (test) { |
| 40 | 0 | resources = new String[] { STANDARD_CONTEXT, TEST_CONTEXT }; |
| 41 | |
} else { |
| 42 | 0 | resources = new String[] { STANDARD_CONTEXT }; |
| 43 | |
} |
| 44 | 0 | LOG.info("Loading contexts: " + StringUtils.join(resources, ", ")); |
| 45 | 0 | appContext = new ClassPathXmlApplicationContext(resources); |
| 46 | |
} |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
public static synchronized ConfigurableApplicationContext getAppContext() { |
| 50 | 0 | return appContext; |
| 51 | |
} |
| 52 | |
} |