KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > IDL3 > ScopeImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.IDL3;
28
29 /**
30  * This class manages definition scopes.
31  *
32  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 abstract public class ScopeImpl
39                 extends DeclarationImpl
40                 implements Scope
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /**
49      ** To store Declaration names.
50      ** It's used to keep the order of the declarations.
51      **/

52     protected org.objectweb.ccm.util.Vector contained_decls_;
53
54     /**
55      ** To know if the contained objects have been loaded.
56      **/

57     protected boolean content_loaded_;
58
59     // ==================================================================
60
//
61
// Constructor.
62
//
63
// ==================================================================
64

65     /**
66      ** The constructor with the parent scope.
67      **
68      ** @param parent The parent scope of the declaration.
69      **/

70     protected
71     ScopeImpl(Repository rep, ScopeImpl parent)
72     {
73         // Call the DeclarationImpl constructor.
74
super(rep, parent);
75
76         // Init internal state.
77
contained_decls_ = new org.objectweb.ccm.util.Vector();
78         content_loaded_ = false;
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     /**
88      ** Add a contained declaration.
89      **
90      ** @param decl The declaration.
91      **/

92     protected void
93     addDecl(Declaration decl)
94     {
95         // System.err.println("### adding declaration : "+decl.getName()+" in scope : "+getName());
96
contained_decls_.add(decl);
97     }
98
99     /**
100      ** To know if a declaration is a contained declaration.
101      **
102      ** @return True if the declaration is contained, false otherwise.
103      ** @param decl The declaration.
104      **/

105     protected boolean
106     containsDecl(Declaration decl)
107     {
108         return ( decl.getAbsoluteName().startsWith(getAbsoluteName()+"::") );
109     }
110
111
112     /**
113      ** Remove a contained declaration.
114      **/

115     protected void
116     removeDecl(String JavaDoc name)
117     {
118         Declaration decl = null;
119         for (int i=0;i<contained_decls_.size();i++)
120         {
121             decl = (Declaration)contained_decls_.get(i);
122             if (decl.getName().equalsIgnoreCase(name))
123                 contained_decls_.remove(i);
124         }
125     }
126
127     /**
128      **
129      **/

130     protected Declaration
131     createDeclaration(int kind,
132                       java.lang.String JavaDoc name)
133     {
134         Declaration decl = null;
135         switch (kind)
136         {
137             // IDL2 objects
138
case org.omg.CORBA.DefinitionKind._dk_Interface :
139                 decl = startInterface(name);
140                 break;
141             case org.omg.CORBA.DefinitionKind._dk_LocalInterface :
142                 decl = startLocalInterface(name);
143                 break;
144             case org.omg.CORBA.DefinitionKind._dk_AbstractInterface :
145                 decl = startAbstractInterface(name);
146                 break;
147             case org.omg.CORBA.DefinitionKind._dk_Module :
148                 decl = startModule(name);
149                 break;
150             case org.omg.CORBA.DefinitionKind._dk_Struct :
151                 decl = startStruct(name);
152                 break;
153             case org.omg.CORBA.DefinitionKind._dk_Value :
154                 decl = startValue(name);
155                 break;
156             case org.omg.CORBA.DefinitionKind._dk_Union :
157                 decl = startUnion(name);
158                 break;
159             case org.omg.CORBA.DefinitionKind._dk_Exception :
160                 decl = startException(name);
161                 break;
162             case org.omg.CORBA.DefinitionKind._dk_Constant :
163                 decl = startConstant(name);
164                 break;
165             case org.omg.CORBA.DefinitionKind._dk_Enum :
166                 decl = startEnum(name);
167                 break;
168             case org.omg.CORBA.DefinitionKind._dk_Alias :
169                 decl = startAlias(name);
170                 break;
171             case org.omg.CORBA.DefinitionKind._dk_Attribute :
172                 decl = startAttribute(name);
173                 break;
174             case org.omg.CORBA.DefinitionKind._dk_Operation :
175                 decl = startOperation(name);
176                 break;
177             case org.omg.CORBA.DefinitionKind._dk_ValueBox :
178                 decl = startValueBox(name);
179                 break;
180             case org.omg.CORBA.DefinitionKind._dk_Native :
181                 decl = startNative(name);
182                 break;
183             case org.omg.CORBA.DefinitionKind._dk_ValueMember :
184                 decl = startValueMember(name);
185                 break;
186
187             // IDL3 objects
188
case org.omg.CORBA.DefinitionKind._dk_Component :
189                 decl = startComponent(name);
190                 break;
191             case org.omg.CORBA.DefinitionKind._dk_Home :
192                 decl = startHome(name);
193                 break;
194             case org.omg.CORBA.DefinitionKind._dk_Factory :
195                 decl = startFactory(name);
196                 break;
197             case org.omg.CORBA.DefinitionKind._dk_Finder :
198                 decl = startFinder(name);
199                 break;
200             case org.omg.CORBA.DefinitionKind._dk_Emits :
201                 decl = startEmits(name);
202                 break;
203             case org.omg.CORBA.DefinitionKind._dk_Publishes :
204                 decl = startPublishes(name);
205                 break;
206             case org.omg.CORBA.DefinitionKind._dk_Consumes :
207                 decl = startConsumes(name);
208                 break;
209             case org.omg.CORBA.DefinitionKind._dk_Provides :
210                 decl = startProvides(name);
211                 break;
212             case org.omg.CORBA.DefinitionKind._dk_Uses :
213                 decl = startUses(name);
214                 break;
215             case org.omg.CORBA.DefinitionKind._dk_Event :
216                 decl = startEvent(name);
217                 break;
218             default :
219                 // should not happen
220
break;
221         }
222
223         return decl;
224     }
225
226
227     /**
228      ** To load an Contained object.
229      **
230      ** @param contained The Contained object.
231      **
232      ** @return The newly created Declaration object.
233      **/

234     protected Declaration
235     loadContained(org.omg.CORBA.Contained JavaDoc contained)
236     {
237         DeclarationImpl decl = null;
238
239         decl = (DeclarationImpl)createDeclaration(contained.def_kind().value(), contained.name());
240         decl.load(contained);
241         decl.setImported();
242
243         return decl;
244     }
245
246     /**
247      ** To load an Contained object.
248      **
249      ** @param contained The Contained object.
250      **
251      ** @return The newly created Declaration object.
252      **/

253     protected Declaration
254     loadContainedAsMapping(org.omg.CORBA.Contained JavaDoc contained)
255     {
256         DeclarationImpl decl = null;
257
258         decl = (DeclarationImpl)createDeclaration(contained.def_kind().value(), contained.name());
259         decl.loadAsMapping(contained);
260
261         return decl;
262     }
263
264     /**
265      ** Start a struct declaration.
266      **
267      ** @return The new created StructDecl.
268      **/

269     protected StructDecl
270     startStruct(String JavaDoc name)
271     {
272         StructDecl decl = new StructDeclImpl(getRepository(), this);
273         decl.setName(name);
274         return decl;
275     }
276
277     /**
278      ** Start an union declaration.
279      **
280      ** @return The new created UnionDecl.
281      **/

282     protected UnionDecl
283     startUnion(String JavaDoc name)
284     {
285         UnionDecl decl = new UnionDeclImpl(getRepository(), this);
286         decl.setName(name);
287         return decl;
288     }
289
290     /**
291      ** Start an interface declaration.
292      **
293      ** @return The new created InterfaceDecl.
294      **/

295     protected InterfaceDecl
296     startInterface(String JavaDoc name)
297     {
298         InterfaceDecl decl = new InterfaceDeclImpl(getRepository(), this);
299         decl.setName(name);
300         return decl;
301     }
302
303     /**
304      ** Start an local interface declaration.
305      **
306      ** @return The new created LocalInterfaceDecl.
307      **/

308     protected LocalInterfaceDecl
309     startLocalInterface(String JavaDoc name)
310     {
311         LocalInterfaceDecl decl = new LocalInterfaceDeclImpl(getRepository(), this);
312         decl.setName(name);
313         return decl;
314     }
315
316     /**
317      ** Start an abstract interface declaration.
318      **
319      ** @return The new created AbstractInterfaceDecl.
320      **/

321     protected AbstractInterfaceDecl
322     startAbstractInterface(String JavaDoc name)
323     {
324         AbstractInterfaceDecl decl = new AbstractInterfaceDeclImpl(getRepository(), this);
325         decl.setName(name);
326         return decl;
327     }
328
329     /**
330      ** Start an value declaration.
331      **
332      ** @return The new created ValueDecl.
333      **/

334     protected ValueDecl
335     startValue(String JavaDoc name)
336     {
337         ValueDecl decl = new ValueDeclImpl(getRepository(), this);
338         decl.setName(name);
339         return decl;
340     }
341
342     /**
343      ** Start a module declaration.
344      **
345      ** @return The new created ModuleDecl.
346      **/

347     protected ModuleDecl
348     startModule(String JavaDoc name)
349     {
350         ModuleDecl module = new ModuleDeclImpl(getRepository(), this);
351         module.setName(name);
352         return module;
353     }
354
355     /**
356      ** Start an component declaration.
357      **
358      ** @return The new created ComponentDecl.
359      **/

360     protected ComponentDecl
361     startComponent(String JavaDoc name)
362     {
363         ComponentDecl decl = new ComponentDeclImpl(getRepository(), this);
364         decl.setName(name);
365         return decl;
366     }
367
368     /**
369      ** Start an event declaration.
370      **
371      ** @return The new created EventDecl.
372      **/

373     protected EventDecl
374     startEvent(String JavaDoc name)
375     {
376         EventDecl decl = new EventDeclImpl(getRepository(), this);
377         decl.setName(name);
378         return decl;
379     }
380
381     /**
382      ** Find a declaration.
383      **
384      ** @param name The name of the searched declaration.
385      **
386      ** @return The declaration that was searched
387      ** or null if it does not exist.
388      **/

389     protected Declaration
390     findInScope(String JavaDoc name)
391     {
392         Declaration decl = null;
393         for (int i=0;i<contained_decls_.size();i++)
394         {
395             decl = (Declaration)contained_decls_.get(i);
396             if (decl.getName().equalsIgnoreCase(name))
397                 return decl;
398         }
399
400         return null;
401     }
402
403     /**
404      ** Find a declaration in the IR3.
405      **
406      ** @param name The name of the searched declaration.
407      **
408      ** @return The declaration that was searched
409      ** or null if it does not exist.
410      **/

411     protected Declaration
412     findInIR3(String JavaDoc name)
413     {
414         Declaration decl = null;
415         org.omg.CORBA.Contained JavaDoc contained = getContainer().lookup(name);
416         if (contained == null)
417             return null;
418
419         return loadContained(contained);
420     }
421
422     /**
423      ** Obtain its CORBA 3.0 Container reference.
424      **
425      ** @return The Container object associated with the scope declaration.
426      **/

427     abstract protected org.omg.CORBA.Container JavaDoc
428     getContainer();
429
430     /**
431      ** To avoid casts
432      **/

433     protected org.omg.CORBA.ComponentIR.ComponentDef
434     getComponentDef()
435     {
436         return null;
437     }
438
439     /**
440      ** To avoid casts
441      **/

442     protected org.omg.CORBA.ExtValueDef
443     getExtValueDef()
444     {
445         return null;
446     }
447
448     /**
449      ** To avoid casts
450      **/

451     protected org.omg.CORBA.ComponentIR.HomeDef
452     getHomeDef()
453     {
454         return null;
455     }
456
457     /**
458      ** To avoid casts
459      **
460      ** @return The Container object associated with the scope declaration.
461      **/

462     protected org.omg.CORBA.ComponentIR.Container
463     getComponentContainer()
464     {
465         return null;
466     }
467
468     /**
469      ** Create an attribute definition.
470      **
471      ** @param attribute The attribute declaration.
472      ** @param type The IDLType of the attribute.
473      ** @param mode The mode of the attribute ie normal or readonly
474      ** @param get_exceptions An array containing the exceptions
475      ** that accessor operations can raise.
476      ** @param set_exceptions An array containing the exceptions
477      ** that mutator operations can raise.
478      **
479      ** @return The new created AttributeDef.
480      **/

481     protected org.omg.CORBA.ExtAttributeDef
482     createExtAttribute(AttributeDecl attribute,
483                        org.omg.CORBA.IDLType JavaDoc type,
484                        org.omg.CORBA.AttributeMode JavaDoc mode,
485                        org.omg.CORBA.ExceptionDef JavaDoc[] get_exceptions,
486                        org.omg.CORBA.ExceptionDef JavaDoc[] set_exceptions)
487     {
488         return null;
489     }
490
491     /**
492      ** Create an operation.
493      **
494      ** @param operation The operation declaration.
495      ** @param type The IDLType of the object that the operations returns.
496      ** @param mode The mode of the operation ie normal or oneway.
497      ** @param params An array containing the parameters description.
498      ** @param exceptions An array containing the exceptions
499      ** that the operation can raise.
500      ** @param contexts An array containing the possible context values.
501      **
502      ** @return The new created OperationDef.
503      **/

504     protected org.omg.CORBA.OperationDef JavaDoc
505     createOperation(OperationDecl operation,
506                     org.omg.CORBA.IDLType JavaDoc type,
507                     org.omg.CORBA.OperationMode JavaDoc mode,
508                     org.omg.CORBA.ParameterDescription JavaDoc[] params,
509                     org.omg.CORBA.ExceptionDef JavaDoc[] exceptions,
510                     String JavaDoc[] contexts)
511     {
512         return null;
513     }
514
515     // ==================================================================
516
//
517
// Methods for the Scope interface (parser view).
518
//
519
// ==================================================================
520

521     /**
522      ** Start a file scope.
523      **
524      ** @param fileName the name of the file represented by this FileScope.
525      **/

526     public FileScope
527     startFileScope(String JavaDoc filename)
528     {
529         FileScope decl = new FileScope(getRepository(), this, contained_decls_);
530         decl.setName(filename);
531         return decl;
532     }
533
534     /**
535      ** Find a module declaration
536      ** If it not exists then create it.
537      **
538      ** @param The name of the module declaration.
539      **
540      ** @return The new created ModuleDecl or a already created ModuleDecl.
541      **/

542     public ModuleDecl
543     declareModule(String JavaDoc name)
544     {
545         // Find a declaration with the same name.
546
Declaration decl = findInScope(name);
547
548         // if it is a module then return it
549
// because this is a module reopening.
550
if (decl != null && decl instanceof ModuleDecl)
551             return (ModuleDecl)decl;
552
553         // else create it.
554
ModuleDeclImpl module = new ModuleDeclImpl(getRepository(), this);
555         module.setName(name);
556
557         // Search its ModuleDef into the IR3.
558
try
559         {
560             org.omg.CORBA.Contained JavaDoc contained = getContainer().lookup(name);
561             if (contained!=null)
562                 module.load(contained);
563         }
564         catch(org.omg.CORBA.SystemException JavaDoc exc)
565     {
566             // TODO: Do nothing if narrow fails?
567
}
568
569         return module;
570     }
571
572     /**
573      ** Start a constant declaration.
574      **
575      ** @return The new created ConstantDecl.
576      **/

577     public ConstantDecl
578     startConstant(String JavaDoc name)
579     {
580         ConstantDecl decl = new ConstantDeclImpl(getRepository(), this);
581         decl.setName(name);
582         return decl;
583     }
584
585     /**
586      ** Start a struct declaration.
587      **
588      ** @return The new created StructDecl.
589      **/

590     public StructDecl
591     declareStruct(String JavaDoc name)
592     {
593         // Find a declaration with the same name.
594
Declaration decl = findInScope(name);
595
596         if ((decl != null) && (decl instanceof StructDecl))
597             return (StructDecl)decl;
598
599         // else create it.
600
decl = new StructDeclImpl(getRepository(), this);
601         decl.setName(name);
602         return (StructDecl)decl;
603     }
604
605     /**
606      ** Start an union declaration.
607      **
608      ** @return The new created UnionDecl.
609      **/

610     public UnionDecl
611     declareUnion(String JavaDoc name)
612     {
613         // Find a declaration with the same name.
614
Declaration decl = findInScope(name);
615
616         if ((decl != null) && (decl instanceof UnionDecl))
617             return (UnionDecl)decl;
618
619         // else create it.
620
decl = new UnionDeclImpl(getRepository(), this);
621         decl.setName(name);
622         return (UnionDecl)decl;
623     }
624
625     /**
626      ** Start an enum declaration.
627      **
628      ** @return The new created EnumDecl.
629      **/

630     public EnumDecl
631     startEnum(String JavaDoc name)
632     {
633         EnumDecl decl = new EnumDeclImpl(getRepository(), this);
634         decl.setName(name);
635         return decl;
636     }
637
638     /**
639      ** Start an alias declaration.
640      **
641      ** @return The new created AliasDecl.
642      **/

643     public AliasDecl
644     startAlias(String JavaDoc name)
645     {
646         AliasDecl decl = new AliasDeclImpl(getRepository(), this);
647         decl.setName(name);
648         return decl;
649     }
650
651     /**
652      ** Declare an interface declaration.
653      ** If it not exists, create it.
654      **
655      ** @param name The name of the interface declaration.
656      **
657      ** @return The new created InterfaceDecl
658      ** or an already created InterfaceDecl.
659      **/

660     public InterfaceDecl
661     declareInterface(String JavaDoc name)
662     {
663         // Find a declaration with the same name.
664
Declaration decl = findInScope(name);
665
666         if (decl != null)
667     {
668             // if it is an interface then return it.
669
if (decl.getClass() == InterfaceDeclImpl.class)
670                 return (InterfaceDecl)decl;
671
672             // if it is an abstract interface then raise an error.
673
if (decl instanceof AbstractInterfaceDeclImpl)
674                 throw new Error JavaDoc("interface `" + name +
675                                 "' does not match forward abstract declaration");
676
677             // if it is a local interface then raise an error.
678
if (decl instanceof LocalInterfaceDeclImpl)
679                 throw new Error JavaDoc("interface `" + name +
680                                 "' does not match forward local declaration");
681     }
682
683         // else create it.
684
decl = new InterfaceDeclImpl(getRepository(), this);
685         decl.setName(name);
686         return (InterfaceDecl)decl;
687     }
688
689     /**
690      ** Declare an abstract interface declaration.
691      ** If it not exits, create it.
692      **
693      ** @param name The name of the abstract interface declaration.
694      **
695      ** @return The new created AbstractInterfaceDecl
696      ** or an already created AbstractInterfaceDecl.
697      **/

698     public AbstractInterfaceDecl
699     declareAbstractInterface(String JavaDoc name)
700     {
701         // Find a declaration with the same name.
702
Declaration decl = findInScope(name);
703
704         if (decl != null)
705         {
706             // if it is an abstract interface then return it.
707
if (decl instanceof AbstractInterfaceDeclImpl)
708                 return (AbstractInterfaceDecl)decl;
709
710             // if it is a local interface then raise an error.
711
if (decl instanceof LocalInterfaceDeclImpl)
712                 throw new Error JavaDoc("interface `" + name +
713                                 "' does not match forward local declaration");
714
715             // if it is an interface then raise an error.
716
if (decl instanceof InterfaceDeclImpl)
717                 throw new Error JavaDoc("interface `" + name +
718                                 "' does not match forward declaration");
719         }
720
721         // else create it.
722
decl = new AbstractInterfaceDeclImpl(getRepository(), this);
723         decl.setName(name);
724         return (AbstractInterfaceDecl)decl;
725     }
726
727     /**
728      ** Declare a local interface declaration.
729      ** If it not exists, create it.
730      **
731      ** @param name The name of the local interface declaration.
732      **
733      ** @return The new created LocalInterfaceDecl
734      ** or an already created LocalInterfaceDecl.
735      **/

736     public LocalInterfaceDecl
737     declareLocalInterface(String JavaDoc name)
738     {
739         // Find a declaration with the same name.
740
Declaration decl = findInScope(name);
741
742         if (decl != null)
743         {
744             // if it is a local interface then return it.
745
if (decl instanceof LocalInterfaceDeclImpl)
746                 return (LocalInterfaceDecl)decl;
747
748             // if it is an abstract interface then raise an error.
749
if (decl instanceof AbstractInterfaceDeclImpl)
750                 throw new Error JavaDoc("interface `" + name +
751                                 "' does not match forward abstract declaration");
752
753             // if it is an interface then raise an error.
754
if (decl instanceof InterfaceDeclImpl)
755                 throw new Error JavaDoc("interface `" + name +
756                                 "' does not match forward declaration");
757         }
758
759         // else create it.
760
decl = new LocalInterfaceDeclImpl(getRepository(), this);
761         decl.setName(name);
762         return (LocalInterfaceDecl)decl;
763     }
764
765     /**
766      ** Declare a value type declaration.
767      ** If it not exists, create it.
768      **
769      ** @param name The name of the value type declaration.
770      **
771      ** @return The new created ValueDecl or an already created ValueDecl.
772      **/

773     public ValueDecl
774     declareValue(String JavaDoc name)
775     {
776         // Find a declaration with the same name.
777
Declaration decl = findInScope(name);
778
779         if ((decl != null) && (decl instanceof ValueDecl))
780             return (ValueDecl)decl;
781
782         // else create it.
783
decl = new ValueDeclImpl(getRepository(), this);
784         decl.setName(name);
785         return (ValueDecl)decl;
786     }
787
788     /**
789      ** Start an initializer declaration.
790      **
791      ** @return The new created Initializer.
792      **/

793     public Initializer
794     startInitializer(String JavaDoc name)
795     {
796         Initializer init = new InitializerImpl();
797         init.setName(name);
798         return init;
799     }
800
801     /**
802      ** Declare a event type declaration.
803      ** If it not exists, create it.
804      **
805      ** @param name The name of the event type declaration.
806      **
807      ** @return The new created EventDecl or an already created EventDecl.
808      **/

809     public EventDecl
810     declareEvent(String JavaDoc name)
811     {
812         // Find a declaration with the same name.
813
Declaration decl = findInScope(name);
814
815         if ((decl != null) && (decl instanceof EventDecl))
816             return (EventDecl)decl;
817
818         // else create it.
819
decl = new EventDeclImpl(getRepository(), this);
820         decl.setName(name);
821         return (EventDecl)decl;
822     }
823
824     /**
825      ** Start a value member declaration.
826      **
827      ** @return The new created ValueMemberDecl.
828      **/

829     public ValueMemberDecl
830     startValueMember(String JavaDoc name)
831     {
832         ValueMemberDecl decl = new ValueMemberDeclImpl(getRepository(), this);
833         decl.setName(name);
834         return decl;
835     }
836
837     /**
838      ** Start a value box declaration.
839      **
840      ** @return The new created ValueBoxDecl.
841      **/

842     public ValueBoxDecl
843     startValueBox(String JavaDoc name)
844     {
845         ValueBoxDecl decl = new ValueBoxDeclImpl(getRepository(), this);
846         decl.setName(name);
847         return decl;
848     }
849
850     /**
851      ** Start an exception declaration.
852      **
853      ** @return The new created ExceptionDecl.
854      **/

855     public ExceptionDecl
856     startException(String JavaDoc name)
857     {
858         ExceptionDecl decl = new ExceptionDeclImpl(getRepository(), this);
859         decl.setName(name);
860         return decl;
861     }
862
863     /**
864      ** Start a native declaration.
865      **
866      ** @return The new created NativeDecl.
867      **/

868     public NativeDecl
869     startNative(String JavaDoc name)
870     {
871         NativeDecl decl = new NativeDeclImpl(getRepository(), this);
872         decl.setName(name);
873         return decl;
874     }
875
876     /**
877      ** Start an attribute declaration.
878      **
879      ** @return The new created AttributeDecl.
880      **/

881     public AttributeDecl
882     startAttribute(String JavaDoc name)
883     {
884         AttributeDecl decl = new AttributeDeclImpl(getRepository(), this);
885         decl.setName(name);
886         return decl;
887     }
888
889     /**
890      ** Start an operation declaration.
891      **
892      ** @return The new created OperationDecl.
893      **/

894     public OperationDecl
895     startOperation(String JavaDoc name)
896     {
897         OperationDecl decl = new OperationDeclImpl(getRepository(), this);
898         decl.setName(name);
899         return decl;
900     }
901
902     /**
903      ** Start a factory declaration.
904      **
905      ** @return The new created FactoryDecl.
906      **/

907     public FactoryDecl
908     startFactory(String JavaDoc name)
909     {
910         FactoryDecl decl = new FactoryDeclImpl(getRepository(), this);
911         decl.setName(name);
912         return decl;
913     }
914
915     /**
916      ** Start a finder declaration.
917      **
918      ** @return The new created FinderDecl.
919      **/

920     public FinderDecl
921     startFinder(String JavaDoc name)
922     {
923         FinderDecl decl = new FinderDeclImpl(getRepository(), this);
924         decl.setName(name);
925         return decl;
926     }
927
928     /**
929      ** Start a provides declaration.
930      **
931      ** @return The new created ProvidesDecl.
932      **/

933     public ProvidesDecl
934     startProvides(String JavaDoc name)
935     {
936         ProvidesDecl decl = new ProvidesDeclImpl(getRepository(), this);
937         decl.setName(name);
938         return decl;
939     }
940
941     /**
942      ** Start a uses declaration.
943      **
944      ** @return The new created UsesDecl.
945      **/

946     public UsesDecl
947     startUses(String JavaDoc name)
948     {
949         UsesDecl decl = new UsesDeclImpl(getRepository(), this);
950         decl.setName(name);
951         return decl;
952     }
953
954     /**
955      ** Start a consumes declaration.
956      **
957      ** @return The new created ConsumesDecl.
958      **/

959     public ConsumesDecl
960     startConsumes(String JavaDoc name)
961     {
962         ConsumesDecl decl = new ConsumesDeclImpl(getRepository(), this);
963         decl.setName(name);
964         return decl;
965     }
966
967     /**
968      ** Start a emits declaration.
969      **
970      ** @return The new created EmitsDecl.
971      **/

972     public EmitsDecl
973     startEmits(String JavaDoc name)
974     {
975         EmitsDecl decl = new EmitsDeclImpl(getRepository(), this);
976         decl.setName(name);
977         return decl;
978     }
979
980     /**
981      ** Start a publishes declaration.
982      **
983      ** @return The new created PublishesDecl.
984      **/

985     public PublishesDecl
986     startPublishes(String JavaDoc name)
987     {
988         PublishesDecl decl = new PublishesDeclImpl(getRepository(), this);
989         decl.setName(name);
990         return decl;
991     }
992
993     /**
994      ** Declare a component declaration.
995      ** If it not exits, create it.
996      **
997      ** @param name The component declaration name.
998      **
999      ** @return The new created ComponentDecl
1000     ** or an already created ComponentDecl.
1001     **/

1002    public ComponentDecl
1003    declareComponent(String JavaDoc name)
1004    {
1005        // Find a declaration with the same name.
1006
Declaration decl = findInScope(name);
1007
1008        if ((decl != null) && (decl instanceof ComponentDecl))
1009            return (ComponentDecl)decl;
1010
1011        // else create it.
1012
decl = new ComponentDeclImpl(getRepository(), this);
1013        decl.setName(name);
1014        return (ComponentDecl)decl;
1015    }
1016
1017    /**
1018     ** Start a home declaration.
1019     **
1020     ** @return The new created HomeDecl.
1021     **/

1022    public HomeDecl
1023    startHome(String JavaDoc name)
1024    {
1025        HomeDecl decl = new HomeDeclImpl(getRepository(), this);
1026        decl.setName(name);
1027        return decl;
1028    }
1029
1030    /**
1031     ** Find a declaration.
1032     **
1033     ** Note that the declaration is also recursively
1034     ** searched in the parent scope.
1035     ** Used from ComponentDeclImpl and HomeDeclImpl classes.
1036     **
1037     ** @param name The name of the searched declaration.
1038     **
1039     ** @return The declaration that was searched
1040     ** or null if it does not exist.
1041     **/

1042    public Declaration
1043    find(String JavaDoc name)
1044    {
1045        Declaration decl = findInScope(name);
1046        // If found then returns it.
1047
if (decl != null) return decl;
1048
1049        // Finds in the parent scope.
1050
if (the_parent_!=null)
1051           decl = the_parent_.find(name);
1052
1053        // If found then returns it.
1054
if (decl != null) return decl;
1055
1056        return findInIR3(name);
1057    }
1058
1059    // ==================================================================
1060
//
1061
// Methods for the Scope interface (visitor view).
1062
//
1063
// ==================================================================
1064

1065    /**
1066     ** To obtain all the contained Declaration objects.
1067     **
1068     ** @param exclude_inherited If false return also objects contained in inherited scopes.
1069     ** @param limited_types A logical combination of DeclarationKind.
1070     **
1071     ** @return An array of Declaration objects.
1072     **/

1073    public Declaration[]
1074    getContents(boolean exclude_inherited, int limited_types)
1075    {
1076        if (!content_loaded_)
1077        {
1078            // if it's a mapping scope, then use the OpenCCM repository as an IDL2 repository
1079
// to retrieve contained objects.
1080
if (is_mapping_)
1081                getRepository().useIDL2Repository();
1082
1083            org.omg.CORBA.Contained JavaDoc[] content = getContainer().contents(org.omg.CORBA.DefinitionKind.dk_all, true);
1084
1085            // we need to reorder the contained declarations !!!
1086
// because the could have been loaded one by one without any
1087
// garanties on the order.
1088
org.objectweb.ccm.util.Vector ordered_decls = new org.objectweb.ccm.util.Vector();
1089            Declaration decl = null;
1090            contained_decls_.clear();
1091
1092            // System.err.println(" ");
1093
// System.err.println("Container is : "+getName());
1094

1095            for (int i=0;i<content.length;i++)
1096            {
1097                // System.err.println(" Contained is : "+content[i].name());
1098
decl = findInScope(content[i].name());
1099                if (decl==null)
1100                {
1101                    if (is_mapping_)
1102                        decl = loadContainedAsMapping(content[i]);
1103                    else
1104                        decl = loadContained(content[i]);
1105                }
1106
1107                // System.err.println(" loaded");
1108
ordered_decls.add(decl);
1109            }
1110
1111            contained_decls_ = ordered_decls;
1112
1113            // get back to an IDL3 repository.
1114
if (is_mapping_)
1115                getRepository().useIDL3Repository();
1116
1117            content_loaded_ = true;
1118        }
1119
1120        Declaration decl = null;
1121        org.objectweb.ccm.util.Vector selection = new org.objectweb.ccm.util.Vector();
1122        for (int i=0;i<contained_decls_.size();i++)
1123        {
1124            decl = (Declaration)contained_decls_.get(i);
1125            if ((decl.getDeclKind()&limited_types)!=0)
1126                selection.add(decl);
1127        }
1128        return (Declaration[])selection.toArray(new Declaration[0]);
1129    }
1130
1131    /**
1132     ** To find a contained Declaration according to it's scoped name.
1133     **
1134     ** @param n The scoped name.
1135     **
1136     ** @return The found or loaded from the IR3 Declaration or null.
1137     **/

1138    public Declaration
1139    lookup(String JavaDoc scoped_name)
1140    {
1141        int idx = scoped_name.indexOf("::");
1142        String JavaDoc s1 = null;
1143        String JavaDoc s2 = null;
1144        if (idx==-1)
1145        {
1146            s1 = scoped_name;
1147            s2 = "";
1148        }
1149        else
1150        {
1151            s1 = scoped_name.substring(0,idx);
1152            s2 = scoped_name.substring(idx+2);
1153        }
1154
1155        Declaration decl = findInScope(s1);
1156        if (decl==null)
1157        {
1158        // try to load it from the IR3
1159
decl = findInIR3(s1);
1160        }
1161
1162        if (s2.equals(""))
1163            return decl;
1164
1165        if (decl instanceof Scope)
1166            return ((Scope)decl).lookup(s2);
1167
1168        return null;
1169    }
1170
1171    // ==================================================================
1172
//
1173
// Methods for the inherited DeclarationImpl class.
1174
//
1175
// ==================================================================
1176

1177    /**
1178     ** Destroy all the contained declarations of the scope in the IR3.
1179     **/

1180    public void
1181    destroy()
1182    {
1183        Declaration decl = null;
1184        for (int i=contained_decls_.size()-1;i>=0;i--)
1185        {
1186            decl = (Declaration)contained_decls_.get(i);
1187            decl.destroy();
1188        }
1189
1190        // destroy it as a declaration if there is no content.
1191
if (contained_decls_.size()==0)
1192            super.destroy();
1193    }
1194}
1195
Popular Tags