1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module;
35
36 import info.magnolia.cms.beans.config.ObservedManager;
37 import info.magnolia.cms.core.Content;
38 import info.magnolia.cms.util.ContentUtil;
39 import info.magnolia.module.model.ModuleDefinition;
40
41 import java.util.Collection;
42 import java.util.LinkedHashMap;
43 import java.util.Map;
44
45
46
47
48
49 public class ModuleLifecycleContextImpl implements ModuleLifecycleContext {
50
51
52
53 private final Map<String, ObservedManager> components;
54
55 private int phase;
56
57 private ModuleDefinition currentModuleDefinition;
58
59 public ModuleLifecycleContextImpl() {
60 components = new LinkedHashMap<String, ObservedManager>();
61 }
62
63
64
65
66 @Deprecated
67 @Override
68 public void registerModuleObservingComponent(String nodeName, ObservedManager component) {
69 if (components.containsKey(nodeName)) {
70 final Object currentObservedManager = components.get(nodeName);
71 throw new IllegalStateException("ObservedManager " + currentObservedManager + " was already registered for nodes of name " + nodeName + ", " + component + " can't be registered.");
72 }
73 components.put(nodeName, component);
74 }
75
76
77
78
79
80 @Deprecated
81 public void start(Collection<Content> moduleNodes) {
82 for (String nodeName : components.keySet()) {
83 final ObservedManager component = components.get(nodeName);
84 for (Content moduleNode : moduleNodes) {
85 initEntry(moduleNode, nodeName, component);
86 }
87 }
88 }
89
90 private void initEntry(Content moduleNode, String nodeName, ObservedManager observedManager) {
91 final Content node = ContentUtil.getCaseInsensitive(moduleNode, nodeName);
92 if (node != null) {
93 observedManager.register(node);
94 }
95 }
96
97 @Override
98 public ModuleDefinition getCurrentModuleDefinition() {
99 return this.currentModuleDefinition;
100 }
101
102 public void setCurrentModuleDefinition(ModuleDefinition currentModuleDefinition) {
103 this.currentModuleDefinition = currentModuleDefinition;
104 }
105
106
107 @Override
108 public int getPhase() {
109 return this.phase;
110 }
111
112
113 public void setPhase(int phase) {
114 this.phase = phase;
115 }
116 }