001: /*
002: * Created on 21.03.2004
003: *
004: * date: 21.03.2004
005: * project: JmcFrame_all
006: *
007: * comment:
008: */
009: package de.ug2t.channel.runtime.swing;
010:
011: import java.util.*;
012:
013: import de.ug2t.channel.ho.service.*;
014: import de.ug2t.channel.ho.session.*;
015: import de.ug2t.kernel.*;
016: import de.ug2t.kernel.id.*;
017: import de.ug2t.unifiedGui.*;
018: import de.ug2t.unifiedGui.exceptions.*;
019: import de.ug2t.unifiedGui.interfaces.*;
020: import de.ug2t.xmlScript.*;
021:
022: /**
023: * @author Dirk
024: *
025: * date: 21.03.2004 project: JmcFrame_all
026: *
027: * <p>
028: * ...
029: * </p>
030: */
031: public class RtSwingStandalone implements IHoServerContainer {
032: private static String pem_file = "environment.xml";
033:
034: private String pem_initScript = null;
035: private String pem_initProc = null;
036: private String pem_initClass = null;
037: private Object pem_staticInitObj = null;
038:
039: public static void start() throws Exception {
040: int l_port = Integer.parseInt((String) KeEnvironment
041: .pcmf_getParameter(pem_file, "RtSwingClient", "PORT"));
042: String l_host = (String) KeEnvironment.pcmf_getParameter(
043: pem_file, "RtSwingClient", "HOST");
044:
045: String l_comp_str = (String) KeEnvironment.pcmf_getParameter(
046: pem_file, "RtSwingClient", "COMPRESS");
047: String l_ssl_str = (String) KeEnvironment.pcmf_getParameter(
048: pem_file, "RtSwingClient", "SSL");
049:
050: boolean l_comp = l_comp_str != null
051: && l_comp_str.toUpperCase().equals("TRUE") ? true
052: : false;
053: boolean l_ssl = l_ssl_str != null
054: && l_ssl_str.toUpperCase().equals("TRUE") ? true
055: : false;
056:
057: de.ug2t.channel.ho.service.HoClientService client = new de.ug2t.channel.ho.service.HoClientService(
058: l_port, l_host, l_ssl, l_comp, true);
059:
060: String l_service = (String) KeEnvironment.pcmf_getParameter(
061: pem_file, "RtSwingClient", "SERVICE_CLASS");
062: String l_init = (String) KeEnvironment.pcmf_getParameter(
063: pem_file, "RtSwingClient", "SERVICE_INIT");
064: String l_alias = (String) KeEnvironment.pcmf_getParameter(
065: pem_file, "RtSwingClient", "SERVICE_ALIAS");
066: String l_cr = (String) KeEnvironment.pcmf_getParameter(
067: pem_file, "RtSwingClient", "CREATE");
068:
069: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
070: "");
071: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
072: ScXmlScript.pcmf_addProc(l_remCall, null);
073:
074: if (l_cr != null && l_cr.equals("true"))
075: ScXmlScript.pcmf_addDecl(l_remCall, l_alias, l_service,
076: "forever");
077:
078: ScXmlScript.pcmf_addCall(l_remCall, null, l_alias, l_init);
079:
080: String l_lang = (String) KeEnvironment.pcmf_getParameter(
081: pem_file, "RtSwingClient", IUnApplication.MY_LANGUAGE);
082: if (l_lang == null)
083: l_lang = Locale.getDefault().getLanguage();
084:
085: ScXmlScript.pcmf_addCallPar(l_remCall, l_lang, "false",
086: "java.lang.String");
087:
088: ScXmlScript.pcmf_endAll(l_remCall);
089:
090: IHoSession l_session = client.pcmf_getSession();
091:
092: l_session.pcmf_call(l_remCall.toString(), null);
093: };
094:
095: public void pcmf_crswapp(String xLang) throws Exception {
096: String l_factpar = (String) KeEnvironment.pcmf_getParameter(
097: pem_file, "RtSwingServer", "FACTORY");
098: String l_main = (String) KeEnvironment.pcmf_getParameter(
099: pem_file, "RtSwingServer", "XML_MAIN");
100:
101: de.ug2t.unifiedGui.UnApplicationFactory
102: .pcmf_setStandAloneMode(true);
103:
104: UnComponentFactory l_fact = new UnComponentFactory(l_factpar);
105: de.ug2t.unifiedGui.UnApplicationFactory l_prod = new de.ug2t.unifiedGui.UnApplicationFactory(
106: l_main, l_fact);
107:
108: try {
109: String l_lang = xLang.toUpperCase();
110: if (l_lang != null) {
111: Object l_langMap = KeEnvironment.pcmf_getParameter(
112: "environment.xml", IUnApplication.MY_LANGUAGE,
113: l_lang);
114: if (l_langMap == null)
115: l_langMap = KeEnvironment.pcmf_getParameter(
116: "environment.xml",
117: IUnApplication.MY_LANGUAGE, "DEFAULT");
118:
119: KeRegisteredObject.pcmf_register(
120: IUnApplication.MY_LANGUAGE_CODE, l_lang
121: .equals("") ? new KeStringWrapper(
122: "DEFAULT")
123: : new KeStringWrapper(l_lang));
124:
125: if (l_langMap == null)
126: throw (new Exception());
127:
128: KeRegisteredObject.pcmf_register(
129: IUnApplication.MY_LANGUAGE,
130: new KeStringWrapper(l_langMap.toString()));
131: KeLog.pcmf_log("ug2t", "set language to: " + l_lang
132: + "=>" + l_langMap, this , KeLog.MESSAGE);
133: }
134: } catch (Exception e) {
135: KeLog.pcmf_log("ug2t",
136: "no valid language definition found", this ,
137: KeLog.MESSAGE);
138: }
139:
140: IUnApplication l_swapp = (IUnApplication) l_prod
141: .pcmf_produce(new Integer(UnComponentFactory.HALFOBJECT));
142: l_swapp.pcmf_execView();
143: };
144:
145: public RtSwingStandalone() {
146: try {
147: KeRegisteredObject.pcmf_registerGlobal(
148: IHoServerContainer.SERVER_CONTAINER, this );
149:
150: pem_initScript = (String) KeEnvironment.pcmf_getParameter(
151: pem_file, "RtSwingServer", "initScript", null);
152: pem_initProc = (String) KeEnvironment.pcmf_getParameter(
153: pem_file, "RtSwingServer", "initProc", null);
154: pem_initClass = (String) KeEnvironment.pcmf_getParameter(
155: pem_file, "RtSwingServer", "initClass", null);
156:
157: if (pem_initScript != null && pem_initProc != null)
158: KeEnvironment.pcmf_initScript(pem_initScript,
159: pem_initProc);
160:
161: try {
162: if (pem_initClass != null)
163: pem_staticInitObj = ((IKeExecutable) Class.forName(
164: pem_initClass).newInstance())
165: .pcmf_execObj(null);
166: } catch (Exception e) {
167: KeLog.pcmf_log("ug2t",
168: "error creating and calling initClass: "
169: + pem_initClass, this , KeLog.ERROR);
170: }
171:
172: // external call
173: String l_call = (String) KeEnvironment.pcmf_getParameter(
174: pem_file, "RtSwingServer", "initCall", null);
175: ;
176: try {
177: if (l_call != null)
178: Runtime.getRuntime().exec(l_call);
179: } catch (Exception e) {
180: KeLog.pcmf_log("ug2t",
181: "error executing external call: " + l_call,
182: this , KeLog.ERROR);
183: }
184: } catch (Exception e) {
185: KeLog.pcmf_log("ug2t",
186: "error initialising standalone application", this ,
187: KeLog.ERROR);
188: }
189: }
190:
191: public static void main(String[] args) throws Exception {
192: try {
193: if (args.length > 0)
194: pem_file = args[0];
195:
196: if (args.length > 1)
197: KeEnvironment.pcmf_setRootDir(args[1]);
198: else
199: KeEnvironment.pcmf_setRootDir("./");
200:
201: if (args.length > 2)
202: KeEnvironment.pcmf_setTmpDir(KeEnvironment
203: .pcmf_getRootDir()
204: + args[2]);
205: else
206: KeEnvironment.pcmf_setTmpDir(KeEnvironment
207: .pcmf_getRootDir()
208: + "tmp");
209: } catch (Exception e) {
210: KeLog
211: .pcmf_log(
212: "N.A.",
213: "error reading command line parameters, assign standard values",
214: null, KeLog.ERROR);
215: pem_file = "environment.xml";
216: KeEnvironment.pcmf_setRootDir("./");
217: KeEnvironment.pcmf_setTmpDir(KeEnvironment
218: .pcmf_getRootDir()
219: + "tmp");
220: }
221:
222: String l_idGen = (String) KeEnvironment.pcmf_getParameter(
223: pem_file, "runtime", "IDGEN", null);
224: if (l_idGen != null) {
225: try {
226: IKeIDGenerator l_gen = (IKeIDGenerator) Class.forName(
227: l_idGen).newInstance();
228: KeRegisteredObject.pcmf_setIDGenerator(l_gen);
229: KeLog.pcmf_log("ug2t", "Setting ID Generator class: "
230: + l_gen, null, KeLog.MESSAGE);
231: } catch (Exception e) {
232: KeLog.pcmf_logException("ug2t", null, e);
233: }
234: }
235:
236: String l_derror = (String) KeEnvironment.pcmf_getParameter(
237: pem_file, "runtime", "DISPATCH_ERROR_HANDLER", null);
238: if (l_derror != null) {
239: try {
240: IUnDispatchExceptionHandler l_dsp = (IUnDispatchExceptionHandler) Class
241: .forName(l_derror).newInstance();
242: UnComponent.pcmf_setDispatcher(new UnEventDispatcher(
243: l_dsp));
244: KeLog.pcmf_log("ug2t",
245: "Setting dispatch error handler class: "
246: + l_dsp, null, KeLog.MESSAGE);
247: } catch (Exception e) {
248: KeLog.pcmf_logException("ug2t", null, e);
249: }
250: } else
251: UnComponent.pcmf_setDispatcher(new UnEventDispatcher(null));
252:
253: String log_level_s = (String) KeEnvironment.pcmf_getParameter(
254: pem_file, "RtSwingClient", "LOG_LEVEL");
255: if (log_level_s == null)
256: log_level_s = "MESSAGE";
257:
258: String l_logWriter = (String) KeEnvironment.pcmf_getParameter(
259: pem_file, "RtSwingClient", "LOG_WRITER");
260: try {
261: if (l_logWriter != null)
262: KeLog.pcmf_setLogWriter((IKeLogWriter) Class.forName(
263: l_logWriter).newInstance());
264: } catch (Exception e) {
265: KeLog.pcmf_log("ug2t", "error setting log writer: "
266: + l_logWriter, null, KeLog.ERROR);
267: }
268:
269: if (log_level_s.equals("FATAL"))
270: KeLog.pcmf_setPrio(KeLog.FATAL);
271: else if (log_level_s.equals("ERROR"))
272: KeLog.pcmf_setPrio(KeLog.ERROR);
273: else if (log_level_s.equals("MESSAGE"))
274: KeLog.pcmf_setPrio(KeLog.MESSAGE);
275: else if (log_level_s.equals("DEBUG"))
276: KeLog.pcmf_setPrio(KeLog.DEBUG);
277: else if (log_level_s.equals("STATISTICS"))
278: KeLog.pcmf_setPrio(KeLog.STATISTICS);
279: else if (log_level_s.equals("TRACE"))
280: KeLog.pcmf_setPrio(KeLog.TRACE);
281: else if (log_level_s.equals("APPL"))
282: KeLog.pcmf_setPrio(KeLog.APPL);
283: else if (log_level_s.equals("SILENT"))
284: KeLog.pcmf_setPrio(KeLog.SILENT);
285:
286: // @@
287:
288: int l_port = Integer.parseInt((String) KeEnvironment
289: .pcmf_getParameter(pem_file, "RtSwingServer", "PORT"));
290:
291: String l_comp_str = (String) KeEnvironment.pcmf_getParameter(
292: pem_file, "RtSwingClient", "COMPRESS");
293: String l_ssl_str = (String) KeEnvironment.pcmf_getParameter(
294: pem_file, "RtSwingClient", "SSL");
295: String l_coll_str = (String) KeEnvironment.pcmf_getParameter(
296: pem_file, "RtSwingServer", "COLLECT_REPLIES");
297: String l_rec_str = (String) KeEnvironment.pcmf_getParameter(
298: pem_file, "RtSwingServer", "RECORD");
299: String l_recClass_str = (String) KeEnvironment
300: .pcmf_getParameter(pem_file, "RtSwingServer",
301: "RECORDER_CLASS");
302:
303: boolean l_comp = l_comp_str != null
304: && l_comp_str.toUpperCase().equals("TRUE") ? true
305: : false;
306: boolean l_ssl = l_ssl_str != null
307: && l_ssl_str.toUpperCase().equals("TRUE") ? true
308: : false;
309: boolean l_coll = l_coll_str != null
310: && l_coll_str.toUpperCase().equals("FALSE") ? false
311: : true;
312: boolean l_rec = l_rec_str != null
313: && l_rec_str.toUpperCase().equals("TRUE") ? true
314: : false;
315:
316: new de.ug2t.channel.ho.service.HoServerService(l_port, l_ssl,
317: l_comp, l_coll, l_recClass_str, l_rec);
318:
319: String l_cr = (String) KeEnvironment.pcmf_getParameter(
320: pem_file, "RtSwingServer", "CREATE");
321: if (l_cr == null || l_cr.equals("false"))
322: new RtSwingStandalone();
323:
324: start();
325:
326: return;
327: };
328:
329: public Object pcmf_getStaticInitObj() {
330: return (this.pem_staticInitObj);
331: }
332: }
|