KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 created on 9 juil. 2003
4 OpenCCM: The Open CORBA Component Model Platform
5 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
6 Contact: openccm@objectweb.org
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 USA
22
23 Initial developer(s): Hameau Fabien.
24 Contributor(s): ______________________________________.
25
26 */

27 package org.objectweb.corba.command.lib;
28
29 import org.objectweb.corba.generator.metainformation.lib.IDL_JavaMIGenerator;
30 import org.objectweb.openccm.command.lib.GeneratorBase;
31 import org.objectweb.openccm.command.lib.OptionMultipleArguments;
32 import org.objectweb.util.cmdline.lib.DefaultCommandLine;
33 import org.objectweb.util.cmdline.lib.DefaultOptionArgument;
34
35 /**
36  * Implementation of the IDLtoMI command
37  *
38  * @author <a HREF="mailto:hameau@lifl.fr">Hameau Fabien</a>
39  *
40  */

41 //implements org.objectweb.openccm.command.api.IDLtoMI
42

43 public class IDLtoMI
44 extends GeneratorBase
45 {
46
47   
48   // ==================================================================
49
//
50
// Constructor.
51
//
52
// ==================================================================
53

54      /** The default constructor. */
55   public
56   IDLtoMI()
57      {
58          // Calls the CompilerGeneratorBase constructor.
59
super(new DefaultCommandLine(
60         "idl_to_mi",
61         "declaration",
62         new String JavaDoc[] {
63         "Compile an OMG IDL3 file and generate its associated:",
64         "- local MI type implementations"
65         },
66         true),
67         "none");
68   
69          // Specify output base directory
70

71        odir_ = new DefaultOptionArgument(
72                        new String JavaDoc[] { "-d" },
73                        "outputdir",
74                        new String JavaDoc[] {
75                          "Generate Java implementations into directory <outputdir>,",
76                          "default is generated/"
77                        },
78                        "generated" );
79        getCommandLine().addOption(odir_);
80   }
81   // ==================================================================
82
//
83
// Internal state.
84
//
85
// ==================================================================
86

87   /** Include Options. */
88   private OptionMultipleArguments userInclude_;
89   /** Output directory Option. */
90   org.objectweb.util.cmdline.api.OptionArgument odir_; // -d <directory>
91

92   /**
93    * run
94    *
95    * @param commandLine
96    *
97    */

98    
99   public int run(String JavaDoc[] args)
100   {
101     String JavaDoc filename = args[0];
102
103        // Inits the OpenCCM's Abstract Syntax Tree.
104

105        if(!initAST())
106            return -1;
107
108        if (!generateMI(args[0],getOutputDirectory()))
109            return -1;
110
111        // All is OK.
112
return 0;
113   }
114   
115   public String JavaDoc getOutputDirectory()
116   {
117     return odir_.getArgument();
118   }
119   //==================================================================
120
//
121
// Public methods for org.objectweb.openccm.command.api.IDLtoMI
122
//
123
// ==================================================================
124

125   /**
126    * Generates MI interfaces from an AST FileScope instance.
127    *
128    * Note that checkComponentRepository() and initAST() methods
129    * must be called before.
130    *
131    * @param filescope The source AST scope of the declaration.
132    * @param base_dir - The base directory for java mapping.
133    *
134    * @return True if ok, else false.
135    */

136   
137   public
138   boolean
139   generateMI(String JavaDoc decl,
140              String JavaDoc base_dir)
141   {
142     // Switch the OpenCCM Interface Repository in mode OMG IDL 3.0
143
getComponentRepository().as_IDL3_repository();
144
145     // Retrieves the scope to generate.
146
org.objectweb.openccm.ast.api.Scope scope = null;
147     try
148     {
149         scope = (org.objectweb.openccm.ast.api.Scope)getAST().lookup(decl);
150     }
151     catch(ClassCastException JavaDoc e)
152     {
153         getConsole().error(decl + "is not a scope!");
154         return false;
155     }
156
157     if(scope == null)
158     {
159         getConsole().error("Declaration " + decl + " not found!");
160         return false;
161     }
162
163     getConsole().message("Generating MetaInformation implementations for " + decl + "...");
164
165     // Launchs the generator.
166

167     IDL_JavaMIGenerator MI_gen = new IDL_JavaMIGenerator(getAST());
168
169     // Generates.
170
try
171     {
172       MI_gen.idl_to_java(base_dir,scope);
173     }
174     catch(org.objectweb.openccm.generator.common.lib.GenerationException ex)
175     {
176         report_exception(ex);
177         return false;
178     }
179
180    
181     getConsole().message(" ...");
182     // generate the MI typ eimplementation for the given AST
183

184     return true;
185   }
186   
187   // ==================================================================
188
//
189
// Static public methods.
190
//
191
// ==================================================================
192

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

198   public static void
199   main(String JavaDoc[] args)
200    {
201       IDLtoMI idl2mi = new IDLtoMI();
202       idl2mi.runMain(args);
203   }
204    
205   
206   
207   
208   
209   
210   
211   
212   
213   
214 }
Popular Tags