KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > Repository_impl


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): Philippe Merle.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 // Package dependencies
30
import org.omg.CORBA.*;
31
32 /**
33  * Implementation of the CORBA::Repository interface.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
37  *
38  * @version 0.4
39  */

40
41 public class Repository_impl
42              extends Container_impl
43              implements RepositoryOperations
44 {
45     // ==================================================================
46
//
47
// Constructor.
48
//
49
// ==================================================================
50

51     /**
52      * TODO
53      */

54     public
55     Repository_impl(IFR ifr)
56     {
57         // call the Contained_impl contructor.
58
this(ifr, false);
59     }
60
61     /**
62      * TODO
63      *
64      * @param ifr
65      * @param enable_mappings
66      */

67     public
68     Repository_impl(IFR ifr,
69                     boolean enable_mappings)
70     {
71         // call the Contained_impl contructor.
72
super(ifr, null);
73
74         // set the tie servant object.
75
setServant(new RepositoryPOATie(this));
76
77         //
78
// create the PrimitiveDef objects.
79
//
80
primDef_null_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_null);
81         primDef_void_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_void);
82         primDef_short_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_short);
83         primDef_long_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_long);
84         primDef_ushort_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_ushort);
85         primDef_ulong_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_ulong);
86         primDef_float_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_float);
87         primDef_double_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_double);
88         primDef_boolean_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_boolean);
89         primDef_char_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_char);
90         primDef_octet_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_octet);
91         primDef_any_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_any);
92         primDef_TypeCode_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_TypeCode);
93         primDef_Principal_ = new PrimitiveDef_impl(ifr,
94                                                    PrimitiveKind.pk_Principal);
95         primDef_string_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_string);
96         primDef_objref_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_objref);
97         primDef_longlong_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_longlong);
98         primDef_ulonglong_ = new PrimitiveDef_impl(ifr,
99                                                    PrimitiveKind.pk_ulonglong);
100         primDef_longdouble_ = new PrimitiveDef_impl(ifr,
101                                                     PrimitiveKind.pk_longdouble);
102         primDef_wchar_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_wchar);
103         primDef_wstring_ = new PrimitiveDef_impl(ifr, PrimitiveKind.pk_wstring);
104         primDef_value_base_ = new PrimitiveDef_impl(ifr,
105                                                     PrimitiveKind.pk_value_base);
106
107         // creates the repository ID list.
108
repID_elements_ = new java.util.Hashtable JavaDoc();
109         mapped_elements_ = new java.util.Hashtable JavaDoc();
110
111         // Init internal state.
112
isIDL2Repository_ = true;
113         enable_mappings_ = enable_mappings;
114     }
115
116     // ==================================================================
117
//
118
// Internal state.
119
//
120
// ==================================================================
121

122     /**
123      * TODO
124      */

125     protected boolean isIDL2Repository_;
126
127     /**
128      * TODO
129      */

130     protected boolean enable_mappings_;
131
132     /**
133      * All the PrimitiveDef objects.
134      */

135     protected PrimitiveDef_impl primDef_null_;
136     protected PrimitiveDef_impl primDef_void_;
137     protected PrimitiveDef_impl primDef_short_;
138     protected PrimitiveDef_impl primDef_long_;
139     protected PrimitiveDef_impl primDef_ushort_;
140     protected PrimitiveDef_impl primDef_ulong_;
141     protected PrimitiveDef_impl primDef_float_;
142     protected PrimitiveDef_impl primDef_double_;
143     protected PrimitiveDef_impl primDef_boolean_;
144     protected PrimitiveDef_impl primDef_char_;
145     protected PrimitiveDef_impl primDef_octet_;
146     protected PrimitiveDef_impl primDef_any_;
147     protected PrimitiveDef_impl primDef_TypeCode_;
148     protected PrimitiveDef_impl primDef_Principal_;
149     protected PrimitiveDef_impl primDef_string_;
150     protected PrimitiveDef_impl primDef_objref_;
151     protected PrimitiveDef_impl primDef_longlong_;
152     protected PrimitiveDef_impl primDef_ulonglong_;
153     protected PrimitiveDef_impl primDef_longdouble_;
154     protected PrimitiveDef_impl primDef_wchar_;
155     protected PrimitiveDef_impl primDef_wstring_;
156     protected PrimitiveDef_impl primDef_value_base_;
157
158     /**
159      * All the Contained objects.
160      */

161     protected java.util.Hashtable JavaDoc repID_elements_;
162
163     /**
164      * All the Contained objects that comes from a mapping.
165      */

