KickJava   Java API By Example, From Geeks To Geeks.

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


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 report ASTError exceptions. */
30 import org.objectweb.openccm.ast.api.ASTError;
31
32 /** To access all the AST API. */
33 import org.objectweb.openccm.ast.api.*;
34
35 /**
36  * ScopeImpl is a wrapper class for all IDL definition scopes.
37  *
38  * Inherits from:
39  * - Declaration as IDL scopes are also IDL declarations.
40  *
41  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
42  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
43  *
44  * @version 0.3
45  */

46
47 abstract public class ScopeImpl
48                 extends DeclarationImpl
49                 implements org.objectweb.openccm.ast.api.Scope
50 {
51     // ==================================================================
52
//
53
// Internal state.
54
//
55
// ==================================================================
56

57     /**
58      * To store Declaration names.
59      * It's used to keep the order of the declarations.
60      */

61     protected java.util.List JavaDoc contained_decls_;
62
63     /** To know if the contained objects have been loaded. */
64     protected boolean content_loaded_;
65
66     // ==================================================================
67
//
68
// Constructor.
69
//
70
// ==================================================================
71

72     /**
73      * The constructor with the parent scope.
74      *
75      * @param rep The repository of the declaration.
76      * @param parent The parent scope of the declaration.
77      */

78     protected
79     ScopeImpl(Repository rep,
80               ScopeImpl parent)
81     {
82         // Call the DeclarationImpl constructor.
83
super(rep, parent);
84
85         // Init internal state.
86
contained_decls_ = new java.util.ArrayList JavaDoc();
87         content_loaded_ = false;
88     }
89
90     // ==================================================================
91
//
92
// Internal methods.
93
//
94
// ==================================================================
95

96     /**
97      * Add a contained declaration.
98      *
99      * @param decl The declaration.
100      */

101     protected void
102     addDecl(Declaration decl)
103     {
104         // Test if the declaration is present
105
Declaration current = null;
106         String JavaDoc name = decl.getName();
107         for (int i=0;i<contained_decls_.size();i++)
108         {
109             current = (Declaration)contained_decls_.get(i);
110             if (current.getName().equalsIgnoreCase(name))
111                 return; // We don't have to add this declaration
112
}
113         // Adding the declaration
114
contained_decls_.add(decl);
115     }
116
117     /**
118      * To know if a declaration is a contained declaration.
119      *
120      * @param decl The declaration.
121      *
122      * @return True if the declaration is contained, false otherwise.
123      */

124     protected boolean
125     containsDecl(Declaration decl)
126     {
127         return ( decl.getAbsoluteName().startsWith(getAbsoluteName()+"::") );
128     }
129
130     /**
131      * Remove a contained declaration.
132      */

133     protected void
134     removeDecl(String JavaDoc name)
135     {
136         Declaration decl = null;
137         for (int i=0;i<contained_decls_.size();i++)
138         {
139             decl = (Declaration)contained_decls_.get(i);
140             if (decl.getName().equalsIgnoreCase(name))
141                 contained_decls_.remove(i);
142         }
143     }
144
145     /**
146      * Create a declaration.
147      */

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

251     protected Declaration
252     loadContained(org.omg.CORBA.Contained JavaDoc contained)
253     {
254         DeclarationImpl decl = (DeclarationImpl)
255             createDeclaration(contained.def_kind().value(), contained.name());
256         decl.load(contained);
257         decl.setImported();
258         return decl;
259     }
260
261     /**
262      * To load an Contained object.
263      *
264      * @param contained The Contained object.
265      *
266      * @return The newly created Declaration object.
267      */

268     protected Declaration
269     loadContainedAsMapping(org.omg.CORBA.Contained JavaDoc contained)
270     {
271         DeclarationImpl decl = (DeclarationImpl)
272             createDeclaration(contained.def_kind().value(), contained.name());
273         decl.loadAsMapping(contained);
274         return decl;
275     }
276
277     /**
278      * Start a struct declaration.
279      *
280      * @param name The associated name.
281      *
282      * @return The new created StructDecl.
283      */

284     protected StructDecl
285     startStruct(String JavaDoc name)
286     {
287         StructDecl decl = new StructDeclImpl(getRepository(), this);
288         decl.setName(name);
289         return decl;
290     }
291
292     /**
293      * Start an union declaration.
294      *
295      * @param name The associated name.
296      *
297      * @return The new created UnionDecl.
298      */

299     protected UnionDecl
300     startUnion(String JavaDoc name)
301     {
302         UnionDecl decl = new UnionDeclImpl(getRepository(), this);
303         decl.setName(name);
304         return decl;
305     }
306
307     /**
308      * Start an interface declaration.
309      *
310      * @param name The associated name.
311      *
312      * @return The new created InterfaceDecl.
313      */

314     protected InterfaceDecl
315     startInterface(String JavaDoc name)
316     {
317         InterfaceDecl decl = new InterfaceDeclImpl(getRepository(), this);
318         decl.setName(name);
319         return decl;
320     }
321
322     /**
323      * Start an local interface declaration.
324      *
325      * @param name The associated name.
326      *
327      * @return The new created LocalInterfaceDecl.
328      */

329     protected LocalInterfaceDecl
330     startLocalInterface(String JavaDoc name)
331     {
332         LocalInterfaceDecl decl = new LocalInterfaceDeclImpl(
333                                           getRepository(), this);
334         decl.setName(name);
335         return decl;
336     }
337
338     /**
339      * Start an abstract interface declaration.
340      *
341      * @param name The associated name.
342      *
343      * @return The new created AbstractInterfaceDecl.
344      */

345     protected AbstractInterfaceDecl
346     startAbstractInterface(String JavaDoc name)
347     {
348         AbstractInterfaceDecl decl = new AbstractInterfaceDeclImpl(
349                                              getRepository(), this);
350         decl.setName(name);
351         return decl;
352     }
353
354     /**
355      * Start an value declaration.
356      *
357      * @param name The associated name.
358      *
359      * @return The new created ValueDecl.
360      */

361     protected ValueDecl
362     startValue(String JavaDoc name)
363     {
364         ValueDecl decl = new ValueDeclImpl(getRepository(), this);
365         decl.setName(name);
366         return decl;
367     }
368
369     /**
370      * Start a module declaration.
371      *
372      * @param name The associated name.
373      *
374      * @return The new created ModuleDecl.
375      */

376     protected ModuleDecl
377     startModule(String JavaDoc name)
378     {
379         ModuleDecl module = new ModuleDeclImpl(getRepository(), this);
380         module.setName(name);
381         return module;
382     }
383
384     /**
385      * Start an component declaration.
386      *
387      * @param name The associated name.
388      *
389      * @return The new created ComponentDecl.
390      */

391     protected ComponentDecl
392     startComponent(String JavaDoc name)
393     {
394         ComponentDecl decl = new ComponentDeclImpl(getRepository(), this);
395         decl.setName(name);
396         return decl;
397     }
398
399     /**
400      * Start an event declaration.
401      *
402      * @param name The associated name.
403      *
404      * @return The new created EventDecl.
405      */

406     protected EventDecl
407     startEvent(String JavaDoc name)
408     {
409         EventDecl decl = new EventDeclImpl(getRepository(), this);
410         decl.setName(name);
411         return decl;
412     }
413
414     /**
415      * Find a declaration.
416      *
417      * @param name The name of the searched declaration.
418      *
419      * @return The declaration that was searched
420      * or null if it does not exist.
421      */

422     protected Declaration
423     findInScope(String JavaDoc name)
424     {
425         Declaration decl = null;
426         for (int i=0;i<contained_decls_.size();i++)
427         {
428             decl = (Declaration)contained_decls_.get(i);
429             if (decl.getName().equalsIgnoreCase(name))
430                 return decl;
431         }
432         return null;
433     }
434
435     /**
436      * Find a declaration in the IR3.
437      *
438      * @param name The name of the searched declaration.
439      *
440      * @return The declaration that was searched
441      * or null if it does not exist.
442      */

443     protected Declaration
444     findInIR3(String JavaDoc name)
445     {
446         org.omg.CORBA.Container JavaDoc container = getContainer();
447         if (container == null)
448             return null;
449
450         org.omg.CORBA.Contained JavaDoc contained = container.lookup(name);
451         if (contained == null)
452             return null;
453
454         return loadContained(contained);
455     }
456
457     /**
458      * Obtain its CORBA 3.0 Container reference.
459      *
460      * @return The Container object associated with the scope declaration.
461      */

462     protected org.omg.CORBA.Container JavaDoc
463     getContainer()
464     {
465         // TODO: Why this method?
466
return null;
467     }
468
469     /**
470      * To avoid casts.
471      */

472     protected org.omg.CORBA.ComponentIR.ComponentDef
473     getComponentDef()
474     {
475         // TODO: Why this method?
476
return null;
477     }
478
479     /**
480      * To avoid casts
481      */

482     protected org.omg.CORBA.ExtValueDef
483     getExtValueDef()
484     {
485         // TODO: Why this method?
486
return null;
487     }
488
489     /**
490      * To avoid casts
491      */

492     protected org.omg.CORBA.ComponentIR.HomeDef
493     getHomeDef()
494     {
495         // TODO: Why this method?
496
return null;
497     }
498
499     /**
500      * To avoid casts
501      *
502      * @return The Container object associated with the scope declaration.
503      */

504     protected org.omg.CORBA.ComponentIR.Container
505     getComponentContainer()
506     {
507         // TODO: Why this method?
508
return null;
509     }
510
511     /**
512      * Create an attribute definition.
513      *
514      * @param attribute The attribute declaration.
515      * @param type The IDLType of the attribute.
516      * @param mode The mode of the attribute ie normal or readonly
517      * @param get_exceptions An array containing the exceptions
518      * that accessor operations can raise.
519      * @param set_exceptions An array containing the exceptions
520      * that mutator operations can raise.
521      *
522      * @return The new created AttributeDef.
523      */

524     protected org.omg.CORBA.ExtAttributeDef
525     createExtAttribute(AttributeDecl attribute,
526                        org.omg.CORBA.IDLType JavaDoc type,
527                        org.omg.CORBA.AttributeMode JavaDoc mode,
528                        org.omg.CORBA.ExceptionDef JavaDoc[] get_exceptions,
529                        org.omg.CORBA.ExceptionDef JavaDoc[] set_exceptions)
530     {
531         // TODO: Why this method?
532
return null;
533     }
534
535     /**
536      * Create an operation.
537      *
538      * @param operation The operation declaration.
539      * @param type The IDLType of the object that the operations returns.
540      * @param mode The mode of the operation ie normal or oneway.
541      * @param params An array containing the parameters description.
542      * @param exceptions An array containing the exceptions
543      * that the operation can raise.
544      * @param contexts An array containing the possible context values.
545      *
546      * @return The new created OperationDef.
547      */

548     protected org.omg.CORBA.OperationDef JavaDoc
549     createOperation(OperationDecl operation,
550                     org.omg.CORBA.IDLType JavaDoc type,
551                     org.omg.CORBA.OperationMode JavaDoc mode,
552                     org.omg.CORBA.ParameterDescription JavaDoc[] params,
553                     org.omg.CORBA.ExceptionDef JavaDoc[] exceptions,
554                     String JavaDoc[] contexts)
555     {
556         // TODO: Why this method?
557
return null;
558     }
559
560     // ==================================================================
561
//
562
// Public methods.
563
//
564
// ==================================================================
565

566     // ==================================================================
567
//
568
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
569
//
570
// ==================================================================
571

572     /**
573      * Destroy all the contained declarations of the scope in the IR3.
574      */

575     public void
576     destroy()
577     {
578         Declaration decl = null;
579         for (int i=contained_decls_.size()-1;i>=0;i--)
580         {
581             decl = (Declaration)contained_decls_.get(i);
582             decl.destroy();
583         }
584
585         // destroy it as a declaration if there is no content.
586
if (contained_decls_.size()==0)
587             super.destroy();
588     }
589
590     // ==================================================================
591
//
592
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
593
//
594
// ==================================================================
595

596     /**
597      * Start a new IDL FileScope scope.
598      *
599      * @param filename The name of the new FileScope.
600      *
601      * @return The new created FileScope.
602      */

603     public FileScope
604     startFileScope(String JavaDoc filename)
605     {
606         FileScope decl = new FileScopeImpl(getRepository(),
607                                            this,
608                                            contained_decls_);
609         decl.setFileName(filename);
610         return decl;
611     }
612
613     /**
614      * Start a new IDL constant declaration.
615      *
616      * @param name The name of the constant declaration.
617      *
618      * @return The new created ConstantDecl.
619      */

620     public ConstantDecl
621     startConstant(String JavaDoc name)
622     {
623         ConstantDecl decl = new ConstantDeclImpl(getRepository(), this);
624         decl.setName(name);
625         return decl;
626     }
627
628     /**
629      * Declare an IDL struct.
630      * If it doesn't exist then create it.
631      *
632      * @param name The name of the struct declaration.
633      *
634      * @return The previous or new created StructDecl.
635      */

636     public StructDecl
637     declareStruct(String JavaDoc name)
638     {
639         // Find a declaration with the same name.
640
Declaration decl = findInScope(name);
641
642         if ((decl != null) && (decl instanceof StructDecl))
643             return (StructDecl)decl;
644
645         // else create it.
646
return startStruct(name);
647     }
648
649     /**
650      * Declare an IDL union.
651      * If it doesn't exist then create it.
652      *
653      * @param name The name of the union declaration.
654      *
655      * @return The previous or new created UnionDecl.
656      */

657     public UnionDecl
658     declareUnion(String JavaDoc name)
659     {
660         // Find a declaration with the same name.
661
Declaration decl = findInScope(name);
662
663         if ((decl != null) && (decl instanceof UnionDecl))
664             return (UnionDecl)decl;
665
666         // else create it.
667
return startUnion(name);
668     }
669
670     /**
671      * Start a new IDL enum declaration.
672      *
673      * @param name The name of the enum declaration.
674      *
675      * @return The new created EnumDecl.
676      */

677     public EnumDecl
678     startEnum(String JavaDoc name)
679     {
680         EnumDecl decl = new EnumDeclImpl(getRepository(), this);
681         decl.setName(name);
682         return decl;
683     }
684
685     /**
686      * Start a new IDL alias declaration.
687      *
688      * @param name The name of the alias declaration.
689      *
690      * @return The new created AliasDecl.
691      */

692     public AliasDecl
693     startAlias(String JavaDoc name)
694     {
695         AliasDecl decl = new AliasDeclImpl(getRepository(), this);
696         decl.setName(name);
697         return decl;
698     }
699
700     /**
701      * Declare an IDL module.
702      * If it doesn't exist then create it.
703      *
704      * @param name The name of the module declaration.
705      *
706      * @return The previous or new created ModuleDecl.
707      */

708     public ModuleDecl
709     declareModule(String JavaDoc name)
710     {
711       // System.out.println("declareModule " + name + " in " + this);
712

713         // Find a declaration with the same name.
714
Declaration decl = findInScope(name);
715
716         // if it is a module then return it
717
// because this is a module reopening.
718
if(decl != null && decl instanceof ModuleDecl)
719         {
720             return (ModuleDecl)decl;
721         }
722
723         // else create it.
724
ModuleDeclImpl module = (ModuleDeclImpl)startModule(name);
725
726         // Search its ModuleDef into the IR3.
727
try
728         {
729             org.omg.CORBA.Contained JavaDoc contained = getContainer().lookup(name);
730             if (contained!=null)
731                 module.load(contained);
732         }
733         catch(org.omg.CORBA.SystemException JavaDoc exc)
734         {
735             // TODO: Do nothing if narrow fails?
736
}
737
738         return module;
739     }
740
741     /**
742      * Declare an IDL interface.
743      * If it doesn't exist then create it.
744      *
745      * @param name The name of the interface declaration.
746      *
747      * @return The previous or new created InterfaceDecl.
748      */

749     public InterfaceDecl
750     declareInterface(String JavaDoc name)
751     {
752         // Find a declaration with the same name.
753
Declaration decl = findInScope(name);
754
755         if (decl != null)
756         {
757             // if it is an interface then return it.
758
if (decl.getClass() == InterfaceDeclImpl.class)
759                 return (InterfaceDecl)decl;
760
761             // if it is an abstract interface then raise an error.
762
if (decl instanceof AbstractInterfaceDeclImpl)
763                 throw new ASTError("interface `" + name +
764                           "' does not match forward abstract declaration");
765
766             // if it is a local interface then raise an error.
767
if (decl instanceof LocalInterfaceDeclImpl)
768                 throw new ASTError("interface `" + name +
769                           "' does not match forward local declaration");
770         }
771
772         // else create it.
773
return startInterface(name);
774     }
775
776     /**
777      * Declare an IDL local interface.
778      * If it doesn't exist then create it.
779      *
780      * @param name The name of the local interface declaration.
781      *
782      * @return The previous or new created LocalInterfaceDecl.
783      */

784     public LocalInterfaceDecl
785     declareLocalInterface(String JavaDoc name)
786     {
787         // Find a declaration with the same name.
788
Declaration decl = findInScope(name);
789
790         if (decl != null)
791         {
792             // if it is a local interface then return it.
793
if (decl instanceof LocalInterfaceDeclImpl)
794                 return (LocalInterfaceDecl)decl;
795
796             // if it is an abstract interface then raise an error.
797
if (decl instanceof AbstractInterfaceDeclImpl)
798                 throw new ASTError("interface `" + name +
799                           "' does not match forward abstract declaration");
800
801             // if it is an interface then raise an error.
802
if (decl instanceof InterfaceDeclImpl)
803                 throw new ASTError("interface `" + name +
804                           "' does not match forward declaration");
805         }
806
807         // else create it.
808
return startLocalInterface(name);
809     }
810
811     /**
812      * Declare an IDL abstract interface.
813      * If it doesn't exist then create it.
814      *
815      * @param name The name of the abstract interface declaration.
816      *
817      * @return The previous or new created AbstractInterfaceDecl.
818      */

819     public AbstractInterfaceDecl
820     declareAbstractInterface(String JavaDoc name)
821     {
822         // Find a declaration with the same name.
823
Declaration decl = findInScope(name);
824
825         if (decl != null)
826         {
827             // if it is an abstract interface then return it.
828
if (decl instanceof AbstractInterfaceDeclImpl)
829                 return (AbstractInterfaceDecl)decl;
830
831             // if it is a local interface then raise an error.
832
if (decl instanceof LocalInterfaceDeclImpl)
833                 throw new ASTError("interface `" + name +
834                           "' does not match forward local declaration");
835
836             // if it is an interface then raise an error.
837
if (decl instanceof InterfaceDeclImpl)
838                 throw new ASTError("interface `" + name +
839                            "' does not match forward declaration");
840         }
841
842         // else create it.
843
return startAbstractInterface(name);
844     }
845
846    /**
847     * Declare an IDL value type.
848     * If it doesn't exist then create it.
849     *
850     * @param name The name of the value type declaration.
851     *
852     * @return The previous or new created ValueDecl.
853     */

854     public ValueDecl
855     declareValue(String JavaDoc name)
856     {
857         // Find a declaration with the same name.
858
Declaration decl = findInScope(name);
859
860         if ((decl != null) && (decl instanceof ValueDecl))
861             return (ValueDecl)decl;
862
863         // else create it.
864
return startValue(name);
865     }
866
867     /**
868      * Start a new IDL initializer declaration.
869      *
870      * @param name The name of the initializer declaration.
871      *
872      * @return The new created Initializer.
873      */

874     public Initializer
875     startInitializer(String JavaDoc name)
876     {
877         Initializer init = new InitializerImpl();
878         init.setName(name);
879         return init;
880     }
881
882     /**
883      * Start a new IDL value member declaration.
884      *
885      * @param name The name of the value member declaration.
886      *
887      * @return The new created ValueMemberDecl.
888      */

889     public ValueMemberDecl
890     startValueMember(String JavaDoc name)
891     {
892         ValueMemberDecl decl = new ValueMemberDeclImpl(getRepository(), this);
893         decl.setName(name);
894         return decl;
895     }
896
897     /**
898      * Start a new IDL value box declaration.
899      *
900      * @param name The name of the value box declaration.
901      *
902      * @return The new created ValueBoxDecl.
903      */

904     public ValueBoxDecl
905     startValueBox(String JavaDoc name)
906     {
907         ValueBoxDecl decl = new ValueBoxDeclImpl(getRepository(), this);
908         decl.setName(name);
909         return decl;
910     }
911
912     /**
913      * Start a new IDL exception declaration.
914      *
915      * @param name The name of the exception declaration.
916      *
917      * @return The new created ExceptionDecl.
918      */

919     public ExceptionDecl
920     startException(String JavaDoc name)
921     {
922         ExceptionDecl decl = new ExceptionDeclImpl(getRepository(), this);
923         decl.setName(name);
924         return decl;
925     }
926
927     /**
928      * Start a new IDL native declaration.
929      *
930      * @param name The name of the native declaration.
931      *
932      * @return The new created NativeDecl.
933      */

934     public NativeDecl
935     startNative(String JavaDoc name)
936     {
937         NativeDecl decl = new NativeDeclImpl(getRepository(), this);
938         decl.setName(name);
939         return decl;
940     }
941
942     /**
943      * Start a new IDL attribute declaration.
944      *
945      * @param name The name of the attribute declaration.
946      *
947      * @return The new created AttributeDecl.
948      */

949     public AttributeDecl
950     startAttribute(String JavaDoc name)
951     {
952         AttributeDecl decl = new AttributeDeclImpl(getRepository(), this);
953         decl.setName(name);
954         return decl;
955     }
956
957     /**
958      * Start a new IDL operation declaration.
959      *
960      * @param name The name of the operation declaration.
961      *
962      * @return The new created OperationDecl.
963      */

964     public OperationDecl
965     startOperation(String JavaDoc name)
966     {
967         OperationDecl decl = new OperationDeclImpl(getRepository(), this);
968         decl.setName(name);
969         return decl;
970     }
971
972     /**
973      * Declare an IDL event type.
974      * If it not exists then create it.
975      *
976      * @param name The name of the event type declaration.
977      *
978      * @return The previous or new created EventDecl.
979      */

980     public EventDecl
981     declareEvent(String JavaDoc name)
982     {
983         // Find a declaration with the same name.
984
Declaration decl = findInScope(name);
985
986         if ((decl != null) && (decl instanceof EventDecl))
987             return (EventDecl)decl;
988
989         // else create it.
990
return startEvent(name);
991     }
992
993     /**
994      * Declare an IDL component.
995      * If it doesn't exist then create it.
996      *
997      * @param name The name of the component declaration.
998      *
999      * @return The previous or new created ComponentDecl.
1000     */

1001    public ComponentDecl
1002    declareComponent(String JavaDoc name)
1003    {
1004        // Find a declaration with the same name.
1005
Declaration decl = findInScope(name);
1006
1007        if ((decl != null) && (decl instanceof ComponentDecl))
1008            return (ComponentDecl)decl;
1009
1010        // else create it.
1011
return startComponent(name);
1012    }
1013
1014    /**
1015     * Start a new IDL provides declaration.
1016     *
1017     * @param name The name of the provides declaration.
1018     *
1019     * @return The new created ProvidesDecl.
1020     */

1021    public ProvidesDecl
1022    startProvides(String JavaDoc name)
1023    {
1024        ProvidesDecl decl = new ProvidesDeclImpl(getRepository(), this);
1025        decl.setName(name);
1026        return decl;
1027    }
1028
1029    /**
1030     * Start a new IDL uses declaration.
1031     *
1032     * @param name The name of the uses declaration.
1033     *
1034     * @return The new created UsesDecl.
1035     */

1036    public UsesDecl
1037    startUses(String JavaDoc name)
1038    {
1039        UsesDecl decl = new UsesDeclImpl(getRepository(), this);
1040        decl.setName(name);
1041        return decl;
1042    }
1043
1044    /**
1045     * Start a new IDL consumes declaration.
1046     *
1047     * @param name The name of the consumes declaration.
1048     *
1049     * @return The new created ConsumesDecl.
1050     */

1051    public ConsumesDecl
1052    startConsumes(String JavaDoc name)
1053    {
1054        ConsumesDecl decl = new ConsumesDeclImpl(getRepository(), this);
1055        decl.setName(name);
1056        return decl;
1057    }
1058
1059    /**
1060     * Start a new IDL emits declaration.
1061     *
1062     * @param name The name of the emits declaration.
1063     *
1064     * @return The new created EmitsDecl.
1065     */

1066    public EmitsDecl
1067    startEmits(String JavaDoc name)
1068    {
1069        EmitsDecl decl = new EmitsDeclImpl(getRepository(), this);
1070        decl.setName(name);
1071        return decl;
1072    }
1073
1074    /**
1075     * Start a new IDL publishes declaration.
1076     *
1077     * @param name The name of the publishes declaration.
1078     *
1079     * @return The new created PublishesDecl.
1080     */

1081    public PublishesDecl
1082    startPublishes(String JavaDoc name)
1083    {
1084        PublishesDecl decl = new PublishesDeclImpl(getRepository(), this);
1085        decl.setName(name);
1086        return decl;
1087    }
1088
1089    /**
1090     * Start a new IDL home declaration.
1091     *
1092     * @param name The name of the home declaration.
1093     *
1094     * @return The new created HomeDecl.
1095     */

1096    public HomeDecl
1097    startHome(String JavaDoc name)
1098    {
1099        HomeDecl decl = new HomeDeclImpl(getRepository(), this);
1100        decl.setName(name);
1101        return decl;
1102    }
1103
1104    /**
1105     * Start a new IDL factory declaration.
1106     *
1107     * @param name The name of the factory declaration.
1108     *
1109     * @return The new created FactoryDecl.
1110     */

1111    public FactoryDecl
1112    startFactory(String JavaDoc name)
1113    {
1114        FactoryDecl decl = new FactoryDeclImpl(getRepository(), this);
1115        decl.setName(name);
1116        return decl;
1117    }
1118
1119    /**
1120     * Start a new IDL finder declaration.
1121     *
1122     * @param name The name of the finder declaration.
1123     *
1124     * @return The new created FinderDecl.
1125     */

1126    public FinderDecl
1127    startFinder(String JavaDoc name)
1128    {
1129        FinderDecl decl = new FinderDeclImpl(getRepository(), this);
1130        decl.setName(name);
1131        return decl;
1132    }
1133
1134    /**
1135     * Declare a PSDL module.
1136     * If it doesn't exist then create it.
1137     *
1138     * @param name The name of the module declaration.
1139     *
1140     * @return The previous or new created PsdlModuleDecl.
1141     */

1142    public PsdlModuleDecl
1143    declarePsdlModule(String JavaDoc name)
1144    {
1145        // TODO: Should ModuleDecl and PsdlModuleDecl implemented by the same class or not?
1146
return (PsdlModuleDecl)declareModule(name);
1147    }
1148
1149    /**
1150     * Declare a PSDL abstract storagehome declaration.
1151     * If it doesn't exist then create it.
1152     *
1153     * @param name The name of the abstract storagehome declaration.
1154     *
1155     * @return The previous or new created AbstractStorageHomeDecl.
1156     */

1157    public AbstractStorageHomeDecl
1158    declareAbstractStorageHome(String JavaDoc name)
1159    {
1160        // Find a declaration with the same name.
1161
Declaration decl = findInScope(name);
1162
1163        if ((decl != null) && (decl instanceof AbstractStorageHomeDecl))
1164            return (AbstractStorageHomeDecl)decl;
1165
1166        // else create it.
1167
AbstractStorageHomeDecl ash = new AbstractStorageHomeDeclImpl(getRepository(), this);
1168        ash.setName(name);
1169        return ash;
1170    }
1171
1172    /**
1173     * Start a new PSDL storagehome declaration.
1174     *
1175     * @param name The name of the storagehome declaration.
1176     *
1177     * @return The new created StorageHomeDecl.
1178     */

1179    public StorageHomeDecl
1180    startStorageHome(String JavaDoc name)
1181    {
1182        // Find a declaration with the same name.
1183
Declaration decl = findInScope(name);
1184
1185        if ((decl != null) && (decl instanceof StorageHomeDecl))
1186            return (StorageHomeDecl)decl;
1187
1188        StorageHomeDecl sh = new StorageHomeDeclImpl(getRepository(), this);
1189        sh.setName(name);
1190        return sh;
1191    }
1192
1193    /**
1194     * Declare a PSDL abstract storagetype declaration.
1195     * If it doesn't exist then create it.
1196     *
1197     * @param name The name of the abstract storagetype declaration.
1198     *
1199     * @return The previous or new created AbstractStorageTypeDecl.
1200     */

1201    public AbstractStorageTypeDecl
1202    declareAbstractStorageType(String JavaDoc name)
1203    {
1204        // Find a declaration with the same name.
1205
Declaration decl = findInScope(name);
1206
1207        if ((decl != null) && (decl instanceof AbstractStorageTypeDecl))
1208            return (AbstractStorageTypeDecl)decl;
1209
1210        // else create it.
1211
AbstractStorageTypeDecl ast = new AbstractStorageTypeDeclImpl(getRepository(), this);
1212        ast.setName(name);
1213        return ast;
1214    }
1215
1216    /**
1217     * Declare a PSDL storagetype declaration.
1218     * If it doesn't exist then create it.
1219     *
1220     * @param name The name of the storagetype declaration.
1221     *
1222     * @return The previous or new created StorageTypeDecl.
1223     */

1224    public StorageTypeDecl
1225    declareStorageType(String JavaDoc name)
1226    {
1227        // Find a declaration with the same name.
1228
Declaration decl = findInScope(name);
1229
1230        if ((decl != null) && (decl instanceof StorageTypeDecl))
1231            return (StorageTypeDecl)decl;
1232
1233        // else create it.
1234
StorageTypeDecl st = new StorageTypeDeclImpl(getRepository(), this);
1235        st.setName(name);
1236        return st;
1237    }
1238
1239    /**
1240     * Start a new PSDL storagetype state member declaration.
1241     *
1242     * @param name The name of the storagetype state member declaration.
1243     *
1244     * @return The new created StorageTypeStateMemberDecl.
1245     */

1246    public StorageTypeStateMemberDecl
1247    startStorageTypeStateMember(String JavaDoc name)
1248    {
1249        StorageTypeStateMemberDecl decl = new StorageTypeStateMemberDeclImpl(getRepository(), this);
1250        decl.setName(name);
1251        return decl;
1252    }
1253
1254    /**
1255     * Start a new PSDL storagetype store directive declaration.
1256     *
1257     * @param name The name of the storagetype state member concerned by the store directive.
1258     *
1259     * @return The new created StorageTypeStoreDirectiveDecl.
1260     */

1261    public StorageTypeStoreDirectiveDecl
1262    startStorageTypeStoreDirective(String JavaDoc name)
1263    {
1264        StorageTypeStoreDirectiveDecl decl = new StorageTypeStoreDirectiveDeclImpl(getRepository(), this);
1265        decl.setName(name+"_store_directive");
1266        return decl;
1267    }
1268
1269    /**
1270     * Start a new PSDL operation declaration.
1271     *
1272     * @param name The name of the operation declaration.
1273     *
1274     * @return The new created PsdlOperationDecl.
1275     */

1276    public PsdlOperationDecl
1277    startPsdlOperation(String JavaDoc name)
1278    {
1279        PsdlOperationDecl decl = new PsdlOperationDeclImpl(getRepository(), this);
1280        decl.setName(name);
1281        return decl;
1282    }
1283
1284    /**
1285     * Declare a CIDL module.
1286     * If it doesn't exist then create it.
1287     *
1288     * @param name The name of the module declaration.
1289     *
1290     * @return The previous or new created CidlModuleDecl.
1291     */

1292    public CidlModuleDecl
1293    declareCidlModule(String JavaDoc name)
1294    {
1295        // TODO: Should ModuleDecl and CidlModuleDecl implemented by the same class or not?
1296
return (CidlModuleDecl)declareModule(name);
1297    }
1298
1299    /**
1300     * Start a new CIDL composition declaration.
1301     *
1302     * @param name The name of the CIDL composition declaration.
1303     *
1304     * @return The new created CompositionDecl.
1305     */

1306    public CompositionDecl
1307    startComposition(String JavaDoc name)
1308    {
1309        CompositionDecl decl = new CompositionDeclImpl(getRepository(), this);
1310        decl.setName(name);
1311        return decl;
1312    }
1313
1314    /**
1315     * Find an IDL declaration.
1316     *
1317     * Note that the declaration is also recursively
1318     * searched in the parent scope and finally searched
1319     * in the Interface Repository.
1320     *
1321     * @param name The name of the searched declaration.
1322     *
1323     * @return The declaration that was searched
1324     * or null if it does not exist.
1325     */

1326    public Declaration
1327    find(String JavaDoc name)
1328    {
1329      // System.out.println("ScopeImpl::find " + name + " in " + this + ' ' +this.getAbsoluteName());
1330

1331        Declaration decl = findInScope(name);
1332        // If found then returns it.
1333
if (decl != null) return decl;
1334
1335        // Finds in the parent scope.
1336
if (the_parent_ != null)
1337           decl = the_parent_.find(name);
1338
1339        // If found then returns it.
1340
if (decl != null) return decl;
1341
1342        // System.out.println("ScopeImpl::findInIR3 " + name + " in " + this + ' ' +this.getAbsoluteName());
1343
return findInIR3(name);
1344    }
1345
1346    /**
1347     * To obtain all the contained Declaration objects.
1348     *
1349     * @param exclude_inherited If false return also objects
1350     * contained in inherited scopes. // NOT IMPLEMENTED
1351     * @param limited_types A logical combination of DeclarationKind.
1352     *
1353     * @return A sequence of Declaration objects.
1354     */

1355    public Declaration[]
1356    getContents(boolean exclude_inherited,
1357                long limited_types)
1358    {
1359        // System.err.println("Content loaded for "+getAbsoluteName()+" ??? : "+content_loaded_);
1360
if (!content_loaded_)
1361        {
1362            // if it's a mapping scope, then use the OpenCCM repository
1363
// as an IDL2 repository to retrieve contained objects.
1364
if (is_mapping_)
1365                getRepository().useIDL2Repository();
1366
1367            org.omg.CORBA.Container JavaDoc container = getContainer();
1368            if(container == null)
1369                return null;
1370            org.omg.CORBA.Contained JavaDoc[] content = container.contents(org.omg.CORBA.DefinitionKind.dk_all, true);
1371
1372            // we need to reorder the contained declarations !!!
1373
// because the could have been loaded one by one without any
1374
// garanties on the order.
1375
java.util.List JavaDoc ordered_decls = new java.util.ArrayList JavaDoc();
1376            Declaration decl = null;
1377
1378            for (int i=0; i<content.length; i++)
1379            {
1380                // System.err.println("Content["+i+"] = "+content[i].name());
1381
decl = findInScope(content[i].name());
1382                if (decl==null)
1383                {
1384                    if (is_mapping_)
1385                        decl = loadContainedAsMapping(content[i]);
1386                    else
1387                        decl = loadContained(content[i]);
1388                    // System.err.println("### Loading decl : "+decl.getAbsoluteName());
1389
}
1390                // Fixed a bug on constant
1391
try{
1392                    // Test if decl is a constant
1393
org.objectweb.openccm.ast.api.ConstantDecl c = (org.objectweb.openccm.ast.api.ConstantDecl)decl;
1394                    // Load the constant
1395
// System.err.println("### Loading decl : "+decl.getAbsoluteName());
1396
decl = loadContained(content[i]);
1397                }catch(ClassCastException JavaDoc ex){
1398                    // nothing to do
1399
}
1400                 // System.err.println("???? Decl found : "+decl.getAbsoluteName());
1401
ordered_decls.add(decl);
1402            }
1403
1404            // Add declarations that are not in the repository (psdl, cidl)
1405
for(int i=0; i<contained_decls_.size(); i++)
1406            {
1407                decl = (Declaration)contained_decls_.get(i);
1408                if ( (decl.getCategory() == org.objectweb.openccm.ast.api.DeclarationCategory.dc_psdl)
1409                     || (decl.getCategory() == org.objectweb.openccm.ast.api.DeclarationCategory.dc_cidl) )
1410                    ordered_decls.add(decl);
1411            }
1412
1413            contained_decls_ = ordered_decls;
1414
1415            // get back to an IDL3 repository.
1416
if (is_mapping_)
1417                getRepository().useIDL3Repository();
1418
1419            content_loaded_ = true;
1420        }
1421
1422        Declaration decl = null;
1423        java.util.List JavaDoc selection = new java.util.ArrayList JavaDoc();
1424        for (int i=0; i<contained_decls_.size(); i++)
1425        {
1426            decl = (Declaration)contained_decls_.get(i);
1427            // System.err.println("@@@@@@@ Contained_decls : "+ decl.getAbsoluteName());
1428
if ((decl.getDeclKind()&limited_types)!=0)
1429                selection.add(decl);
1430        }
1431        // System.err.println("fin content loaded");
1432
return (Declaration[])selection.toArray(new Declaration[0]);
1433    }
1434
1435    /**
1436     * To find a contained Declaration according to it's scoped name.
1437     *
1438     * @param scoped_name The scoped name.
1439     *
1440     * @return The found Declaration (or loaded from the Interface
1441     * Repository) or null.
1442     */

1443    public Declaration
1444    lookup(String JavaDoc scoped_name)
1445    {
1446        if (scoped_name.startsWith("::")) return the_repository_.lookup(scoped_name);
1447
1448        int idx = scoped_name.indexOf("::");
1449        String JavaDoc s1 = null;
1450        String JavaDoc s2 = null;
1451        if (idx==-1)
1452        {
1453            s1 = scoped_name;
1454            s2 = "";
1455        }
1456        else
1457        {
1458            s1 = scoped_name.substring(0,idx);
1459            s2 = scoped_name.substring(idx+2);
1460        }
1461
1462        Declaration decl = findInScope(s1);
1463        if (decl==null)
1464        {
1465        // try to load it from the IR3
1466
decl = findInIR3(s1);
1467        }
1468
1469        if (s2.equals(""))
1470            return decl;
1471
1472        if (decl instanceof Scope)
1473            return ((Scope)decl).lookup(s2);
1474
1475        return null;
1476    }
1477
1478    /**
1479     * Print the Declaration.
1480     */

1481    public void
1482    print()
1483    {
1484        System.out.println(getAbsoluteName());
1485        Declaration[] decls = getContents(true, DeclarationKind.dk_all);
1486        for(int i=0; i<decls.length; i++)
1487        {
1488            System.out.print("+--");
1489            decls[i].print();
1490        }
1491    }
1492
1493}
1494
Popular Tags