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.ImmutableConfiguration; 020import org.apache.commons.configuration2.event.EventType; 021 022/** 023 * <p> 024 * A specialized event class which is generated by a 025 * {@link ConfigurationBuilder} when a result configuration has been created. 026 * </p> 027 * <p> 028 * Events of this type are fired in the {@code getConfiguration()} method of a 029 * configuration builder each time a new result object is created. At the time 030 * the event is fired, no lock is held. The newly created {@code ImmutableConfiguration} 031 * object is available as a property of this event. 032 * </p> 033 * <p> 034 * A use case for this event is to perform special initializations on newly 035 * created configuration objects. It is also an indication that a builder is now 036 * fully initialized; i.e. the managed configuration is available. 037 * </p> 038 * 039 * @since 2.0 040 */ 041public class ConfigurationBuilderResultCreatedEvent extends 042 ConfigurationBuilderEvent 043{ 044 /** 045 * The specialized event type for a newly created result configuration. 046 * Events of this type are generated by a configuration builder when a 047 * result configuration has been created. 048 */ 049 public static final EventType<ConfigurationBuilderResultCreatedEvent> RESULT_CREATED = 050 new EventType<>(ANY, 051 "RESULT_CREATED"); 052 053 /** The newly created configuration object. */ 054 private final ImmutableConfiguration configuration; 055 056 /** 057 * Creates a new instance of {@code ConfigurationBuilderResultCreatedEvent} 058 * and initializes its properties. 059 * 060 * @param source the {@code ConfigurationBuilder} object which triggered 061 * this event (must not be <b>null</b>) 062 * @param evType the type of this event (must not be <b>null</b>) 063 * @param createdConfiguration the newly created {@code ImmutableConfiguration} 064 * object (must not be <b>null</b>) 065 * @throws IllegalArgumentException if a required parameter is null 066 */ 067 public ConfigurationBuilderResultCreatedEvent( 068 final ConfigurationBuilder<?> source, 069 final EventType<? extends ConfigurationBuilderResultCreatedEvent> evType, 070 final ImmutableConfiguration createdConfiguration) 071 { 072 super(source, evType); 073 if (createdConfiguration == null) 074 { 075 throw new IllegalArgumentException( 076 "Configuration must not be null!"); 077 } 078 configuration = createdConfiguration; 079 } 080 081 /** 082 * Returns the newly created {@code ImmutableConfiguration} object. 083 * 084 * @return the newly created {@code ImmutableConfiguration} 085 */ 086 public ImmutableConfiguration getConfiguration() 087 { 088 return configuration; 089 } 090}