01: // ServerHelperFactory.java
02: // $Id: ServerHelperFactory.java,v 1.4 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.Properties;
09:
10: import org.w3c.jigadmin.PropertyManager;
11: import org.w3c.jigadmin.RemoteResourceWrapper;
12:
13: /**
14: * The server helper factory.
15: * @version $Revision: 1.4 $
16: * @author Benoît Mahé (bmahe@w3.org)
17: */
18: public class ServerHelperFactory {
19:
20: public final static String SERVER_HELPER_P = "shelper";
21:
22: /**
23: * Get the server helper associated to the given sever name
24: * @param name the name of the server
25: * @param rrw the RemoteResourceWrapper of the server
26: * @return a ServerHelperInterface instance
27: */
28: public static ServerHelperInterface getServerHelper(String name,
29: RemoteResourceWrapper rrw) {
30: PropertyManager pm = PropertyManager.getPropertyManager();
31:
32: Properties props = pm.getEditorProperties(rrw);
33: String editorClass = (String) props.get(SERVER_HELPER_P);
34:
35: if (editorClass == null)
36: return null;
37:
38: ServerHelperInterface helper = null;
39:
40: try {
41: Class c = Class.forName(editorClass);
42: Object o = c.newInstance();
43: if (o instanceof ServerHelperInterface) {
44: helper = (ServerHelperInterface) o;
45: helper.initialize(name, rrw, props);
46: } else {
47: throw new RuntimeException(editorClass + " doesn't "
48: + "implements ServerHelperInterface.");
49: }
50: } catch (Exception ex) {
51: ex.printStackTrace();
52: throw new RuntimeException("cannot create server helper: "
53: + editorClass + " for \"" + name);
54: }
55: return helper;
56: }
57: }
|