KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ast > lib > Repository


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

26
27 package org.objectweb.openccm.ast.lib;
28
29 /** To access AST TypeKind. */
30 import org.objectweb.openccm.ast.api.TypeKind;
31
32 /** To access AST TypeRef. */
33 import org.objectweb.openccm.ast.api.TypeRef;
34
35 /** To access AST PsdlTypeRef. */
36 import org.objectweb.openccm.ast.api.PsdlTypeRef;
37
38 /** To access AST DeclarationKind. */
39 import org.objectweb.openccm.ast.api.DeclarationKind;
40
41 /** To access AST Declaration. */
42 import org.objectweb.openccm.ast.api.Declaration;
43
44 /** To access AST Scope. */
45 import org.objectweb.openccm.ast.api.Scope;
46
47 /** To access AST AnyValue. */
48 import org.objectweb.openccm.ast.api.AnyValue;
49
50 /** To manipulate CORBA::PrimitiveKind. */
51 import org.omg.CORBA.PrimitiveKind JavaDoc;
52
53 /**
54  * Main class of the OMG IDL / PSDL / CIDL Abstract Syntax Tree.
55  *
56  * This provides the factory of any values and primitive TypeRefs,
57  * and some parser helper functions like startFileScope and
58  * import ones.
59  *
60  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
61  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
62  *
63  * @version 0.3
64  */

