cc452f67a965301d285676d3640f6dff839a9a30
[JavaForFun] /
1 package de.spring.example;
2
3 import org.springframework.context.ApplicationContext;
4 import org.springframework.context.support.ClassPathXmlApplicationContext;
5
6
7 /**
8  * Localizador de beans para de los dispositivos
9  *
10  * @author rvp001es
11  */
12 public final class SpringContextLocator {
13
14
15         // Singleton Pattern
16         private static SpringContextLocator instance;
17
18         // Spring ApplicationContext
19         private static ApplicationContext context;
20
21         // Dispositivos logicos
22         private static final String SPRING_CONFIG_CONTEXT="spring-config.xml";
23         //private static final String DATABASE_CONFIG="database-config.xml";
24
25         
26         /**
27          * Private constructor. Singleton pattern.
28          */
29         private SpringContextLocator() {
30                 String[] factoryFiles = null;
31                 System.out.println("Loading files context " + 
32                                                                                 SpringContextLocator.SPRING_CONFIG_CONTEXT);
33
34                 factoryFiles = new String[] { SPRING_CONFIG_CONTEXT };
35                 
36                 SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles);
37
38                 System.out.println("The N2A devices context and test " +
39                                                                                 "context has been loaded successfully!! ");
40         }
41
42         /**
43          * Singleton pattern. GetInstance()
44          */
45         public synchronized static SpringContextLocator getInstance() {
46                 if (SpringContextLocator.instance == null) {
47                         SpringContextLocator.instance = new SpringContextLocator();
48                 }
49                 return SpringContextLocator.instance;
50         }
51
52         /**
53          * Return a bean in application context.
54          */
55         public Object getBean(final String name) {
56                 return SpringContextLocator.context.getBean(name);
57         }
58 }