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.observation;
35
36 import javax.jcr.observation.Event;
37 import javax.jcr.observation.EventListener;
38
39 import org.apache.jackrabbit.core.observation.SynchronousEventListener;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43
44
45
46
47
48
49 public class ObservationConfiguration {
50 private final static Logger log = LoggerFactory
51 .getLogger(ObservationConfiguration.class);
52
53
54 private String name;
55
56
57 private String description;
58
59
60 private boolean active = false;
61
62
63
64
65
66 private String eventTypes = "NODE_ADDED,NODE_REMOVED,PROPERTY_ADDED,PROPERTY_CHANGED,PROPERTY_REMOVED";
67
68
69 private String path;
70
71
72 private String repository;
73
74
75
76 private String nodeType = null;
77
78
79 private boolean includeSubNodes = false;
80
81
82 private long delay;
83
84
85 private long maxDelay;
86
87
88
89
90 public EventListener deferredListener;
91
92
93 private EventListener listener;
94
95 public SynchronousEventListener synchListener;
96
97 private boolean synchronous = false;
98
99 public boolean isSynchronous() {
100 return synchronous;
101 }
102
103 public void setSynchronous(boolean synchronous) {
104 this.synchronous = synchronous;
105 }
106
107 public ObservationConfiguration() {
108 }
109
110 public ObservationConfiguration(String name, String description,
111 boolean active, EventListener listener, String repository,
112 String path, String eventTypes, boolean includeSubNodes,
113 String nodeType, long delay, long maxDelay) {
114
115 this.name = name;
116 this.description = description;
117 this.active = active;
118 this.listener = listener;
119 this.repository = repository;
120 this.path = path;
121 this.eventTypes = eventTypes;
122 this.includeSubNodes = includeSubNodes;
123 this.nodeType = nodeType;
124 this.delay = delay;
125 this.maxDelay = maxDelay;
126 }
127
128 public long getDelay() {
129 return delay;
130 }
131
132 public void setDelay(long delay) {
133 this.delay = delay;
134 }
135
136 public long getMaxDelay() {
137 return maxDelay;
138 }
139
140 public void setMaxDelay(long maxDelay) {
141 this.maxDelay = maxDelay;
142 }
143
144 public String getNodeType() {
145 return nodeType;
146 }
147
148 public void setNodeType(String nodeType) {
149 this.nodeType = nodeType;
150 }
151
152 public boolean getIncludeSubNodes() {
153 return includeSubNodes;
154 }
155
156 public void setIncludeSubNodes(boolean includeSubNodes) {
157 this.includeSubNodes = includeSubNodes;
158 }
159
160 public boolean isActive() {
161 return active;
162 }
163
164 public void setActive(boolean active) {
165 this.active = active;
166 }
167
168 public String getDescription() {
169 return description;
170 }
171
172 public void setDescription(String description) {
173 this.description = description;
174 }
175
176 public EventListener getListener() {
177 return this.listener;
178 }
179
180 public void setListener(EventListener listener) {
181 this.listener = listener;
182 }
183
184
185
186
187 public String getName() {
188 return name;
189 }
190
191
192
193
194 public void setName(String name) {
195 this.name = name;
196 }
197
198 public String getEventTypes() {
199 return eventTypes;
200 }
201
202 public void setEventTypes(String eventTypes) {
203 if (eventTypes != null && eventTypes.length() > 0) {
204 this.eventTypes = eventTypes;
205 }
206 getConvertedEventTypes();
207 }
208
209 public String getPath() {
210 return path;
211 }
212
213 public void setPath(String path) {
214 this.path = path;
215 }
216
217 public String getRepository() {
218 return repository;
219 }
220
221 public void setRepository(String repository) {
222 this.repository = repository;
223 }
224
225
226
227
228 public int getConvertedEventTypes() {
229
230 String[] eTypes = eventTypes.split(",");
231 int eConvertedTypes = 0;
232 String item;
233 for (int i = 0; i < eTypes.length; i++) {
234 item = (eTypes[i]).trim();
235 if (item.equals("NODE_ADDED")) {
236 eConvertedTypes |= Event.NODE_ADDED;
237 } else if (item.equals("NODE_REMOVED")) {
238 eConvertedTypes |= Event.NODE_REMOVED;
239 } else if (item.equals("PROPERTY_ADDED")) {
240 eConvertedTypes |= Event.PROPERTY_ADDED;
241 } else if (item.equals("PROPERTY_CHANGED")) {
242 eConvertedTypes |= Event.PROPERTY_CHANGED;
243 } else if (item.equals("PROPERTY_REMOVED")) {
244 eConvertedTypes |= Event.PROPERTY_REMOVED;
245 } else {
246 log.error("Event Type not recognized " + item);
247 }
248 }
249 return eConvertedTypes;
250 }
251
252
253
254
255 public boolean isPopulated() {
256 boolean isPopulated = false;
257 if (this.repository != null && this.repository.length() > 0
258 && this.path != null && this.path.length() > 0
259 && this.getConvertedEventTypes() > 0
260 && this.getListener() != null) {
261 isPopulated = true;
262 }
263 return isPopulated;
264 }
265
266 }