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