KickJava   Java API By Example, From Geeks To Geeks.

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


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.corba.idl2java;
28
29 // Package dependencies.
30
import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.NoSuchElementException JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34
35 /**
36  * Application to wrap an IDL to Java generator.
37  *
38  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
39  *
40  * @version 0.1
41  */

42 public abstract class IdlToJavaApplication
43               extends IdlToJavaApplicationBase
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The IDL file to parse. */
52     protected String JavaDoc input_file_;
53     
54     /** The destination directory for generated files. */
55     protected String JavaDoc dest_dir_;
56     
57     /** List of directories to include in the search path. */
58     protected List JavaDoc includes_;
59     
60     /** Package mappings definitions. */
61     protected Map JavaDoc package_mappings_;
62
63     // ==================================================================
64
//
65
// Constructors.
66
//
67
// ==================================================================
68

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

72     public
73     IdlToJavaApplication()
74     {
75         // Call the IdlToJavaApplicationBase constructor
76
super();
77         
78         // Init internal states
79
input_file_ = null;
80         dest_dir_ = null;
81         includes_ = new java.util.ArrayList JavaDoc();
82         package_mappings_ = new java.util.HashMap JavaDoc();
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.corba.idl2java.IdlToJavaOperations
100
//
101
// ==================================================================
102

103     /**
104      * Set the IDL file to parse.
105      *
106      * @param file - The input file.
107      */

108     public void
109     setInputFile(String JavaDoc file)
110     {
111         input_file_ = file;
112     }
113     
114     /**
115      * Get the IDL file to parse.
116      *
117      * @return The input file.
118      */

119     public String JavaDoc
120     getInputFile()
121     {
122         return input_file_;
123     }
124     
125     /**
126      * Set the destination directory for generated java files.
127      *
128      * @param destdir - The destination directory.
129      */

130     public void
131     setDestinationDirectory(String JavaDoc destdir)
132     {
133         dest_dir_ = destdir;
134     }
135     
136     /**
137      * Get the destination directory for generated java files.
138      *
139      * @return The destination directory.
140      */

141     public String JavaDoc
142     getDestinationDirectory()
143     {
144         return dest_dir_;
145     }
146     
147     /**
148      * Add a directory to the include list.
149      * (Preprocessor -I option)
150      *
151      * @param directory - The directory to add.
152      */

153     public void
154     addIncludeDirectory(String JavaDoc directory)
155     {
156         includes_.add(directory);
157     }
158
159     /**
160      * Get directories added to the include list.
161      * (Preprocessor -I option)
162      *
163      * @return The list of included directories.
164      */

165     public String JavaDoc[]
166     getIncludeDirectories()
167     {
168         return (String JavaDoc[]) includes_.toArray(new String JavaDoc[0]);
169     }
170
171     /**
172      * Add a package mapping definition.
173      *
174      * @param idl_package - The idl package name.
175      * @param java_package - The java package name.
176      */

177     public void
178     addPackageMapping(String JavaDoc idl_package, String JavaDoc java_package)
179     {
180         package_mappings_.put(idl_package, java_package);
181     }
182
183     /**
184      * Get package mapping definitions.
185      *
186      * @return The map of package mappings.
187      */

188     public Map JavaDoc
189     getPackageMappings()
190     {
191         return package_mappings_;
192     }
193
194     // ==================================================================
195
//
196
// Public methods
197
//
198
// ==================================================================
199

200     /**
201       * Parse and store command line options.
202       *
203       * @param args The command line arguments.
204       */

205     public void
206     parse_cmdline(String JavaDoc[] args)
207     {
208         String JavaDoc[] mappings = null;
209         StringTokenizer JavaDoc st = null;
210         
211         dest_dir_ = destdir_opt_.getArgument();
212         input_file_ = args[0];
213         
214         mappings = i2jpackage_opt_.getOptionValues();
215         for (int i=0; i<mappings.length; i++)
216         {
217             st = new StringTokenizer JavaDoc(mappings[i], ":");
218             try
219             {
220                 addPackageMapping(st.nextToken(), st.nextToken());
221             } catch (NoSuchElementException JavaDoc ex) {
222                 getConsole().error("Warning : No mapping defined for " + mappings[i]);
223             }
224         }
225     }
226 }
227
Popular Tags