1
|
package eu.etaxonomy.cdm.vaadin.util;
|
2
|
|
3
|
import javax.servlet.ServletContext;
|
4
|
|
5
|
import org.springframework.context.ApplicationContext;
|
6
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
7
|
|
8
|
import com.vaadin.server.VaadinServlet;
|
9
|
import com.vaadin.server.VaadinSession;
|
10
|
|
11
|
public class CdmSpringContextHelper {
|
12
|
|
13
|
private ApplicationContext context;
|
14
|
|
15
|
private static CdmSpringContextHelper contextHelper;
|
16
|
|
17
|
private CdmSpringContextHelper(ServletContext servletContext) {
|
18
|
context = WebApplicationContextUtils.
|
19
|
getRequiredWebApplicationContext(servletContext);
|
20
|
|
21
|
}
|
22
|
|
23
|
|
24
|
public static CdmSpringContextHelper newInstance() {
|
25
|
if(VaadinServlet.getCurrent() == null || VaadinServlet.getCurrent().getServletContext() == null) {
|
26
|
throw new RuntimeException("Vaadin Servlet or Vaadin Servlet Context not initialized");
|
27
|
}
|
28
|
|
29
|
if(contextHelper == null) {
|
30
|
ServletContext sc = VaadinServlet.getCurrent().getServletContext();
|
31
|
contextHelper = new CdmSpringContextHelper(sc);
|
32
|
return contextHelper;
|
33
|
} else {
|
34
|
return contextHelper;
|
35
|
}
|
36
|
}
|
37
|
|
38
|
public Object getBean(final String beanRef) {
|
39
|
return context.getBean(beanRef);
|
40
|
}
|
41
|
}
|