7273 |
20 Jan 17 |
nicklas |
1 |
/** |
7273 |
20 Jan 17 |
nicklas |
$Id $ |
7273 |
20 Jan 17 |
nicklas |
3 |
|
7273 |
20 Jan 17 |
nicklas |
Copyright (C) 2017 Nicklas Nordborg |
7273 |
20 Jan 17 |
nicklas |
5 |
|
7273 |
20 Jan 17 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7273 |
20 Jan 17 |
nicklas |
Available at http://base.thep.lu.se/ |
7273 |
20 Jan 17 |
nicklas |
8 |
|
7273 |
20 Jan 17 |
nicklas |
BASE is free software; you can redistribute it and/or |
7273 |
20 Jan 17 |
nicklas |
modify it under the terms of the GNU General Public License |
7273 |
20 Jan 17 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7273 |
20 Jan 17 |
nicklas |
of the License, or (at your option) any later version. |
7273 |
20 Jan 17 |
nicklas |
13 |
|
7273 |
20 Jan 17 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7273 |
20 Jan 17 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7273 |
20 Jan 17 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7273 |
20 Jan 17 |
nicklas |
GNU General Public License for more details. |
7273 |
20 Jan 17 |
nicklas |
18 |
|
7273 |
20 Jan 17 |
nicklas |
You should have received a copy of the GNU General Public License |
7273 |
20 Jan 17 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7273 |
20 Jan 17 |
nicklas |
21 |
*/ |
7273 |
20 Jan 17 |
nicklas |
22 |
package net.sf.basedb.util.extensions.events; |
7273 |
20 Jan 17 |
nicklas |
23 |
|
7273 |
20 Jan 17 |
nicklas |
24 |
import net.sf.basedb.util.extensions.Extension; |
7273 |
20 Jan 17 |
nicklas |
25 |
import net.sf.basedb.util.extensions.ExtensionPoint; |
7273 |
20 Jan 17 |
nicklas |
26 |
|
7273 |
20 Jan 17 |
nicklas |
27 |
/** |
7273 |
20 Jan 17 |
nicklas |
Event filter that only passes events for a specific extension. |
7273 |
20 Jan 17 |
nicklas |
29 |
|
7273 |
20 Jan 17 |
nicklas |
@author nicklas |
7273 |
20 Jan 17 |
nicklas |
@since 3.10 |
7273 |
20 Jan 17 |
nicklas |
32 |
*/ |
7273 |
20 Jan 17 |
nicklas |
33 |
public class ExtensionEventFilter |
7273 |
20 Jan 17 |
nicklas |
34 |
implements EventFilter |
7273 |
20 Jan 17 |
nicklas |
35 |
{ |
7273 |
20 Jan 17 |
nicklas |
36 |
private final String id; |
7273 |
20 Jan 17 |
nicklas |
37 |
private final EventType eventType; |
7273 |
20 Jan 17 |
nicklas |
38 |
|
7273 |
20 Jan 17 |
nicklas |
39 |
/** |
7273 |
20 Jan 17 |
nicklas |
Create a new extension event filter. |
7273 |
20 Jan 17 |
nicklas |
@param extension The extension to pass events for |
7273 |
20 Jan 17 |
nicklas |
@param eventType The event type to pass events for, or null to pass all event types |
7273 |
20 Jan 17 |
nicklas |
43 |
*/ |
7273 |
20 Jan 17 |
nicklas |
44 |
public ExtensionEventFilter(Extension<?> extension, EventType eventType) |
7273 |
20 Jan 17 |
nicklas |
45 |
{ |
7273 |
20 Jan 17 |
nicklas |
46 |
this(extension.getId(), eventType); |
7273 |
20 Jan 17 |
nicklas |
47 |
} |
7273 |
20 Jan 17 |
nicklas |
48 |
|
7273 |
20 Jan 17 |
nicklas |
49 |
/** |
7273 |
20 Jan 17 |
nicklas |
Create a new extension event filter. |
7273 |
20 Jan 17 |
nicklas |
@param id The ID of the extension point |
7273 |
20 Jan 17 |
nicklas |
@param eventType The event type to pass events for, or null to pass all event types |
7273 |
20 Jan 17 |
nicklas |
53 |
*/ |
7273 |
20 Jan 17 |
nicklas |
54 |
public ExtensionEventFilter(String id, EventType eventType) |
7273 |
20 Jan 17 |
nicklas |
55 |
{ |
7273 |
20 Jan 17 |
nicklas |
56 |
this.id = id; |
7273 |
20 Jan 17 |
nicklas |
57 |
this.eventType = eventType; |
7273 |
20 Jan 17 |
nicklas |
58 |
} |
7273 |
20 Jan 17 |
nicklas |
59 |
|
7273 |
20 Jan 17 |
nicklas |
60 |
/** |
7273 |
20 Jan 17 |
nicklas |
@return TRUE if the extension has the same ID as the one |
7273 |
20 Jan 17 |
nicklas |
given in the constructor and if the event type matches |
7273 |
20 Jan 17 |
nicklas |
63 |
*/ |
7273 |
20 Jan 17 |
nicklas |
64 |
@Override |
7273 |
20 Jan 17 |
nicklas |
65 |
public boolean shouldSend(EventType event, ExtensionPoint<?> extensionPoint, |
7273 |
20 Jan 17 |
nicklas |
66 |
Extension<?> extension) |
7273 |
20 Jan 17 |
nicklas |
67 |
{ |
7273 |
20 Jan 17 |
nicklas |
68 |
return (eventType == null || eventType.equals(event)) |
7273 |
20 Jan 17 |
nicklas |
69 |
&& extension != null && id.equals(extension.getId()); |
7273 |
20 Jan 17 |
nicklas |
70 |
} |
7273 |
20 Jan 17 |
nicklas |
71 |
|
7273 |
20 Jan 17 |
nicklas |
72 |
} |