001package systems.dmx.core.impl;
002
003import systems.dmx.core.Association;
004import systems.dmx.core.AssociationType;
005import systems.dmx.core.Topic;
006import systems.dmx.core.TopicType;
007import systems.dmx.core.model.AssociationModel;
008import systems.dmx.core.model.AssociationTypeModel;
009import systems.dmx.core.model.TopicModel;
010import systems.dmx.core.model.TopicTypeModel;
011import systems.dmx.core.service.DMXEvent;
012import systems.dmx.core.service.EventListener;
013import systems.dmx.core.service.event.*;
014
015// ### TODO: hide Jersey internals. Move to JAX-RS 2.0.
016import com.sun.jersey.spi.container.ContainerRequest;
017import com.sun.jersey.spi.container.ContainerResponse;
018
019import javax.servlet.http.HttpServletRequest;
020import javax.servlet.http.HttpServletResponse;
021
022
023
024/**
025 * Events fired by the DMX core service.
026 * Plugins can listen to these events by implementing the respective listener interfaces.
027 *
028 * @see systems.dmx.core.service.event
029 */
030class CoreEvent {
031
032    static DMXEvent CHECK_TOPIC_READ_ACCESS = new DMXEvent(CheckTopicReadAccessListener.class) {
033        @Override
034        public void dispatch(EventListener listener, Object... params) {
035            ((CheckTopicReadAccessListener) listener).checkTopicReadAccess(
036                (Long) params[0]
037            );
038        }
039    };
040
041    static DMXEvent CHECK_ASSOCIATION_READ_ACCESS =
042                                                         new DMXEvent(CheckAssociationReadAccessListener.class) {
043        @Override
044        public void dispatch(EventListener listener, Object... params) {
045            ((CheckAssociationReadAccessListener) listener).checkAssociationReadAccess(
046                (Long) params[0]
047            );
048        }
049    };
050
051    // ---
052
053    static DMXEvent CHECK_TOPIC_WRITE_ACCESS = new DMXEvent(CheckTopicWriteAccessListener.class) {
054        @Override
055        public void dispatch(EventListener listener, Object... params) {
056            ((CheckTopicWriteAccessListener) listener).checkTopicWriteAccess(
057                (Long) params[0]
058            );
059        }
060    };
061
062    static DMXEvent CHECK_ASSOCIATION_WRITE_ACCESS =
063                                                        new DMXEvent(CheckAssociationWriteAccessListener.class) {
064        @Override
065        public void dispatch(EventListener listener, Object... params) {
066            ((CheckAssociationWriteAccessListener) listener).checkAssociationWriteAccess(
067                (Long) params[0]
068            );
069        }
070    };
071
072    // ---
073
074    static DMXEvent PRE_CREATE_TOPIC = new DMXEvent(PreCreateTopicListener.class) {
075        @Override
076        public void dispatch(EventListener listener, Object... params) {
077            ((PreCreateTopicListener) listener).preCreateTopic(
078                (TopicModel) params[0]
079            );
080        }
081    };
082
083    static DMXEvent PRE_CREATE_ASSOCIATION = new DMXEvent(PreCreateAssociationListener.class) {
084        @Override
085        public void dispatch(EventListener listener, Object... params) {
086            ((PreCreateAssociationListener) listener).preCreateAssociation(
087                (AssociationModel) params[0]
088            );
089        }
090    };
091
092    static DMXEvent PRE_CREATE_TOPIC_TYPE = new DMXEvent(PreCreateTopicTypeListener.class) {
093        @Override
094        public void dispatch(EventListener listener, Object... params) {
095            ((PreCreateTopicTypeListener) listener).preCreateTopicType(
096                (TopicTypeModel) params[0]
097            );
098        }
099    };
100
101    static DMXEvent PRE_CREATE_ASSOCIATION_TYPE = new DMXEvent(PreCreateAssociationTypeListener.class) {
102        @Override
103        public void dispatch(EventListener listener, Object... params) {
104            ((PreCreateAssociationTypeListener) listener).preCreateAssociationType(
105                (AssociationTypeModel) params[0]
106            );
107        }
108    };
109
110    // ---
111
112    static DMXEvent POST_CREATE_TOPIC = new DMXEvent(PostCreateTopicListener.class) {
113        @Override
114        public void dispatch(EventListener listener, Object... params) {
115            ((PostCreateTopicListener) listener).postCreateTopic(
116                (Topic) params[0]
117            );
118        }
119    };
120
121    static DMXEvent POST_CREATE_ASSOCIATION = new DMXEvent(PostCreateAssociationListener.class) {
122        @Override
123        public void dispatch(EventListener listener, Object... params) {
124            ((PostCreateAssociationListener) listener).postCreateAssociation(
125                (Association) params[0]
126            );
127        }
128    };
129
130    // ---
131
132    static DMXEvent PRE_UPDATE_TOPIC = new DMXEvent(PreUpdateTopicListener.class) {
133        @Override
134        public void dispatch(EventListener listener, Object... params) {
135            ((PreUpdateTopicListener) listener).preUpdateTopic(
136                (Topic) params[0], (TopicModel) params[1]
137            );
138        }
139    };
140
141    static DMXEvent PRE_UPDATE_ASSOCIATION = new DMXEvent(PreUpdateAssociationListener.class) {
142        @Override
143        public void dispatch(EventListener listener, Object... params) {
144            ((PreUpdateAssociationListener) listener).preUpdateAssociation(
145                (Association) params[0], (AssociationModel) params[1]
146            );
147        }
148    };
149
150    // ---
151
152    static DMXEvent POST_UPDATE_TOPIC = new DMXEvent(PostUpdateTopicListener.class) {
153        @Override
154        public void dispatch(EventListener listener, Object... params) {
155            ((PostUpdateTopicListener) listener).postUpdateTopic(
156                (Topic) params[0], (TopicModel) params[1], (TopicModel) params[2]
157            );
158        }
159    };
160
161    static DMXEvent POST_UPDATE_ASSOCIATION = new DMXEvent(PostUpdateAssociationListener.class) {
162        @Override
163        public void dispatch(EventListener listener, Object... params) {
164            ((PostUpdateAssociationListener) listener).postUpdateAssociation(
165                (Association) params[0], (AssociationModel) params[1], (AssociationModel) params[2]
166            );
167        }
168    };
169
170    // ---
171
172    static DMXEvent POST_UPDATE_TOPIC_REQUEST = new DMXEvent(PostUpdateTopicRequestListener.class) {
173        @Override
174        public void dispatch(EventListener listener, Object... params) {
175            ((PostUpdateTopicRequestListener) listener).postUpdateTopicRequest(
176                (Topic) params[0]
177            );
178        }
179    };
180
181    // Note: a corresponding POST_UPDATE_ASSOCIATION_REQUEST event is not necessary.
182    // It would be equivalent to POST_UPDATE_ASSOCIATION.
183    // Per request exactly one association is updated. Its childs are topics (never associations).
184
185    // ---
186
187    static DMXEvent PRE_DELETE_TOPIC = new DMXEvent(PreDeleteTopicListener.class) {
188        @Override
189        public void dispatch(EventListener listener, Object... params) {
190            ((PreDeleteTopicListener) listener).preDeleteTopic(
191                (Topic) params[0]
192            );
193        }
194    };
195
196    static DMXEvent PRE_DELETE_ASSOCIATION = new DMXEvent(PreDeleteAssociationListener.class) {
197        @Override
198        public void dispatch(EventListener listener, Object... params) {
199            ((PreDeleteAssociationListener) listener).preDeleteAssociation(
200                (Association) params[0]
201            );
202        }
203    };
204
205    // ---
206
207    static DMXEvent POST_DELETE_TOPIC = new DMXEvent(PostDeleteTopicListener.class) {
208        @Override
209        public void dispatch(EventListener listener, Object... params) {
210            ((PostDeleteTopicListener) listener).postDeleteTopic(
211                (TopicModel) params[0]
212            );
213        }
214    };
215
216    static DMXEvent POST_DELETE_ASSOCIATION = new DMXEvent(PostDeleteAssociationListener.class) {
217        @Override
218        public void dispatch(EventListener listener, Object... params) {
219            ((PostDeleteAssociationListener) listener).postDeleteAssociation(
220                (AssociationModel) params[0]
221            );
222        }
223    };
224
225    // ---
226
227    static DMXEvent ALL_PLUGINS_ACTIVE = new DMXEvent(AllPluginsActiveListener.class) {
228        @Override
229        public void dispatch(EventListener listener, Object... params) {
230            ((AllPluginsActiveListener) listener).allPluginsActive();
231        }
232    };
233
234    // ---
235
236    // This event has a double nature:
237    //   a) it is fired regularily (see CoreServiceImpl.createTopicType()).
238    //   b) it is fired locally (see PluginImpl.introduceTopicTypesToPlugin()).
239    static DMXEvent INTRODUCE_TOPIC_TYPE = new DMXEvent(IntroduceTopicTypeListener.class) {
240        @Override
241        public void dispatch(EventListener listener, Object... params) {
242            ((IntroduceTopicTypeListener) listener).introduceTopicType(
243                (TopicType) params[0]
244            );
245        }
246    };
247
248    // This event has a double nature:
249    //   a) it is fired regularily (see CoreServiceImpl.createAssociationType()).
250    //   b) it is fired locally (see PluginImpl.introduceAssociationTypesToPlugin()).
251    static DMXEvent INTRODUCE_ASSOCIATION_TYPE = new DMXEvent(IntroduceAssociationTypeListener.class) {
252        @Override
253        public void dispatch(EventListener listener, Object... params) {
254            ((IntroduceAssociationTypeListener) listener).introduceAssociationType(
255                (AssociationType) params[0]
256            );
257        }
258    };
259
260
261
262    // === WebPublishing Events ===
263
264    static DMXEvent SERVICE_REQUEST_FILTER = new DMXEvent(ServiceRequestFilterListener.class) {
265        @Override
266        public void dispatch(EventListener listener, Object... params) {
267            ((ServiceRequestFilterListener) listener).serviceRequestFilter(
268                (ContainerRequest) params[0]
269            );
270        }
271    };
272
273    static DMXEvent SERVICE_RESPONSE_FILTER = new DMXEvent(ServiceResponseFilterListener.class) {
274        @Override
275        public void dispatch(EventListener listener, Object... params) {
276            ((ServiceResponseFilterListener) listener).serviceResponseFilter(
277                (ContainerResponse) params[0]
278            );
279        }
280    };
281
282    static DMXEvent STATIC_RESOURCE_FILTER = new DMXEvent(StaticResourceFilterListener.class) {
283        @Override
284        public void dispatch(EventListener listener, Object... params) {
285            ((StaticResourceFilterListener) listener).staticResourceFilter(
286                (HttpServletRequest) params[0], (HttpServletResponse) params[1]
287            );
288        }
289    };
290
291    // ---
292
293    static DMXEvent PRE_SEND_TOPIC = new DMXEvent(PreSendTopicListener.class) {
294        @Override
295        public void dispatch(EventListener listener, Object... params) {
296            ((PreSendTopicListener) listener).preSendTopic(
297                (Topic) params[0]
298            );
299        }
300    };
301
302    static DMXEvent PRE_SEND_ASSOCIATION = new DMXEvent(PreSendAssociationListener.class) {
303        @Override
304        public void dispatch(EventListener listener, Object... params) {
305            ((PreSendAssociationListener) listener).preSendAssociation(
306                (Association) params[0]
307            );
308        }
309    };
310
311    static DMXEvent PRE_SEND_TOPIC_TYPE = new DMXEvent(PreSendTopicTypeListener.class) {
312        @Override
313        public void dispatch(EventListener listener, Object... params) {
314            ((PreSendTopicTypeListener) listener).preSendTopicType(
315                (TopicType) params[0]
316            );
317        }
318    };
319
320    static DMXEvent PRE_SEND_ASSOCIATION_TYPE = new DMXEvent(PreSendAssociationTypeListener.class) {
321        @Override
322        public void dispatch(EventListener listener, Object... params) {
323            ((PreSendAssociationTypeListener) listener).preSendAssociationType(
324                (AssociationType) params[0]
325            );
326        }
327    };
328
329
330
331    // === WebSockets Events ===
332
333    static DMXEvent WEBSOCKET_TEXT_MESSAGE = new DMXEvent(WebsocketTextMessageListener.class) {
334        @Override
335        public void dispatch(EventListener listener, Object... params) {
336            ((WebsocketTextMessageListener) listener).websocketTextMessage(
337                (String) params[0]
338            );
339        }
340    };
341}