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 * @version $Id: ConfigurationBuilderResultCreatedEvent.java 1790899 2017-04-10 21:56:46Z ggregory $ 040 * @since 2.0 041 */ 042public class ConfigurationBuilderResultCreatedEvent extends 043 ConfigurationBuilderEvent 044{ 045 /** 046 * The specialized event type for a newly created result configuration. 047 * Events of this type are generated by a configuration builder when a 048 * result configuration has been created. 049 */ 050 public static final EventType<ConfigurationBuilderResultCreatedEvent> RESULT_CREATED = 051 new EventType<>(ANY, 052 "RESULT_CREATED"); 053 054 /** The newly created configuration object. */ 055 private final ImmutableConfiguration configuration; 056 057 /** 058 * Creates a new instance of {@code ConfigurationBuilderResultCreatedEvent} 059 * and initializes its properties. 060 * 061 * @param source the {@code ConfigurationBuilder} object which triggered 062 * this event (must not be <b>null</b>) 063 * @param evType the type of this event (must not be <b>null</b>) 064 * @param createdConfiguration the newly created {@code ImmutableConfiguration} 065 * object (must not be <b>null</b>) 066 * @throws IllegalArgumentException if a required parameter is null 067 */ 068 public ConfigurationBuilderResultCreatedEvent( 069 ConfigurationBuilder<?> source, 070 EventType<? extends ConfigurationBuilderResultCreatedEvent> evType, 071 ImmutableConfiguration createdConfiguration) 072 { 073 super(source, evType); 074 if (createdConfiguration == null) 075 { 076 throw new IllegalArgumentException( 077 "Configuration must not be null!"); 078 } 079 configuration = createdConfiguration; 080 } 081 082 /** 083 * Returns the newly created {@code ImmutableConfiguration} object. 084 * 085 * @return the newly created {@code ImmutableConfiguration} 086 */ 087 public ImmutableConfiguration getConfiguration() 088 { 089 return configuration; 090 } 091}