KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > runtime > jdo > kodo > Connector


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.runtime.jdo.kodo;
28
29
30 /**
31  * JDO Connector for Kodo.
32  *
33  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
34  *
35  * @version 0.1
36  */

37
38 public class Connector
39      extends org.objectweb.openccm.pss.runtime.jdo.lib.Connector
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     /** Configuration properties. */
48     java.util.Properties JavaDoc props_ = null;
49
50     // ==================================================================
51
//
52
// Constructor.
53
//
54
// ==================================================================
55

56     /**
57      * The default constructor.
58      */

59     public Connector()
60     {
61         super();
62     }
63
64     // ==================================================================
65
//
66
// Internal methods.
67
//
68
// ==================================================================
69

70     /**
71      * Load Kodo configuration file.
72      *
73      * @param file - The configuration file to load.
74      */

75     private void
76     load_kodo_properties(String JavaDoc file)
77     {
78         props_ = new java.util.Properties JavaDoc();
79
80         try {
81             java.io.InputStream JavaDoc propStream = null;
82     
83             propStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
84             props_.load(propStream);
85         }catch (Exception JavaDoc e) {
86             throw new RuntimeException JavaDoc(e);
87         }
88
89         System.getProperties().putAll(props_);
90     }
91
92     /**
93      * Get JDO generic Connector session parameters.
94      *
95      * @return JDO generic Connector session parameters.
96      */

97     private org.omg.CosPersistentState.Parameter[]
98     get_session_parameters()
99     {
100         org.omg.CosPersistentState.Parameter[] parameters = null;
101         org.omg.CosPersistentState.Parameter param = null;
102         org.omg.CORBA.Any JavaDoc a = null;
103         String JavaDoc value = null;
104
105         // Init parameters
106
parameters = new org.omg.CosPersistentState.Parameter[5];
107
108         a = org.objectweb.openccm.corba.TheORB.getORB().create_any();
109         value = System.getProperty("javax.jdo.option.ConnectionURL");
110         a.insert_string(value);
111         param = new org.omg.CosPersistentState.Parameter("DB_URL", a);
112         parameters[0] = param;
113         
114         a = org.objectweb.openccm.corba.TheORB.getORB().create_any();
115         value = System.getProperty("javax.jdo.option.ConnectionDriverName");
116         a.insert_string(value);
117         param = new org.omg.CosPersistentState.Parameter("DB_DRIVER", a);
118         parameters[1] = param;
119         
120         a = org.objectweb.openccm.corba.TheORB.getORB().create_any();
121         value = System.getProperty("javax.jdo.PersistenceManagerFactoryClass");
122         a.insert_string(value);
123         param = new org.omg.CosPersistentState.Parameter("PM_FACTORY", a);
124         parameters[2] = param;
125         
126         a = org.objectweb.openccm.corba.TheORB.getORB().create_any();
127         value = System.getProperty("javax.jdo.option.ConnectionUserName");
128         a.insert_string(value);
129         param = new org.omg.CosPersistentState.Parameter("USER_NAME", a);
130         parameters[3] = param;
131         
132         a = org.objectweb.openccm.corba.TheORB.getORB().create_any();
133         value = System.getProperty("javax.jdo.option.ConnectionPassword");
134         a.insert_string(value);
135         param = new org.omg.CosPersistentState.Parameter("PASSWORD", a);
136         parameters[4] = param;
137
138         return parameters;
139     }
140     
141     // ==================================================================
142
//
143
// Public methods.
144
//
145
// ==================================================================
146

147     // ==================================================================
148
//
149
// Methods for org.omg.CosPersistentState.Connector
150
//
151
// ==================================================================
152

153     /**
154      * Create a basic session.
155      */

156     public org.omg.CosPersistentState.Session
157     create_basic_session(short access_mode,
158                          org.omg.CosPersistentState.Parameter[] additional_parameters)
159     {
160         if (additional_parameters.length == 1)
161         {
162             org.omg.CosPersistentState.Parameter param = additional_parameters[0];
163
164             if (param.name.compareTo(Connector.CONF_FILE_KEY) == 0)
165             {
166                 load_kodo_properties( param.val.extract_string() );
167             }
168             else
169                 throw new RuntimeException JavaDoc("CONF_FILE parameter is missing!");
170         }
171         else
172             throw new RuntimeException JavaDoc("CONF_FILE parameter is missing!");
173
174         return super.create_basic_session(access_mode, get_session_parameters());
175     }
176
177     /**
178      * Create a transactional session.
179      */

180     public org.omg.CosPersistentState.TransactionalSession
181     create_transactional_session(short access_mode,
182                                  short default_isolation_level,
183                                  org.omg.CosPersistentState.EndOfAssociationCallback callback,
184                                  org.omg.CosPersistentState.Parameter[] additional_parameters)
185     {
186         // TO DO
187
return null;
188     }
189
190     /**
191      * Create a session pool.
192      */

193     public org.omg.CosPersistentState.SessionPool
194     create_session_pool(short access_mode,
195                         short tx_policy,
196                         org.omg.CosPersistentState.Parameter[] additional_parameters)
197     {
198         // TO DO
199
return null;
200     }
201
202     // ==================================================================
203
//
204
// Methods for org.objectweb.openccm.pss.runtime.api.Connector
205
//
206
// ==================================================================
207

208 }
209
210
Popular Tags