KickJava   Java API By Example, From Geeks To Geeks.

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


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): 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.api.OptionArgument;
31 import org.objectweb.util.cmdline.api.OptionFlag;
32 import org.objectweb.util.cmdline.lib.DefaultCommandLine;
33 import org.objectweb.util.cmdline.lib.DefaultOptionArgument;
34 import org.objectweb.util.cmdline.lib.DefaultOptionFlag;
35 import org.objectweb.openccm.corba.TheORB;
36 import org.objectweb.openccm.ir3.IFR;
37 import org.omg.CORBA.ComponentIR.Repository;
38
39 /**
40  * Implementation of the ir3_start command.
41  *
42  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
43  *
44  * @version 0.1
45  */

46
47 public class IR3Server
48      extends ApplicationServerBase
49 {
50     // ==================================================================
51
//
52
// Internal state.
53
//
54
// ==================================================================
55

56     /** The command line option for the file to store the IOR. */
57     private OptionArgument option_IOR_file_;
58
59     /** The command line option for disabling OMG IDL 2.x mappings. */
60     private OptionFlag option_disable_mapping_;
61
62     /** Reference to the OMG IDL compiler. */
63     private IR3Feed compiler_;
64
65     // ==================================================================
66
//
67
// Constructor.
68
//
69
// ==================================================================
70

71     /** The default constructor. */
72     public
73     IR3Server()
74     {
75         // Calls the ApplicationServerBase constructor.
76
super(new DefaultCommandLine("ir3server",
77                                      "[omg_idl_files]",
78                                      "Start the OpenCCM Interface Repository",
79                                      true));
80
81         // Specify the command line option for the file to store the IOR.
82
option_IOR_file_ = new DefaultOptionArgument(
83                                    "--ior-file",
84                                    "ior_file",
85                                    new String JavaDoc [] {
86                                        "Set the file to store the OpenCCM Interface Repository IOR,",
87                                        "default is ./InterfaceRepository.IOR"
88                                    },
89                                    "./InterfaceRepository.IOR" );
90         getCommandLine().addOption(option_IOR_file_);
91
92         // Specify the command line option for disabling OMG IDL 2.x mappings.
93
option_disable_mapping_ = new DefaultOptionFlag(
94                                           "--no-mappings",
95                                           "Disable OMG IDL 2.x mappings",
96                                           false);
97         getCommandLine().addOption(option_disable_mapping_);
98
99         // Create the OMG IDL 3.0 compiler.
100
compiler_ = new IR3Feed(getCommandLine());
101         compiler_.setConsole(getConsole());
102         compiler_.getPreprocessorApplication().setConsole(getConsole());
103     }
104
105     // ==================================================================
106
//
107
// Internal methods.
108
//
109
// ==================================================================
110

111     // ==================================================================
112
//
113
// Public methods for org.objectweb.util.cmdline.api.Application
114
//
115
// ==================================================================
116

117     // ==================================================================
118
//
119
// Public methods for org.objectweb.openccm.command.api.Application
120
//
121
// ==================================================================
122

123     // ==================================================================
124
//
125
// Public methods for org.objectweb.openccm.command.api.ApplicationServer
126
//
127
// ==================================================================
128

129     /**
130      * Before running the CORBA::ORB object.
131      *
132      * Must be defined in subclasses.
133      *
134      * @param args The command line arguments.
135      *
136      * @return The status.
137      */

138     public int
139     before_run(String JavaDoc[] args)
140     {
141         // Create an OMG IDL3 repository.
142
IFR repositoryServer = new IFR(!option_disable_mapping_.getFlag());
143         Repository repositoryRef = repositoryServer.getRepository().asComponentRepository();
144
145         // Set the initial CORBA reference of the InterfaceRepository.
146
TheORB.register_initial_reference("InterfaceRepository", repositoryRef);
147
148         // Compiles the OMG IDL 3.0 files.
149
int result = compiler_.run(args);
150         if(result != 0)
151             return result;
152
153         System.out.println("The OpenCCM OMG IDL3 Repository is ready.");
154
155         // Output the IOR of the IR3.
156
TheORB.save_IOR(repositoryRef, option_IOR_file_.getArgument());
157
158         return 0;
159     }
160
161     /**
162      * After running the CORBA::ORB object.
163      *
164      * Must be defined in subclasses.
165      */

166     public void
167     after_run()
168     {
169     }
170
171     // ==================================================================
172
//
173
// Static public methods.
174
//
175
// ==================================================================
176

177     /**
178      * The main bootstrap method.
179      *
180      * @param args The command line arguments.
181      */

182     public static void
183     main(String JavaDoc[] args)
184     {
185         IR3Server ir3server = new IR3Server();
186         ir3server.runMain(args);
187     }
188 }
Popular Tags