KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > connection > JRSpringLoadedHibernateConnection


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * JRSpringLoadedHibernateConnection.java
28  *
29  */

30
31 package it.businesslogic.ireport.connection;
32
33 import java.util.StringTokenizer JavaDoc;
34
35 import org.hibernate.SessionFactory;
36 import org.springframework.context.ApplicationContext;
37 import org.springframework.context.support.ClassPathXmlApplicationContext;
38
39 /**
40  *
41  *
42  * @author Jeffrey Payne
43  *
44  */

45
46 public class JRSpringLoadedHibernateConnection extends JRHibernateConnection {
47     
48     private final static String JavaDoc PROP_KEY_SPRING_CONFIG = "spring.loaded.hibernate.spring.config";
49     private final static String JavaDoc PROP_KEY_SESSION_FACTORY_ID = "spring.loaded.hibernate.session.factory.id";
50     
51     private String JavaDoc springConfig = null;
52     private String JavaDoc sessionFactoryBeanId = null;
53     
54     public String JavaDoc getDescription(){ return "Spring Loaded Hibernate connection"; }
55
56     
57     public ApplicationContext getApplicationContext() {
58         
59                 StringTokenizer JavaDoc parser = new StringTokenizer JavaDoc(getSpringConfig(), ",");
60                 String JavaDoc[] configs = new String JavaDoc[parser.countTokens()];
61                 int iCount = 0;
62                 while (parser.hasMoreTokens()) {
63                         configs[iCount++] = parser.nextToken();
64                 }
65                 return new ClassPathXmlApplicationContext(configs);
66     }
67
68     public String JavaDoc getSessionFactoryBeanId() {
69         return sessionFactoryBeanId;
70     }
71
72
73     public void setSessionFactoryBeanId(String JavaDoc sessionFactoryBeanId) {
74         this.sessionFactoryBeanId = sessionFactoryBeanId;
75     }
76
77
78     public String JavaDoc getSpringConfig() {
79         return springConfig;
80     }
81
82
83     public void setSpringConfig(String JavaDoc springConfig) {
84         this.springConfig = springConfig;
85     }
86     
87      public SessionFactory getSessionFactory() {
88          
89          return (SessionFactory)getApplicationContext().getBean(getSessionFactoryBeanId());
90          
91      }
92      
93         /*
94          * This method return all properties used by this connection
95          */

96         public java.util.HashMap JavaDoc getProperties()
97         {
98             java.util.HashMap JavaDoc map = new java.util.HashMap JavaDoc();
99             map.put(PROP_KEY_SESSION_FACTORY_ID, getSessionFactoryBeanId());
100             map.put(PROP_KEY_SPRING_CONFIG, getSpringConfig());
101             return map;
102         }
103
104         public void loadProperties(java.util.HashMap JavaDoc map)
105         {
106             setSessionFactoryBeanId((String JavaDoc)map.get(PROP_KEY_SESSION_FACTORY_ID));
107             setSpringConfig((String JavaDoc)map.get(PROP_KEY_SPRING_CONFIG));
108         }
109     
110 }
111
Popular Tags