Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / jigadmin / editors / ServerHelperFactory.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadmin/editors/ServerHelperFactory.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadmin/editors/ServerHelperFactory.java
new file mode 100644 (file)
index 0000000..ec2506f
--- /dev/null
@@ -0,0 +1,61 @@
+// ServerHelperFactory.java\r
+// $Id: ServerHelperFactory.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.Properties;\r
+\r
+import org.w3c.jigadmin.PropertyManager;\r
+import org.w3c.jigadmin.RemoteResourceWrapper;\r
+\r
+/**\r
+ * The server helper factory.\r
+ * @version $Revision: 1.2 $\r
+ * @author  Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class ServerHelperFactory {\r
+\r
+    public final static String SERVER_HELPER_P = "shelper";\r
+\r
+    /**\r
+     * Get the server helper associated to the given sever name\r
+     * @param name the name of the server\r
+     * @param rrw the RemoteResourceWrapper of the server\r
+     * @return a ServerHelperInterface instance\r
+     */\r
+    public static \r
+       ServerHelperInterface getServerHelper(String name, \r
+                                             RemoteResourceWrapper rrw) \r
+    {\r
+       PropertyManager pm = PropertyManager.getPropertyManager();\r
+\r
+       Properties props = pm.getEditorProperties(rrw);\r
+       String editorClass = (String) props.get(SERVER_HELPER_P);\r
+\r
+       if (editorClass == null)\r
+           return null;\r
+\r
+       ServerHelperInterface helper = null;\r
+\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 ServerHelperInterface) {\r
+               helper = (ServerHelperInterface) o;\r
+               helper.initialize(name, rrw, props);\r
+           } else {\r
+               throw new RuntimeException(editorClass+" doesn't "+\r
+                                  "implements ServerHelperInterface.");\r
+           }\r
+       } catch (Exception ex) {\r
+           ex.printStackTrace();\r
+           throw new RuntimeException("cannot create server helper: "+\r
+                                      editorClass+" for \""+name);\r
+       }\r
+       return helper;\r
+    }\r
+}\r