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 de.ug2t.channel.ho.service.*;
012: import de.ug2t.kernel.*;
013: import de.ug2t.kernel.id.*;
014: import de.ug2t.unifiedGui.*;
015: import de.ug2t.unifiedGui.exceptions.*;
016: import de.ug2t.unifiedGui.interfaces.*;
017:
018: /**
019: * @author Dirk
020: *
021: * date: 21.03.2004 project: JmcFrame_all
022: *
023: * <p>
024: * ...
025: * </p>
026: */
027: public class RtSwingServer implements IHoServerContainer {
028: private static String pem_file = "environment.xml";
029:
030: private String pem_initScript = null;
031: private String pem_initProc = null;
032: private String pem_initClass = null;
033: private Object pem_staticInitObj = null;
034:
035: public RtSwingServer() {
036: try {
037: KeRegisteredObject.pcmf_registerGlobal(
038: IHoServerContainer.SERVER_CONTAINER, this );
039:
040: pem_initScript = (String) KeEnvironment.pcmf_getParameter(
041: pem_file, "RtSwingServer", "initScript", null);
042: pem_initProc = (String) KeEnvironment.pcmf_getParameter(
043: pem_file, "RtSwingServer", "initProc", null);
044: pem_initClass = (String) KeEnvironment.pcmf_getParameter(
045: pem_file, "RtSwingServer", "initClass", null);
046:
047: if (pem_initScript != null && pem_initProc != null)
048: KeEnvironment.pcmf_initScript(pem_initScript,
049: pem_initProc);
050:
051: try {
052: if (pem_initClass != null)
053: pem_staticInitObj = ((IKeExecutable) Class.forName(
054: pem_initClass).newInstance())
055: .pcmf_execObj(null);
056: } catch (Exception e) {
057: KeLog.pcmf_log("ug2t",
058: "error creating and calling initClass: "
059: + pem_initClass, this , KeLog.ERROR);
060: }
061:
062: // external call
063: String l_call = (String) KeEnvironment.pcmf_getParameter(
064: pem_file, "RtSwingServer", "initCall", null);
065: ;
066: try {
067: if (l_call != null)
068: Runtime.getRuntime().exec(l_call);
069: } catch (Exception e) {
070: KeLog.pcmf_log("ug2t",
071: "error executing external call: " + l_call,
072: this , KeLog.ERROR);
073: }
074: } catch (Exception e) {
075: KeLog.pcmf_log("ug2t",
076: "error initialising C/S application", this ,
077: KeLog.ERROR);
078: }
079: }
080:
081: public void pcmf_crswapp(String xLang) throws Exception {
082: String l_factpar = (String) KeEnvironment.pcmf_getParameter(
083: pem_file, "RtSwingServer", "FACTORY");
084: String l_main = (String) KeEnvironment.pcmf_getParameter(
085: pem_file, "RtSwingServer", "XML_MAIN");
086:
087: de.ug2t.unifiedGui.UnApplicationFactory
088: .pcmf_setStandAloneMode(false);
089:
090: UnComponentFactory l_fact = new UnComponentFactory(l_factpar);
091: de.ug2t.unifiedGui.UnApplicationFactory l_prod = new de.ug2t.unifiedGui.UnApplicationFactory(
092: l_main, l_fact);
093:
094: try {
095: String l_lang = xLang.toUpperCase();
096: if (l_lang != null) {
097: Object l_langMap = KeEnvironment.pcmf_getParameter(
098: "environment.xml", IUnApplication.MY_LANGUAGE,
099: l_lang);
100: if (l_langMap == null)
101: l_langMap = KeEnvironment.pcmf_getParameter(
102: "environment.xml",
103: IUnApplication.MY_LANGUAGE, "DEFAULT");
104:
105: KeRegisteredObject.pcmf_register(
106: IUnApplication.MY_LANGUAGE_CODE, l_lang
107: .equals("") ? new KeStringWrapper(
108: "DEFAULT")
109: : new KeStringWrapper(l_lang));
110:
111: if (l_langMap == null)
112: throw (new Exception());
113:
114: KeRegisteredObject.pcmf_register(
115: IUnApplication.MY_LANGUAGE,
116: new KeStringWrapper(l_langMap.toString()));
117: KeLog.pcmf_log("ug2t", "set language to: " + l_lang
118: + "=>" + l_langMap, this , KeLog.MESSAGE);
119: }
120: } catch (Exception e) {
121: KeLog.pcmf_log("ug2t",
122: "no valid language definition found", this ,
123: KeLog.MESSAGE);
124: }
125:
126: IUnApplication l_swapp = (IUnApplication) l_prod
127: .pcmf_produce(new Integer(UnComponentFactory.HALFOBJECT));
128: l_swapp.pcmf_execView();
129: };
130:
131: public static void main(String[] args) throws Exception {
132: try {
133: if (args.length > 0)
134: pem_file = args[0];
135:
136: if (args.length > 1)
137: KeEnvironment.pcmf_setRootDir(args[1]);
138: else
139: KeEnvironment.pcmf_setRootDir("./");
140:
141: if (args.length > 2)
142: KeEnvironment.pcmf_setTmpDir(KeEnvironment
143: .pcmf_getRootDir()
144: + args[2]);
145: else
146: KeEnvironment.pcmf_setTmpDir(KeEnvironment
147: .pcmf_getRootDir()
148: + "tmp");
149: } catch (Exception e) {
150: KeLog
151: .pcmf_log(
152: "N.A.",
153: "error reading command line parameters, assign standard values",
154: null, KeLog.ERROR);
155: pem_file = "environment.xml";
156: KeEnvironment.pcmf_setRootDir("./");
157: KeEnvironment.pcmf_setTmpDir(KeEnvironment
158: .pcmf_getRootDir()
159: + "tmp");
160: }
161:
162: String l_idGen = (String) KeEnvironment.pcmf_getParameter(
163: pem_file, "runtime", "IDGEN", null);
164: if (l_idGen != null) {
165: try {
166: IKeIDGenerator l_gen = (IKeIDGenerator) Class.forName(
167: l_idGen).newInstance();
168: KeRegisteredObject.pcmf_setIDGenerator(l_gen);
169: KeLog.pcmf_log("ug2t", "Setting ID Generator class: "
170: + l_gen, null, KeLog.MESSAGE);
171: } catch (Exception e) {
172: KeLog.pcmf_logException("ug2t", null, e);
173: }
174: }
175:
176: String l_derror = (String) KeEnvironment.pcmf_getParameter(
177: pem_file, "runtime", "DISPATCH_ERROR_HANDLER", null);
178: if (l_derror != null) {
179: try {
180: IUnDispatchExceptionHandler l_dsp = (IUnDispatchExceptionHandler) Class
181: .forName(l_derror).newInstance();
182: UnComponent.pcmf_setDispatcher(new UnEventDispatcher(
183: l_dsp));
184: KeLog.pcmf_log("ug2t",
185: "Setting dispatch error handler class: "
186: + l_dsp, null, KeLog.MESSAGE);
187: } catch (Exception e) {
188: KeLog.pcmf_logException("ug2t", null, e);
189: }
190: } else
191: UnComponent.pcmf_setDispatcher(new UnEventDispatcher(null));
192:
193: String log_level_s = (String) KeEnvironment.pcmf_getParameter(
194: pem_file, "RtSwingServer", "LOG_LEVEL");
195: if (log_level_s == null)
196: log_level_s = "MESSAGE";
197:
198: String l_logWriter = (String) KeEnvironment.pcmf_getParameter(
199: pem_file, "RtSwingServer", "LOG_WRITER");
200: try {
201: if (l_logWriter != null)
202: KeLog.pcmf_setLogWriter((IKeLogWriter) Class.forName(
203: l_logWriter).newInstance());
204: } catch (Exception e) {
205: KeLog.pcmf_log("ug2t", "error setting log writer: "
206: + l_logWriter, null, KeLog.ERROR);
207: }
208:
209: if (log_level_s.equals("FATAL"))
210: KeLog.pcmf_setPrio(KeLog.FATAL);
211: else if (log_level_s.equals("ERROR"))
212: KeLog.pcmf_setPrio(KeLog.ERROR);
213: else if (log_level_s.equals("MESSAGE"))
214: KeLog.pcmf_setPrio(KeLog.MESSAGE);
215: else if (log_level_s.equals("DEBUG"))
216: KeLog.pcmf_setPrio(KeLog.DEBUG);
217: else if (log_level_s.equals("STATISTICS"))
218: KeLog.pcmf_setPrio(KeLog.STATISTICS);
219: else if (log_level_s.equals("TRACE"))
220: KeLog.pcmf_setPrio(KeLog.TRACE);
221: else if (log_level_s.equals("APPL"))
222: KeLog.pcmf_setPrio(KeLog.APPL);
223: else if (log_level_s.equals("SILENT"))
224: KeLog.pcmf_setPrio(KeLog.SILENT);
225:
226: // @@
227:
228: int l_port = Integer.parseInt((String) KeEnvironment
229: .pcmf_getParameter(pem_file, "RtSwingServer", "PORT"));
230:
231: String l_comp_str = (String) KeEnvironment.pcmf_getParameter(
232: pem_file, "RtSwingServer", "COMPRESS");
233: String l_ssl_str = (String) KeEnvironment.pcmf_getParameter(
234: pem_file, "RtSwingServer", "SSL");
235: String l_coll_str = (String) KeEnvironment.pcmf_getParameter(
236: pem_file, "RtSwingServer", "COLLECT_REPLIES");
237: String l_rec_str = (String) KeEnvironment.pcmf_getParameter(
238: pem_file, "RtSwingServer", "RECORD");
239: String l_recClass_str = (String) KeEnvironment
240: .pcmf_getParameter(pem_file, "RtSwingServer",
241: "RECORDER_CLASS");
242:
243: boolean l_comp = l_comp_str != null
244: && l_comp_str.toUpperCase().equals("TRUE") ? true
245: : false;
246: boolean l_ssl = l_ssl_str != null
247: && l_ssl_str.toUpperCase().equals("TRUE") ? true
248: : false;
249: boolean l_coll = l_coll_str != null
250: && l_coll_str.toUpperCase().equals("FALSE") ? false
251: : true;
252: boolean l_rec = l_rec_str != null
253: && l_rec_str.toUpperCase().equals("TRUE") ? true
254: : false;
255:
256: new de.ug2t.channel.ho.service.HoServerService(l_port, l_ssl,
257: l_comp, l_coll, l_recClass_str, l_rec);
258:
259: String l_cr = (String) KeEnvironment.pcmf_getParameter(
260: pem_file, "RtSwingServer", "CREATE");
261: if (l_cr == null || l_cr.equals("false"))
262: new RtSwingServer();
263:
264: return;
265: };
266:
267: public Object pcmf_getStaticInitObj() {
268: return (this.pem_staticInitObj);
269: }
270: }
|