KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
32
33 /**
34  * Implementation of the ir3_idl3 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 IR3toIDL3
43      extends GeneratorBase
44   implements org.objectweb.openccm.command.api.IR3toIDL3
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     /** Import Option.*/
53     private OptionMultipleArguments import_;
54
55     // ==================================================================
56
//
57
// Constructor.
58
//
59
// ==================================================================
60

61     /** The default constructor. */
62     public
63     IR3toIDL3()
64     {
65         // Calls the GeneratorBase constructor.
66
super(new DefaultCommandLine("ir3_idl3",
67                                      "declaration",
68                                      "Generate OMG IDL 3.0 for a declaration from the OpenCCM Interface Repository",
69                                      true),
70               "generated.idl3");
71  
72         // Inits internal state.
73

74         // Adds the import option.
75
import_ = new OptionMultipleArguments(
76                           "-i",
77                           new String JavaDoc[] { "-i" },
78                           "ir_object",
79                           new String JavaDoc[] { "Add import ir_object statement" },
80                           "",
81                           true);
82         getCommandLine().addOption(import_);
83     }
84
85     // ==================================================================
86
//
87
// Internal methods.
88
//
89
// ==================================================================
90

91     // ==================================================================
92
//
93
// Public methods for org.objectweb.util.cmdline.api.Application
94
//
95
// ==================================================================
96

97     // ==================================================================
98
//
99
// Public methods for org.objectweb.openccm.command.api.Application
100
//
101
// ==================================================================
102

103     /**
104      * Runs the application.
105      *
106      * @param args The command line arguments.
107      *
108      * @return The status.
109      */

110     public int
111     run(java.lang.String JavaDoc[] args)
112     {
113         // Inits the OpenCCM Abstract Syntax Tree.
114
if(!initAST())
115             return -1;
116
117         // Generates OMG IDL 3.0.
118
if (!generate_idl3(args[0],
119                            getOutputFileName(),
120                            import_.getOptionArguments()))
121             return -1;
122
123         // All is OK.
124
return 0;
125     }
126
127     // ==================================================================
128
//
129
// Public methods for org.objectweb.openccm.command.api.CommandOnIR3
130
//
131
// ==================================================================
132

133     // ==================================================================
134
//
135
// Public methods for org.objectweb.openccm.command.api.CommandOnAST
136
//
137
// ==================================================================
138

139     // ==================================================================
140
//
141
// Public methods for org.objectweb.openccm.command.api.Generator
142
//
143
// ==================================================================
144

145     // ==================================================================
146
//
147
// Public methods for org.objectweb.openccm.command.api.IR3toIDL3
148
//
149
// ==================================================================
150

151     /**
152      * Generates OMG IDL 3.0 for a scope.
153      *
154      * @param decl_name The scope to be generated.
155      * @param outputfile The file name to write in.
156      * @param imports IR declarations to import.
157      *
158      * @return True if ok, else false.
159      */

160     public boolean
161     generate_idl3(String JavaDoc decl_name,
162                   String JavaDoc outputfile,
163                   String JavaDoc[] imports)
164     {
165         // Switch the OpenCCM Interface Repository in mode OMG IDL 3.0
166
getComponentRepository().as_IDL3_repository();
167
168         // Retrieves the scope to generate.
169
org.objectweb.openccm.ast.api.Scope scope = null;
170         try
171         {
172             scope = (org.objectweb.openccm.ast.api.Scope)getAST().lookup(decl_name);
173         }
174         catch(ClassCastException JavaDoc e)
175         {
176             getConsole().error(decl_name + "is not a scope!");
177             return false;
178         }
179
180         if(scope == null)
181         {
182             getConsole().error("Declaration " + decl_name + " not found!");
183             return false;
184         }
185
186         getConsole().message("Generating OMG IDL 3.0 for " + decl_name + "...");
187
188         // Launchs the generator.
189
org.objectweb.openccm.generator.idl.api.IDL3Generator gen =
190                          new org.objectweb.openccm.generator.idl.lib.IDL3Generator(getAST());
191         gen.initialize( outputfile,
192                         new ArrayList JavaDoc(java.util.Arrays.asList(imports)),
193                         "IR3toIDL3" );
194
195         // Generates.
196
try
197         {
198             gen.generate(scope);
199         }
200         catch(org.objectweb.openccm.generator.common.lib.GenerationException ex)
201         {
202             report_exception(ex);
203             return false;
204         }
205
206         getConsole().message("OMG IDL 3.0 generated in " + outputfile + ".");
207         return true;
208     }
209
210     // ==================================================================
211
//
212
// Static 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         IR3toIDL3 ir3_idl3 = new IR3toIDL3();
225         ir3_idl3.runMain(args);
226     }
227 }
228
Popular Tags