View Javadoc

1   /***
2    * 
3    */
4   package org.promotego.runmode;
5   
6   import java.util.LinkedList;
7   import java.util.List;
8   
9   import org.springframework.beans.factory.InitializingBean;
10  import org.springframework.beans.factory.annotation.Required;
11  import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
12  import org.springframework.core.io.ClassPathResource;
13  import org.springframework.core.io.Resource;
14  
15  /***
16   * @author alf
17   *
18   */
19  public class RunModePropertyPlaceholderConfigurer extends
20  		PropertyPlaceholderConfigurer implements InitializingBean
21  {
22  	private RunModeChooser m_runModeChooser;
23  
24  	@Required
25  	public void setRunModeChooser(RunModeChooser runModeChooser)
26  	{
27  		m_runModeChooser = runModeChooser;
28  	}
29  
30  	public void afterPropertiesSet() throws Exception
31  	{
32  		List<Resource> locations = new LinkedList<Resource>();
33  		
34  		locations.add(new ClassPathResource("app.properties"));
35  		RunMode runMode = m_runModeChooser.getRunMode();
36  		locations.add(new ClassPathResource(runMode.toString().toLowerCase() + ".properties"));
37  		
38  		if (runMode == RunMode.DEV)
39  		{
40  			locations.add(new ClassPathResource("local.properties"));
41  		}
42  		
43  		setLocations(locations.toArray(new Resource[locations.size()]));
44  	}
45  }