Class TypeEventFilter

  • All Implemented Interfaces:
    EventFilter

    public class TypeEventFilter
    extends AbstractEventFilter

    A specialized EventFilter implementation that filters by an event type.

    This event filter class allows to filter by concrete event (sub) types. So a developer can specify in a fine-grained way, which events should pass the filter. For instance it is possible to filter only for window events of type WINDOW_OPENED.

    Instances of this class are initialized with the name of the type to filter for. It is not necessary to specify a specific event class because event type names should be unique. Because not every event class supports sub types this filter implementation uses reflection for obtaining the type. An event object is accepted only if

    • it has a public method named getType()
    • invocation of the getType() method does not cause an exception and returns an Enum object
    • the name of the Enum object matches the type name this filter was initialized with.
    Any exceptions related to reflection that occur while checking whether the event is accepted cause the event to be not accepted.

    Version:
    $Id: TypeEventFilter.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • TypeEventFilter

        public TypeEventFilter()
        Creates a new instance of TypeEventFilter. The event type is set to the default type. null values are not accepted.
      • TypeEventFilter

        public TypeEventFilter​(String type)
        Creates a new instance of TypeEventFilter and sets the name of the event type to be filtered. If the type is null, no events are accepted.
        Parameters:
        type - the name of the event type
    • Method Detail

      • acceptEvent

        protected boolean acceptEvent​(BuilderEvent event)
        Tests the given event. This implementation compares the event's type with the configured event type.
        Specified by:
        acceptEvent in class AbstractEventFilter
        Parameters:
        event - the event to be tested
        Returns:
        a flag if this event is accepted
      • getEventType

        public String getEventType()
        Returns the event type name.
        Returns:
        the event type
      • setEventType

        public void setEventType​(String eventType)
        Sets the event type name. Only events with this type can pass this filter. If the type is null, no events are accepted.
        Parameters:
        eventType - the event type