• R/O
  • SSH
  • HTTPS

sweep: Commit


Commit MetaInfo

Revision48 (tree)
Time2022-08-13 14:54:27
Authoriwao

Log Message

kfc project にはkfc.jar のコードを含めることにする
kfc.jarのコードに一部手を入れ、Java2のテキストインライン変換を有効にしたい

Change Summary

Incremental Difference

--- branches/client/kfc/src/main/java/sweep/container/GenericKFCApp.java (revision 47)
+++ branches/client/kfc/src/main/java/sweep/container/GenericKFCApp.java (nonexistent)
@@ -1,968 +0,0 @@
1-package sweep.container;
2-
3-import sweep.client.*;
4-
5-/** 古いVMでも動作するように調整したアプレット
6- */
7-public class GenericKFCApp extends jp.kyasu.awt.Applet implements Runnable, sweep.client.JobAction {
8-
9- static java.io.PrintStream out = System.out, err = System.err;
10- static final Class [] _appTypes = { String.class, };
11-
12- /** nullあるいは空白文字だけで構成されているテキストであるか診断 */
13- boolean empty(String t) { return t == null || t.trim().length() == 0; }
14-
15- boolean verbose;
16- /** トレース・ログ*/
17- void trace(Object t) { if(verbose) err.println(t); }
18-
19- /// フレーム間で共有する属性
20- java.util.Hashtable ht = new java.util.Hashtable();
21-
22- public String[][] getParameterInfo() {
23- String info[][]={
24- { "app", "FQCN", "Class of jp.sourceforge.sweep.client.AWTapplication or " +
25- "jp.sourceforge.sweep.client.JFCapplication", },
26- { "open", "resource mame", "Name of Resource treaded by sweep.client.OpenFiles", },
27- { "verbose", "true|[false]", "debug message switch", }
28- };
29- return info;
30- }
31-
32- /** コンテナが配置されているウィンドウを検出する
33- * @throws IllegalStateException ウインドウに配置されていない */
34- static java.awt.Window findWindow(java.awt.Component c) {
35- java.awt.Container t = c instanceof java.awt.Container ?
36- (java.awt.Container)c : c.getParent();
37- while (t != null) {
38- if (t instanceof java.awt.Window) return (java.awt.Window)t;
39- t = t.getParent();
40- }
41-
42- throw new IllegalStateException("not binding; " +
43- c.getName() + ":" + c.getClass().getName());
44- }
45-
46- java.util.Hashtable rdbm = new java.util.Hashtable();
47- java.util.Hashtable dir = new java.util.Hashtable();
48- java.util.Hashtable store = new java.util.Hashtable();
49- AppletContext cc;
50-
51- public void init() {
52- setLayout(new java.awt.BorderLayout());
53- cc = new AppletContext();
54- cc.init();
55- verbose = cc.testFlag(getParameter("verbose"), false);
56- trace("#init applet");
57-
58- String appName = getParameter("app");
59- if (appName == null) {
60- java.awt.TextArea ta;
61- add(ta = new java.awt.TextArea(5,10), java.awt.BorderLayout.CENTER);
62- ta.setText("no \"app\" parameter or class instantiaion failed!");
63- return;
64- }
65-
66- AWTapplication app = cc.createOldApp(appName);
67- app.setClientContext(cc);
68- cc.app = app;
69- String title = app.getTitle();
70- if (empty(title)) title = app.getClass().getName();
71-
72- java.awt.Component comp = app.getComponent();
73- if (comp == null) {
74- java.awt.Label cap = new java.awt.Label("application componenent was not created.");
75- comp = cap;
76- }
77- removeAll();
78- add(comp, java.awt.BorderLayout.CENTER);
79- }
80-
81- public void start() {
82- trace("#start applet");
83-
84- if (cc.app instanceof OpenFiles) {
85- java.util.Vector files = new java.util.Vector();
86- String open = getParameter("open");
87- if (!empty(open)) {
88- java.util.StringTokenizer tk = new java.util.StringTokenizer(open, ",");
89- while(tk.hasMoreElements()) {
90- files.addElement(tk.nextElement());
91- }
92- }
93- trace(files + "" + files.size() + " open files");
94- String [] names;
95- files.copyInto(names = new String[files.size()]);
96- ((OpenFiles)cc.app).openFiles(names, 0);
97- }
98- }
99-
100- public void stop() {
101- cc.app.release();
102- trace("#stop applet");
103- }
104-
105- public void destroy() {
106- try { cc.app.release(); } finally { cc.shutdown(); }
107- trace("#destroy applet");
108- }
109-
110- /** {@link JFCapplication}を表示するアプレット
111- */
112- class AppletContext implements sweep.client.ClientContext, ObjectFactory,
113- java.io.Serializable, java.awt.event.WindowListener, java.awt.event.ActionListener,
114- java.awt.datatransfer.ClipboardOwner, java.awt.event.KeyListener {
115-
116- sweep.client.AWTapplication app;
117- Preference pref;
118-
119- ObjectFactory of = this;
120- public ObjectFactory getObjectFactory() { return of; }
121-
122- String getUserName() {
123- String uname = getParameter("remoteUser");
124- return empty(uname) ? "guest" : uname.trim();
125- }
126-
127- void init() {
128- try {
129- String propName = getUserName();
130- pref = new RemotePreference(propName, cc.getCodeBase(), 5, GenericKFCApp.this);
131- if (!pref.loadPreference("", false))
132- err.println("ERROR: " + propName + " load failed.");
133- else if(verbose)
134- err.println("INFO: " + propName + " loaded.");
135- } catch(java.io.IOException ignore) { trace(ignore); }
136- catch(SecurityException ignore) { trace(ignore); }
137- }
138-
139- boolean testFlag(String tt, boolean def) {
140- if (tt == null || tt.length() == 0) return def;
141- char ch = tt.charAt(0);
142- switch(ch) { case 'J': case 'j': case 'T': case 't': case 'Y': case 'y': case '1': return true;
143- case 'O': case 'o': return "on".equalsIgnoreCase(tt);
144- default: return false;
145- }
146- }
147-
148- String getName() {
149- String name = getParameter("name");
150- return name == null ? "" : name.trim();
151- }
152-
153- private String trimStar(String tt) {
154- if (tt.endsWith("*")) return tt.substring(tt.length() - 1);
155- return tt;
156- }
157-
158- public String fetchProperty(String propName, String def) {
159- String name = getName(), ts = trimStar(propName);
160- if (empty(name) || propName.endsWith("*")) return pref.value(ts, def);
161- return pref.value(ts, def, name);
162- }
163-
164- public int fetchNumberProperty(String propName, int def) {
165- String name = getName(), ts = trimStar(propName);
166- if (empty(name) || propName.endsWith("*")) return pref.intValue(ts, def);
167- return pref.intValue(ts, def, name);
168- }
169-
170- public boolean fetchFlagProperty(String propName, boolean def) {
171- String name = getName(), ts = trimStar(propName);
172- if (empty(name) || propName.endsWith("*")) return pref.booleanValue(ts, def);
173- return pref.booleanValue(ts, def, name);
174- }
175-
176- public void storeProperty(String propName, String value) {
177- String name = getName(), ts = trimStar(propName);
178- if (empty(name) || propName.endsWith("*")) pref.storeValue(ts, value, false);
179- else pref.storeValue(ts, value, name, false);
180- }
181-
182- public void storeNumberProperty(String propName, int value) {
183- storeProperty(propName, String.valueOf(value));
184- }
185-
186- public void storeFlagProperty(String propName, boolean value) {
187- storeProperty(propName, String.valueOf(value));
188- }
189-
190- public void actionPerformed(java.awt.event.ActionEvent event) {
191- // TODO Auto-generated method stub
192-
193- }
194-
195- void storeUserProperties() {
196- java.net.URL base = getCodeBase();
197- if (!"file".equalsIgnoreCase(base.getProtocol())) return;
198-
199- try {
200- pref.storePreference(getUserName(), false);
201- } catch(java.io.IOException ignore) { trace(ignore); }
202- }
203-
204-
205- /** 保持しているコンテナリソースを開放する
206- */
207- void shutdown() {
208- for(java.util.Enumeration en = rdbm.elements(); en.hasMoreElements(); ) {
209- RdbManager mgr = (RdbManager)en.nextElement();
210- try {
211- mgr.disconnect(false);
212- } catch (java.sql.SQLException e) { e.printStackTrace(); }
213- }
214- for(java.util.Enumeration en = dir.elements(); en.hasMoreElements(); ) {
215- DirManager mgr = (DirManager)en.nextElement();
216- try {
217- mgr.unbind();
218- } catch (java.io.IOException e) { e.printStackTrace(); }
219- }
220- for(java.util.Enumeration en = store.elements(); en.hasMoreElements(); ) {
221- MessageStore mgr = (MessageStore)en.nextElement();
222- try {
223- mgr.disconnect();
224- } catch (java.io.IOException e) { e.printStackTrace(); }
225- }
226- }
227-
228- int parseInt(String t) {
229- if (empty(t)) return 0;
230- if (t.charAt(0) == '+') t = t.substring(1);
231- return Integer.parseInt(t);
232- }
233-
234- /** <width>x<height>[+|-]<x>[+|-]<y> という構成のテキストを分解して
235- * {@link java.awt.Rectangle} に変換して返す。
236- */
237- java.awt.Rectangle parseGeometry(String geom) {
238- try {
239- java.awt.Rectangle rect = new java.awt.Rectangle();
240- int p = geom.indexOf('+'), q = geom.indexOf('-');
241- if (p < 0) p = q; else if (q < p) p = q;
242-
243- String rec = p < 0 ? geom : geom.substring(0,p);
244- String pos = p < 0 ? "" : geom.substring(p);
245-
246- p = rec.indexOf('x');
247- if (p < 0) return null;
248- rect.width = parseInt(rec.substring(0, p));
249- rect.height = parseInt(rec.substring(p + 1));
250-
251- if (!empty(pos)) {
252- p = pos.indexOf('+', 1);
253- if (p < 0) p = pos.indexOf('-', 1);
254- if (p > 0) {
255- rect.x = parseInt(pos.substring(0, p));
256- rect.y = parseInt(pos.substring(p));
257- }
258- }
259- return rect;
260-
261- } catch(NumberFormatException e) { return null; }
262- }
263-
264- void saveWindowPosition(java.awt.Rectangle rect) { }
265- java.awt.Rectangle loadWindowPosition() { return null; }
266-
267- public void windowActivated(java.awt.event.WindowEvent e) {
268- String title = app.getTitle();
269- if (empty(title)) title = app.getClass().getName();
270- java.awt.Window win = e.getWindow();
271- if (win instanceof java.awt.Dialog)
272- ((java.awt.Dialog)win).setTitle(title);
273- else if (win instanceof java.awt.Frame)
274- ((java.awt.Frame)win).setTitle(title);
275- }
276-
277- public void windowClosed(java.awt.event.WindowEvent e) {
278- trace("window closed.");
279- try { app.release(); } finally { shutdown(); }
280- }
281-
282- public void windowClosing(java.awt.event.WindowEvent e) {
283- java.awt.Rectangle bounds = e.getWindow().getBounds();
284- trace("window closing:" + bounds);
285- saveWindowPosition(bounds);
286- e.getWindow().dispose();
287- }
288-
289- public void windowDeactivated(java.awt.event.WindowEvent e) { }
290- public void windowDeiconified(java.awt.event.WindowEvent e) { }
291- public void windowIconified(java.awt.event.WindowEvent e) { trace("window iconified."); }
292- public void windowOpened(java.awt.event.WindowEvent e) { }
293-
294- public void setStatusText(String t) { setStatusText(t, 0); }
295-
296- String lastStatus;
297- public void setStatusText(String tt, int idx) {
298- if (idx == 0) {
299- if (lastStatus != null && lastStatus.equals(tt)) return;
300- java.applet.AppletContext ac = GenericKFCApp.this.getAppletContext();
301- if (ac != null) ac.showStatus(tt);
302- err.println(tt);
303- lastStatus = tt;
304- }
305- }
306-
307- public int addStatusText(int column) {
308- // TODO Auto-generated method stub
309- return 0;
310- }
311-
312- public java.net.URL getCodeBase() { return GenericKFCApp.this.getCodeBase(); }
313- public java.util.Locale getLocale() { return GenericKFCApp.this.getLocale(); }
314-
315- TaskThreadManager tm = new TaskThreadManager() {
316- void errorHandler(java.lang.Throwable fail) {
317- if (fail != null && fail instanceof InterruptedException) {
318- String msg = fail.getMessage();
319- if (empty(msg)) msg = "processing Interrupted.";
320- setStatusText(msg);
321- return;
322- }
323- popupErrorDialog(fail);
324- }
325- };
326-
327- public Thread createTaskThread(String name, Object closure, Task target) {
328- return tm.newTask(name, closure, target);
329- }
330-
331- public void invokeLater(String name, Object closure) {
332- tm.invokeLater(name, closure);
333- }
334-
335- public void invokeAndWait(String name, Object closure) throws InterruptedException, java.lang.reflect.InvocationTargetException {
336- tm.invokeAndWait(name, closure);
337- }
338-
339- public String findWorkFolder(String name) throws java.io.IOException, SecurityException {
340- throw new SecurityException("applet cannot use work folder");
341- }
342-
343- public void setCursor(int type) {
344- // TODO Auto-generated method stub
345- }
346-
347- public void revalidate() {
348- // TODO Auto-generated method stub
349-
350- }
351-
352- String popupErrorMessageText(Throwable t) {
353- if (t == null) return "";
354- String title = t.getClass().getName();
355- StringBuffer msg = new StringBuffer();
356- if (t instanceof java.sql.SQLException) {
357- java.sql.SQLException e = (java.sql.SQLException)t;
358- while (e != null) {
359- msg.append(e.getMessage()).append("\n").
360- append("Error-Code: ").append(e.getErrorCode()).
361- append(" State:").append(e.getSQLState()).append("\n");
362- e = e.getNextException();
363- }
364- }
365- else {
366- msg.append(t.getMessage());
367- if (empty(msg.toString())) msg.append(title);
368- if ("null".equals(msg.toString())) msg.append(": ").
369- append(t.getClass().getName());
370- }
371-
372- java.io.ByteArrayOutputStream ba = new java.io.ByteArrayOutputStream();
373- t.printStackTrace(new java.io.PrintStream(ba));
374- /*
375- * PrintStreamは、改行があれば自動的にフラッシュするので、この記述でよい
376- */
377- try { clip(ba.toString()); } catch(SecurityException ignore) { }
378- /*
379- * クリップボードもにスタックトレースを出力する。
380- */
381-
382- return msg.toString();
383- }
384-
385- java.awt.Frame baseFrame;
386-
387- java.awt.Frame findBaseFrame() {
388- if (baseFrame == null) baseFrame = new jp.kyasu.awt.Frame();
389- return baseFrame;
390- }
391-
392- java.awt.Dialog showMessageDialog(java.awt.Frame owner, String message, String title) {
393- if (owner == null) owner = findBaseFrame();
394- java.awt.Dialog di = new java.awt.Dialog(owner, title);
395- java.awt.TextArea buf = new java.awt.TextArea(5,25);
396- buf.setText(message);
397- di.add(buf);
398- di.addWindowListener(this);
399- di.pack();
400- di.show();
401- return di;
402- }
403-
404- public void popupErrorDialog(Throwable tt) {
405- if (tt == null) return;
406- String msg = popupErrorMessageText(tt);
407- if (verbose) tt.printStackTrace(err); else err.println(msg);
408- showMessageDialog(null, msg, "Exception occurred: " + tt.getClass().getName());
409- }
410-
411- java.awt.Toolkit getToolkit() {
412- return GenericKFCApp.this.getToolkit();
413- }
414-
415- public void clip(String t) throws SecurityException {
416- if (empty(t)) return;
417- getToolkit().getSystemClipboard().setContents(
418- new java.awt.datatransfer.StringSelection(t), this);
419- }
420-
421- public String getClipText() {
422- // TODO Auto-generated method stub
423- return null;
424- }
425-
426- public javax.swing.JDialog createJDialog(java.awt.Container base, sweep.client.JFCapplication app) {
427- throw new IllegalArgumentException("not supported yet");
428- }
429-
430- java.awt.Container findToplevelContainer(java.awt.Component comp) {
431- java.awt.Container cont = null;
432- if(comp != null)
433- if((comp instanceof java.awt.Window) || (comp instanceof java.applet.Applet)) {
434- cont = (java.awt.Container)comp;
435- } else {
436- for(java.awt.Container c1 = comp.getParent(); c1 != null; c1 = c1.getParent()) {
437- if(!(c1 instanceof java.awt.Window) && !(c1 instanceof java.applet.Applet))
438- continue;
439- cont = c1;
440- break;
441- }
442- }
443- return cont;
444- }
445-
446- void setLocationRelativeTo(java.awt.Component comp, java.awt.Dialog di) {
447- java.awt.Container container = findToplevelContainer(comp);
448-
449- if(comp != null && !comp.isShowing() || container == null || !container.isShowing()) {
450- java.awt.Dimension dn = di.getSize();
451- java.awt.Dimension d2 = di.getToolkit().getScreenSize();
452- di.setLocation((d2.width - dn.width) / 2, (d2.height - dn.height) / 2);
453- return;
454- }
455-
456- java.awt.Dimension d1 = comp.getSize();
457- java.awt.Point pt;
458- if(container instanceof java.applet.Applet)
459- pt = comp.getLocationOnScreen();
460- else {
461- pt = new java.awt.Point(0, 0);
462- for(Object obj = comp; obj != null; obj = ((java.awt.Component)(obj)).getParent()) {
463- java.awt.Point p1 = ((java.awt.Component)(obj)).getLocation();
464- pt.x += p1.x;
465- pt.y += p1.y;
466- if(obj == container) break;
467- }
468- }
469-
470- java.awt.Rectangle rec = di.getBounds();
471- int i = pt.x + (d1.width - rec.width >> 1);
472- int j = pt.y + (d1.height - rec.height >> 1);
473-
474- java.awt.Dimension d3 = di.getToolkit().getScreenSize();
475- if(j + rec.height > d3.height) {
476- j = d3.height - rec.height;
477- i = pt.x >= d3.width >> 1 ? pt.x - rec.width : pt.x + d1.width;
478- }
479- if(i + rec.width > d3.width)
480- i = d3.width - rec.width;
481- if(i < 0) i = 0;
482- if(j < 0) j = 0;
483- di.setLocation(i, j);
484- }
485-
486- public java.awt.Dialog createDialog(java.awt.Container base, sweep.client.AWTapplication app) {
487- if (app == null) return null;
488- app.setClientContext(this);
489- String title = app.getTitle();
490- if (empty(title)) title = app.getClass().getName();
491- java.awt.Window win = findWindow(base);
492- java.awt.Frame fr = win instanceof java.awt.Frame ?
493- (java.awt.Frame)win : new jp.kyasu.awt.Frame();
494-
495- jp.kyasu.awt.Dialog di = new jp.kyasu.awt.Dialog(fr, title);
496-
497- err.println("base: " + base + " frame: " + fr);
498-
499- java.awt.Component comp = app.getComponent();
500- if (comp == null) {
501- java.awt.Label cap = new java.awt.Label(
502- "アプリケーション・コンポーネントが生成されていません。");
503- comp = cap;
504- }
505- di.setLayout(new java.awt.BorderLayout());
506- di.add(comp);
507- di.addKeyListener(this);
508- di.addWindowListener(this);
509- di.pack();
510- setLocationRelativeTo(findToplevelContainer(base), di);
511- return di;
512- }
513-
514- public javax.swing.JFrame createJFrame(sweep.client.JFCapplication app) {
515- throw new IllegalArgumentException("not supported yet");
516- }
517-
518- sweep.client.ClientContext createContext(sweep.client.AWTapplication app) {
519- AppletContext ac = new AppletContext();
520- ac.app = app;
521- ac.init();
522- return ac;
523- }
524-
525- jp.kyasu.awt.TextField statusBar;
526-
527- public java.awt.Frame createFrame(sweep.client.AWTapplication app) {
528- if (app == null) return null;
529- sweep.client.ClientContext cc = this.app == app ? this : createContext(app);
530- app.setClientContext(cc);
531- String title = app.getTitle();
532- if (empty(title)) title = app.getClass().getName();
533- java.awt.Component comp = app.getComponent();
534- if (comp == null) {
535- java.awt.Panel p = new java.awt.Panel(new java.awt.BorderLayout());
536- p.setSize(250,100);
537- java.awt.Label cap = new java.awt.Label(
538- "アプリケーション・コンポーネントが生成されていません。", java.awt.Label.CENTER);
539- p.add(cap);
540- comp = p;
541- }
542- jp.kyasu.awt.Frame frame = new jp.kyasu.awt.Frame(title);
543- statusBar = new jp.kyasu.awt.TextField(40);
544- statusBar.setEditable(false);
545-
546- java.awt.Panel p = new java.awt.Panel(new java.awt.BorderLayout());
547- p.add(statusBar, java.awt.BorderLayout.SOUTH);
548-
549- frame.add(comp);
550- frame.add(p, java.awt.BorderLayout.SOUTH);
551- java.awt.MenuBar bar = app.createMenuBar();
552- if (bar != null && bar.getMenuCount() > 0) frame.setMenuBar(bar);
553- frame.pack();
554- frame.addWindowListener(this);
555-
556- java.awt.Rectangle rect = loadWindowPosition();
557- if (rect != null) {
558- trace("last bounds:" + rect);
559-
560- try {
561- frame.getClass().getMethod("setLocationByPlatform", new Class[]{ Boolean.TYPE}).
562- invoke(frame, new Object[]{ Boolean.TRUE});
563- /*
564- * この機能はJava5より有効
565- */
566- } catch (IllegalAccessException ignore) { trace(ignore);
567- } catch (java.lang.reflect.InvocationTargetException ignore) { trace(ignore);
568- } catch (NoSuchMethodException ignore) { trace(ignore);
569- }
570-
571- frame.setBounds(rect);
572- frame.setLocation(rect.x, rect.y);
573- }
574-
575- if (baseFrame == null) baseFrame = frame;
576- return frame;
577- }
578-
579- /** クラスのインスタンス化のために利用されます。
580- * @param name FQCN[;option] セミコロン(;)で区切って文字列を一つパラメータにもつクラスの生成もサポートします。
581- **/
582- public Object newInstance(String name) {
583- int p = name.indexOf(';');
584- String opt = p < 0 ? "" : name.substring(p+1).trim();
585- if (p > 0) name = name.substring(0,p);
586-
587- Throwable fail = null;
588- try {
589- err.println("Application: " + name);
590- err.println("ClientContext: " + this);
591- err.println("ClassLoader: " + getClass().getClassLoader());
592-
593- Class c = Class.forName(name);
594- if (opt.length() > 0) { String [] params = { opt, };
595- java.lang.reflect.Constructor con = c.getConstructor(_appTypes);
596- return con.newInstance(params);
597- }
598-
599- return c.newInstance();
600-
601- } catch(ClassNotFoundException e) { fail = e; }
602- catch (InstantiationException e) { fail = e; }
603- catch (IllegalAccessException e) { fail = e; }
604- catch (NoSuchMethodException e) { fail = e; err.println(name + " has no public constructor."); }
605- catch (java.lang.reflect.InvocationTargetException e) { fail = e.getTargetException(); }
606-
607- throw new ContainerRuntimeError(name, fail);
608- }
609-
610- public Object newInstance(Class klass) {
611- Exception fail = null;
612- try {
613- return klass.newInstance();
614- } catch (InstantiationException e) { fail = e;
615- } catch (IllegalAccessException e) { fail = e;
616- }
617- throw new ContainerRuntimeError("newInstance fail: " + klass.getName(), fail);
618- }
619-
620- public Object [] newInstance(Class klass, int len) {
621- return (Object [])java.lang.reflect.Array.newInstance(klass, len);
622- }
623-
624- sweep.client.AWTapplication createOldApp(String appName) {
625- sweep.client.AWTapplication app = null;
626- Throwable fail = null;
627- try {
628- app = (sweep.client.AWTapplication)newInstance(appName);
629- if (app instanceof ObjectFactory) of = (ObjectFactory)app;
630- } catch (RuntimeException e) { fail = e; }
631- popupErrorDialog(fail);
632- return app;
633- }
634-
635- public Object getAttribute(String name) { return ht.get(name); }
636- public void setAttribute(String name, Object value) { ht.put(name, value); }
637-
638- void closeFrame(java.awt.Component comp) {
639- java.awt.Window win = findWindow(comp);
640- if (win instanceof java.awt.Frame) {
641- saveWindowPosition(win.getBounds());
642- ((java.awt.Frame)win).dispose();
643- }
644- else if (win instanceof java.awt.Dialog)
645- ((java.awt.Dialog)win).dispose();
646- else
647- err.println("WARNNIG: cannot remove top level compponent on applet.");
648- }
649-
650- public void removeComponent(sweep.client.JFCapplication app) {
651- throw new IllegalArgumentException("not supported yet");
652- }
653-
654- public void removeComponent(AWTapplication ac) {
655- if (ac == app) {
656- if (statusBar != null) closeFrame(statusBar);
657- }
658- }
659-
660- FileChooser fc;
661-
662- public FileChooser getFileChooser() {
663- java.net.URL base = getCodeBase();
664- if (fc == null && "file".equalsIgnoreCase(base.getProtocol()))
665- fc = new LocalFileChooserOld();
666-
667- else if (fc == null) {
668- String pathinfo = cc.fetchProperty("container.filesPath", "/sweep/fs");
669- String prot = base.getProtocol(), host = base.getHost(), path = base.getFile();
670- int port = base.getPort();
671- RemoteFileChooserKFC rfc = new RemoteFileChooserKFC();
672- rfc.setClientContext(this);
673- String cbase = prot + "://" + host + ":" + port + pathinfo;
674- rfc.setRemoteCodeBase(cbase);
675- fc = rfc;
676- }
677- return fc;
678- }
679-
680- public RdbManager findRdbManager(String name) throws java.io.IOException {
681- if (empty(name)) name = pref.value("last-rdb", "");
682-
683- RdbManagerImpl mgr = (RdbManagerImpl)rdbm.get(name);
684- if (mgr == null) {
685- mgr = new RdbManagerImpl();
686- mgr.pref = pref;
687- RdbInfo info = mgr.loadRdbInfo(name); // 存在確認
688- mgr.dbname = name;
689- rdbm.put(name, mgr);
690- }
691- pref.storeValue("last-rdb", name, false);
692- return mgr;
693- }
694-
695- public sweep.client.DirManager findDirManager(String name) throws java.io.IOException {
696- if (empty(name)) name = pref.value("last-dir", "");
697-
698- DirManagerImpl mgr = (DirManagerImpl)dir.get(name);
699- if (mgr == null) {
700- mgr = new DirManagerImpl();
701- mgr.pref = pref;
702- DirInfo info = mgr.loadDirInfo(name); // 存在確認
703- mgr.dirname = name;
704- dir.put(name, mgr);
705- }
706- pref.storeValue("last-dir", name, false);
707- return mgr;
708- }
709-
710- public MessageStore findMessageStore(String name) throws java.io.IOException {
711- if (empty(name)) name = pref.value("last-store", "");
712-
713- MessageStoreImpl mgr = (MessageStoreImpl)store.get(name);
714- if (mgr == null) {
715- mgr = new MessageStoreImpl();
716- mgr.pref = pref;
717- MessageStoreInfo info = mgr.loadMessageAccount(name); // 存在確認
718- mgr.storeName = name;
719- store.put(name, mgr);
720- }
721- pref.storeValue("last-store", name, false);
722- return mgr;
723- }
724-
725- public void lostOwnership(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable transferable) {
726- trace("lost owner ship");
727- }
728-
729- public void keyPressed(java.awt.event.KeyEvent event) {
730- err.println(event);
731- }
732- public void keyReleased(java.awt.event.KeyEvent event) { }
733- public void keyTyped(java.awt.event.KeyEvent event) {
734- err.println(event);
735- }
736-
737- public java.awt.Image findImage(java.net.URL base, String image) {
738- if (base == null) base = getCodeBase();
739- return GenericKFCApp.this.getImage(base, image);
740- }
741-
742- ChanelManagerImpl cm;
743- public Channel findChannel(String name) throws java.io.IOException {
744- if (cm == null) {
745- cm = new ChanelManagerImpl();
746- cm.setClientContext(this);
747- }
748- Channel ch = cm.findChannel(name);
749- return ch;
750- }
751-
752- public String[] getRemoteNames() {
753- String secs[] = pref.getSectionNames();
754-
755- java.util.Vector vec = new java.util.Vector();
756- for (int i = 0; i < secs.length; i++){
757- String sn = secs[i];
758- if (!sn.endsWith(".remote")) continue;
759- vec.addElement(sn.substring(0, sn.length() - ".remote".length()));
760- }
761- if (vec.isEmpty()) return ContainerCommon.EMPTY_VALUES;
762-
763- String[] pn = new String[vec.size()];
764- vec.copyInto(pn);
765- return pn;
766- }
767-
768- public RemoteInfo loadRemoteInfo(String name) throws java.io.IOException {
769- RmoteInfoVO aa = new RmoteInfoVO().load(pref, name);
770- return aa;
771- }
772-
773- public void storeRemoteInfo(RemoteInfo info) throws java.io.IOException {
774- RmoteInfoVO aa = new RmoteInfoVO().load(info);
775- boolean sys = false;
776- String host = info.getRemoteHost();
777- if (empty(host)) aa.remove(pref, sys); else aa.store(pref, sys);
778- pref.storePreference("", sys);
779- }
780- }
781-
782- static java.io.File dot = new java.io.File(".");
783-
784- /** Javaアプリケーション向けのクライアント・コンテキスト
785- * こちらは、ローカル・ファイルシステムを操作することができる。
786- */
787- class ApplicationContext extends AppletContext {
788-
789- sweep.client.ClientContext createContext(sweep.client.AWTapplication app) {
790- ApplicationContext ac = new ApplicationContext();
791- ac.app = app;
792- ac.init();
793- return ac;
794- }
795-
796- String getUserName() { return System.getProperty("user.name"); }
797-
798- void init() {
799- try {
800- String propName = getUserName();
801- pref = new LocalPreference(propName, 0);
802-
803- if (!pref.loadPreference("", false))
804- err.println("ERROR: " + propName + " load failed.");
805- else if(verbose)
806- err.println("INFO: " + propName + " loaded.");
807- } catch(java.io.IOException ignore) { trace(ignore); }
808- catch(SecurityException ignore) { trace(ignore); }
809- }
810-
811- public String findWorkFolder(String name) throws java.io.IOException, SecurityException {
812- String userHome = System.getProperty("user.dir");
813- java.io.File base = new java.io.File(userHome, ".clientContainer"), work;
814- work = empty(name) ? base : new java.io.File(base, name);
815- if (work.isDirectory() && work.canWrite()) return work.getPath();
816- if (!work.exists() && !work.mkdirs())
817- throw new java.io.IOException("create dir failed: " + work);
818-
819- if (work.isDirectory() && work.canWrite()) return work.getPath();
820-
821- throw new java.io.IOException("work directory not exists or can not write: " + work);
822- }
823-
824- java.net.URL createFileURL(java.io.File t) throws java.net.MalformedURLException {
825- String path = t.getName().replace(java.io.File.separatorChar, '/').replace(':', '|');
826- java.net.URL r = new java.net.URL("file", "", -1, path);
827- return r;
828- }
829-
830- public java.net.URL getCodeBase() {
831- try {
832- String cb = jc.getProperty("container.debug.codebase", "");
833- if (!empty(cb)) return new java.net.URL(cb);
834-
835- return createFileURL(dot);
836- } catch(java.net.MalformedURLException e) {
837- throw new IllegalStateException(e.getMessage());
838- }
839- }
840-
841- public java.util.Locale getLocale() {
842- return java.util.Locale.getDefault();
843- }
844-
845- public FileChooser getFileChooser() {
846- if (fc == null) {
847- String codebase = jc.getProperty("container.debug.codebase", "");
848- if (!empty(codebase)) {
849- // リモート・アクセスの確認用
850- RemoteFileChooserKFC rfc = new RemoteFileChooserKFC();
851- rfc.setClientContext(this);
852- rfc.setRemoteCodeBase(codebase);
853- fc = rfc;
854- }
855- }
856- if (fc == null) fc = new LocalFileChooser();
857- return fc;
858- }
859-
860- String signValue(int num) {
861- return num >= 0 ? "+" + num : String.valueOf(num);
862- }
863-
864- String getName() { return jc.getJobId(); }
865-
866- void saveWindowPosition(java.awt.Rectangle rect) {
867- String id = jc.getJobId();
868- pref.storeValue("frame.geometry",
869- rect.width + "x" + rect.height + signValue(rect.x) + signValue(rect.y), id, false);
870- storeUserProperties();
871- trace("#saveWindowPosition pos: " +rect);
872- }
873-
874- java.awt.Rectangle loadWindowPosition() {
875- String id = jc.getJobId();
876- String geom = pref.value("frame.geometry", "", id);
877- if (empty(geom)) return null;
878- java.awt.Rectangle rect = parseGeometry(geom);
879- trace("#loadWindowPosition pos: " + geom + ":" + rect);
880- return rect;
881- }
882-
883- public void setStatusText(String tt, int idx) {
884- err.println(tt);
885- }
886-
887- public java.awt.Image findImage(java.net.URL base, String image) {
888- if (verbose) err.println("Image: " + base + " " + image);
889- try {
890- java.awt.Image img;
891- if (base == null || base.toExternalForm().equals("file:."))
892- img = java.awt.Toolkit.getDefaultToolkit().getImage(image);
893- else {
894- java.net.URL location = new java.net.URL(base, image);
895- img = java.awt.Toolkit.getDefaultToolkit().getImage(location);
896- }
897- loadImage(img);
898- return img;
899- } catch(java.io.IOException e) { return null; }
900- }
901- }
902-
903- void loadImage(java.awt.Image image) {
904- synchronized(tracker) {
905- tracker.addImage(image, 0);
906- try {
907- tracker.waitForID(0, 5000);
908- } catch (InterruptedException e) { err.println("INTERRUPTED while loading Image"); }
909- int loadStatus = tracker.statusID(0, false);
910- tracker.removeImage(image, 0);
911- }
912- }
913-
914- final static java.awt.Component component = new java.awt.Component() {};
915- final static java.awt.MediaTracker tracker = new java.awt.MediaTracker(component);
916-
917- JobContext jc;
918- public void setJobContext(JobContext context) { jc = context; }
919-
920- public void setup() throws java.io.IOException, java.sql.SQLException {
921- ApplicationContext cc = new ApplicationContext();
922- cc.init();
923-
924- String cv = (String)jc.getAttribute("container.verbose");
925- verbose = cc.testFlag(jc.getProperty("verbose", cv), false);
926- trace("#setup");
927-
928- String appName = jc.getProperty("app", null);
929- if (appName == null) {
930- throw new ContainerRuntimeError("no \"app\" parameter or class instantiaion failed!");
931- }
932-
933- cc.app = cc.createOldApp(appName);
934- jc.setAttribute("client.container", cc);
935- }
936-
937- public void run() {
938- ApplicationContext cc = (ApplicationContext)jc.getAttribute("client.container");
939- java.awt.Frame fr = cc.createFrame(cc.app);
940- String iconName = jc.getProperty("frame-icon", "");
941- if (!empty(iconName)) {
942- java.awt.Image img = cc.findImage(null, iconName);
943- if (img != null) fr.setIconImage(img);
944- }
945- fr.setVisible(true);
946- }
947-
948- public int executeJob() throws java.io.IOException, java.sql.SQLException, InterruptedException {
949- try {
950- Class.forName("javax.swing.SwingUtilities")
951- .getMethod("invokeAndWait",new Class[]{ Runnable.class, })
952- .invoke(null, new Object[]{ this,});
953- } catch (Throwable ignore) { run(); }
954-
955- ApplicationContext cc = (ApplicationContext)jc.getAttribute("client.container");
956-
957- if (cc.app instanceof OpenFiles) {
958- String args[] = jc.getJobOption();
959- ((OpenFiles) cc.app).openFiles(args, 0);
960- }
961- return 0;
962- }
963-
964- public void tearDown() throws java.io.IOException, java.sql.SQLException {
965- trace("#tearDown");
966- }
967-}
968-
--- branches/client/kfc-apps/src/main/java/sweep/container/GenericKFCApp.java (nonexistent)
+++ branches/client/kfc-apps/src/main/java/sweep/container/GenericKFCApp.java (revision 48)
@@ -0,0 +1,968 @@
1+package sweep.container;
2+
3+import sweep.client.*;
4+
5+/** 古いVMでも動作するように調整したアプレット
6+ */
7+public class GenericKFCApp extends jp.kyasu.awt.Applet implements Runnable, sweep.client.JobAction {
8+
9+ static java.io.PrintStream out = System.out, err = System.err;
10+ static final Class [] _appTypes = { String.class, };
11+
12+ /** nullあるいは空白文字だけで構成されているテキストであるか診断 */
13+ boolean empty(String t) { return t == null || t.trim().length() == 0; }
14+
15+ boolean verbose;
16+ /** トレース・ログ*/
17+ void trace(Object t) { if(verbose) err.println(t); }
18+
19+ /// フレーム間で共有する属性
20+ java.util.Hashtable ht = new java.util.Hashtable();
21+
22+ public String[][] getParameterInfo() {
23+ String info[][]={
24+ { "app", "FQCN", "Class of jp.sourceforge.sweep.client.AWTapplication or " +
25+ "jp.sourceforge.sweep.client.JFCapplication", },
26+ { "open", "resource mame", "Name of Resource treaded by sweep.client.OpenFiles", },
27+ { "verbose", "true|[false]", "debug message switch", }
28+ };
29+ return info;
30+ }
31+
32+ /** コンテナが配置されているウィンドウを検出する
33+ * @throws IllegalStateException ウインドウに配置されていない */
34+ static java.awt.Window findWindow(java.awt.Component c) {
35+ java.awt.Container t = c instanceof java.awt.Container ?
36+ (java.awt.Container)c : c.getParent();
37+ while (t != null) {
38+ if (t instanceof java.awt.Window) return (java.awt.Window)t;
39+ t = t.getParent();
40+ }
41+
42+ throw new IllegalStateException("not binding; " +
43+ c.getName() + ":" + c.getClass().getName());
44+ }
45+
46+ java.util.Hashtable rdbm = new java.util.Hashtable();
47+ java.util.Hashtable dir = new java.util.Hashtable();
48+ java.util.Hashtable store = new java.util.Hashtable();
49+ AppletContext cc;
50+
51+ public void init() {
52+ setLayout(new java.awt.BorderLayout());
53+ cc = new AppletContext();
54+ cc.init();
55+ verbose = cc.testFlag(getParameter("verbose"), false);
56+ trace("#init applet");
57+
58+ String appName = getParameter("app");
59+ if (appName == null) {
60+ java.awt.TextArea ta;
61+ add(ta = new java.awt.TextArea(5,10), java.awt.BorderLayout.CENTER);
62+ ta.setText("no \"app\" parameter or class instantiaion failed!");
63+ return;
64+ }
65+
66+ AWTapplication app = cc.createOldApp(appName);
67+ app.setClientContext(cc);
68+ cc.app = app;
69+ String title = app.getTitle();
70+ if (empty(title)) title = app.getClass().getName();
71+
72+ java.awt.Component comp = app.getComponent();
73+ if (comp == null) {
74+ java.awt.Label cap = new java.awt.Label("application componenent was not created.");
75+ comp = cap;
76+ }
77+ removeAll();
78+ add(comp, java.awt.BorderLayout.CENTER);
79+ }
80+
81+ public void start() {
82+ trace("#start applet");
83+
84+ if (cc.app instanceof OpenFiles) {
85+ java.util.Vector files = new java.util.Vector();
86+ String open = getParameter("open");
87+ if (!empty(open)) {
88+ java.util.StringTokenizer tk = new java.util.StringTokenizer(open, ",");
89+ while(tk.hasMoreElements()) {
90+ files.addElement(tk.nextElement());
91+ }
92+ }
93+ trace(files + "" + files.size() + " open files");
94+ String [] names;
95+ files.copyInto(names = new String[files.size()]);
96+ ((OpenFiles)cc.app).openFiles(names, 0);
97+ }
98+ }
99+
100+ public void stop() {
101+ cc.app.release();
102+ trace("#stop applet");
103+ }
104+
105+ public void destroy() {
106+ try { cc.app.release(); } finally { cc.shutdown(); }
107+ trace("#destroy applet");
108+ }
109+
110+ /** {@link JFCapplication}を表示するアプレット
111+ */
112+ class AppletContext implements sweep.client.ClientContext, ObjectFactory,
113+ java.io.Serializable, java.awt.event.WindowListener, java.awt.event.ActionListener,
114+ java.awt.datatransfer.ClipboardOwner, java.awt.event.KeyListener {
115+
116+ sweep.client.AWTapplication app;
117+ Preference pref;
118+
119+ ObjectFactory of = this;
120+ public ObjectFactory getObjectFactory() { return of; }
121+
122+ String getUserName() {
123+ String uname = getParameter("remoteUser");
124+ return empty(uname) ? "guest" : uname.trim();
125+ }
126+
127+ void init() {
128+ try {
129+ String propName = getUserName();
130+ pref = new RemotePreference(propName, cc.getCodeBase(), 5, GenericKFCApp.this);
131+ if (!pref.loadPreference("", false))
132+ err.println("ERROR: " + propName + " load failed.");
133+ else if(verbose)
134+ err.println("INFO: " + propName + " loaded.");
135+ } catch(java.io.IOException ignore) { trace(ignore); }
136+ catch(SecurityException ignore) { trace(ignore); }
137+ }
138+
139+ boolean testFlag(String tt, boolean def) {
140+ if (tt == null || tt.length() == 0) return def;
141+ char ch = tt.charAt(0);
142+ switch(ch) { case 'J': case 'j': case 'T': case 't': case 'Y': case 'y': case '1': return true;
143+ case 'O': case 'o': return "on".equalsIgnoreCase(tt);
144+ default: return false;
145+ }
146+ }
147+
148+ String getName() {
149+ String name = getParameter("name");
150+ return name == null ? "" : name.trim();
151+ }
152+
153+ private String trimStar(String tt) {
154+ if (tt.endsWith("*")) return tt.substring(tt.length() - 1);
155+ return tt;
156+ }
157+
158+ public String fetchProperty(String propName, String def) {
159+ String name = getName(), ts = trimStar(propName);
160+ if (empty(name) || propName.endsWith("*")) return pref.value(ts, def);
161+ return pref.value(ts, def, name);
162+ }
163+
164+ public int fetchNumberProperty(String propName, int def) {
165+ String name = getName(), ts = trimStar(propName);
166+ if (empty(name) || propName.endsWith("*")) return pref.intValue(ts, def);
167+ return pref.intValue(ts, def, name);
168+ }
169+
170+ public boolean fetchFlagProperty(String propName, boolean def) {
171+ String name = getName(), ts = trimStar(propName);
172+ if (empty(name) || propName.endsWith("*")) return pref.booleanValue(ts, def);
173+ return pref.booleanValue(ts, def, name);
174+ }
175+
176+ public void storeProperty(String propName, String value) {
177+ String name = getName(), ts = trimStar(propName);
178+ if (empty(name) || propName.endsWith("*")) pref.storeValue(ts, value, false);
179+ else pref.storeValue(ts, value, name, false);
180+ }
181+
182+ public void storeNumberProperty(String propName, int value) {
183+ storeProperty(propName, String.valueOf(value));
184+ }
185+
186+ public void storeFlagProperty(String propName, boolean value) {
187+ storeProperty(propName, String.valueOf(value));
188+ }
189+
190+ public void actionPerformed(java.awt.event.ActionEvent event) {
191+ // TODO Auto-generated method stub
192+
193+ }
194+
195+ void storeUserProperties() {
196+ java.net.URL base = getCodeBase();
197+ if (!"file".equalsIgnoreCase(base.getProtocol())) return;
198+
199+ try {
200+ pref.storePreference(getUserName(), false);
201+ } catch(java.io.IOException ignore) { trace(ignore); }
202+ }
203+
204+
205+ /** 保持しているコンテナリソースを開放する
206+ */
207+ void shutdown() {
208+ for(java.util.Enumeration en = rdbm.elements(); en.hasMoreElements(); ) {
209+ RdbManager mgr = (RdbManager)en.nextElement();
210+ try {
211+ mgr.disconnect(false);
212+ } catch (java.sql.SQLException e) { e.printStackTrace(); }
213+ }
214+ for(java.util.Enumeration en = dir.elements(); en.hasMoreElements(); ) {
215+ DirManager mgr = (DirManager)en.nextElement();
216+ try {
217+ mgr.unbind();
218+ } catch (java.io.IOException e) { e.printStackTrace(); }
219+ }
220+ for(java.util.Enumeration en = store.elements(); en.hasMoreElements(); ) {
221+ MessageStore mgr = (MessageStore)en.nextElement();
222+ try {
223+ mgr.disconnect();
224+ } catch (java.io.IOException e) { e.printStackTrace(); }
225+ }
226+ }
227+
228+ int parseInt(String t) {
229+ if (empty(t)) return 0;
230+ if (t.charAt(0) == '+') t = t.substring(1);
231+ return Integer.parseInt(t);
232+ }
233+
234+ /** <width>x<height>[+|-]<x>[+|-]<y> という構成のテキストを分解して
235+ * {@link java.awt.Rectangle} に変換して返す。
236+ */
237+ java.awt.Rectangle parseGeometry(String geom) {
238+ try {
239+ java.awt.Rectangle rect = new java.awt.Rectangle();
240+ int p = geom.indexOf('+'), q = geom.indexOf('-');
241+ if (p < 0) p = q; else if (q < p) p = q;
242+
243+ String rec = p < 0 ? geom : geom.substring(0,p);
244+ String pos = p < 0 ? "" : geom.substring(p);
245+
246+ p = rec.indexOf('x');
247+ if (p < 0) return null;
248+ rect.width = parseInt(rec.substring(0, p));
249+ rect.height = parseInt(rec.substring(p + 1));
250+
251+ if (!empty(pos)) {
252+ p = pos.indexOf('+', 1);
253+ if (p < 0) p = pos.indexOf('-', 1);
254+ if (p > 0) {
255+ rect.x = parseInt(pos.substring(0, p));
256+ rect.y = parseInt(pos.substring(p));
257+ }
258+ }
259+ return rect;
260+
261+ } catch(NumberFormatException e) { return null; }
262+ }
263+
264+ void saveWindowPosition(java.awt.Rectangle rect) { }
265+ java.awt.Rectangle loadWindowPosition() { return null; }
266+
267+ public void windowActivated(java.awt.event.WindowEvent e) {
268+ String title = app.getTitle();
269+ if (empty(title)) title = app.getClass().getName();
270+ java.awt.Window win = e.getWindow();
271+ if (win instanceof java.awt.Dialog)
272+ ((java.awt.Dialog)win).setTitle(title);
273+ else if (win instanceof java.awt.Frame)
274+ ((java.awt.Frame)win).setTitle(title);
275+ }
276+
277+ public void windowClosed(java.awt.event.WindowEvent e) {
278+ trace("window closed.");
279+ try { app.release(); } finally { shutdown(); }
280+ }
281+
282+ public void windowClosing(java.awt.event.WindowEvent e) {
283+ java.awt.Rectangle bounds = e.getWindow().getBounds();
284+ trace("window closing:" + bounds);
285+ saveWindowPosition(bounds);
286+ e.getWindow().dispose();
287+ }
288+
289+ public void windowDeactivated(java.awt.event.WindowEvent e) { }
290+ public void windowDeiconified(java.awt.event.WindowEvent e) { }
291+ public void windowIconified(java.awt.event.WindowEvent e) { trace("window iconified."); }
292+ public void windowOpened(java.awt.event.WindowEvent e) { }
293+
294+ public void setStatusText(String t) { setStatusText(t, 0); }
295+
296+ String lastStatus;
297+ public void setStatusText(String tt, int idx) {
298+ if (idx == 0) {
299+ if (lastStatus != null && lastStatus.equals(tt)) return;
300+ java.applet.AppletContext ac = GenericKFCApp.this.getAppletContext();
301+ if (ac != null) ac.showStatus(tt);
302+ err.println(tt);
303+ lastStatus = tt;
304+ }
305+ }
306+
307+ public int addStatusText(int column) {
308+ // TODO Auto-generated method stub
309+ return 0;
310+ }
311+
312+ public java.net.URL getCodeBase() { return GenericKFCApp.this.getCodeBase(); }
313+ public java.util.Locale getLocale() { return GenericKFCApp.this.getLocale(); }
314+
315+ TaskThreadManager tm = new TaskThreadManager() {
316+ void errorHandler(java.lang.Throwable fail) {
317+ if (fail != null && fail instanceof InterruptedException) {
318+ String msg = fail.getMessage();
319+ if (empty(msg)) msg = "processing Interrupted.";
320+ setStatusText(msg);
321+ return;
322+ }
323+ popupErrorDialog(fail);
324+ }
325+ };
326+
327+ public Thread createTaskThread(String name, Object closure, Task target) {
328+ return tm.newTask(name, closure, target);
329+ }
330+
331+ public void invokeLater(String name, Object closure) {
332+ tm.invokeLater(name, closure);
333+ }
334+
335+ public void invokeAndWait(String name, Object closure) throws InterruptedException, java.lang.reflect.InvocationTargetException {
336+ tm.invokeAndWait(name, closure);
337+ }
338+
339+ public String findWorkFolder(String name) throws java.io.IOException, SecurityException {
340+ throw new SecurityException("applet cannot use work folder");
341+ }
342+
343+ public void setCursor(int type) {
344+ // TODO Auto-generated method stub
345+ }
346+
347+ public void revalidate() {
348+ // TODO Auto-generated method stub
349+
350+ }
351+
352+ String popupErrorMessageText(Throwable t) {
353+ if (t == null) return "";
354+ String title = t.getClass().getName();
355+ StringBuffer msg = new StringBuffer();
356+ if (t instanceof java.sql.SQLException) {
357+ java.sql.SQLException e = (java.sql.SQLException)t;
358+ while (e != null) {
359+ msg.append(e.getMessage()).append("\n").
360+ append("Error-Code: ").append(e.getErrorCode()).
361+ append(" State:").append(e.getSQLState()).append("\n");
362+ e = e.getNextException();
363+ }
364+ }
365+ else {
366+ msg.append(t.getMessage());
367+ if (empty(msg.toString())) msg.append(title);
368+ if ("null".equals(msg.toString())) msg.append(": ").
369+ append(t.getClass().getName());
370+ }
371+
372+ java.io.ByteArrayOutputStream ba = new java.io.ByteArrayOutputStream();
373+ t.printStackTrace(new java.io.PrintStream(ba));
374+ /*
375+ * PrintStreamは、改行があれば自動的にフラッシュするので、この記述でよい
376+ */
377+ try { clip(ba.toString()); } catch(SecurityException ignore) { }
378+ /*
379+ * クリップボードもにスタックトレースを出力する。
380+ */
381+
382+ return msg.toString();
383+ }
384+
385+ java.awt.Frame baseFrame;
386+
387+ java.awt.Frame findBaseFrame() {
388+ if (baseFrame == null) baseFrame = new jp.kyasu.awt.Frame();
389+ return baseFrame;
390+ }
391+
392+ java.awt.Dialog showMessageDialog(java.awt.Frame owner, String message, String title) {
393+ if (owner == null) owner = findBaseFrame();
394+ java.awt.Dialog di = new java.awt.Dialog(owner, title);
395+ java.awt.TextArea buf = new java.awt.TextArea(5,25);
396+ buf.setText(message);
397+ di.add(buf);
398+ di.addWindowListener(this);
399+ di.pack();
400+ di.show();
401+ return di;
402+ }
403+
404+ public void popupErrorDialog(Throwable tt) {
405+ if (tt == null) return;
406+ String msg = popupErrorMessageText(tt);
407+ if (verbose) tt.printStackTrace(err); else err.println(msg);
408+ showMessageDialog(null, msg, "Exception occurred: " + tt.getClass().getName());
409+ }
410+
411+ java.awt.Toolkit getToolkit() {
412+ return GenericKFCApp.this.getToolkit();
413+ }
414+
415+ public void clip(String t) throws SecurityException {
416+ if (empty(t)) return;
417+ getToolkit().getSystemClipboard().setContents(
418+ new java.awt.datatransfer.StringSelection(t), this);
419+ }
420+
421+ public String getClipText() {
422+ // TODO Auto-generated method stub
423+ return null;
424+ }
425+
426+ public javax.swing.JDialog createJDialog(java.awt.Container base, sweep.client.JFCapplication app) {
427+ throw new IllegalArgumentException("not supported yet");
428+ }
429+
430+ java.awt.Container findToplevelContainer(java.awt.Component comp) {
431+ java.awt.Container cont = null;
432+ if(comp != null)
433+ if((comp instanceof java.awt.Window) || (comp instanceof java.applet.Applet)) {
434+ cont = (java.awt.Container)comp;
435+ } else {
436+ for(java.awt.Container c1 = comp.getParent(); c1 != null; c1 = c1.getParent()) {
437+ if(!(c1 instanceof java.awt.Window) && !(c1 instanceof java.applet.Applet))
438+ continue;
439+ cont = c1;
440+ break;
441+ }
442+ }
443+ return cont;
444+ }
445+
446+ void setLocationRelativeTo(java.awt.Component comp, java.awt.Dialog di) {
447+ java.awt.Container container = findToplevelContainer(comp);
448+
449+ if(comp != null && !comp.isShowing() || container == null || !container.isShowing()) {
450+ java.awt.Dimension dn = di.getSize();
451+ java.awt.Dimension d2 = di.getToolkit().getScreenSize();
452+ di.setLocation((d2.width - dn.width) / 2, (d2.height - dn.height) / 2);
453+ return;
454+ }
455+
456+ java.awt.Dimension d1 = comp.getSize();
457+ java.awt.Point pt;
458+ if(container instanceof java.applet.Applet)
459+ pt = comp.getLocationOnScreen();
460+ else {
461+ pt = new java.awt.Point(0, 0);
462+ for(Object obj = comp; obj != null; obj = ((java.awt.Component)(obj)).getParent()) {
463+ java.awt.Point p1 = ((java.awt.Component)(obj)).getLocation();
464+ pt.x += p1.x;
465+ pt.y += p1.y;
466+ if(obj == container) break;
467+ }
468+ }
469+
470+ java.awt.Rectangle rec = di.getBounds();
471+ int i = pt.x + (d1.width - rec.width >> 1);
472+ int j = pt.y + (d1.height - rec.height >> 1);
473+
474+ java.awt.Dimension d3 = di.getToolkit().getScreenSize();
475+ if(j + rec.height > d3.height) {
476+ j = d3.height - rec.height;
477+ i = pt.x >= d3.width >> 1 ? pt.x - rec.width : pt.x + d1.width;
478+ }
479+ if(i + rec.width > d3.width)
480+ i = d3.width - rec.width;
481+ if(i < 0) i = 0;
482+ if(j < 0) j = 0;
483+ di.setLocation(i, j);
484+ }
485+
486+ public java.awt.Dialog createDialog(java.awt.Container base, sweep.client.AWTapplication app) {
487+ if (app == null) return null;
488+ app.setClientContext(this);
489+ String title = app.getTitle();
490+ if (empty(title)) title = app.getClass().getName();
491+ java.awt.Window win = findWindow(base);
492+ java.awt.Frame fr = win instanceof java.awt.Frame ?
493+ (java.awt.Frame)win : new jp.kyasu.awt.Frame();
494+
495+ jp.kyasu.awt.Dialog di = new jp.kyasu.awt.Dialog(fr, title);
496+
497+ err.println("base: " + base + " frame: " + fr);
498+
499+ java.awt.Component comp = app.getComponent();
500+ if (comp == null) {
501+ java.awt.Label cap = new java.awt.Label(
502+ "アプリケーション・コンポーネントが生成されていません。");
503+ comp = cap;
504+ }
505+ di.setLayout(new java.awt.BorderLayout());
506+ di.add(comp);
507+ di.addKeyListener(this);
508+ di.addWindowListener(this);
509+ di.pack();
510+ setLocationRelativeTo(findToplevelContainer(base), di);
511+ return di;
512+ }
513+
514+ public javax.swing.JFrame createJFrame(sweep.client.JFCapplication app) {
515+ throw new IllegalArgumentException("not supported yet");
516+ }
517+
518+ sweep.client.ClientContext createContext(sweep.client.AWTapplication app) {
519+ AppletContext ac = new AppletContext();
520+ ac.app = app;
521+ ac.init();
522+ return ac;
523+ }
524+
525+ jp.kyasu.awt.TextField statusBar;
526+
527+ public java.awt.Frame createFrame(sweep.client.AWTapplication app) {
528+ if (app == null) return null;
529+ sweep.client.ClientContext cc = this.app == app ? this : createContext(app);
530+ app.setClientContext(cc);
531+ String title = app.getTitle();
532+ if (empty(title)) title = app.getClass().getName();
533+ java.awt.Component comp = app.getComponent();
534+ if (comp == null) {
535+ java.awt.Panel p = new java.awt.Panel(new java.awt.BorderLayout());
536+ p.setSize(250,100);
537+ java.awt.Label cap = new java.awt.Label(
538+ "アプリケーション・コンポーネントが生成されていません。", java.awt.Label.CENTER);
539+ p.add(cap);
540+ comp = p;
541+ }
542+ jp.kyasu.awt.Frame frame = new jp.kyasu.awt.Frame(title);
543+ statusBar = new jp.kyasu.awt.TextField(40);
544+ statusBar.setEditable(false);
545+
546+ java.awt.Panel p = new java.awt.Panel(new java.awt.BorderLayout());
547+ p.add(statusBar, java.awt.BorderLayout.SOUTH);
548+
549+ frame.add(comp);
550+ frame.add(p, java.awt.BorderLayout.SOUTH);
551+ java.awt.MenuBar bar = app.createMenuBar();
552+ if (bar != null && bar.getMenuCount() > 0) frame.setMenuBar(bar);
553+ frame.pack();
554+ frame.addWindowListener(this);
555+
556+ java.awt.Rectangle rect = loadWindowPosition();
557+ if (rect != null) {
558+ trace("last bounds:" + rect);
559+
560+ try {
561+ frame.getClass().getMethod("setLocationByPlatform", new Class[]{ Boolean.TYPE}).
562+ invoke(frame, new Object[]{ Boolean.TRUE});
563+ /*
564+ * この機能はJava5より有効
565+ */
566+ } catch (IllegalAccessException ignore) { trace(ignore);
567+ } catch (java.lang.reflect.InvocationTargetException ignore) { trace(ignore);
568+ } catch (NoSuchMethodException ignore) { trace(ignore);
569+ }
570+
571+ frame.setBounds(rect);
572+ frame.setLocation(rect.x, rect.y);
573+ }
574+
575+ if (baseFrame == null) baseFrame = frame;
576+ return frame;
577+ }
578+
579+ /** クラスのインスタンス化のために利用されます。
580+ * @param name FQCN[;option] セミコロン(;)で区切って文字列を一つパラメータにもつクラスの生成もサポートします。
581+ **/
582+ public Object newInstance(String name) {
583+ int p = name.indexOf(';');
584+ String opt = p < 0 ? "" : name.substring(p+1).trim();
585+ if (p > 0) name = name.substring(0,p);
586+
587+ Throwable fail = null;
588+ try {
589+ err.println("Application: " + name);
590+ err.println("ClientContext: " + this);
591+ err.println("ClassLoader: " + getClass().getClassLoader());
592+
593+ Class c = Class.forName(name);
594+ if (opt.length() > 0) { String [] params = { opt, };
595+ java.lang.reflect.Constructor con = c.getConstructor(_appTypes);
596+ return con.newInstance(params);
597+ }
598+
599+ return c.newInstance();
600+
601+ } catch(ClassNotFoundException e) { fail = e; }
602+ catch (InstantiationException e) { fail = e; }
603+ catch (IllegalAccessException e) { fail = e; }
604+ catch (NoSuchMethodException e) { fail = e; err.println(name + " has no public constructor."); }
605+ catch (java.lang.reflect.InvocationTargetException e) { fail = e.getTargetException(); }
606+
607+ throw new ContainerRuntimeError(name, fail);
608+ }
609+
610+ public Object newInstance(Class klass) {
611+ Exception fail = null;
612+ try {
613+ return klass.newInstance();
614+ } catch (InstantiationException e) { fail = e;
615+ } catch (IllegalAccessException e) { fail = e;
616+ }
617+ throw new ContainerRuntimeError("newInstance fail: " + klass.getName(), fail);
618+ }
619+
620+ public Object [] newInstance(Class klass, int len) {
621+ return (Object [])java.lang.reflect.Array.newInstance(klass, len);
622+ }
623+
624+ sweep.client.AWTapplication createOldApp(String appName) {
625+ sweep.client.AWTapplication app = null;
626+ Throwable fail = null;
627+ try {
628+ app = (sweep.client.AWTapplication)newInstance(appName);
629+ if (app instanceof ObjectFactory) of = (ObjectFactory)app;
630+ } catch (RuntimeException e) { fail = e; }
631+ popupErrorDialog(fail);
632+ return app;
633+ }
634+
635+ public Object getAttribute(String name) { return ht.get(name); }
636+ public void setAttribute(String name, Object value) { ht.put(name, value); }
637+
638+ void closeFrame(java.awt.Component comp) {
639+ java.awt.Window win = findWindow(comp);
640+ if (win instanceof java.awt.Frame) {
641+ saveWindowPosition(win.getBounds());
642+ ((java.awt.Frame)win).dispose();
643+ }
644+ else if (win instanceof java.awt.Dialog)
645+ ((java.awt.Dialog)win).dispose();
646+ else
647+ err.println("WARNNIG: cannot remove top level compponent on applet.");
648+ }
649+
650+ public void removeComponent(sweep.client.JFCapplication app) {
651+ throw new IllegalArgumentException("not supported yet");
652+ }
653+
654+ public void removeComponent(AWTapplication ac) {
655+ if (ac == app) {
656+ if (statusBar != null) closeFrame(statusBar);
657+ }
658+ }
659+
660+ FileChooser fc;
661+
662+ public FileChooser getFileChooser() {
663+ java.net.URL base = getCodeBase();
664+ if (fc == null && "file".equalsIgnoreCase(base.getProtocol()))
665+ fc = new LocalFileChooserOld();
666+
667+ else if (fc == null) {
668+ String pathinfo = cc.fetchProperty("container.filesPath", "/sweep/fs");
669+ String prot = base.getProtocol(), host = base.getHost(), path = base.getFile();
670+ int port = base.getPort();
671+ RemoteFileChooserKFC rfc = new RemoteFileChooserKFC();
672+ rfc.setClientContext(this);
673+ String cbase = prot + "://" + host + ":" + port + pathinfo;
674+ rfc.setRemoteCodeBase(cbase);
675+ fc = rfc;
676+ }
677+ return fc;
678+ }
679+
680+ public RdbManager findRdbManager(String name) throws java.io.IOException {
681+ if (empty(name)) name = pref.value("last-rdb", "");
682+
683+ RdbManagerImpl mgr = (RdbManagerImpl)rdbm.get(name);
684+ if (mgr == null) {
685+ mgr = new RdbManagerImpl();
686+ mgr.pref = pref;
687+ RdbInfo info = mgr.loadRdbInfo(name); // 存在確認
688+ mgr.dbname = name;
689+ rdbm.put(name, mgr);
690+ }
691+ pref.storeValue("last-rdb", name, false);
692+ return mgr;
693+ }
694+
695+ public sweep.client.DirManager findDirManager(String name) throws java.io.IOException {
696+ if (empty(name)) name = pref.value("last-dir", "");
697+
698+ DirManagerImpl mgr = (DirManagerImpl)dir.get(name);
699+ if (mgr == null) {
700+ mgr = new DirManagerImpl();
701+ mgr.pref = pref;
702+ DirInfo info = mgr.loadDirInfo(name); // 存在確認
703+ mgr.dirname = name;
704+ dir.put(name, mgr);
705+ }
706+ pref.storeValue("last-dir", name, false);
707+ return mgr;
708+ }
709+
710+ public MessageStore findMessageStore(String name) throws java.io.IOException {
711+ if (empty(name)) name = pref.value("last-store", "");
712+
713+ MessageStoreImpl mgr = (MessageStoreImpl)store.get(name);
714+ if (mgr == null) {
715+ mgr = new MessageStoreImpl();
716+ mgr.pref = pref;
717+ MessageStoreInfo info = mgr.loadMessageAccount(name); // 存在確認
718+ mgr.storeName = name;
719+ store.put(name, mgr);
720+ }
721+ pref.storeValue("last-store", name, false);
722+ return mgr;
723+ }
724+
725+ public void lostOwnership(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable transferable) {
726+ trace("lost owner ship");
727+ }
728+
729+ public void keyPressed(java.awt.event.KeyEvent event) {
730+ err.println(event);
731+ }
732+ public void keyReleased(java.awt.event.KeyEvent event) { }
733+ public void keyTyped(java.awt.event.KeyEvent event) {
734+ err.println(event);
735+ }
736+
737+ public java.awt.Image findImage(java.net.URL base, String image) {
738+ if (base == null) base = getCodeBase();
739+ return GenericKFCApp.this.getImage(base, image);
740+ }
741+
742+ ChanelManagerImpl cm;
743+ public Channel findChannel(String name) throws java.io.IOException {
744+ if (cm == null) {
745+ cm = new ChanelManagerImpl();
746+ cm.setClientContext(this);
747+ }
748+ Channel ch = cm.findChannel(name);
749+ return ch;
750+ }
751+
752+ public String[] getRemoteNames() {
753+ String secs[] = pref.getSectionNames();
754+
755+ java.util.Vector vec = new java.util.Vector();
756+ for (int i = 0; i < secs.length; i++){
757+ String sn = secs[i];
758+ if (!sn.endsWith(".remote")) continue;
759+ vec.addElement(sn.substring(0, sn.length() - ".remote".length()));
760+ }
761+ if (vec.isEmpty()) return ContainerCommon.EMPTY_VALUES;
762+
763+ String[] pn = new String[vec.size()];
764+ vec.copyInto(pn);
765+ return pn;
766+ }
767+
768+ public RemoteInfo loadRemoteInfo(String name) throws java.io.IOException {
769+ RmoteInfoVO aa = new RmoteInfoVO().load(pref, name);
770+ return aa;
771+ }
772+
773+ public void storeRemoteInfo(RemoteInfo info) throws java.io.IOException {
774+ RmoteInfoVO aa = new RmoteInfoVO().load(info);
775+ boolean sys = false;
776+ String host = info.getRemoteHost();
777+ if (empty(host)) aa.remove(pref, sys); else aa.store(pref, sys);
778+ pref.storePreference("", sys);
779+ }
780+ }
781+
782+ static java.io.File dot = new java.io.File(".");
783+
784+ /** Javaアプリケーション向けのクライアント・コンテキスト
785+ * こちらは、ローカル・ファイルシステムを操作することができる。
786+ */
787+ class ApplicationContext extends AppletContext {
788+
789+ sweep.client.ClientContext createContext(sweep.client.AWTapplication app) {
790+ ApplicationContext ac = new ApplicationContext();
791+ ac.app = app;
792+ ac.init();
793+ return ac;
794+ }
795+
796+ String getUserName() { return System.getProperty("user.name"); }
797+
798+ void init() {
799+ try {
800+ String propName = getUserName();
801+ pref = new LocalPreference(propName, 0);
802+
803+ if (!pref.loadPreference("", false))
804+ err.println("ERROR: " + propName + " load failed.");
805+ else if(verbose)
806+ err.println("INFO: " + propName + " loaded.");
807+ } catch(java.io.IOException ignore) { trace(ignore); }
808+ catch(SecurityException ignore) { trace(ignore); }
809+ }
810+
811+ public String findWorkFolder(String name) throws java.io.IOException, SecurityException {
812+ String userHome = System.getProperty("user.dir");
813+ java.io.File base = new java.io.File(userHome, ".clientContainer"), work;
814+ work = empty(name) ? base : new java.io.File(base, name);
815+ if (work.isDirectory() && work.canWrite()) return work.getPath();
816+ if (!work.exists() && !work.mkdirs())
817+ throw new java.io.IOException("create dir failed: " + work);
818+
819+ if (work.isDirectory() && work.canWrite()) return work.getPath();
820+
821+ throw new java.io.IOException("work directory not exists or can not write: " + work);
822+ }
823+
824+ java.net.URL createFileURL(java.io.File t) throws java.net.MalformedURLException {
825+ String path = t.getName().replace(java.io.File.separatorChar, '/').replace(':', '|');
826+ java.net.URL r = new java.net.URL("file", "", -1, path);
827+ return r;
828+ }
829+
830+ public java.net.URL getCodeBase() {
831+ try {
832+ String cb = jc.getProperty("container.debug.codebase", "");
833+ if (!empty(cb)) return new java.net.URL(cb);
834+
835+ return createFileURL(dot);
836+ } catch(java.net.MalformedURLException e) {
837+ throw new IllegalStateException(e.getMessage());
838+ }
839+ }
840+
841+ public java.util.Locale getLocale() {
842+ return java.util.Locale.getDefault();
843+ }
844+
845+ public FileChooser getFileChooser() {
846+ if (fc == null) {
847+ String codebase = jc.getProperty("container.debug.codebase", "");
848+ if (!empty(codebase)) {
849+ // リモート・アクセスの確認用
850+ RemoteFileChooserKFC rfc = new RemoteFileChooserKFC();
851+ rfc.setClientContext(this);
852+ rfc.setRemoteCodeBase(codebase);
853+ fc = rfc;
854+ }
855+ }
856+ if (fc == null) fc = new LocalFileChooser();
857+ return fc;
858+ }
859+
860+ String signValue(int num) {
861+ return num >= 0 ? "+" + num : String.valueOf(num);
862+ }
863+
864+ String getName() { return jc.getJobId(); }
865+
866+ void saveWindowPosition(java.awt.Rectangle rect) {
867+ String id = jc.getJobId();
868+ pref.storeValue("frame.geometry",
869+ rect.width + "x" + rect.height + signValue(rect.x) + signValue(rect.y), id, false);
870+ storeUserProperties();
871+ trace("#saveWindowPosition pos: " +rect);
872+ }
873+
874+ java.awt.Rectangle loadWindowPosition() {
875+ String id = jc.getJobId();
876+ String geom = pref.value("frame.geometry", "", id);
877+ if (empty(geom)) return null;
878+ java.awt.Rectangle rect = parseGeometry(geom);
879+ trace("#loadWindowPosition pos: " + geom + ":" + rect);
880+ return rect;
881+ }
882+
883+ public void setStatusText(String tt, int idx) {
884+ err.println(tt);
885+ }
886+
887+ public java.awt.Image findImage(java.net.URL base, String image) {
888+ if (verbose) err.println("Image: " + base + " " + image);
889+ try {
890+ java.awt.Image img;
891+ if (base == null || base.toExternalForm().equals("file:."))
892+ img = java.awt.Toolkit.getDefaultToolkit().getImage(image);
893+ else {
894+ java.net.URL location = new java.net.URL(base, image);
895+ img = java.awt.Toolkit.getDefaultToolkit().getImage(location);
896+ }
897+ loadImage(img);
898+ return img;
899+ } catch(java.io.IOException e) { return null; }
900+ }
901+ }
902+
903+ void loadImage(java.awt.Image image) {
904+ synchronized(tracker) {
905+ tracker.addImage(image, 0);
906+ try {
907+ tracker.waitForID(0, 5000);
908+ } catch (InterruptedException e) { err.println("INTERRUPTED while loading Image"); }
909+ int loadStatus = tracker.statusID(0, false);
910+ tracker.removeImage(image, 0);
911+ }
912+ }
913+
914+ final static java.awt.Component component = new java.awt.Component() {};
915+ final static java.awt.MediaTracker tracker = new java.awt.MediaTracker(component);
916+
917+ JobContext jc;
918+ public void setJobContext(JobContext context) { jc = context; }
919+
920+ public void setup() throws java.io.IOException, java.sql.SQLException {
921+ ApplicationContext cc = new ApplicationContext();
922+ cc.init();
923+
924+ String cv = (String)jc.getAttribute("container.verbose");
925+ verbose = cc.testFlag(jc.getProperty("verbose", cv), false);
926+ trace("#setup");
927+
928+ String appName = jc.getProperty("app", null);
929+ if (appName == null) {
930+ throw new ContainerRuntimeError("no \"app\" parameter or class instantiaion failed!");
931+ }
932+
933+ cc.app = cc.createOldApp(appName);
934+ jc.setAttribute("client.container", cc);
935+ }
936+
937+ public void run() {
938+ ApplicationContext cc = (ApplicationContext)jc.getAttribute("client.container");
939+ java.awt.Frame fr = cc.createFrame(cc.app);
940+ String iconName = jc.getProperty("frame-icon", "");
941+ if (!empty(iconName)) {
942+ java.awt.Image img = cc.findImage(null, iconName);
943+ if (img != null) fr.setIconImage(img);
944+ }
945+ fr.setVisible(true);
946+ }
947+
948+ public int executeJob() throws java.io.IOException, java.sql.SQLException, InterruptedException {
949+ try {
950+ Class.forName("javax.swing.SwingUtilities")
951+ .getMethod("invokeAndWait",new Class[]{ Runnable.class, })
952+ .invoke(null, new Object[]{ this,});
953+ } catch (Throwable ignore) { run(); }
954+
955+ ApplicationContext cc = (ApplicationContext)jc.getAttribute("client.container");
956+
957+ if (cc.app instanceof OpenFiles) {
958+ String args[] = jc.getJobOption();
959+ ((OpenFiles) cc.app).openFiles(args, 0);
960+ }
961+ return 0;
962+ }
963+
964+ public void tearDown() throws java.io.IOException, java.sql.SQLException {
965+ trace("#tearDown");
966+ }
967+}
968+
Show on old repository browser