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 events are derived from this class. This 028 * event base class does not define any additional properties. However, it defines that the event source must be a 029 * {@code ConfigurationBuilder}. 030 * </p> 031 * 032 * @since 2.0 033 */ 034public class ConfigurationBuilderEvent extends Event { 035 036 private static final long serialVersionUID = -7488811456039315104L; 037 038 /** The common super type for all events related to configuration builders. */ 039 public static final EventType<ConfigurationBuilderEvent> ANY = new EventType<>(Event.ANY, "BUILDER"); 040 041 /** 042 * The specific event type for builder reset events. Events of this type are generated each time the builder's 043 * {@code resetResult()} method is called. 044 */ 045 public static final EventType<ConfigurationBuilderEvent> RESET = new EventType<>(ANY, "RESET"); 046 047 /** 048 * The specific event type for configuration request events. Events of this type are generated each time the builder's 049 * {@code getConfiguration()} method is called (before the managed configuration is actually accessed and the lock is 050 * acquired). This gives listeners the opportunity to perform some checks which may invalidate the configuration, e.g. 051 * trigger a reload check. <strong>Note:</strong> A listener must not call the builder's {@code getConfiguration()} 052 * method - this will cause an infinite loop! 053 * 054 * @see ConfigurationBuilder#getConfiguration() 055 */ 056 public static final EventType<ConfigurationBuilderEvent> CONFIGURATION_REQUEST = new EventType<>(ANY, "CONFIGURATION_REQUEST"); 057 058 /** 059 * Creates a new instance of {@code ConfigurationBuilderEvent} and sets basic properties. 060 * 061 * @param source the {@code ConfigurationBuilder} object which triggered this event (must not be <b>null</b>) 062 * @param evType the type of this event (must not be <b>null</b>) 063 * @throws IllegalArgumentException if a required parameter is null 064 */ 065 public ConfigurationBuilderEvent(final ConfigurationBuilder<?> source, final EventType<? extends ConfigurationBuilderEvent> evType) { 066 super(source, evType); 067 } 068 069 /** 070 * Gets the source of this event as a {@code ConfigurationBuilder}. 071 * 072 * @return the {@code ConfigurationBuilder} which generated this event 073 */ 074 @Override 075 public ConfigurationBuilder<?> getSource() { 076 return (ConfigurationBuilder<?>) super.getSource(); 077 } 078}