166     protected java.util.Hashtable JavaDoc mapped_elements_;
167
168     // ==================================================================
169
//
170
// Public methods.
171
//
172
// ==================================================================
173

174     /**
175      * To know if the repository is viewed as an IDL2 or IDL3 repository.
176      */

177     public boolean
178     isIDL2Repository()
179     {
180         return isIDL2Repository_;
181     }
182
183     /**
184      * Obtain its CORBA::Repository object reference.
185      */

186     public Repository
187     asRepository()
188     {
189         return RepositoryHelper.narrow(asObject());
190     }
191
192     /**
193      * Add a Contained_impl object.
194      */

195     public void
196     addRID(String JavaDoc id, Contained_impl contained)
197     {
198         if (contained.container_.mapping_started_)
199             mapped_elements_.put(id, contained);
200         else
201             repID_elements_.put(id, contained);
202     }
203
204     /**
205      * Remove a Contained_impl object.
206      */

207     public void
208     removeRID(String JavaDoc id)
209     {
210          mapped_elements_.remove(id);
211          repID_elements_.remove(id);
212     }
213
214     /**
215      * Obtain a Contained_impl object by its repository ID.
216      */

217     public Contained_impl
218     getRID(String JavaDoc id)
219     {
220         if (!isIDL2Repository())
221             return (Contained_impl)repID_elements_.get(id);
222
223         java.lang.Object JavaDoc obj = mapped_elements_.get(id);
224         if (obj!=null)
225             return (Contained_impl)obj;
226
227         return (Contained_impl)repID_elements_.get(id);
228     }
229
230     /**
231      * Obtain a Contained_impl object by its repository ID.
232      */

233     public Contained_impl
234     getMappedRID(String JavaDoc id)
235     {
236         return (Contained_impl)mapped_elements_.get(id);
237     }
238
239     /**
240      * Obtain the PrimitiveDef for the void type.
241      */

242     public PrimitiveDef_impl
243     getPrimDefVoid()
244     {
245         return primDef_void_;
246     }
247
248     // ==================================================================
249
//
250
// For Contained_impl class.
251
//
252
// ==================================================================
253

254     /**
255      * To set the value field of the CORBA::Contained::Description struct.
256      *
257      * Do nothing because this method is here due to the lack of
258      * multiple inheritance in Java!
259      */

260     public void
261     setDescriptionValue(Any any)
262     {
263        // Nothing to do!
264
}
265
266     // ==================================================================
267
//
268
// For CORBA::IRObject interface.
269
//
270
// ==================================================================
271

272     /**
273      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
274      */

275     public DefinitionKind
276     def_kind()
277     {
278         return DefinitionKind.dk_Repository;
279     }
280
281     /**
282      * IDL:omg.org/CORBA/IRObject/destroy:1.0
283      */

284     public void
285     destroy()
286     {
287         // this is an indestructible IFR object!
288
throw exceptionCanNotBeDestroyed();
289     }
290
291     // ==================================================================
292
//
293
// For CORBA::Contained interface.
294
//
295
// ==================================================================
296

297     /**
298      * IDL:omg.org/CORBA/Container/lookup:1.0
299      */

300     public Contained
301     lookup(String JavaDoc search_name)
302     {
303         // Remove the :: at the begining of the search_name.
304
while(search_name.startsWith("::"))
305             search_name = search_name.substring(2);
306
307         // Call the Container_impl::lookup() operation.
308
return super.lookup(search_name);
309     }
310
311     // ==================================================================
312
//
313
// For CORBA::Repository interface.
314
//
315
// ==================================================================
316

317     /**
318      * IDL:omg.org/CORBA/Repository/lookup_id:1.0
319      */

320     public Contained
321     lookup_id(String JavaDoc search_id)
322     {
323         Contained_impl contained = getRID(search_id);
324
325         // If not found then returns a nil contained reference.
326
if (contained == null) return null;
327         
328         return contained.asContained();
329     }
330
331     /**
332      * IDL:omg.org/CORBA/Repository/get_canonical_typecode:1.0
333      */

334     public TypeCode
335     get_canonical_typecode(TypeCode tc)
336     {
337         // Something to do?
338
// But this depends on the ORB!
339
return tc;
340     }
341
342     /**
343      * IDL:omg.org/CORBA/Repository/get_primitive:1.0
344      */

