KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > runtime > common > lib > CatalogBase


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.common.lib;
28
29
30 /**
31  * CatalogBase is a base class for Catalog.
32  * It implements the org.objectweb.openccm.pss.runtime.api.Catalog interface.
33  *
34  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
35  *
36  * @version 0.1
37  */

38
39 public abstract class CatalogBase
40               extends org.omg.CORBA.LocalObject JavaDoc
41            implements org.objectweb.openccm.pss.runtime.common.api.CatalogBase
42 {
43     // ==================================================================
44
//
45
// Internal state.
46
//
47
// ==================================================================
48

49     /**
50      * Catalog ID.
51      */

52     private int _id;
53
54     /**
55      * Connector reference.
56      */

57     private org.objectweb.openccm.pss.runtime.common.api.Connector _connector;
58
59     /**
60      * Catalog access mode, i.e. READ_ONLY or READ_WRTIE.
61      */

62     private short _access_mode;
63
64     /**
65      * Managed storage home incarnations.
66      */

67     protected java.util.Map JavaDoc _storage_home_incarnations;
68
69     // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74

75     /**
76      * The default constructor.
77      *
78      * @param id - The catalog id.
79      */

80     public CatalogBase(int id)
81     {
82         _id = id;
83         _storage_home_incarnations = new java.util.HashMap JavaDoc();
84         _connector = null;
85     }
86
87     // ==================================================================
88
//
89
// Internal methods.
90
//
91
// ==================================================================
92

93     // ==================================================================
94
//
95
// Public methods.
96
//
97
// ==================================================================
98

99     // ==================================================================
100
//
101
// Methods for org.omg.CosPersistentState.Catalog
102
//
103
// ==================================================================
104

105     /**
106      * Read accessor for access_mode attribute.
107      *
108      * @return the attribute value.
109      */

110     public short
111     access_mode()
112     {
113         return _access_mode;
114     }
115
116     /**
117      * Find a storage home incarnation from its id.
118      */

119     public org.omg.CosPersistentState.StorageHomeBase
120     find_storage_home(String JavaDoc storage_home_id)
121     throws org.omg.CosPersistentState.NotFound
122     {
123         org.objectweb.openccm.pss.runtime.common.api.StorageHomeBase sh = null;
124
125         sh = (org.objectweb.openccm.pss.runtime.common.api.StorageHomeBase) _storage_home_incarnations.get(storage_home_id);
126
127         if (sh == null)
128         {
129             java.lang.Class JavaDoc clazz = null;
130
131             clazz = _connector.get_storage_home_factory(storage_home_id);
132             if (clazz == null)
133             {
134                 throw new org.omg.CosPersistentState.NotFound();
135             }
136
137             try
138             {
139                 sh = (org.objectweb.openccm.pss.runtime.common.api.StorageHomeBase) clazz.newInstance();
140                 sh.initialize(this);
141                 register_storage_home_incarnation(storage_home_id, sh);
142             }catch(Exception JavaDoc ex){
143                 ex.printStackTrace();
144                 throw new org.omg.CORBA.PERSIST_STORE JavaDoc("Problem in find_storage_home");
145             }
146         }
147
148         return sh;
149     }
150
151     /**
152      * Retrieve a storage object with its pid.
153      */

154     public abstract java.lang.Object JavaDoc
155     find_by_pid(byte[] the_pid)
156     throws org.omg.CosPersistentState.NotFound;
157
158     /**
159      * Operation flush
160      */

161     public abstract void
162     flush();
163
164     /**
165      * Operation refresh
166      */

167     public abstract void
168     refresh();
169
170     /**
171      * Operation free_all
172      */

173     public abstract void
174     free_all();
175
176     /**
177      * Operation close
178      */

179     public abstract void
180     close();
181
182     // ==================================================================
183
//
184
// Methods for org.objectweb.openccm.pss.runtime.common.api.CatalogBase
185
//
186
// ==================================================================
187

188     /**
189      * Set the reference to the connector.
190      *
191      * @param connector - The connector to set.
192      */

193     public void
194     set_connector(org.objectweb.openccm.pss.runtime.common.api.Connector connector)
195     {
196         _connector = connector;
197     }
198
199     /**
200      * Get the reference to the connector.
201      *
202      * @return The associated connector.
203      */

204     public org.objectweb.openccm.pss.runtime.common.api.Connector
205     get_connector()
206     {
207         return _connector;
208     }
209
210     /**
211      * Get the catalog ID.
212      *
213      * @return The associated ID.
214      */

215     public int
216     get_id()
217     {
218         return _id;
219     }
220
221    /**
222      * Register a storage home incarnation.
223      *
224      * @param storage_home_id - The storage home id.
225      * @param storage_home - The binding class.
226      */

227     public void
228     register_storage_home_incarnation(String JavaDoc storage_home_id,
229                                       org.omg.CosPersistentState.StorageHomeBase storage_home)
230     {
231         _storage_home_incarnations.put(storage_home_id, storage_home);
232     }
233
234     /**
235      * Create a new storage_object incarnation.
236      *
237      * @param storage_type_id - The storage type id.
238      *
239      * @return A new storage object instance.
240      */

241     public org.objectweb.openccm.pss.runtime.common.api.StorageObject
242     create_storage_object(String JavaDoc storage_type_id)
243     throws org.omg.CosPersistentState.NotFound
244     {
245         java.lang.Class JavaDoc clazz = null;
246
247         clazz = get_connector().get_storage_object_factory(storage_type_id);
248         if (clazz == null)
249         {
250             throw new org.omg.CosPersistentState.NotFound();
251         }
252
253         try
254         {
255             return (org.objectweb.openccm.pss.runtime.common.api.StorageObject) clazz.newInstance();
256         }catch(Exception JavaDoc ex){
257             ex.printStackTrace();
258             throw new org.omg.CORBA.PERSIST_STORE JavaDoc("Problem in create_storage_object");
259         }
260     }
261 }
262
Popular Tags