KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > command > lib > CIFtoJavaImpl


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.command.lib;
28
29 // Package dependencies.
30
import org.objectweb.util.cmdline.lib.DefaultCommandLine;
31 import org.objectweb.util.cmdline.lib.DefaultOptionArgument;
32 import org.objectweb.openccm.ast.api.FileScope;
33 import org.objectweb.openccm.command.lib.CompilerGeneratorBase;
34
35 /**
36  * Implementation of the cif_jimpl command.
37  *
38  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
39  *
40  * @version 0.1
41  */

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

53     /** Output directory Option. */
54     private org.objectweb.util.cmdline.api.OptionArgument odir_; // -d <directory>
55

56     // ==================================================================
57
//
58
// Constructors.
59
//
60
// ==================================================================
61

62     /** The default constructor. */
63     public
64     CIFtoJavaImpl()
65     {
66         // Calls the CompilerGeneratorBase constructor.
67
super(new DefaultCommandLine("cif_jimpl",
68                                      "file",
69                                      new String JavaDoc[] {
70                                         "Compile an OMG CIDL file and generate its associated Java implementation templates."
71                                      },
72                                      true)
73              );
74
75         // Inits internal state.
76
// Specify output base directory
77
odir_ = new DefaultOptionArgument(
78                         new String JavaDoc[] { "-d" },
79                         "outputdir",
80                         new String JavaDoc[] {
81                           "Generate Java implementations templates into directory <outputdir>,",
82                           "default is generated/"
83                         },
84                         "generated" );
85         getCommandLine().addOption(odir_);
86     }
87
88     // ==================================================================
89
//
90
// Internal methods.
91
//
92
// ==================================================================
93

94     // ==================================================================
95
//
96
// Public methods for org.objectweb.util.cmdline.api.Application
97
//
98
// ==================================================================
99

100     // ==================================================================
101
//
102
// Public methods for org.objectweb.openccm.command.api.Application
103
//
104
// ==================================================================
105

106     /**
107      * Runs the application.
108      *
109      * @param args - The command line arguments.
110      *
111      * @return The status.
112      */

113     public int
114     run(java.lang.String JavaDoc[] args)
115     {
116         String JavaDoc filename = args[0];
117
118         // Inits the OpenCCM Abstract Syntax Tree.
119
if(!initAST())
120             return -1;
121
122         // Compiles the file.
123
FileScope fileScope = compile(filename);
124         if(fileScope == null)
125             return -1;
126
127         // Generates Java implementations templates
128
if (!generate_cif_jimpl(fileScope,
129                                 filename, // Input File
130
getOutputDirectory())) // Base directory for Java Mapping
131
return -1;
132
133         // All is OK.
134
return 0;
135     }
136
137     // ==================================================================
138
//
139
// Public methods for org.objectweb.openccm.command.api.CommandOnIR3
140
//
141
// ==================================================================
142

143     // ==================================================================
144
//
145
// Public methods for org.objectweb.openccm.command.api.CommandOnAST
146
//
147
// ==================================================================
148

149     // ==================================================================
150
//
151
// Public methods for org.objectweb.openccm.command.api.Compiler
152
//
153
// ==================================================================
154

155     // ==================================================================
156
//
157
// Public methods for org.objectweb.openccm.command.api.Generator
158
//
159
// ==================================================================
160

161     // ==================================================================
162
//
163
// Public methods for org.objectweb.openccm.command.api.CIDLtoCIF
164
//
165
// ==================================================================
166

167     /**
168      * Obtains the output directory.
169      *
170      * @result The output directory.
171      */

172     public String JavaDoc
173     getOutputDirectory()
174     {
175         return odir_.getArgument();
176     }
177
178     /**
179      * Generates Java implementations template files for the CIF.
180      *
181      * Note that checkComponentRepository() and initAST() methods
182      * must be called before.
183      *
184      * @param filescope The source AST FileScope returned by the compile() method.
185      * @param inputfile - The source file.
186      * @param base_dir - The base directory for java mapping.
187      *
188      * @return True if ok, else false.
189      */

190     public boolean
191     generate_cif_jimpl(org.objectweb.openccm.ast.api.FileScope filescope,
192                        String JavaDoc inputfile,
193                        String JavaDoc base_dir)
194     {
195        // Launchs the CIF_Jimpl generator.
196
org.objectweb.corba.generator.cif.api.CIF_JavaImplGenerator gen =
197             new org.objectweb.corba.generator.cif.lib.CIF_JavaImplGenerator(getAST());
198         try
199         {
200             gen.cif_to_java_impl(base_dir, filescope);
201         }
202         catch(org.objectweb.openccm.generator.common.lib.GenerationException ex)
203         {
204             report_exception(ex);
205             return false;
206         }
207         return true;
208     }
209
210     // ==================================================================
211
//
212
// Public methods.
213
//
214
// ==================================================================
215

216     /**
217      * The main bootstrap method.
218      *
219      * @param args The command line arguments.
220      */

221     public static void
222     main(String JavaDoc[] args)
223     {
224         CIFtoJavaImpl cif2jimpl = new CIFtoJavaImpl();
225         cif2jimpl.runMain(args);
226     }
227 }
228
Popular Tags