KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > command > lib > CIDLtoCIDL


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, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.command.lib;
28
29 // Package dependencies.
30
import org.objectweb.util.cmdline.lib.DefaultCommandLine;
31 import org.objectweb.openccm.ast.api.FileScope;
32
33 /**
34  * Implementation of the cidl_cidl command.
35  *
36  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
37  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
38  *
39  * @version 0.2
40  */

41
42 public class CIDLtoCIDL
43      extends CompilerGeneratorBase
44   implements org.objectweb.openccm.command.api.CIDLtoCIDL
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     // ==================================================================
53
//
54
// Constructor.
55
//
56
// ==================================================================
57

58     /** The default constructor. */
59     public
60     CIDLtoCIDL()
61     {
62         // Calls the CompilerGeneratorBase constructor.
63
super(new DefaultCommandLine("cidl",
64                                      "file",
65                                      "Compile a file and regenerate the OMG CIDL part only",
66                                      true),
67               "generated.cidl");
68     }
69
70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ==================================================================
75

76     // ==================================================================
77
//
78
// Public methods for org.objectweb.util.cmdline.api.Application
79
//
80
// ==================================================================
81

82     // ==================================================================
83
//
84
// Public methods for org.objectweb.openccm.command.api.Application
85
//
86
// ==================================================================
87

88     /**
89      * Runs the application.
90      *
91      * @param args The command line arguments.
92      *
93      * @return The status.
94      */

95     public int
96     run(java.lang.String JavaDoc[] args)
97     {
98         String JavaDoc filename = args[0];
99
100         // Inits the OpenCCM Abstract Syntax Tree.
101
if(!initAST())
102             return -1;
103
104         // Compiles the file.
105
FileScope fileScope = compile(filename);
106         if(fileScope == null)
107             return -1;
108
109         // Generates CIDL (inputfile, outputfile)
110
if (!generate_cidl(fileScope, filename, getOutputFileName()))
111             return -1;
112
113        // All is OK.
114
return 0;
115     }
116
117     // ==================================================================
118
//
119
// Public methods for org.objectweb.openccm.command.api.CommandOnIR3
120
//
121
// ==================================================================
122

123     // ==================================================================
124
//
125
// Public methods for org.objectweb.openccm.command.api.CommandOnAST
126
//
127
// ==================================================================
128

129     // ==================================================================
130
//
131
// Public methods for org.objectweb.openccm.command.api.Compiler
132
//
133
// ==================================================================
134

135     // ==================================================================
136
//
137
// Public methods for org.objectweb.openccm.command.api.Generator
138
//
139
// ==================================================================
140

141     // ==================================================================
142
//
143
// Public methods for org.objectweb.openccm.command.api.CIDLtoCIDL
144
//
145
// ==================================================================
146

147     /**
148      * Generates CIDL from an AST FileScope instance.
149      *
150      * Note that checkComponentRepository() and initAST() methods
151      * must be called before.
152      *
153      * @param filescope The source AST FileScope returned by the compile() method.
154      * @param inputfile The source file name.
155      * @param outputfile The target file name.
156      *
157      * @return True if ok, else false.
158      */

159     public boolean
160     generate_cidl(org.objectweb.openccm.ast.api.FileScope filescope,
161                   String JavaDoc inputfile,
162                   String JavaDoc outputfile)
163     {
164         // Launchs the generator.
165
org.objectweb.openccm.generator.cidl.api.CIDLGenerator gen =
166             new org.objectweb.openccm.generator.cidl.lib.CIDLGenerator(getAST());
167         gen.initialize(outputfile, "CIDLtoCIDL");
168
169         // Generates.
170
getConsole().message("Generating CIDL from " + inputfile + "...");
171         try
172         {
173             gen.generate( filescope, org.objectweb.openccm.ast.api.DeclarationKind.dk_cidl );
174         }
175         catch(org.objectweb.openccm.generator.common.lib.GenerationException ex)
176         {
177             report_exception(ex);
178             return false;
179         }
180
181         getConsole().message("CIDL generated in " + outputfile + ".");
182         return true;
183     }
184
185    // ==================================================================
186
//
187
// Static public methods.
188
//
189
// ==================================================================
190

191     /**
192      * The main bootstrap method.
193      *
194      * @param args The command line arguments.
195      */

196     public static void
197     main(String JavaDoc[] args)
198     {
199         CIDLtoCIDL cidl2cidl = new CIDLtoCIDL();
200         cidl2cidl.runMain(args);
201     }
202 }
203
Popular Tags