KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > generator > cif > lib > CIF_JavaImplGenerator


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.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.generator.java.core.lib.*;
31 import org.objectweb.openccm.generator.java.ast.api.*;
32 import org.objectweb.openccm.generator.java.ast.lib.*;
33 import org.objectweb.openccm.generator.common.lib.GenerationException;
34 import org.objectweb.openccm.ast.api.*;
35
36 /**
37  * This class generates CIF implementation templates files.
38  * Firstly, a java AST is fed, then classes are generated by the JavaGenerator.
39  *
40  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
41  *
42  * @version 0.1
43  */

44
45 public class CIF_JavaImplGenerator
46      extends org.objectweb.openccm.generator.common.lib.GeneratorBase
47   implements org.objectweb.corba.generator.cif.api.CIF_JavaImplGenerator
48 {
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

55     /** The java repository */
56     private Repository repository_;
57
58     // ==================================================================
59
//
60
// Constructors.
61
//
62
// ==================================================================
63

64     /**
65      * The default constructor.
66      *
67      * @param ast - The Abstract Syntax Tree.
68      **/

69     public CIF_JavaImplGenerator(org.objectweb.openccm.ast.api.AST ast)
70     {
71         super(ast);
72
73         // Init internal state
74
repository_ = new RepositoryImpl();
75     }
76
77     // ==================================================================
78
//
79
// Internal methods.
80
//
81
// ==================================================================
82

83     // ==================================================================
84
//
85
// Public methods for org.objectweb.openccm.generator.cif.api.CIF_JavaImplGenerator.
86
//
87
// ==================================================================
88

89     /**
90      * Generate java files for the CIF.
91      *
92      * @param base_dir - The base directory where files will be generated.
93      * @param scope - The scope to map.
94      *
95      * @exception GenerationException - Thrown if a problem occurs during generation.
96      **/

97     public void
98     cif_to_java_impl(String JavaDoc base_dir, Scope scope)
99     throws GenerationException
100     {
101         java.io.File JavaDoc out_dir = null;
102         repository_ = new RepositoryImpl();
103         java.util.List JavaDoc list = null;
104         ValueDecl[] value_array = null;
105         CompositionDecl[] compositions = null;
106
107         // Check and create the output directory
108
try{
109             out_dir = org.objectweb.openccm.generator.common.lib.FileManager.mkdir(base_dir);
110         }catch(GenerationException ex){
111             System.err.println(ex.getMessage());
112             return;
113         }
114
115         /** Get all Value Types and Events contained in the file scope **/
116         list = getAllDeclarations(scope, DeclarationKind.dk_event +
117                                          DeclarationKind.dk_value);
118         value_array = (ValueDecl[]) list.toArray(new ValueDecl[0]);
119         for (int i=0; i<value_array.length; i++)
120         {
121             org.objectweb.corba.generator.cif.api.ValueTypeImplMapping value
122                 = new ValueTypeImplMapping(value_array[i]);
123             value.toJavaValueTemplate(repository_);
124             value.toJavaValueFactoryTemplate(repository_);
125         }
126
127         /** Get all compositions contained in the file scope **/
128         list = getAllDeclarations(scope, DeclarationKind.dk_composition);
129         compositions = (CompositionDecl[]) list.toArray(new CompositionDecl[0]);
130
131         // For each composition, call mapping
132
for (int i=0; i<compositions.length; i++)
133         {
134             // Generate the home implementation template
135
org.objectweb.corba.generator.cif.api.HomeImplMapping home_mapping
136                 = new HomeImplMapping(compositions[i]);
137             home_mapping.toJavaHomeTemplate(repository_);
138
139             // Generate the component implementation template
140
org.objectweb.corba.generator.cif.api.ComponentImplMapping comp_mapping
141                 = new ComponentImplMapping(compositions[i]);
142             comp_mapping.toJavaComponentTemplate(repository_);
143
144             // Generate segments implementation templates
145
org.objectweb.corba.generator.cif.api.SegmentImplMapping seg_mapping
146                 = new SegmentImplMapping(compositions[i]);
147             seg_mapping.toJavaSegmentTemplates(repository_);
148         }
149
150         // Generate Java Files
151
org.objectweb.openccm.generator.java.core.lib.JavaGenerator java_gen = new JavaGenerator();
152         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
153         v.add("org/objectweb/corba/generator/cif/cif_jimpl.vm");
154         java_gen.initialize("CIF_JIMPL", v);
155         java_gen.generate(repository_, base_dir);
156     }
157
158     // ==================================================================
159
//
160
// Public methods.
161
//
162
// ==================================================================
163

164 }
165
Popular Tags