5224 |
27 Jan 10 |
nicklas |
1 |
/** |
5224 |
27 Jan 10 |
nicklas |
$Id$ |
5224 |
27 Jan 10 |
nicklas |
3 |
|
5224 |
27 Jan 10 |
nicklas |
Copyright (C) 2009 Nicklas Nordborg |
5224 |
27 Jan 10 |
nicklas |
5 |
|
5224 |
27 Jan 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5224 |
27 Jan 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5224 |
27 Jan 10 |
nicklas |
8 |
|
5224 |
27 Jan 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
5224 |
27 Jan 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5224 |
27 Jan 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5224 |
27 Jan 10 |
nicklas |
of the License, or (at your option) any later version. |
5224 |
27 Jan 10 |
nicklas |
13 |
|
5224 |
27 Jan 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5224 |
27 Jan 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5224 |
27 Jan 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5224 |
27 Jan 10 |
nicklas |
GNU General Public License for more details. |
5224 |
27 Jan 10 |
nicklas |
18 |
|
5224 |
27 Jan 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5224 |
27 Jan 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5224 |
27 Jan 10 |
nicklas |
21 |
*/ |
5224 |
27 Jan 10 |
nicklas |
22 |
package net.sf.basedb.util.bfs; |
5224 |
27 Jan 10 |
nicklas |
23 |
|
5224 |
27 Jan 10 |
nicklas |
24 |
import java.util.ArrayList; |
5224 |
27 Jan 10 |
nicklas |
25 |
import java.util.List; |
5224 |
27 Jan 10 |
nicklas |
26 |
|
5224 |
27 Jan 10 |
nicklas |
27 |
/** |
5224 |
27 Jan 10 |
nicklas |
Event handler implementation that forwards a single event to multiple |
5224 |
27 Jan 10 |
nicklas |
event handlers. This is useful since a parser only sends the event |
5224 |
27 Jan 10 |
nicklas |
to a single handler. The event is forwarded to all registered event |
5224 |
27 Jan 10 |
nicklas |
handlers in the order they have been registered. |
5224 |
27 Jan 10 |
nicklas |
32 |
|
5224 |
27 Jan 10 |
nicklas |
@author Nicklas |
5224 |
27 Jan 10 |
nicklas |
@version 2.15 |
5224 |
27 Jan 10 |
nicklas |
@base.modified $Date$ |
5224 |
27 Jan 10 |
nicklas |
36 |
*/ |
5224 |
27 Jan 10 |
nicklas |
37 |
public class MultiEventHandler |
5224 |
27 Jan 10 |
nicklas |
38 |
implements EventHandler |
5224 |
27 Jan 10 |
nicklas |
39 |
{ |
5224 |
27 Jan 10 |
nicklas |
40 |
|
5224 |
27 Jan 10 |
nicklas |
41 |
|
5224 |
27 Jan 10 |
nicklas |
42 |
private List<EventHandler> handlers; |
5224 |
27 Jan 10 |
nicklas |
43 |
/** |
5224 |
27 Jan 10 |
nicklas |
Create a new event handler. Use {@link #addEventHandler(EventHandler)} |
5224 |
27 Jan 10 |
nicklas |
to add the event handlers that the events should be forwarded to. |
5224 |
27 Jan 10 |
nicklas |
46 |
*/ |
5224 |
27 Jan 10 |
nicklas |
47 |
public MultiEventHandler() |
5224 |
27 Jan 10 |
nicklas |
48 |
{ |
5224 |
27 Jan 10 |
nicklas |
49 |
this.handlers = new ArrayList<EventHandler>(); |
5224 |
27 Jan 10 |
nicklas |
50 |
} |
5224 |
27 Jan 10 |
nicklas |
51 |
|
5224 |
27 Jan 10 |
nicklas |
52 |
/** |
5224 |
27 Jan 10 |
nicklas |
Adds an event handler. |
5224 |
27 Jan 10 |
nicklas |
54 |
*/ |
5224 |
27 Jan 10 |
nicklas |
55 |
public void addEventHandler(EventHandler e) |
5224 |
27 Jan 10 |
nicklas |
56 |
{ |
5224 |
27 Jan 10 |
nicklas |
57 |
if (e == null) throw new NullPointerException("e"); |
5224 |
27 Jan 10 |
nicklas |
58 |
handlers.add(e); |
5224 |
27 Jan 10 |
nicklas |
59 |
} |
5224 |
27 Jan 10 |
nicklas |
60 |
|
5224 |
27 Jan 10 |
nicklas |
61 |
/** |
5224 |
27 Jan 10 |
nicklas |
Removes an event handler. |
5224 |
27 Jan 10 |
nicklas |
63 |
*/ |
5224 |
27 Jan 10 |
nicklas |
64 |
public void removeEventHandler(EventHandler e) |
5224 |
27 Jan 10 |
nicklas |
65 |
{ |
5224 |
27 Jan 10 |
nicklas |
66 |
handlers.remove(e); |
5224 |
27 Jan 10 |
nicklas |
67 |
} |
5224 |
27 Jan 10 |
nicklas |
68 |
|
5224 |
27 Jan 10 |
nicklas |
69 |
/** |
5224 |
27 Jan 10 |
nicklas |
Resends the incoming event to all registered event handlers. |
5224 |
27 Jan 10 |
nicklas |
71 |
*/ |
5224 |
27 Jan 10 |
nicklas |
72 |
@Override |
5224 |
27 Jan 10 |
nicklas |
73 |
public <T> void handleEvent(EventType<T> eventType, T eventData, BfsParser parser) |
5224 |
27 Jan 10 |
nicklas |
74 |
{ |
5224 |
27 Jan 10 |
nicklas |
75 |
for (EventHandler e : handlers) |
5224 |
27 Jan 10 |
nicklas |
76 |
{ |
5224 |
27 Jan 10 |
nicklas |
77 |
e.handleEvent(eventType, eventData, parser); |
5224 |
27 Jan 10 |
nicklas |
78 |
} |
5224 |
27 Jan 10 |
nicklas |
79 |
} |
5224 |
27 Jan 10 |
nicklas |
80 |
|
5224 |
27 Jan 10 |
nicklas |
81 |
} |