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