src/core/net/sf/basedb/util/extensions/events/ExtensionEventFilter.java

Code
Comments
Other
Rev Date Author Line
7273 20 Jan 17 nicklas 1 /**
7273 20 Jan 17 nicklas 2   $Id $
7273 20 Jan 17 nicklas 3
7273 20 Jan 17 nicklas 4   Copyright (C) 2017 Nicklas Nordborg
7273 20 Jan 17 nicklas 5
7273 20 Jan 17 nicklas 6   This file is part of BASE - BioArray Software Environment.
7273 20 Jan 17 nicklas 7   Available at http://base.thep.lu.se/
7273 20 Jan 17 nicklas 8
7273 20 Jan 17 nicklas 9   BASE is free software; you can redistribute it and/or
7273 20 Jan 17 nicklas 10   modify it under the terms of the GNU General Public License
7273 20 Jan 17 nicklas 11   as published by the Free Software Foundation; either version 3
7273 20 Jan 17 nicklas 12   of the License, or (at your option) any later version.
7273 20 Jan 17 nicklas 13
7273 20 Jan 17 nicklas 14   BASE is distributed in the hope that it will be useful,
7273 20 Jan 17 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
7273 20 Jan 17 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7273 20 Jan 17 nicklas 17   GNU General Public License for more details.
7273 20 Jan 17 nicklas 18
7273 20 Jan 17 nicklas 19   You should have received a copy of the GNU General Public License
7273 20 Jan 17 nicklas 20   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 28   Event filter that only passes events for a specific extension.
7273 20 Jan 17 nicklas 29
7273 20 Jan 17 nicklas 30   @author nicklas
7273 20 Jan 17 nicklas 31   @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 40     Create a new extension event filter.
7273 20 Jan 17 nicklas 41     @param extension The extension to pass events for
7273 20 Jan 17 nicklas 42     @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 50     Create a new extension event filter.
7273 20 Jan 17 nicklas 51     @param id The ID of the extension point
7273 20 Jan 17 nicklas 52     @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 61     @return TRUE if the extension has the same ID as the one
7273 20 Jan 17 nicklas 62       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 }