65
66 public class Repository
67        extends ScopeImpl
68        implements org.objectweb.openccm.ast.api.AST
69 {
70     // ==================================================================
71
//
72
// Internal state.
73
//
74
// ==================================================================
75

76     /** Reference to the PrimitiveDef for the null type. */
77     private TypeRefImpl null_ = null;
78
79     /** Reference to the PrimitiveDef for the void type. */
80     private TypeRefImpl void_ = null;
81
82     /** Reference to the PrimitiveDef for the short type. */
83     private TypeRefImpl short_ = null;
84
85     /** Reference to the PrimitiveDef for the long type. */
86     private TypeRefImpl long_ = null;
87
88     /** Reference to the PrimitiveDef for the unsigned short type. */
89     private TypeRefImpl unsigned_short_ = null;
90
91     /** Reference to the PrimitiveDef for the unsigned long type. */
92     private TypeRefImpl unsigned_long_ = null;
93
94     /** Reference to the PrimitiveDef for the float type. */
95     private TypeRefImpl float_ = null;
96
97     /** Reference to the PrimitiveDef for the double type. */
98     private TypeRefImpl double_ = null;
99
100     /** Reference to the PrimitiveDef for the boolean type. */
101     private TypeRefImpl boolean_ = null;
102
103     /** Reference to the PrimitiveDef for the char type. */
104     private TypeRefImpl char_ = null;
105
106     /** Reference to the PrimitiveDef for the octet type. */
107     private TypeRefImpl octet_ = null;
108
109     /** Reference to the PrimitiveDef for the any type. */
110     private TypeRefImpl any_ = null;
111
112     /** Reference to the PrimitiveDef for the TypeCode type. */
113     private TypeRefImpl TypeCode_ = null;
114
115     /** Reference to the PrimitiveDef for the Principal type. */
116     private TypeRefImpl Principal_ = null;
117
118     /** Reference to the PrimitiveDef for the string type. */
119     private TypeRefImpl string_ = null;
120
121     /** Reference to the PrimitiveDef for the Object type. */
122     private TypeRefImpl object_ = null;
123
124     /** Reference to the PrimitiveDef for the long long type. */
125     private TypeRefImpl long_long_ = null;
126
127     /** Reference to the PrimitiveDef for the unsigned long long type. */
128     private TypeRefImpl unsigned_long_long_ = null;
129
130     /** Reference to the PrimitiveDef for the long double type. */
131     private TypeRefImpl long_double_ = null;
132
133     /** Reference to the PrimitiveDef for the wchar type. */
134     private TypeRefImpl wchar_ = null;
135
136     /** Reference to the PrimitiveDef for the wstring type. */
137     private TypeRefImpl wstring_ = null;
138
139     /** Reference to the PrimitiveDef for the value base type. */
140     private TypeRefImpl value_base_ = null;
141
142     /** Table of registered declarations. */
143     private java.util.Hashtable JavaDoc declarations_;
144
145     /** Table of registered mapping declarations. */
146     private java.util.Hashtable JavaDoc mapped_declarations_;
147
148     /** Reference to the CORBA 3.0 Interface Repository. */
149     private org.omg.CORBA.Repository JavaDoc repository_;
150
151     /** Reference to the OpenCCM Interface Repository. */
152     private org.objectweb.openccm.ir3.api.ComponentRepository openccm_repository_;
153
154     // ==================================================================
155
//
156
// Constructor.
157
//
158
// ==================================================================
159

160     /**
161      * The constructor with the CORBA Interface Repository.
162      *
163      * @param repository The CORBA Repository that should be used.
164      */

165     public
166     Repository(org.omg.CORBA.Repository JavaDoc repository)
167     {
168         // Call the ScopeImpl constructor.
169
super(null, null);
170
171         // Init DeclarationImpl internal state.
172
the_repository_ = this;
173
174         // Init internal state.
175
declarations_ = new java.util.Hashtable JavaDoc();
176         mapped_declarations_ = new java.util.Hashtable JavaDoc();
177         repository_ = repository;
178         openccm_repository_ = org.objectweb.openccm.ir3.api.ComponentRepositoryHelper.
179                               narrow(repository);
180     }
181
182     // ==================================================================
183
//
184
// Internal methods.
185
//
186
// ==================================================================
187

188     /**
189      * Add a declaration to the Repository.
190      *
191      * @param rep_id The associated repository ID.
192      * @param decl The declaration to add.
193      */

194     protected void
195     addDeclInRep(String JavaDoc rep_id,
196                  Declaration decl)
197     {
198         declarations_.put(rep_id, decl);
199     }
200
201     /**
202      * Remove a declaration from the Repository.
203      *
204      * @param rep_id The associated repository ID.
205      */

206     protected void
207     removeDeclFromRep(String JavaDoc rep_id)
208     {
209         declarations_.remove(rep_id);
210     }
211
212     /**
213      * Add a mapped declaration to the Repository.
214      *
215      * @param rep_id The associated repository ID.
216      * @param decl The mapped declaration to add.
217      */

218     protected void
219     addMappedDeclInRep(String JavaDoc rep_id,
220                        Declaration decl)
221     {
222         mapped_declarations_.put(rep_id, decl);
223     }
224
225     /**
226      * Remove a mapped declaration from the Repository.
227      *
228      * @param rep_id The associated repository ID.
229      */

230     protected void
231     removeMappedDeclFromRep(String JavaDoc rep_id)
232     {
233         mapped_declarations_.remove(rep_id);
234     }
235
236     /**
237      * Obtain a newly created Declaration of a IR3 Contained.
238      * Note: only the following Contained can be loaded :
239      * dk_Module, dk_Interface, dk_LocalInterface, dk_AbstractInterface,
240      * dk_Value, dk_Struct, dk_Union, dk_Exception, dk_Component, dk_Home,
241      * dk_Event.
242      *
243      * @param contained The Contained to use.
244      * @param scope The Scope in which the Contained will be loaded.
245      *
246      * @return The associated Declaration or null if it not exists or if
247      * the DefinitionKind is not valid.
248      */

249     protected Declaration
250     loadContained(Scope scope, org.omg.CORBA.Contained JavaDoc contained)
251     {
252         ScopeImpl si = (ScopeImpl)scope;
253         org.omg.CORBA.DefinitionKind JavaDoc kind = contained.def_kind();
254
255         if ((kind!=org.omg.CORBA.DefinitionKind.dk_Module) &&
256             (kind!=org.omg.CORBA.DefinitionKind.dk_Interface) &&
257             (kind!=org.omg.CORBA.DefinitionKind.dk_LocalInterface) &&
258             (kind!=org.omg.CORBA.DefinitionKind.dk_AbstractInterface) &&
259             (kind!=org.omg.CORBA.DefinitionKind.dk_Value) &&
260             (kind!=org.omg.CORBA.DefinitionKind.dk_Struct) &&
261             (kind!=org.omg.CORBA.DefinitionKind.dk_Union) &&
262             (kind!=org.omg.CORBA.DefinitionKind.dk_Exception) &&
263             (kind!=org.omg.CORBA.DefinitionKind.dk_Component) &&
264             (kind!=org.omg.CORBA.DefinitionKind.dk_Home) &&
265             (kind!=org.omg.CORBA.DefinitionKind.dk_Event))
266             return null;
267
268         return si.loadContained(contained);
269     }
270
271     /**
272      * Obtain the TypeRef associated to a CORBA::IDLType.
273      *
274      * @param type The CORBA::IDLType used to search.
275      * @param is_mapped True if it is a mapped type else false.
276      *
277      * @return The associated TypeRef found.
278      */

279     protected TypeRef
280     getAsTypeRef(org.omg.CORBA.IDLType JavaDoc type,
281                  boolean is_mapped)
282     {
283         org.omg.CORBA.TypeCode JavaDoc tc = type.type();
284         try
285         {
286             switch(tc.kind().value())
287             {
288             case org.omg.CORBA.TCKind._tk_null:
289                 return getNullType();
290             case org.omg.CORBA.TCKind._tk_void:
291                 return getVoidType();
292             case org.omg.CORBA.TCKind._tk_short:
293                 return getShortType();
294             case org.omg.CORBA.TCKind._tk_long:
295                 return getLongType();
296             case org.omg.CORBA.TCKind._tk_ushort:
297                 return getUShortType();
298             case org.omg.CORBA.TCKind._tk_ulong:
299                 return getULongType();
300             case org.omg.CORBA.TCKind._tk_float:
301                 return getFloatType();
302             case org.omg.CORBA.TCKind._tk_double:
303                 return getDoubleType();
304             case org.omg.CORBA.TCKind._tk_boolean:
305                 return getBooleanType();
306             case org.omg.CORBA.TCKind._tk_char:
307                 return getCharType();
308             case org.omg.CORBA.TCKind._tk_octet:
309                 return getOctetType();
310             case org.omg.CORBA.TCKind._tk_any:
311                 return getAnyType();
312             case org.omg.CORBA.TCKind._tk_TypeCode:
313                 return getTypeCodeType();
314             case org.omg.CORBA.TCKind._tk_Principal:
315                 return getPrincipalType();
316             case org.omg.CORBA.TCKind._tk_longlong:
317                 return getLongLongType();
318             case org.omg.CORBA.TCKind._tk_ulonglong:
319                 return getULongLongType();
320             case org.omg.CORBA.TCKind._tk_longdouble:
321                 return getLongDoubleType();
322             case org.omg.CORBA.TCKind._tk_wchar:
323                 return getWCharType();
324
325             case org.omg.CORBA.TCKind._tk_string:
326                 return new TypeRefWithLengthImpl(type,
327                                                  TypeKind.tk_string,
328                                                  tc.length());
329             case org.omg.CORBA.TCKind._tk_sequence:
330                 org.omg.CORBA.SequenceDef JavaDoc seq = org.omg.CORBA.SequenceDefHelper.
331                                                 narrow(type);
332                 return new TypeRefWithContentImpl(type,
333                                                  TypeKind.tk_sequence,
334                                                  tc.length(),
335                                                  getAsTypeRef(seq.element_type_def()));
336             case org.omg.CORBA.TCKind._tk_array:
337                 org.omg.CORBA.ArrayDef JavaDoc arr = org.omg.CORBA.ArrayDefHelper.narrow(type);
338                 return new TypeRefWithContentImpl(type,
339                                                  TypeKind.tk_array,
340                                                  tc.length(),
341                                                  getAsTypeRef(arr.element_type_def()));
342             case org.omg.CORBA.TCKind._tk_wstring:
343                 return new TypeRefWithLengthImpl(type,
344                                                  TypeKind.tk_wstring,
345                                                  tc.length());
346             case org.omg.CORBA.TCKind._tk_fixed:
347                 return new FixedTypeRefImpl(type,
348                                            tc.fixed_digits(),
349                                            tc.fixed_scale());
350             case org.omg.CORBA.TCKind._tk_objref:
351               if (tc.id().equals("IDL:omg.org/CORBA/Object:1.0"))
352                 return getObjectType();
353
354             case org.omg.CORBA.TCKind._tk_struct:
355             case org.omg.CORBA.TCKind._tk_union:
356             case org.omg.CORBA.TCKind._tk_enum:
357             case org.omg.CORBA.TCKind._tk_alias:
358             case org.omg.CORBA.TCKind._tk_value:
359             case org.omg.CORBA.TCKind._tk_value_box:
360             case org.omg.CORBA.TCKind._tk_native:
361             case org.omg.CORBA.TCKind._tk_abstract_interface:
362 /*
363  * not defined !
364             case org.omg.CORBA.TCKind._tk_local_interface:
365             case org.omg.CORBA.TCKind_.tk_event:
366             case org.omg.CORBA.TCKind._tk_home:
367             case org.omg.CORBA.TCKind._tk_component:
368  */

369                 if (is_mapped)
370                     return (TypeRef)lookupMappedId(tc.id());
371                 else
372                     return (TypeRef)lookupId(tc.id());
373
374             //
375
// PB: an exception is not an IDLType
376
// so it can't have an associated TypeRef
377
//
378
case org.omg.CORBA.TCKind._tk_except:
379             default:
380                 return getNullType();
381             }
382         }
383         catch(org.omg.CORBA.TypeCodePackage.BadKind JavaDoc ex)
384         {
385             throw new org.objectweb.openccm.corba.UserExceptionWrapper(ex);
386         }
387     }
388
389     /**
390      * Create a TypeRefImpl.
391      *
392      * @param pk The associated CORBA::PrimitiveKind.
393      * @param tk The associated AST TypeKind.
394      *
395      * @return The create TypeRefImpl.
396      */

397     protected TypeRefImpl
398     createTypeRefImpl(PrimitiveKind JavaDoc pk,
399                       TypeKind tk)
400     {
401       return new TypeRefImpl(repository_.get_primitive(pk), tk);
402     }
403
404     // ==================================================================
405
//
406
// Public methods.
407
//
408
// ==================================================================
409

410     /**
411      * To use the OpenCCM Interface Repository as OMG IDL 3.x one.
412      */

413     public void
414     useIDL3Repository()
415     {
416         // if we're not using the OpenCCM repository, mappings are not available.
417
if (openccm_repository_!=null)
418             openccm_repository_.as_IDL3_repository();
419     }
420
421     /**
422      * To use the OpenCCM Interface Repository as OMG IDL 2.x one.
423      */

424     public void
425     useIDL2Repository()
426     {
427         // if we're not using the OpenCCM repository, mappings are not available.
428
if (openccm_repository_!=null)
429             openccm_repository_.as_IDL2_repository();
430     }
431
432     /**
433      * TODO: Should be commented!
434      */

435     public Declaration
436     loadMapping(Scope scope, String JavaDoc rep_id)
437     {
438         // if we're not using the OpenCCM repository, mappings are not available.
439
if (openccm_repository_==null)
440             return null;
441
442         // use the OpenCCM repository as an IDL2 repository to extract the mapping !!!
443
useIDL2Repository();
444
445         // check if it was not already loaded.
446
Declaration result = (Declaration)mapped_declarations_.get(rep_id);
447         if (result==null)
448         {
449             org.omg.CORBA.Contained JavaDoc decl = openccm_repository_.lookup_mapped_id(rep_id);
450             if (decl!=null)
451             {
452                 // load the contained.
453
ScopeImpl si = (ScopeImpl)scope;
454                 result = si.loadContainedAsMapping(decl);
455             }
456         }
457
458         // get back to an IDL3 repository.
459
useIDL3Repository();
460
461         return result;
462     }
463
464     /**
465      * To obtain the Declaration object with it's absolute name.
466      *
467      * @param abs_name The absolute name of the searched Declaration object.
468      *
469      * @return The Declaration object or null if the absolute
470      * name was not found.
471      */

472     public Declaration
473     lookup(String JavaDoc scoped_name)
474     {
475         if (scoped_name.startsWith("::"))
476             return super.lookup(scoped_name.substring(2));
477         else
478             return super.lookup(scoped_name);
479     }
480
481     /**
482      * TODO: Should be commented!
483      */

484     public Declaration
485     lookupMappedId(String JavaDoc rep_id)
486     {
487         Object JavaDoc obj = mapped_declarations_.get(rep_id);
488         if (obj!=null)
489             return (Declaration)obj;
490
491         // if not found then load it from the IR3
492
org.omg.CORBA.Contained JavaDoc decl = openccm_repository_.lookup_mapped_id(rep_id);
493
494         // if not found, it's a "normal" id
495
if (decl==null)
496             return lookupId(rep_id);
497
498         // else load it as a mapped id
499
org.omg.CORBA.Contained JavaDoc decl2 = null;
500         String JavaDoc abs_name = decl.absolute_name();
501         String JavaDoc name = "";
502         if (abs_name.startsWith("::"))
503             abs_name = abs_name.substring(2, abs_name.length());
504
505         int idx = 0;
506         ScopeImpl scope = null;
507         obj = this;
508         while (true)
509         {
510             scope = (ScopeImpl)obj;
511             idx = abs_name.indexOf(':');
512             if (idx==-1)
513                 return scope.loadContainedAsMapping(decl);
514             name = abs_name.substring(0, idx);
515             abs_name = abs_name.substring(idx+2, abs_name.length());
516             obj = scope.findInScope(name);
517             if (obj==null)
518             {
519                 decl2 = scope.getContainer().lookup(name);
520                 obj = scope.loadContainedAsMapping(decl2);
521             }
522         }
523     }
524
525     /**
526      * TODO: Should be commented!
527      */

528     public Declaration
529     lookupId(String JavaDoc rep_id)
530     {
531         Object JavaDoc obj = declarations_.get(rep_id);
532
533         if (obj!=null)
534             return (Declaration)obj;
535
536         // if not found then load it from the IR3
537
org.omg.CORBA.Contained JavaDoc decl = repository_.lookup_id(rep_id);
538         org.omg.CORBA.Contained JavaDoc decl2 = null;
539         String JavaDoc abs_name = decl.absolute_name();
540         String JavaDoc name = "";
541         if (abs_name.startsWith("::"))
542             abs_name = abs_name.substring(2, abs_name.length());
543
544         int idx = 0;
545         ScopeImpl scope = null;
546         obj = this;
547         while (true)
548         {
549             scope = (ScopeImpl)obj;
550             idx = abs_name.indexOf(':');
551             if (idx==-1)
552                 return scope.loadContained(decl);
553             name = abs_name.substring(0, idx);
554             abs_name = abs_name.substring(idx+2, abs_name.length());
555             obj = scope.findInScope(name);
556             if (obj==null)
557             {
558                 decl2 = scope.getContainer().lookup(name);
559                 obj = scope.loadContained(decl2);
560             }
561         }
562     }
563
564     /**
565      * TODO: Should be commented!
566      */

567     public TypeRef
568     getAsMappedTypeRef(org.omg.CORBA.IDLType JavaDoc type)
569     {
570         return getAsTypeRef(type, true);
571     }
572
573     /**
574      * TODO: Should be commented!
575      */

576     public TypeRef
577     getAsTypeRef(org.omg.CORBA.IDLType JavaDoc type)
578     {
579         return getAsTypeRef(type, false);
580     }
581
582     // ==================================================================
583
//
584
// Methods for the inherited DeclarationImpl class.
585
//
586
// ==================================================================
587

588     /**
589      * Obtain its CORBA 3.0 Contained reference.
590      *
591      * @return null because a Repository does not support the
592      * Contained interface.
593      */

594     protected org.omg.CORBA.Contained JavaDoc
595     getContained()
596     {
597        return null;
598     }
599
600     /**
601      * Obtain its DeclarationKind.
602      *
603      * @return The DeclarationKind of the object.
604      */

605     public long
606     getDeclKind()
607     {
608         return DeclarationKind.dk_repository;
609     }
610
611     // ==================================================================
612
//
613
// Methods for the inherited ScopeImpl class.
614
//
615
// ==================================================================
616

617     /**
618      * Obtain its CORBA 3.0 Container reference.
619      *
620      * @return The Repository.
621      */

622     protected org.omg.CORBA.Container JavaDoc
623     getContainer()
624     {
625        return repository_;
626     }
627
628     /**
629      * Obtain its CORBA 3.0 Container reference.
630      *
631      * @return The Container object associated with the module declaration.
632      */

633     protected org.omg.CORBA.ComponentIR.Container
634     getComponentContainer()
635     {
636         return openccm_repository_;
637     }
638
639     // ==================================================================
640
//
641
// Methods for OMG IDL org.objectweb.openccm.ast.api.AST
642
//
643
// ==================================================================
644

645     /**
646      * Import an IDL Declaration by its full name
647      * from the Interface Repository.
648      *
649      * @param sc The Scope in which the IDL Declaration
650      * will be imported.
651      * @param name The name of the IDL Declaration.
652      *
653      * @return The newly created Declaration associated
654      * with the IDL Declaration.
655      */

656     public Declaration
657     importByName(Scope sc, String JavaDoc name)
658     {
659         // Check if the declaration is present in the syntax tree
660
Declaration d = ((ScopeImpl)sc).findInScope(name);
661         if (d != null)
662             return d;
663
664         // Else retrieve the declaration from the repository
665
org.omg.CORBA.Contained JavaDoc decl = repository_.lookup(name);
666         if (decl==null)
667             return null;
668
669         return loadContained(sc, decl);
670     }
671
672     /**
673      * Import an IDL Declaration by its repository id
674      * from the Interface Repository.
675      *
676      * @param sc The Scope in which the IDL Declaration
677      * will be imported.
678      * @param id The RepositoryId of the IDL Declaration.
679      *
680      * @return The newly created Declaration associated
681      * with the IDL Declaration.
682      */

683     public Declaration
684     importById(Scope sc, String JavaDoc id)
685     {
686         // Check if the declaration is present in the syntax tree
687
Declaration d = (Declaration)declarations_.get(id);
688         if (d != null)
689             return d;
690
691         // Else retrieve the declaration from the repository
692
org.omg.CORBA.Contained JavaDoc decl = repository_.lookup_id(id);
693         if (decl==null)
694             return null;
695
696         return loadContained(sc, decl);
697     }
698
699     /**
700      * Create a new any value.
701      *
702      * @return The new AnyValue.
703      */

704     public AnyValue
705     createAnyValue()
706     {
707         return new AnyValueImpl();
708     }
709
710
711     /**
712      * Obtain the null type reference.
713      *
714      * @return The associated TypeRef.
715      */

716     public TypeRef
717     getNullType()
718     {
719         if (null_ == null)
720         {
721             null_ = createTypeRefImpl(PrimitiveKind.pk_null,
722                                       TypeKind.tk_null);
723         }
724         return null_;
725     }
726
727     /**
728      * Obtain the void type reference.
729      *
730      * @return The associated TypeRef.
731      */

732     public TypeRef
733     getVoidType()
734     {
735         if (void_ == null)
736         {
737             void_ = createTypeRefImpl(PrimitiveKind.pk_void,
738                                       TypeKind.tk_void);
739         }
740         return void_;
741     }
742
743     /**
744      * Obtain the short type reference.
745      *
746      * @return The associated TypeRef.
747      */

748     public TypeRef
749     getShortType()
750     {
751         if (short_ == null)
752         {
753             short_ = createTypeRefImpl(PrimitiveKind.pk_short,
754                                        TypeKind.tk_short);
755         }
756         return short_;
757     }
758
759     /**
760      * Obtain the long type reference.
761      *
762      * @return The associated TypeRef.
763      */

764     public TypeRef
765     getLongType()
766     {
767         if (long_ == null)
768         {
769             long_ = createTypeRefImpl(PrimitiveKind.pk_long,
770                                       TypeKind.tk_long);
771         }
772         return long_;
773     }
774
775     /**
776      * Obtain the unsigned short type reference.
777      *
778      * @return The associated TypeRef.
779      */

780     public TypeRef
781     getUShortType()
782     {
783         if (unsigned_short_ == null)
784         {
785             unsigned_short_ = createTypeRefImpl(PrimitiveKind.pk_ushort,
786                                                 TypeKind.tk_ushort);
787         }
788         return unsigned_short_;
789     }
790
791     /**
792      * Obtain the unsigned long type reference.
793      *
794      * @return The associated TypeRef.
795      */

796     public TypeRef
797     getULongType()
798     {
799         if (unsigned_long_ == null)
800         {
801             unsigned_long_ = createTypeRefImpl(PrimitiveKind.pk_ulong,
802                                                TypeKind.tk_ulong);
803         }
804         return unsigned_long_;
805     }
806
807     /**
808      * Obtain the float type reference.
809      *
810      * @return The associated TypeRef.
811      */

812     public TypeRef
813     getFloatType()
814     {
815         if (float_ == null)
816         {
817             float_ = createTypeRefImpl(PrimitiveKind.pk_float,
818                                        TypeKind.tk_float);
819         }
820         return float_;
821     }
822
823     /**
824      * Obtain the double type reference.
825      *
826      * @return The associated TypeRef.
827      */

828     public TypeRef
829     getDoubleType()
830     {
831         if (double_ == null)
832         {
833             double_ = createTypeRefImpl(PrimitiveKind.pk_double,
834                                         TypeKind.tk_double);
835         }
836         return double_;
837     }
838
839     /**
840      * Obtain the boolean type reference.
841      *
842      * @return The associated TypeRef.
843      */

844     public TypeRef
845     getBooleanType()
846     {
847         if (boolean_ == null)
848         {
849             boolean_ = createTypeRefImpl(PrimitiveKind.pk_boolean,
850                                          TypeKind.tk_boolean);
851         }
852         return boolean_;
853     }
854
855     /**
856      * Obtain the char type reference.
857      *
858      * @return The associated TypeRef.
859      */

860     public TypeRef
861     getCharType()
862     {
863         if (char_ == null)
864         {
865             char_ = createTypeRefImpl(PrimitiveKind.pk_char,
866                                       TypeKind.tk_char);
867         }
868         return char_;
869     }
870
871     /**
872      * Obtain the octet type reference.
873      *
874      * @return The associated TypeRef.
875      */

876     public TypeRef
877     getOctetType()
878     {
879         if (octet_ == null)
880         {
881             octet_ = createTypeRefImpl(PrimitiveKind.pk_octet,
882                                        TypeKind.tk_octet);
883         }
884         return octet_;
885     }
886
887     /**
888      * Obtain the any type reference.
889      *
890      * @return The associated TypeRef.
891      */

892     public TypeRef
893     getAnyType()
894     {
895         if (any_ == null)
896         {
897             any_ = createTypeRefImpl(PrimitiveKind.pk_any,
898                                      TypeKind.tk_any);
899         }
900         return any_;
901     }
902
903     /**
904      * Obtain the TypeCode type reference.
905      *
906      * @return The associated TypeRef.
907      */

908     public TypeRef
909     getTypeCodeType()
910     {
911         if (TypeCode_ == null)
912         {
913             TypeCode_ = createTypeRefImpl(PrimitiveKind.pk_TypeCode,
914                                           TypeKind.tk_TypeCode);
915         }
916         return TypeCode_;
917     }
918
919     /**
920      * Obtain the Principal type reference.
921      *
922      * @return The associated TypeRef.
923      */

924     public TypeRef
925     getPrincipalType()
926     {
927         if (Principal_ == null)
928         {
929             Principal_ = createTypeRefImpl(PrimitiveKind.pk_Principal,
930                                            TypeKind.tk_Principal);
931         }
932         return Principal_;
933     }
934
935     /**
936      * Obtain the string type reference.
937      *
938      * @return The associated TypeRef.
939      */

940     public TypeRef
941     getStringType()
942     {
943         if (string_ == null)
944         {
945          string_ = new TypeRefWithLengthImpl(
946                                repository_.get_primitive(PrimitiveKind.pk_string),
947                                 TypeKind.tk_string, 0);
948         }
949         return string_;
950     }
951
952     /**
953      * Obtain the Object type reference.
954      *
955      * @return The associated TypeRef.
956      */

957     public TypeRef
958     getObjectType()
959     {
960         if (object_ == null)
961         {
962             object_ = createTypeRefImpl(PrimitiveKind.pk_objref,
963                                         TypeKind.tk_objref);
964         }
965         return object_;
966     }
967
968     /**
969      * Obtain the long long type reference.
970      *
971      * @return The associated TypeRef.
972      */

973     public TypeRef
974     getLongLongType()
975     {
976         if (long_long_ == null)
977         {
978             long_long_ = createTypeRefImpl(PrimitiveKind.pk_longlong,
979                                            TypeKind.tk_longlong);
980         }
981         return long_long_;
982     }
983
984     /**
985      * Obtain the unsigned long long type reference.
986      *
987      * @return The associated TypeRef.
988      */

989     public TypeRef
990     getULongLongType()
991     {
992         if (unsigned_long_long_ == null)
993         {
994             unsigned_long_long_ = createTypeRefImpl(PrimitiveKind.pk_ulonglong,
995                                                     TypeKind.tk_ulonglong);
996         }
997         return unsigned_long_long_;
998     }
999
1000    /**
1001     * Obtain the long double type reference.
1002     *
1003     * @return The associated TypeRef.
1004     */

1005    public TypeRef
1006    getLongDoubleType()
1007    {
1008        if (long_double_ == null)
1009        {
1010            long_double_ = createTypeRefImpl(PrimitiveKind.pk_longdouble,
1011                                             TypeKind.tk_longdouble);
1012        }
1013        return long_double_;
1014    }
1015
1016    /**
1017     * Obtain the wchar type reference.
1018     *
1019     * @return The associated TypeRef.
1020     */

1021    public TypeRef
1022    getWCharType()
1023    {
1024        if (wchar_ == null)
1025        {
1026            wchar_ = createTypeRefImpl(PrimitiveKind.pk_wchar,
1027                                       TypeKind.tk_wchar);
1028        }
1029        return wchar_;
1030    }
1031
1032    /**
1033     * Obtain the wstring type reference.
1034     *
1035     * @return The associated TypeRef.
1036     */

1037    public TypeRef
1038    getWStringType()
1039    {
1040        if (wstring_ == null)
1041        {
1042         wstring_ = new TypeRefWithLengthImpl(
1043                                repository_.get_primitive(PrimitiveKind.pk_wstring),
1044                                TypeKind.tk_wstring, 0);
1045        }
1046        return wstring_;
1047    }
1048
1049    /**
1050     * Obtain the value base type reference.
1051     *
1052     * @return The associated TypeRef.
1053     */

1054    public TypeRef
1055    getValueBaseType()
1056    {
1057        if (value_base_ == null)
1058        {
1059            value_base_ = createTypeRefImpl(PrimitiveKind.pk_value_base,
1060                                           TypeKind.tk_value);
1061        }
1062        return value_base_;
1063    }
1064
1065    /**
1066     * Create an anonymous string<bound> type reference.
1067     *
1068     * @param bound The bound of the string.
1069     *
1070     * @return The new created TypeRef.
1071     */

1072    public TypeRef
1073    createStringType(int bound)
1074    {
1075        // Create a StringDef into the Interface Repository.
1076
org.omg.CORBA.StringDef JavaDoc stringDef = repository_.create_string(bound);
1077        return new TypeRefWithLengthImpl(stringDef, TypeKind.tk_string, bound);
1078    }
1079
1080    /**
1081     * Create an anonymous wstring<bound> type reference.
1082     *
1083     * @param bound The bound of the wstring.
1084     *
1085     * @return The new created TypeRef.
1086     */

1087    public TypeRef
1088    createWStringType(int bound)
1089    {
1090        // Create a WstringDef into the Interface Repository.
1091
org.omg.CORBA.WstringDef JavaDoc wstringDef = repository_.create_wstring(bound);
1092        return new TypeRefWithLengthImpl(wstringDef, TypeKind.tk_wstring, bound);
1093    }
1094
1095    /**
1096     * Create an anonymous sequence<bound,element_type> type reference.
1097     *
1098     * @param bound The bound of the sequence.
1099     * @param element_type The TypeRef of the elements.
1100     *
1101     * @return The new created TypeRef.
1102     */

1103    public TypeRef
1104    createSequenceType(int bound,
1105                       TypeRef element_type)
1106    {
1107        if(element_type == null)
1108            return null;
1109
1110        // Create a SequenceDef into the Interface Repository.
1111
org.omg.CORBA.SequenceDef JavaDoc sequenceDef =
1112            repository_.create_sequence(bound,
1113                                        ((IDLTypeWrapper)element_type).getIDLType());
1114        return new TypeRefWithContentImpl(sequenceDef, TypeKind.tk_sequence,
1115                                          bound, element_type);
1116    }
1117
1118    /**
1119     * Create an anonymous array, i.e. element_type[length], type reference.
1120     *
1121     * @param length The length of the array.
1122     * @param element_type The TypeRef of the elements.
1123     *
1124     * @return The new created TypeRef.
1125     */

1126    public TypeRef
1127    createArrayType(int length,
1128                    TypeRef element_type)
1129    {
1130        if(element_type == null)
1131            return null;
1132
1133        // Create an ArrayDef into the Interface Repository.
1134
org.omg.CORBA.ArrayDef JavaDoc arrayDef =
1135             repository_.create_array(length,
1136                                        ((IDLTypeWrapper)element_type).getIDLType());
1137        return new TypeRefWithContentImpl(arrayDef, TypeKind.tk_array,
1138                                          length, element_type);
1139    }
1140
1141    /**
1142     * Create a fixed, i.e. fixed<digits,scale>, type reference.
1143     *
1144     * @param digits The number of decimal digits.
1145     * @param scale The position of the decimal point.
1146     *
1147     * @return The new created TypeRef.
1148     */

1149    public TypeRef
1150    createFixedType(short digits,
1151                    short scale)
1152    {
1153        // Create a FixedDef into the Interface Repository.
1154
org.omg.CORBA.FixedDef JavaDoc fixedDef =
1155            repository_.create_fixed (digits, scale);
1156        return new FixedTypeRefImpl(fixedDef, digits, scale);
1157    }
1158
1159    /**
1160     * Create a PSDL type reference for an idl type.
1161     *
1162     * @param idl_type - The IDL type that should be referenced.
1163     *
1164     * @return The new created PsdlTypeRef.
1165     */

1166    public PsdlTypeRef
1167    createPsdlType(TypeRef idl_type)
1168    {
1169        return new PsdlTypeRefImpl(idl_type);
1170    }
1171
1172    /**
1173     * Create a PSDL abstract storagetype type reference.
1174     *
1175     * @param isRef - True if it is a reference, else false.
1176     * i.e. ["strong"] "ref" "<" <abstract_storagetype_name> ">".
1177     * @param isStrong - True if it is a strong reference, else false.
1178     * @param ast - The associated abstract storagetype.
1179     *
1180     * @return The new created PsdlTypeRef.
1181     */

1182    public PsdlTypeRef
1183    createAbstractStorageTypePsdlType( boolean isStrong,
1184                                       boolean isRef,
1185        org.objectweb.openccm.ast.api.AbstractStorageTypeDecl ast)
1186    {
1187        return new PsdlTypeRefImpl(ast, isRef, isStrong);
1188    }
1189
1190    /**
1191     * Create a PSDL storagetype type reference,
1192     *
1193     * @param isRef - True if it is a reference, else false.
1194     * i.e. "ref" "<" <storagetype_name> ">".
1195     * @param st - The associated storagetype.
1196     *
1197     * @return The new created PsdlTypeRef.
1198     */

1199    public PsdlTypeRef
1200    createStorageTypePsdlType( boolean isRef,
1201                               org.objectweb.openccm.ast.api.StorageTypeDecl st)
1202    {
1203        return new PsdlTypeRefImpl(st, isRef, false);
1204    }
1205}
1206
Popular Tags