1 package eu
.etaxonomy
.cdm
.vaadin
.util
;
3 import java
.sql
.Connection
;
4 import java
.sql
.SQLException
;
6 import javax
.servlet
.ServletContext
;
7 import javax
.sql
.DataSource
;
9 import org
.springframework
.context
.ApplicationContext
;
10 import org
.springframework
.web
.context
.support
.WebApplicationContextUtils
;
12 import com
.vaadin
.data
.util
.sqlcontainer
.connection
.J2EEConnectionPool
;
13 import com
.vaadin
.data
.util
.sqlcontainer
.connection
.JDBCConnectionPool
;
14 import com
.vaadin
.server
.VaadinServlet
;
16 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
17 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
18 import eu
.etaxonomy
.cdm
.api
.service
.ICommonService
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
24 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
28 public class CdmSpringContextHelper
{
30 private final ApplicationContext context
;
31 private final DataSource dataSource
;
33 private final JDBCConnectionPool connPool
;
34 private static CdmSpringContextHelper contextHelper
;
36 private CdmSpringContextHelper(ServletContext servletContext
) throws SQLException
{
37 context
= WebApplicationContextUtils
.
38 getRequiredWebApplicationContext(servletContext
);
39 dataSource
= (DataSource
)getBean("dataSource");
40 connPool
= new J2EEConnectionPool(dataSource
);
45 public static CdmSpringContextHelper
getCurrent() {
46 if(VaadinServlet
.getCurrent() == null || VaadinServlet
.getCurrent().getServletContext() == null) {
47 throw new RuntimeException("Vaadin Servlet or Vaadin Servlet Context not initialized");
50 if(contextHelper
== null) {
51 ServletContext sc
= VaadinServlet
.getCurrent().getServletContext();
53 contextHelper
= new CdmSpringContextHelper(sc
);
54 } catch (SQLException e
) {
55 // TODO Auto-generated catch block
63 public Object
getBean(final String beanRef
) {
64 return context
.getBean(beanRef
);
67 public Object
getBean(Class clazz
) {
68 return context
.getBean(clazz
);
71 public <T
extends IService
> T
getService(Class
<T
> clazz
) {
72 return context
.getBean(clazz
);
75 public DataSource
getDataSource() {
79 public JDBCConnectionPool
getConnectionPool() {
83 // public static JDBCConnectionPool createConnectionPool() {
84 // return new J2EEConnectionPool(getCurrent().getDataSource());
87 // public static JDBCConnectionPool getConnectionPool() {
88 // return new J2EEConnectionPool(getCurrent().getDataSource());
93 public static Connection
getConnection() throws SQLException
{
94 return getCurrent().getDataSource().getConnection();
97 public static ICdmApplicationConfiguration
getApplicationConfiguration() {
98 return (ICdmApplicationConfiguration
) getCurrent().getBean("cdmApplicationDefaultConfiguration");
100 public static ITaxonService
getTaxonService() {
101 return (ITaxonService
)getCurrent().getBean(ITaxonService
.class);
104 public static ITaxonNodeService
getTaxonNodeService() {
105 return (ITaxonNodeService
)getCurrent().getBean(ITaxonNodeService
.class);
108 public static IReferenceService
getReferenceService() {
109 return (IReferenceService
)getCurrent().getBean(IReferenceService
.class);
112 public static INameService
getNameService() {
113 return (INameService
)getCurrent().getBean(INameService
.class);
116 public static ICommonService
getCommonService() {
117 return (ICommonService
)getCurrent().getBean(ICommonService
.class);
120 public static IClassificationService
getClassificationService() {
121 return (IClassificationService
)getCurrent().getBean(IClassificationService
.class);
124 public static IVocabularyService
getVocabularyService() {
125 return (IVocabularyService
)getCurrent().getBean(IVocabularyService
.class);
128 public static ITermService
getTermService() {
129 return (ITermService
)getCurrent().getBean(ITermService
.class);
132 public static IDescriptionService
getDescriptionService() {
133 return (IDescriptionService
)getCurrent().getBean(IDescriptionService
.class);