01: package org.objectweb.celtix.application;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05:
06: import org.objectweb.celtix.plugins.PluginManager;
07:
08: public class PluginInfo {
09:
10: private final String className;
11: private final PluginManager loadingManager;
12: private final PluginStateMachine state;
13: private final Collection<PluginManager> referringManagers;
14: private Object plugin;
15: private PluginInfo requiredFor;
16:
17: PluginInfo(String cn, PluginManager o) {
18: className = cn;
19: loadingManager = o;
20: state = new PluginStateMachine();
21: referringManagers = new ArrayList<PluginManager>();
22: }
23:
24: String getClassName() {
25: return className;
26: }
27:
28: ClassLoader getClassLoader() {
29: return loadingManager.getPluginClassLoader();
30: }
31:
32: PluginStateMachine getState() {
33: return state;
34: }
35:
36: Object getPlugin() {
37: return plugin;
38: }
39:
40: void setPlugin(Object p) {
41: plugin = p;
42: }
43:
44: void setRequiredFor(PluginInfo r) {
45: requiredFor = r;
46: }
47:
48: boolean isCircularDependency() {
49: PluginInfo r = requiredFor;
50: while (null != r) {
51: if (getClassName().equals(requiredFor.getClassName())
52: && getClassLoader() == requiredFor.getClassLoader()) {
53: return true;
54: }
55: r = r.requiredFor;
56: }
57:
58: return false;
59: }
60:
61: boolean isRegistered() {
62: return referringManagers.size() > 0;
63: }
64:
65: boolean isRegisteredWith(PluginManager manager) {
66: for (PluginManager pm : referringManagers) {
67: if (manager == pm) {
68: return true;
69: }
70: }
71: return false;
72: }
73:
74: void register(PluginManager manager) {
75: referringManagers.add(manager);
76: }
77:
78: void unregister(PluginManager manager) {
79: referringManagers.remove(manager);
80: }
81: }
|