KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > corba > idl2java > IdlToJava


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 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): Philippe Merle.
24
25 ====================================================================
26 $Id: IdlToJava.java,v 1.5 2005/06/29 17:45:53 merle Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.corba.idl2java;
30
31 // Package dependencies.
32
import java.io.IOException JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Set JavaDoc;
36
37 /**
38  * This application wraps the BES 5.2 idl2java command.
39  *
40  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
41  *
42  * @version 0.1
43  */

44 public class IdlToJava
45      extends IdlToJavaApplication
46 {
47     // ==================================================================
48
//
49
// Internal state.
50
//
51
// ==================================================================
52

53     /** Arguments delimiter. */
54     private String JavaDoc arg_delimiter_;
55
56     // ==================================================================
57
//
58
// Constructors.
59
//
60
// ==================================================================
61

62     /** The default constructor */
63     public IdlToJava()
64     {
65         if ( System.getProperty("file.separator").compareTo("\\") == 0 )
66             arg_delimiter_ = "\"";
67         else
68             arg_delimiter_ = "";
69     }
70     
71     // ==================================================================
72
//
73
// Internal methods.
74
//
75
// ==================================================================
76

77     /**
78      * Get the BES IDL Compiler command.
79      *
80      * @return The full path to the binary command.
81      */

82     private String JavaDoc
83     getCommand()
84     {
85         return System.getProperty("ORB_HOMEDIR") + "/bin/idl2java ";
86     }
87
88     /**
89      * Get the BES IDL Compiler arguments.
90      *
91      * @return A string with all arguments.
92      */

93     private String JavaDoc
94     getArguments()
95     {
96         String JavaDoc args = null,
97                key = null,
98                value = null;
99         String JavaDoc[] includes = null;
100         Map JavaDoc mappings = null;
101         Set JavaDoc mapping_keys = null;
102        
103         // Default arguments
104
args = "-strict ";
105         
106         // Add the destination directory
107
args += "-root_dir " + arg_delimiter_ + getDestinationDirectory() + arg_delimiter_ + " ";
108         
109         // Add Include directory list
110
includes = getIncludeDirectories();
111         for (int i=0; i<includes.length; i++)
112         {
113             args += arg_delimiter_ + "-I" + includes[i] + arg_delimiter_ + " ";
114         }
115
116         // Add Package mappings
117
mappings = getPackageMappings();
118         mapping_keys = getPackageMappings().keySet();
119         for (Iterator JavaDoc it=mapping_keys.iterator(); it.hasNext(); )
120         {
121             key = (String JavaDoc) it.next();
122             value = (String JavaDoc) mappings.get(key);
123             args += "-idl2package ::" + key + " " + value + " ";
124         }
125
126         // Add the file to parse
127
args += arg_delimiter_ + getInputFile() + arg_delimiter_;
128         
129         return args;
130     }
131
132     // ==================================================================
133
//
134
// Public methods for org.objectweb.util.cmdline.api.Application
135
//
136
// ==================================================================
137

138     /**
139       * Starts the main function.
140       *
141       * @param args The command line arguments.
142       *
143       * @return The status of the application.
144       */

145     public int
146     start(String JavaDoc[] args)
147     {
148         Process JavaDoc process = null;
149         Redirector redirector = null;
150         
151         parse_cmdline(args);
152         
153         try
154         {
155             process = Runtime.getRuntime().exec( getCommand() + getArguments() );
156             
157             redirector = new Redirector(process);
158             redirector.redirectOutput();
159         } catch (IOException JavaDoc e) {
160             e.printStackTrace();
161         }
162         
163         try
164         {
165             process.waitFor();
166         } catch (InterruptedException JavaDoc e) {
167             e.printStackTrace();
168         }
169         
170         return process.exitValue();
171     }
172     
173     // ==================================================================
174
//
175
// Public methods
176
//
177
// ==================================================================
178

179     public static void
180     main(String JavaDoc[] args)
181     {
182         IdlToJava app = new IdlToJava();
183         app.runMain(args);
184     }
185 }
186
Popular Tags