001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.configuration2.builder;
018
019import org.apache.commons.configuration2.event.Event;
020import org.apache.commons.configuration2.event.EventType;
021
022/**
023 * <p>
024 * A base event class for events generated by a {@link ConfigurationBuilder}.
025 * </p>
026 * <p>
027 * Configuration builders can trigger a number of different events. All these
028 * events are derived from this class. This event base class does not define any
029 * additional properties. However, it defines that the event source must be a
030 * {@code ConfigurationBuilder}.
031 * </p>
032 *
033 * @version $Id: ConfigurationBuilderEvent.java 1790899 2017-04-10 21:56:46Z ggregory $
034 * @since 2.0
035 */
036public class ConfigurationBuilderEvent extends Event
037{
038    /** The common super type for all events related to configuration builders. */
039    public static final EventType<ConfigurationBuilderEvent> ANY =
040            new EventType<>(Event.ANY, "BUILDER");
041
042    /**
043     * The specific event type for builder reset events. Events of this type are
044     * generated each time the builder's {@code resetResult()} method is called.
045     */
046    public static final EventType<ConfigurationBuilderEvent> RESET =
047            new EventType<>(ANY, "RESET");
048
049    /**
050     * The specific event type for configuration request events. Events of this
051     * type are generated each time the builder's {@code getConfiguration()}
052     * method is called (before the managed configuration is actually accessed
053     * and the lock is acquired). This gives listeners the opportunity to
054     * perform some checks which may invalidate the configuration, e.g. trigger
055     * a reload check. <strong>Note:</strong> A listener must not call the
056     * builder's {@code getConfiguration()} method - this will cause an
057     * infinite loop!
058     *
059     * @see ConfigurationBuilder#getConfiguration()
060     */
061    public static final EventType<ConfigurationBuilderEvent> CONFIGURATION_REQUEST =
062            new EventType<>(ANY,
063                    "CONFIGURATION_REQUEST");
064
065    /**
066     * Creates a new instance of {@code ConfigurationBuilderEvent} and sets
067     * basic properties.
068     *
069     * @param source the {@code ConfigurationBuilder} object which triggered
070     *        this event (must not be <b>null</b>)
071     * @param evType the type of this event (must not be <b>null</b>)
072     * @throws IllegalArgumentException if a required parameter is null
073     */
074    public ConfigurationBuilderEvent(ConfigurationBuilder<?> source,
075            EventType<? extends ConfigurationBuilderEvent> evType)
076    {
077        super(source, evType);
078    }
079
080    /**
081     * Returns the source of this event as a {@code ConfigurationBuilder}.
082     *
083     * @return the {@code ConfigurationBuilder} which generated this event
084     */
085    @Override
086    public ConfigurationBuilder<?> getSource()
087    {
088        return (ConfigurationBuilder<?>) super.getSource();
089    }
090}