KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > generator > cif_idl > lib > CIF_IDLGenerator


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.corba.generator.cif_idl.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.ast.api.Declaration;
31 import org.objectweb.openccm.ast.api.Scope;
32 import org.objectweb.openccm.ast.api.CompositionDecl;
33 import org.objectweb.openccm.ast.api.ModuleDecl;
34 import org.objectweb.openccm.ast.api.DeclarationKind;
35 import org.objectweb.corba.generator.cif_idl.api.CompositionMapping;
36 import org.objectweb.openccm.generator.common.lib.GenerationException;
37 import java.util.List JavaDoc;
38 import java.util.ArrayList JavaDoc;
39 import java.util.Iterator JavaDoc;
40
41 /**
42  * This class generates CIF interfaces in the Interface Repository.
43  *
44  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
45  */

46
47 public class CIF_IDLGenerator
48      extends org.objectweb.openccm.generator.common.lib.GeneratorBase
49   implements org.objectweb.corba.generator.cif_idl.api.CIF_IDLGenerator
50 {
51
52     // ===========================================================
53
//
54
// Internal methods.
55
//
56
// ===========================================================
57

58     /** Declarations created for CIF. **/
59     private List JavaDoc cif_decls_;
60
61     /** CIF Declarations to remove from IR. **/
62     private List JavaDoc decls_to_remove_;
63
64     /** The OpenCCM Interface Repository reference. **/
65     private org.objectweb.openccm.ir3.api.ComponentRepository rep_;
66
67     // ===========================================================
68
//
69
// Constructors.
70
//
71
// ===========================================================
72

73     /**
74      * The default constructor.
75      *
76      * @param ast - The Abstract Syntax Tree.
77      * @param rep - The OpenCCM Interface Repository reference.
78      * Used to remove CIF mapping from IR.
79      **/

80
81     public CIF_IDLGenerator( org.objectweb.openccm.ast.api.AST ast,
82                              org.objectweb.openccm.ir3.api.ComponentRepository rep)
83     {
84         // Call the GeneratorBase constructor
85
super(ast);
86
87         // Init internal states
88
rep_ = rep;
89         cif_decls_ = null;
90         decls_to_remove_ = null;
91     }
92
93     // ==================================================================
94
//
95
// Public methods.
96
//
97
// ==================================================================
98

99     /**
100      * Generate CIF interfaces from AST.
101      * IR must be initialized first with method "initRepository()".
102      *
103      * @param scope - The scope to map.
104      *
105      * @return The list of mapped modules.
106      **/

107     public List JavaDoc
108     declare_cif(Scope scope)
109     throws GenerationException
110     {
111         List JavaDoc list = null;
112         Declaration[] decls = null;
113         org.objectweb.openccm.ast.api.NativeDecl nativ = null;
114
115         cif_decls_ = new ArrayList JavaDoc();
116         decls_to_remove_ = new ArrayList JavaDoc();
117
118         /** Get all psdl abstract storage home and map to native **/
119         list = getAllDeclarations(scope, DeclarationKind.dk_abstract_storage_home);
120         decls = (Declaration[]) list.toArray(new Declaration[0]);
121         for (int i=0; i<decls.length; i++)
122         {
123             // System.out.println("decl : "+decls[i].getName());
124
nativ = ((org.objectweb.openccm.ast.api.AbstractStorageHomeDecl)decls[i]).getMapping();
125             cif_decls_.add(nativ);
126             decls_to_remove_.add(nativ);
127         }
128
129         /** Get all psdl abstract storage type and map to native **/
130         list = getAllDeclarations(scope, DeclarationKind.dk_abstract_storage_type);
131         decls = (Declaration[]) list.toArray(new Declaration[0]);
132         for (int i=0; i<decls.length; i++)
133         {
134             nativ = ((org.objectweb.openccm.ast.api.AbstractStorageTypeDecl)decls[i]).getMapping();
135             cif_decls_.add(nativ);
136             decls_to_remove_.add(nativ);
137         }
138
139         /** Get all compositions contained in the file scope **/
140         list = getAllDeclarations(scope, DeclarationKind.dk_composition);
141         decls = (Declaration[]) list.toArray(new Declaration[0]);
142
143         // For each composition, call declare_cif()
144
for (int i=0; i<decls.length; i++)
145         {
146             CompositionMapping comp = null;
147             ModuleDecl module = null;
148
149             comp = new org.objectweb.corba.generator.cif_idl.lib.CompositionMapping(
150                             (CompositionDecl) decls[i]);
151             module = comp.declareCIF();
152             cif_decls_.add(module);
153             decls_to_remove_.add(module);
154         }
155
156         // return new created declarations
157
return cif_decls_;
158     }
159
160
161     /**
162      * Remove CIF declarations from I.R.
163      **/

164     public void
165     remove_decls()
166     {
167         Declaration decl = null;
168         Iterator JavaDoc it = null;
169
170         for(it=decls_to_remove_.iterator(); it.hasNext(); )
171         {
172             decl = (Declaration) it.next();
173             if (decl.getDeclKind() == DeclarationKind.dk_module)
174             {
175                 org.omg.CORBA.Contained JavaDoc contained = null;
176
177                 // Remove Compositions Mapping (CIF module)
178
contained = rep_.lookup_id( decl.getId() );
179                 contained.destroy();
180             }
181             else
182             {
183                 // Remove remaining declarations (i.e. Natives)
184
decl.destroy();
185             }
186         }
187     }
188 }
189
Popular Tags