Source code: com/prolifics/ejb/Initializer.java
1 /* @(#)Initializer.java 77.1 00/07/11 18:37:04 */
2
3 /*************************************************/
4 /* Copyright (c) 2000 */
5 /* by */
6 /* JYACC, Inc., New York NY USA */
7 /* and contributors. */
8 /* Use of this program is governed by the */
9 /* JYACC Public License Version 1.0, a copy of */
10 /* which can be obtained at */
11 /* http://www.possl.org/jyacc-license.html */
12 /*************************************************/
13
14 package com.prolifics.ejb;
15
16 import java.io.*;
17 import java.lang.reflect.*;
18
19 import com.prolifics.ejb.IniFile;
20
21 /**
22 * @version @(#)Initializer.java 77.1 00/07/11 18:37:04
23 * @author Prolifics
24 */
25 public class Initializer
26 {
27 private static String sccsid = "@(#)Initializer.java 77.1 00/07/11 18:37:04";
28 private static final String logFileName = "server.log";
29 private static final String iniFileName = "panther.ini";
30 private static final String dollarSmbase = "$SMBASE";
31 private static final String globalSection = "EJB Global";
32
33 public static void main(String args[])
34 {
35 File log = new File(logFileName);
36 Throwable throwable = null;
37
38 try
39 {
40 main1(args);
41 }
42 catch (ClassNotFoundException excp) { throwable = excp; }
43 catch (NoSuchMethodException excp) { throwable = excp; }
44 catch (InvocationTargetException excp) { throwable = excp; }
45 catch (IllegalAccessException excp) { throwable = excp; }
46 catch (UnsatisfiedLinkError err) { throwable = err; }
47
48 if (throwable == null)
49 {
50 return;
51 }
52
53 if (log.exists())
54 {
55
56 PrintStream out = null;
57
58 try
59 {
60 out = new PrintStream(
61 new FileOutputStream(logFileName,
62 true));
63 }
64 catch (FileNotFoundException excp)
65 {
66 }
67 catch (IOException excp)
68 {
69 }
70
71 if (out != null)
72 {
73 out.println(throwable);
74 out.close();
75 out = null;
76 }
77 }
78
79 throwable.printStackTrace();
80 }
81
82 public static void main1(String args[])
83 throws ClassNotFoundException,
84 NoSuchMethodException,
85 InvocationTargetException,
86 IllegalAccessException
87 {
88 System.loadLibrary("PanSmEJB");
89 System.loadLibrary("PanDmEJB");
90 System.loadLibrary("PanTmEJB");
91 String smbase =
92 IniFile.GetPrivateProfileString(globalSection,
93 "SMBASE", "", iniFileName);
94 String smTpClient =
95 IniFile.GetPrivateProfileString(globalSection,
96 "SMTPCLIENT", "", iniFileName);
97
98 if (smTpClient == null)
99 {
100 }
101 else if (smTpClient.equalsIgnoreCase("ws"))
102 {
103 System.loadLibrary("PanTwEJB");
104 }
105 else if (smTpClient.equalsIgnoreCase("ws6"))
106 {
107 System.loadLibrary("PanTwEJB6");
108 }
109 else if (smTpClient.equalsIgnoreCase("native"))
110 {
111 System.loadLibrary("PanTnEJB");
112 }
113 else if (smTpClient.equalsIgnoreCase("native6"))
114 {
115 System.loadLibrary("PanTnEJB6");
116 }
117
118 String databases =
119 IniFile.GetPrivateProfileString("databases",
120 "installed", "", iniFileName);
121
122 while (databases != null && ! databases.equals(""))
123 {
124 if (databases.startsWith(" "))
125 {
126 databases = databases.substring(1);
127 continue;
128 }
129
130 int nextSpace = databases.indexOf(" ");
131 if (nextSpace < 0)
132 {
133 nextSpace = databases.length();
134 }
135 String database = databases.substring(0, nextSpace);
136 databases = databases.substring(nextSpace);
137
138 String dbmsSection = "dbms " + database;
139
140 String driver =
141 IniFile.GetPrivateProfileString(dbmsSection,
142 "driver", "", iniFileName);
143
144 System.load(expandSmbase(smbase, driver));
145
146 String model =
147 IniFile.GetPrivateProfileString(dbmsSection,
148 "model", "", iniFileName);
149
150 System.load(expandSmbase(smbase, model));
151 }
152
153 String dlls =
154 IniFile.GetPrivateProfileString(globalSection,
155 "SMNATIVELIBS", "", iniFileName);
156
157 while (dlls != null && ! dlls.equals(""))
158 {
159 if (dlls.startsWith(" "))
160 {
161 dlls = dlls.substring(1);
162 continue;
163 }
164
165 int nextSpace = dlls.indexOf(" ");
166 if (nextSpace < 0)
167 {
168 nextSpace = dlls.length();
169 }
170 String dll = dlls.substring(0, nextSpace);
171 dlls = dlls.substring(nextSpace);
172
173 String dllFileName = expandSmbase(smbase, dll);
174 File dllFile = new File(dllFileName);
175 int dllFileExtPos = dllFileName.lastIndexOf('.');
176 String dllFileExt = "";
177
178 if (dllFileExtPos >= 0)
179 {
180 dllFileExt =
181 dllFileName.substring(dllFileExtPos);
182 }
183
184 if ((dllFileName.indexOf(File.pathSeparatorChar) >= 0)||
185 (dllFileName.indexOf(File.separatorChar) >= 0) ||
186 (dllFileExt.equalsIgnoreCase(".dll")) ||
187 (dllFileExt.equalsIgnoreCase(".lib")) ||
188 (dllFileExt.equals(".so")) ||
189 (dllFileExt.equals(".sl")) ||
190 (dllFileExt.equals(".a")))
191
192 {
193 System.load(dllFileName);
194 }
195 else
196 {
197 System.loadLibrary(dll);
198 }
199 }
200
201 Class mainClass = Class.forName(args[0]);
202 Class mainParamTypes[] = new Class[1];
203 Object mainParamList[] = new Object[1];
204 String mainArgs[] = new String[args.length-1];
205 mainParamTypes[0] = args.getClass();
206 Method mainMethod = mainClass.getDeclaredMethod("main",
207 mainParamTypes);
208 System.arraycopy(args, 1, mainArgs, 0, args.length - 1);
209 mainParamList[0] = mainArgs;
210 mainMethod.invoke(null, mainParamList);
211 }
212
213 public static String expandSmbase(String smbase, String str)
214 {
215 if (str.startsWith(dollarSmbase))
216 {
217 str = str.substring(dollarSmbase.length());
218 str = (new File(smbase, str)).getPath();
219 }
220
221 return str;
222 }
223 }