    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 *     https://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.reloading;
    018
    019import org.apache.commons.configuration2.event.Event;
    020import org.apache.commons.configuration2.event.EventType;
    021
    022/**
    023 * <p>
    024 * An event that is fired when a reload operation is required.
    025 * </p>
    026 * <p>
    027 * Events of this type are generated by {@link ReloadingController} if the need for a reload operation is detected. From
    028 * the pay-load of the event information about the components involved is available.
    029 * </p>
    030 *
    031 * @since 2.0
    032 */
    033public class ReloadingEvent extends Event {
    034
    035    /** The common event super type for all reloading events. */
    036    public static final EventType<ReloadingEvent> ANY = new EventType<>(Event.ANY, "RELOAD");
    037
    038    /**
    039     * The serial version UID.
    040     */
    041    private static final long serialVersionUID = 20140701L;
    042
    043    /** Stores additional data about this event. */
    044    private final Object data;
    045
    046    /**
    047     * Creates a new instance of {@code ReloadingEvent} and initializes it.
    048     *
    049     * @param source the controller which generated this event
    050     * @param addData an arbitrary data object to be evaluated by event listeners
    051     */
    052    public ReloadingEvent(final ReloadingController source, final Object addData) {
    053        super(source, ANY);
    054        data = addData;
    055    }
    056
    057    /**
    058     * Gets the {@code ReloadingController} which caused this event.
    059     *
    060     * @return the responsible {@code ReloadingController}
    061     */
    062    public ReloadingController getController() {
    063        return (ReloadingController) getSource();
    064    }
    065
    066    /**
    067     * Gets an object with additional data about the reload operation. This is the object that was passed to the
    068     * {@link ReloadingController} when it was asked to do a reloading check. This is a generic mechanism to pass arbitrary
    069     * data to reloading listeners.
    070     *
    071     * @return additional data about the reload operation (can be <strong>null</strong>)
    072     */
    073    public Object getData() {
    074        return data;
    075    }
    076}