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.kuali.rice.kns.util.spring.ClassPathXmlApplicationContext;
21  import org.springframework.context.ConfigurableApplicationContext;
22  
23  
24  
25  
26  
27  public class TravelServiceLocator {
28      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  		if (appContext == null) {
37  		    final String[] resources;
38  		    
39  		    if (test) {
40  		        resources = new String[] { STANDARD_CONTEXT, TEST_CONTEXT };
41  		    } else {
42  		        resources = new String[] { STANDARD_CONTEXT };
43  		    }
44  		    LOG.info("Loading contexts: " + StringUtils.join(resources, ", "));
45  			appContext = new ClassPathXmlApplicationContext(resources);
46  		}
47  	}
48  
49  	public static synchronized ConfigurableApplicationContext getAppContext() {
50  		return appContext;
51  	}	
52  }