KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Run > TRLauncher


1 /* $Id: TRLauncher.java,v 1.3 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Run;
3
4 import org.omg.CosNaming.NameComponent JavaDoc;
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 /** Launcher of SOFA applications - it takes depldescr from TR
12   *
13   * @author Petr Hnetynka
14   */

15 public class TRLauncher {
16  
17   /** Launching of SOFA applications. Full application name must be set as a 1st cmdline argument,
18     * 2nd argument is name of the home depldock. Set also all necessary properties
19     * ("sofa.sofanode", "sofa.rmihost", "sofa.rmiport","sofa.orbport", "sofa.orbhost".
20     * All depldocks necessary for application must run.
21     */

22   public static void main(String JavaDoc 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 JavaDoc());
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 JavaDoc nc = new NameComponent JavaDoc("DeplDockRegistry", "");
45     NameComponent JavaDoc 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 JavaDoc 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 JavaDoc applname, String JavaDoc ddname) {
117     try {
118       String JavaDoc trString = System.getProperty("sofa.tr.url","file:/sofa/tr/");
119       String JavaDoc path = trString+"impl";
120       path = path + fullNameToFileName(applname, ddname);
121       java.net.URL JavaDoc url = new java.net.URL JavaDoc(path);
122       java.net.URLConnection JavaDoc con = url.openConnection();
123       java.io.InputStream JavaDoc 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 JavaDoc e) {
128       System.out.println("MalformedURLException: "+e.getMessage());
129       e.printStackTrace();
130       System.exit(1);
131     } catch (java.io.IOException JavaDoc e) {
132       System.out.println("IOException: "+e.getMessage());
133       System.exit(1);
134     } catch (javax.xml.parsers.ParserConfigurationException JavaDoc e) {
135       System.out.println("ParserConfigurationExceptioni: "+e.getMessage() );
136       System.exit(1);
137     } catch (org.xml.sax.SAXException JavaDoc e) {
138       System.out.println("SAXException: "+e.getMessage() );
139       System.exit(1);
140     }
141     return null;
142   }
143
144   private static String JavaDoc fullNameToFileName(String JavaDoc clname, String JavaDoc 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