KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > hello > cif > Install


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 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, Sylvain Leblanc.
23 Contributor(s): Christophe Demarey, Christophe Contreras.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.hello.cif;
28
29 import org.objectweb.ccm.hello.*;
30
31 /**
32  * The hello application deployment.
33  */

34 public class Install
35 {
36   /**
37    * The usage message.
38    */

39   public static void
40   usage()
41   {
42     System.err.println("usage: Install [<component_server_name> <NS_name>]");
43     System.err.println("");
44     System.err.println(" <component_server_name> " +
45                        "The component server name on which the " +
46                        "ServerHome will be deployed.");
47     System.err.println(" <NS_name> " +
48                        "The name used to register the ServerHome " +
49                        "instance.");
50   }
51
52   /**
53    * The bootstrap of the hello application.
54    */

55   public static void
56   main(String JavaDoc[] args)
57     throws Exception JavaDoc
58   {
59     String JavaDoc _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase();
60
61     // Init the ORB.
62
System.out.println("Initializing the ORB...");
63     
64     // TODO: Need to report this ORB.init() problem to OpenORB developers!
65
// Due to an OpenORB problem, the following line:
66
// org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
67
// are replaced by the next line.
68

69      // Init the ORB.
70
args = org.objectweb.openccm.corba.TheORB.initialize(args);
71
72     // Init the OpenCCM runtime.
73
org.objectweb.openccm.Components.Runtime.init();
74
75     // Obtain the ORB.
76
org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.corba.TheORB.getORB();
77
78     if (args.length > 2) {
79       usage();
80       System.exit(1);
81     }
82
83     String JavaDoc cs_name = (args.length >= 2)?args[0]:"ComponentServer1";
84     String JavaDoc ns_name = (args.length >= 2)?args[1]:"MyHelloServerHome";
85
86     // Obtain the Name Service.
87
System.out.println("Obtaining the Name Service...");
88     org.omg.CORBA.Object JavaDoc obj = orb.resolve_initial_references("NameService");
89     org.omg.CosNaming.NamingContext JavaDoc nc = org.omg.CosNaming.NamingContextHelper.narrow(obj);
90
91     org.omg.CosTransactions.Current current = null;
92     if (_OTS.equals("yes")) {
93       System.out.println("Obtaining the Transaction Service...");
94       org.omg.CORBA.Object JavaDoc objOTS = orb.resolve_initial_references("TransactionCurrent");
95       current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS );
96     }
97
98     try {
99       if ((current!=null)&&(_OTS.equals("yes"))) {
100         System.out.println("Beginning the transaction...");
101         current.begin();
102       }
103
104       // Obtain the component servers.
105
System.out.println("Obtaining Component Servers...");
106       org.omg.CosNaming.NameComponent JavaDoc[] ncomp = new org.omg.CosNaming.NameComponent JavaDoc[1];
107       ncomp[0] = new org.omg.CosNaming.NameComponent JavaDoc(cs_name, "");
108       obj = nc.resolve(ncomp);
109       org.objectweb.openccm.Deployment.Server server = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj);
110
111       // Obtain the container homes and archive installators.
112
org.omg.Components.Deployment.ComponentServer server_cs = server.provide_component_server();
113       org.omg.Components.Deployment.ComponentInstallation server_inst = server.provide_install();
114
115       // Install archives.
116
System.out.println("Installing archives...");
117       // get the current directory and store it as a String
118
String JavaDoc demoPath = null;
119       try {
120           demoPath = new java.io.File JavaDoc(".").getCanonicalPath()+ java.io.File.separator ;
121       }catch(Exception JavaDoc e) {
122           e.printStackTrace();
123       }
124
125       server_inst.install("hello","file:"+ demoPath + "./archives/hello.jar");
126       // install some plugins already provided by OpenCCM.
127
server_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar");
128
129       // instantiate a container on each server.
130
org.omg.Components.Deployment.Container server_cont =
131         server_cs.create_container(new org.omg.Components.ConfigValue[0]);
132
133       // Install homes.
134
System.out.println("Instantiating home...");
135       org.omg.Components.CCMHome h =
136                 server_cont.install_home("hello",
137                                          "org.objectweb.ccm.hello.cif.ServerHomeImpl.create_home",
138                                          new org.omg.Components.ConfigValue[0]);
139       ServerHome sh = ServerHomeHelper.narrow(h);
140
141       // register the home in the name service with the specified name
142
ncomp[0] = new org.omg.CosNaming.NameComponent JavaDoc(ns_name, "");
143       nc.rebind(ncomp, sh);
144       System.out.println("ServerHome instance register under \'" +
145                          ns_name + " \' in the name service");
146
147     } catch (Exception JavaDoc e) {
148       if ((current!=null)&&(_OTS.equals("yes"))) {
149         System.out.println("Error during deployment :");
150         e.printStackTrace();
151         System.out.print("Rolling Back ... ");
152         current.rollback();
153         System.out.println("Done");
154         // Force to exit.
155
System.exit(0);
156       }
157     }
158     
159     if ((current!=null)&&(_OTS.equals("yes"))) {
160       System.out.print("Do you want to commit the Deployment ? [Y/n] ");
161       
162       java.io.BufferedReader JavaDoc _buffer
163         = new java.io.BufferedReader JavaDoc(new java.io.InputStreamReader JavaDoc(System.in));
164       char _answer = (char) _buffer.read();
165       
166       if ((_answer=='n')||(_answer=='N'))
167       {
168         System.out.print("Rolling Back ... ");
169         current.rollback();
170         System.out.println("Done");
171       } else {
172         System.out.print("Committing ... ");
173         current.commit(false);
174         System.out.println("Done");
175         System.out.println(ns_name + " is ready to be used...");
176       }
177     } else {
178       System.out.println(ns_name + " is ready to be used...");
179     }
180     
181     System.exit(0);
182   }
183 }
184
185
186
187
188
189
190
Popular Tags