KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > generator > common > lib > PSDLtoJavaCommand


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.openccm.pss.generator.common.lib;
28
29 // Package dependencies.
30
import org.objectweb.util.cmdline.api.OptionArgument;
31 import org.objectweb.util.cmdline.lib.DefaultCommandLine;
32 import org.objectweb.util.cmdline.lib.DefaultOptionArgument;
33 import org.objectweb.openccm.ast.api.FileScope;
34
35 /**
36  * This class allows you to generate Java mapping from a PSDL file.
37  *
38  * @author <a HREF="mailto:Chrsitophe.Demarey@lifl.fr">Christophe Demarey</a>
39  *
40  * @version 0.1
41  */

42
43 public class PSDLtoJavaCommand
44      extends org.objectweb.openccm.command.lib.CompilerGeneratorBase
45   implements org.objectweb.openccm.pss.generator.common.api.PSDLtoJavaCommand
46 {
47     // ==================================================================
48
//
49
// Internal state.
50
//
51
// ==================================================================
52

53     /** Output directory Option. */
54     OptionArgument odir_; // -d <directory>
55

56     /** User properties file name. */
57     OptionArgument user_props_; // -userprop <file_name>
58

59     /** Persistent Framework used. */
60     OptionArgument backend_; // -backend [jdo,hibernate]
61

62     // ==================================================================
63
//
64
// Constructor.
65
//
66
// ==================================================================
67

68     /**
69      * The default constructor.
70      */

71     public
72     PSDLtoJavaCommand()
73     {
74         // Calls the CompilerGeneratorBase constructor.
75
super(new DefaultCommandLine("psdl_java",
76                                      "file",
77                                      "Compile an OMG PSDL file and generate its associated Java mapping",
78                                      true));
79
80         // Specify output base directory
81
odir_ = new DefaultOptionArgument(
82                         new String JavaDoc[] { "-d" },
83                         "outputdir",
84                         new String JavaDoc[] {
85                           "Generate Java mapping into directory <outputdir>,",
86                           "default is generated/"
87                         },
88                         "generated" );
89         getCommandLine().addOption(odir_);
90
91         // Specify User properties file name
92
user_props_ = new DefaultOptionArgument(
93                         new String JavaDoc[] { "-userprop" },
94                         "user_properties_file",
95                         new String JavaDoc[] {
96                           "Get user classes definition from the properties file <user_properties_file>",
97                           "default is \"user.properties\""
98                         },
99                         "user.properties" );
100         getCommandLine().addOption(user_props_);
101
102         // Specify Persistent Framework name
103
backend_ = new DefaultOptionArgument(
104                         new String JavaDoc[] { "-backend" },
105                         "jdo|hibernate",
106                         new String JavaDoc[] {
107                           "Choose the persistent framework to use : jdo or hibernate",
108                           "default is \"jdo\""
109                         },
110                         "jdo" );
111         getCommandLine().addOption(backend_);
112     }
113
114     // ==================================================================
115
//
116
// Internal methods.
117
//
118
// ==================================================================
119

120     // ==================================================================
121
//
122
// Public methods for org.objectweb.util.cmdline.api.Application
123
//
124
// ==================================================================
125

126     // ==================================================================
127
//
128
// Public methods for org.objectweb.openccm.command.api.Application
129
//
130
// ==================================================================
131

132     /**
133      * Runs the application.
134      *
135      * @param args The command line arguments.
136      *
137      * @return The status.
138      */

139     public int
140     run(java.lang.String JavaDoc[] args)
141     {
142         String JavaDoc filename = args[0];
143
144         // Inits the OpenCCM Abstract Syntax Tree.
145
if(!initAST())
146             return -1;
147
148         // Compiles the file.
149
FileScope fileScope = compile(filename);
150         if(fileScope == null)
151             return -1;
152
153         // Generates PSDL Mapping
154
if (!generate_java_mapping(fileScope,
155                                    filename, // Input File
156
getOutputDirectory(), // Base directory for Java Mapping
157
getUserPropertiesFile(), // User JDO properties file
158
getBackend() )) // The Persistent framework
159
return -1;
160
161         // All is OK.
162
return 0;
163     }
164
165     // ==================================================================
166
//
167
// Public methods for org.objectweb.openccm.command.api.CommandOnIR3
168
//
169
// ==================================================================
170

171     // ==================================================================
172
//
173
// Public methods for org.objectweb.openccm.command.api.CommandOnAST
174
//
175
// ==================================================================
176

177     // ==================================================================
178
//
179
// Public methods for org.objectweb.openccm.command.api.Compiler
180
//
181
// ==================================================================
182

183     // ==================================================================
184
//
185
// Public methods for org.objectweb.openccm.command.api.Generator
186
//
187
// ==================================================================
188

189     // ==================================================================
190
//
191
// Public methods for org.objectweb.openccm.command.api.PSDLtoJavaCommand
192
//
193
// ==================================================================
194

195     /**
196      * Obtains the output directory.
197      *
198      * @result The output directory.
199      */

200     public String JavaDoc
201     getOutputDirectory()
202     {
203         return odir_.getArgument();
204     }
205
206     /**
207      * Obtains the user properties file name.
208      *
209      * @result The user properties file name.
210      */

211     public String JavaDoc
212     getUserPropertiesFile()
213     {
214         return user_props_.getArgument();
215     }
216
217     /**
218      * Obtains the persistent framework choosen.
219      *
220      * @result The persistent framework choosen.
221      */

222     public String JavaDoc
223     getBackend()
224     {
225         return backend_.getArgument();
226     }
227
228     /**
229      * Generates PSDL Mapping from an AST FileScope instance.
230      *
231      * Note that checkComponentRepository() and initAST() methods
232      * must be called before.
233      *
234      * @param filescope The source AST FileScope returned by the compile() method.
235      * @param inputfile - The source file.
236      * @param base_dir - The base directory for java mapping.
237      * @param user_properties_file - The user jdo properties file.
238      * @param backend - The target persistent framework.
239      *
240      * @return True if ok, else false.
241      */

242     public boolean
243     generate_java_mapping(FileScope filescope,
244                           String JavaDoc inputfile,
245                           String JavaDoc base_dir,
246                           String JavaDoc user_properties_file,
247                           String JavaDoc backend)
248     {
249         // Launchs the PSDL to Java generator.
250
org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator gen =
251             new org.objectweb.openccm.pss.generator.common.lib.PSDL2JavaGenerator(getAST());
252
253         // Generates Java Mapping.
254
getConsole().message("Generating Java mapping from " + inputfile + " ...");
255         try
256         {
257             gen.psdl_to_java( base_dir,
258                               filescope,
259                               user_properties_file,
260                               backend);
261         }
262         catch(org.objectweb.openccm.generator.common.lib.GenerationException ex)
263         {
264             report_exception(ex);
265             return false;
266         }
267         getConsole().message("Java mapping generated.");
268
269         return true;
270     }
271
272     // ==================================================================
273
//
274
// Static public methods.
275
//
276
// ==================================================================
277

278     /**
279      * The main bootstrap method.
280      *
281      * @param args The command line arguments.
282      */

283     public static void
284     main(String JavaDoc[] args)
285     {
286         PSDLtoJavaCommand psdl2java = new PSDLtoJavaCommand();
287         psdl2java.runMain(args);
288     }
289 }
290
Popular Tags