1 2 package SOFA.SOFAnode.Run; 3 4 import org.omg.CosNaming.NameComponent ; 5 6 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistry; 7 import SOFA.SOFAnode.Run.DeplDockRegistry.DeplDockRegistryHelper; 8 import SOFA.SOFAnode.Run.DeplDockRegistry.NotFoundException; 9 import SOFA.SOFAnode.Run.Deployment.DeplDock; 10 11 15 public class TRLauncher { 16 17 22 public static void main(String argv[]) { 23 if (argv.length != 2) { 24 System.out.println("Bad number of arguments."); 25 System.out.println("Specify full application name and name of the home deployment dock"); 26 System.exit(1); 27 } 28 29 if (!argv[0].matches("^.+\\[.+\\]$")) { 30 System.out.println("Bad format of application name."); 31 System.exit(1); 32 } 33 34 if (System.getSecurityManager() == null) { 35 System.setSecurityManager(new java.rmi.RMISecurityManager ()); 36 } 37 38 System.out.print("Obtaining and parsing deployment descriptor..."); 39 SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor depldesc = getDeplDescr(argv[0], "run.dd"); 40 System.out.println("OK"); 41 42 SOFA.Util.CORBAAccess ca = new SOFA.Util.CORBAAccess(); 43 44 NameComponent nc = new NameComponent ("DeplDockRegistry", ""); 45 NameComponent path[] = {nc}; 46 DeplDockRegistry ddr = null; 47 try { 48 System.out.print("Obtaining depldock registry..."); 49 ddr = DeplDockRegistryHelper.narrow(SOFA.Util.CORBAAccess.ncRef.resolve(path)); 50 System.out.println("OK"); 51 } catch (Exception e) { 52 System.out.println("Can't get DeplDock registry."); 53 e.printStackTrace(); 54 System.exit(1); 55 } 56 57 byte[] serRef = null; 58 try { 59 System.out.print("Obtaining reference to depldock..."); 60 serRef = ddr.lookup(argv[1]); 61 System.out.println("OK"); 62 } catch (NotFoundException e) { 63 System.out.println("No deployment dock with name \""+argv[1]+"\"."); 64 System.exit(1); 65 } 66 67 SOFA.Connector.Reference ddRef = SOFA.SOFAnode.Run.Deployment.DeplDockImpl.bytesToSofaReference(serRef); 68 69 DeplDock ddock = null; 70 try { 71 System.out.print("Creating connector to depldock..."); 72 ddock = (DeplDock) SOFA.Connector.Boot.DeplDockConnector.createClt(ddRef); 73 System.out.println("OK"); 74 } catch (SOFA.Connector.ConnectorException e) { 75 System.out.println("Can't create connector to deployment dock."); 76 e.printStackTrace(); 77 System.exit(1); 78 } 79 80 SOFA.Connector.Reference apl = null; 81 try { 82 System.out.print("Instatiate component..."); 83 apl = ddock.instantiate(depldesc, ""); 84 System.out.println("OK"); 85 } catch (SOFA.SOFAnode.Run.Deployment.DeploymentException e) { 86 System.out.println("DeploymentException: "+e.getMessage()); 87 e.printStackTrace(); 88 System.exit(1); 89 } 90 91 SOFA.Component.DCUP.DCUPComponentManager aplcm = null; 92 try { 93 System.out.print("Creating connector to aplication component manager..."); 94 aplcm = (SOFA.Component.DCUP.DCUPComponentManager) SOFA.Connector.Boot.DCUPComponentManagerConnector.createClt(apl); 95 System.out.println("OK"); 96 } catch (SOFA.Connector.ConnectorException e) { 97 System.out.println("Can't create connector to aplication component manager."); 98 e.printStackTrace(); 99 System.exit(1); 100 } 101 102 try { 103 System.out.print("Launching component..."); 104 aplcm.createComponent(new StorageImpl()); 105 System.out.println("OK"); 106 } catch (SOFA.Component.ComponentLifecycleException e) { 107 System.out.println("ComponentLifecycleException: "+e.getMessage()); 108 e.printStackTrace(); 109 System.exit(1); 110 } 111 112 System.out.println(apl); 113 System.out.println("Application is runnig :-)"); 114 } 115 116 static SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor getDeplDescr(String applname, String ddname) { 117 try { 118 String trString = System.getProperty("sofa.tr.url","file:/sofa/tr/"); 119 String path = trString+"impl"; 120 path = path + fullNameToFileName(applname, ddname); 121 java.net.URL url = new java.net.URL (path); 122 java.net.URLConnection con = url.openConnection(); 123 java.io.InputStream is = con.getInputStream(); 124 SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor dd = new SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl(is); 125 is.close(); 126 return dd; 127 } catch (java.net.MalformedURLException e) { 128 System.out.println("MalformedURLException: "+e.getMessage()); 129 e.printStackTrace(); 130 System.exit(1); 131 } catch (java.io.IOException e) { 132 System.out.println("IOException: "+e.getMessage()); 133 System.exit(1); 134 } catch (javax.xml.parsers.ParserConfigurationException e) { 135 System.out.println("ParserConfigurationExceptioni: "+e.getMessage() ); 136 System.exit(1); 137 } catch (org.xml.sax.SAXException e) { 138 System.out.println("SAXException: "+e.getMessage() ); 139 System.exit(1); 140 } 141 return null; 142 } 143 144 private static String fullNameToFileName(String clname, String ddname) { 145 clname = clname.replaceAll("::", "/"); 146 clname = clname.replace('[', '/'); 147 clname = clname.replace(']', '/'); 148 clname = clname + ddname; 149 if (clname.charAt(0) != '/') 150 clname = "/" + clname; 151 return clname; 152 } 153 } 154 | Popular Tags |