ConfigurationBuilderEvent.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.configuration2.builder;

  18. import org.apache.commons.configuration2.event.Event;
  19. import org.apache.commons.configuration2.event.EventType;

  20. /**
  21.  * <p>
  22.  * A base event class for events generated by a {@link ConfigurationBuilder}.
  23.  * </p>
  24.  * <p>
  25.  * Configuration builders can trigger a number of different events. All these events are derived from this class. This
  26.  * event base class does not define any additional properties. However, it defines that the event source must be a
  27.  * {@code ConfigurationBuilder}.
  28.  * </p>
  29.  *
  30.  * @since 2.0
  31.  */
  32. public class ConfigurationBuilderEvent extends Event {

  33.     private static final long serialVersionUID = -7488811456039315104L;

  34.     /** The common super type for all events related to configuration builders. */
  35.     public static final EventType<ConfigurationBuilderEvent> ANY = new EventType<>(Event.ANY, "BUILDER");

  36.     /**
  37.      * The specific event type for builder reset events. Events of this type are generated each time the builder's
  38.      * {@code resetResult()} method is called.
  39.      */
  40.     public static final EventType<ConfigurationBuilderEvent> RESET = new EventType<>(ANY, "RESET");

  41.     /**
  42.      * The specific event type for configuration request events. Events of this type are generated each time the builder's
  43.      * {@code getConfiguration()} method is called (before the managed configuration is actually accessed and the lock is
  44.      * acquired). This gives listeners the opportunity to perform some checks which may invalidate the configuration, for example
  45.      * trigger a reload check. <strong>Note:</strong> A listener must not call the builder's {@code getConfiguration()}
  46.      * method - this will cause an infinite loop!
  47.      *
  48.      * @see ConfigurationBuilder#getConfiguration()
  49.      */
  50.     public static final EventType<ConfigurationBuilderEvent> CONFIGURATION_REQUEST = new EventType<>(ANY, "CONFIGURATION_REQUEST");

  51.     /**
  52.      * Creates a new instance of {@code ConfigurationBuilderEvent} and sets basic properties.
  53.      *
  54.      * @param source the {@code ConfigurationBuilder} object which triggered this event (must not be <strong>null</strong>)
  55.      * @param evType the type of this event (must not be <strong>null</strong>)
  56.      * @throws IllegalArgumentException if a required parameter is null
  57.      */
  58.     public ConfigurationBuilderEvent(final ConfigurationBuilder<?> source, final EventType<? extends ConfigurationBuilderEvent> evType) {
  59.         super(source, evType);
  60.     }

  61.     /**
  62.      * Gets the source of this event as a {@code ConfigurationBuilder}.
  63.      *
  64.      * @return the {@code ConfigurationBuilder} which generated this event
  65.      */
  66.     @Override
  67.     public ConfigurationBuilder<?> getSource() {
  68.         return (ConfigurationBuilder<?>) super.getSource();
  69.     }
  70. }