1 26 27 package org.objectweb.ccm.hello; 28 29 32 33 public class Run 34 { 35 36 39 public static void 40 usage() 41 { 42 System.err.println("usage: Run [NS_name]"); 43 System.err.println(""); 44 System.err.println(" <NS_name> " + 45 "The name of the registered ServerHome " + 46 "instance."); 47 } 48 49 52 public static void 53 main(String [] args) 54 throws Exception 55 { 56 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 57 58 System.out.println("Initializing the ORB..."); 60 61 66 args = org.objectweb.openccm.corba.TheORB.initialize(args); 68 69 org.objectweb.openccm.Components.Runtime.init(); 71 72 org.omg.CORBA.ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 74 75 76 if (args.length > 1) { 77 usage(); 78 System.exit(1); 79 } 80 81 String ns_name = (args.length >= 1)?args[0]:"MyHelloServerHome"; 82 83 System.out.println("Obtaining the Name Service..."); 85 org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); 86 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 87 88 System.out.println("Obtaining the " + ns_name + " ServerHome instance..."); 90 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 91 ncomp[0] = new org.omg.CosNaming.NameComponent (ns_name, ""); 92 obj = nc.resolve(ncomp); 93 ServerHome home = ServerHomeHelper.narrow(obj); 94 95 org.omg.CosTransactions.Current current = null; 96 if (_OTS.equals("yes")) { 97 System.out.println("Obtaining the Transaction Service..."); 98 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 99 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 100 } 101 102 try { 103 if ((current!=null)&&(_OTS.equals("yes"))) { 104 System.out.println("Beginning the transaction..."); 105 current.begin(); 106 } 107 108 System.out.println("Creating a new Server component instance..."); 110 Server server = home.create(); 111 112 System.out.println("Completing the server configuration..."); 113 server.configuration_complete(); 114 115 System.out.println("Retrieving the facet 'for_clients'..."); 117 HelloWorld for_clients = server.provide_for_clients(); 118 119 System.out.println("Calling the 'say_hello' method..."); 121 System.out.println( for_clients.say_hello() ); 122 123 System.out.println("Destroying the server component instance..."); 125 server.remove(); 126 127 System.out.println("Bye !!"); 128 } catch (Exception e) { 129 if ((current!=null)&&(_OTS.equals("yes"))) { 130 System.out.println("Error during deployment :"); 131 e.printStackTrace(); 132 System.out.print("Rolling Back ... "); 133 current.rollback(); 134 System.out.println("Done"); 135 System.exit(0); 137 } 138 } 139 140 if ((current!=null)&&(_OTS.equals("yes"))) { 141 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 142 143 java.io.BufferedReader _buffer 144 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 145 char _answer = (char) _buffer.read(); 146 147 if ((_answer=='n')||(_answer=='N')) 148 { 149 System.out.print("Rolling Back ... "); 150 current.rollback(); 151 System.out.println("Done"); 152 } else { 153 System.out.print("Committing ... "); 154 current.commit(false); 155 System.out.println("Done"); 156 System.out.println(ns_name + " is ready to be used..."); 157 } 158 } else { 159 System.out.println(ns_name + " is ready to be used..."); 160 } 161 162 System.exit(0); 163 } 164 } 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | Popular Tags |