1:
31:
32: package ;
33:
34: import ;
35: import ;
36:
37: import ;
38: import ;
39: import ;
40:
41:
46: public class DefaultActionFactory implements ActionFactory
47: {
48: private static final String PREFIX =
49: "org.jfree.report.modules.gui.swing.actions.";
50:
51: public DefaultActionFactory()
52: {
53: }
54:
55: public ActionPlugin[] getActions(final SwingGuiContext context, final String category)
56: {
57: final Configuration configuration = context.getConfiguration();
58: final String prefix = PREFIX + category;
59: final Iterator keys = configuration.findPropertyKeys(prefix);
60: if (keys.hasNext() == false)
61: {
62: Log.debug("Returning : NO actions for " + category);
63: return new ActionPlugin[0];
64: }
65:
66: final HashMap plugins = new HashMap();
67: while (keys.hasNext())
68: {
69: final String key = (String) keys.next();
70: final String base = key.substring(prefix.length());
71: if (isPluginKey(base) == false)
72: {
73: continue;
74: }
75:
76: final String clazz = configuration.getConfigProperty(key);
77: final Object maybeActionPlugin = ObjectUtilities.loadAndInstantiate
78: (clazz, DefaultActionFactory.class, ActionPlugin.class);
79: if (maybeActionPlugin == null)
80: {
81: Log.debug("Error : " + category + ": " + clazz + " is no action plugin");
82: continue;
83: }
84:
85: final ActionPlugin plugin = (ActionPlugin) maybeActionPlugin;
86: if (plugin.initialize(context) == false)
87: {
88: continue;
89: }
90: final String role = plugin.getRole();
91: if (role == null)
92: {
93: plugins.put(plugin, plugin);
94: }
95: else
96: {
97: final ActionPlugin otherPlugin = (ActionPlugin) plugins.get(role);
98: if (otherPlugin != null)
99: {
100: if (plugin.getRolePreference() > otherPlugin.getRolePreference())
101: {
102: plugins.put(role, plugin);
103: }
104: else
105: {
106: Log.debug("Loaded : " + category + ": " + clazz + ": Overridden by " + otherPlugin.getClass().getName());
107: }
108: }
109: else
110: {
111: plugins.put(role, plugin);
112: }
113: }
114: }
115:
116: Log.debug("Returning : " + plugins.size() + " actions for " + category);
117:
118: return (ActionPlugin[]) plugins.values().toArray
119: (new ActionPlugin[plugins.size()]);
120: }
121:
122: private boolean isPluginKey(final String base)
123: {
124: if (base.length() < 1)
125: {
126: return false;
127: }
128: if (base.indexOf('.', 1) > 0)
129: {
130: return false;
131: }
132: return true;
133: }
134: }