--- /dev/null
+// ServerEditorFactory.java\r
+// $Id: ServerEditorFactory.java,v 1.2 2010/06/15 17:52:57 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1998.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigadmin.editors;\r
+\r
+import java.util.Hashtable;\r
+import java.util.Properties;\r
+\r
+import org.w3c.jigadmin.RemoteResourceWrapper;\r
+import org.w3c.jigadmin.PropertyManager;\r
+import org.w3c.jigadmin.gui.ServerBrowser;\r
+\r
+/**\r
+ * The ServerEditor Factory\r
+ * @version $Revision: 1.2 $\r
+ * @author Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class ServerEditorFactory {\r
+\r
+ private static Hashtable editors = new Hashtable(5);\r
+\r
+ /**\r
+ * Get the identifier of the server.\r
+ * @param name the server name\r
+ * @param browser the browser of the server\r
+ * @return a String\r
+ */\r
+ public static String getIdentifier(String name, ServerBrowser browser) {\r
+ return name+(String.valueOf(browser.hashCode()));\r
+ }\r
+\r
+ /**\r
+ * Get the ServerEditor of the server.\r
+ * @param name the server name\r
+ * @param browser the ServerBrowser\r
+ * @param server the RemoteResourceWrapper of the server\r
+ * @return The ServerEditor\r
+ */\r
+ public static \r
+ ServerEditorInterface getServerEditor(String name, \r
+ ServerBrowser browser,\r
+ RemoteResourceWrapper server) \r
+ {\r
+ PropertyManager pm = PropertyManager.getPropertyManager();\r
+ String editorClass = pm.getEditorClass(server);\r
+\r
+ if (editorClass == null)\r
+ return null;\r
+\r
+ ServerEditorInterface editor = \r
+ (ServerEditorInterface)editors.get(name+browser);\r
+\r
+ if (editor == null) {\r
+ try {\r
+ Class c = Class.forName(editorClass);\r
+ Object o = c.newInstance();\r
+ //Added by Jeff Huang\r
+ //TODO: FIXIT\r
+ if (o instanceof ServerEditorInterface) {\r
+ editor = (ServerEditorInterface) o;\r
+ editor.initialize(name, \r
+ server, \r
+ pm.getEditorProperties(server));\r
+ } else {\r
+ throw new RuntimeException(editorClass+" doesn't "+\r
+ "implements ServerEditorInterface.");\r
+ }\r
+ } catch (Exception ex) {\r
+ ex.printStackTrace();\r
+ throw new RuntimeException("cannot create editor: "+\r
+ editorClass+" for \""+name);\r
+ }\r
+ editors.put(getIdentifier(name,browser), editor);\r
+ } else {\r
+ editor.setServer(server);\r
+ }\r
+ return editor;\r
+ }\r
+\r
+ /**\r
+ * Update the ServerEditor.\r
+ * @param name the server name\r
+ * @param browser the ServerBrowser\r
+ * @param server the RemoteResourceWrapper of the server\r
+ */\r
+ public static void updateServerEditor(String name,\r
+ ServerBrowser browser,\r
+ RemoteResourceWrapper server) \r
+ {\r
+ ServerEditorInterface editor = \r
+ (ServerEditorInterface)editors.get(getIdentifier(name,browser));\r
+ if (editor != null)\r
+ editor.setServer(server);\r
+ }\r
+\r
+}\r