01: // ServerEditorFactory.java
02: // $Id: ServerEditorFactory.java,v 1.7 2000/08/16 21:37:31 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigadmin.editors;
07:
08: import java.util.Hashtable;
09: import java.util.Properties;
10:
11: import org.w3c.jigadmin.RemoteResourceWrapper;
12: import org.w3c.jigadmin.PropertyManager;
13: import org.w3c.jigadmin.gui.ServerBrowser;
14:
15: /**
16: * The ServerEditor Factory
17: * @version $Revision: 1.7 $
18: * @author Benoît Mahé (bmahe@w3.org)
19: */
20: public class ServerEditorFactory {
21:
22: private static Hashtable editors = new Hashtable(5);
23:
24: /**
25: * Get the identifier of the server.
26: * @param name the server name
27: * @param browser the browser of the server
28: * @return a String
29: */
30: public static String getIdentifier(String name,
31: ServerBrowser browser) {
32: return name + (String.valueOf(browser.hashCode()));
33: }
34:
35: /**
36: * Get the ServerEditor of the server.
37: * @param name the server name
38: * @param browser the ServerBrowser
39: * @param server the RemoteResourceWrapper of the server
40: * @return The ServerEditor
41: */
42: public static ServerEditorInterface getServerEditor(String name,
43: ServerBrowser browser, RemoteResourceWrapper server) {
44: PropertyManager pm = PropertyManager.getPropertyManager();
45: String editorClass = pm.getEditorClass(server);
46:
47: if (editorClass == null)
48: return null;
49:
50: ServerEditorInterface editor = (ServerEditorInterface) editors
51: .get(name + browser);
52:
53: if (editor == null) {
54: try {
55: Class c = Class.forName(editorClass);
56: Object o = c.newInstance();
57: if (o instanceof ServerEditorInterface) {
58: editor = (ServerEditorInterface) o;
59: editor.initialize(name, server, pm
60: .getEditorProperties(server));
61: } else {
62: throw new RuntimeException(editorClass
63: + " doesn't "
64: + "implements ServerEditorInterface.");
65: }
66: } catch (Exception ex) {
67: ex.printStackTrace();
68: throw new RuntimeException("cannot create editor: "
69: + editorClass + " for \"" + name);
70: }
71: editors.put(getIdentifier(name, browser), editor);
72: } else {
73: editor.setServer(server);
74: }
75: return editor;
76: }
77:
78: /**
79: * Update the ServerEditor.
80: * @param name the server name
81: * @param browser the ServerBrowser
82: * @param server the RemoteResourceWrapper of the server
83: */
84: public static void updateServerEditor(String name,
85: ServerBrowser browser, RemoteResourceWrapper server) {
86: ServerEditorInterface editor = (ServerEditorInterface) editors
87: .get(getIdentifier(name, browser));
88: if (editor != null)
89: editor.setServer(server);
90: }
91:
92: }
|