345     public PrimitiveDef
346     get_primitive(PrimitiveKind kind)
347     {
348         switch(kind.value())
349         {
350         case PrimitiveKind._pk_null:
351         return primDef_null_.asPrimitiveDef();
352
353         case PrimitiveKind._pk_void:
354         return primDef_void_.asPrimitiveDef();
355
356         case PrimitiveKind._pk_short:
357         return primDef_short_.asPrimitiveDef();
358
359         case PrimitiveKind._pk_long:
360         return primDef_long_.asPrimitiveDef();
361
362         case PrimitiveKind._pk_ushort:
363         return primDef_ushort_.asPrimitiveDef();
364
365         case PrimitiveKind._pk_ulong:
366         return primDef_ulong_.asPrimitiveDef();
367
368         case PrimitiveKind._pk_float:
369         return primDef_float_.asPrimitiveDef();
370
371         case PrimitiveKind._pk_double:
372         return primDef_double_.asPrimitiveDef();
373
374         case PrimitiveKind._pk_boolean:
375         return primDef_boolean_.asPrimitiveDef();
376
377         case PrimitiveKind._pk_char:
378         return primDef_char_.asPrimitiveDef();
379
380         case PrimitiveKind._pk_octet:
381         return primDef_octet_.asPrimitiveDef();
382
383         case PrimitiveKind._pk_any:
384         return primDef_any_.asPrimitiveDef();
385
386         case PrimitiveKind._pk_TypeCode:
387         return primDef_TypeCode_.asPrimitiveDef();
388
389         case PrimitiveKind._pk_Principal:
390         return primDef_Principal_.asPrimitiveDef();
391
392         case PrimitiveKind._pk_string:
393         return primDef_string_.asPrimitiveDef();
394
395         case PrimitiveKind._pk_objref:
396         return primDef_objref_.asPrimitiveDef();
397
398         case PrimitiveKind._pk_longlong:
399         return primDef_longlong_.asPrimitiveDef();
400
401         case PrimitiveKind._pk_ulonglong:
402         return primDef_ulonglong_.asPrimitiveDef();
403
404         case PrimitiveKind._pk_longdouble:
405         return primDef_longdouble_.asPrimitiveDef();
406
407         case PrimitiveKind._pk_wchar:
408         return primDef_wchar_.asPrimitiveDef();
409
410         case PrimitiveKind._pk_wstring:
411         return primDef_wstring_.asPrimitiveDef();
412
413         case PrimitiveKind._pk_value_base:
414         return primDef_value_base_.asPrimitiveDef();
415         }
416
417        return null;
418     }
419
420     /**
421      * IDL:omg.org/CORBA/Repository/create_string:1.0
422      */

423     public StringDef
424     create_string(int bound)
425     {
426         StringDef_impl s = new StringDef_impl(getIFR());
427
428         try
429         {
430             s.bound(bound);
431         }
432         catch(SystemException exc)
433         {
434             s.destroy();
435             throw exc;
436         }
437
438         return s.asStringDef();
439     }
440
441     /**
442      * IDL:omg.org/CORBA/Repository/create_wstring:1.0
443      */

444     public WstringDef
445     create_wstring(int bound)
446     {
447         WstringDef_impl s = new WstringDef_impl(getIFR());
448
449         try
450         {
451             s.bound(bound);
452         }
453         catch(SystemException exc)
454         {
455             s.destroy();
456             throw exc;
457         }
458
459         return s.asWstringDef();
460     }
461
462     /**
463      * IDL:omg.org/CORBA/Repository/create_sequence:1.0
464      */

465     public SequenceDef
466     create_sequence(int bound,
467                     IDLType element_type)
468     {
469         SequenceDef_impl s = new SequenceDef_impl(getIFR());
470
471         try {
472             s.bound(bound);
473             s.element_type_def(element_type);
474         } catch(SystemException exc) {
475             s.destroy();
476             throw exc;
477         }
478
479         return s.asSequenceDef();
480     }
481
482     /**
483      * IDL:omg.org/CORBA/Repository/create_array:1.0
484      */

485     public ArrayDef
486     create_array(int length,
487                  IDLType element_type)
488     {
489         ArrayDef_impl a = new ArrayDef_impl(getIFR());
490
491         try
492         {
493             a.length(length);
494             a.element_type_def(element_type);
495         }
496         catch(SystemException exc)
497         {
498             a.destroy();
499             throw exc;
500         }
501
502         return a.asArrayDef();
503     }
504
505     /**
506      * IDL:omg.org/CORBA/Repository/create_fixed:1.0
507      */

508     public FixedDef
509     create_fixed(short digits,
510                  short scale)
511     {
512         FixedDef_impl f = new FixedDef_impl(getIFR());
513
514         try
515         {
516             f.digits(digits);
517             f.scale(scale);
518         }
519         catch(SystemException exc)
520         {
521             f.destroy();
522             throw exc;
523         }
524
525         return f.asFixedDef();
526     }
527 }
528
Popular Tags