01: // AttributeEditorFactory.java
02: // $Id: AttributeEditorFactory.java,v 1.3 2000/08/16 21:37:30 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1997.
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.jigsaw.admin.RemoteResource;
11:
12: import org.w3c.tools.resources.Attribute;
13:
14: import org.w3c.jigadmin.PropertyManager;
15:
16: import org.w3c.jigadmin.RemoteResourceWrapper;
17:
18: import org.w3c.jigadm.editors.AttributeEditor;
19:
20: /**
21: * The AttributeEditor factory.
22: * @version $Revision: 1.3 $
23: * @author Benoît Mahé (bmahe@w3.org)
24: */
25: public class AttributeEditorFactory {
26:
27: /**
28: * Get an editor for the Attribute element of the Resource. If the editor
29: * for the specified attribute in the specified resource is not found,
30: * we try to find an editor for the same attribute in the superclasses
31: * of the resource. If it is still not found, we try to find an editor
32: * for the superclass of the attribute in the specified resource,
33: * if still not found, we iterate the process.
34: * @param resource the RemoteResource which contains informations about
35: * the server resource.
36: * @param attribute the attribute to be edited
37: * @return an AttributeEditor, or <strong>null</strong> if none found
38: */
39:
40: public static synchronized AttributeEditor getEditor(
41: RemoteResourceWrapper rrw, Attribute attribute) {
42: RemoteResource resource = rrw.getResource();
43:
44: PropertyManager pm = PropertyManager.getPropertyManager();
45: Properties props = pm.getAttributeProperties(rrw, attribute);
46: String className = (String) props.get("class");
47: if (className == null) {
48: System.out.println("can't edit " + attribute.getName()
49: + " !");
50: return null;
51: }
52: try {
53: Class cls = Class.forName(className);
54: return (AttributeEditor) cls.newInstance();
55: } catch (Exception ex) {
56: ex.printStackTrace();
57: }
58: return null;
59: }
60: }
|