ConfigurationBuilderResultCreatedEvent.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.configuration2.builder;

  18. import org.apache.commons.configuration2.ImmutableConfiguration;
  19. import org.apache.commons.configuration2.event.EventType;

  20. /**
  21.  * <p>
  22.  * A specialized event class which is generated by a {@link ConfigurationBuilder} when a result configuration has been
  23.  * created.
  24.  * </p>
  25.  * <p>
  26.  * Events of this type are fired in the {@code getConfiguration()} method of a configuration builder each time a new
  27.  * result object is created. At the time the event is fired, no lock is held. The newly created
  28.  * {@code ImmutableConfiguration} object is available as a property of this event.
  29.  * </p>
  30.  * <p>
  31.  * A use case for this event is to perform special initializations on newly created configuration objects. It is also an
  32.  * indication that a builder is now fully initialized; i.e. the managed configuration is available.
  33.  * </p>
  34.  *
  35.  * @since 2.0
  36.  */
  37. public class ConfigurationBuilderResultCreatedEvent extends ConfigurationBuilderEvent {

  38.     /**
  39.      * The specialized event type for a newly created result configuration. Events of this type are generated by a
  40.      * configuration builder when a result configuration has been created.
  41.      */
  42.     public static final EventType<ConfigurationBuilderResultCreatedEvent> RESULT_CREATED = new EventType<>(ANY, "RESULT_CREATED");

  43.     // SpotBugs
  44.     // [ERROR] Medium: Class org.apache.commons.configuration2.builder.ConfigurationBuilderResultCreatedEvent defines
  45.     // non-transient non-serializable instance field configuration
  46.     // [org.apache.commons.configuration2.builder.ConfigurationBuilderResultCreatedEvent] In
  47.     // ConfigurationBuilderResultCreatedEvent.java SE_BAD_FIELD
  48.     //
  49.     // private static final long serialVersionUID = 1L;

  50.     /** The newly created configuration object. */
  51.     private final ImmutableConfiguration configuration;

  52.     /**
  53.      * Creates a new instance of {@code ConfigurationBuilderResultCreatedEvent} and initializes its properties.
  54.      *
  55.      * @param source the {@code ConfigurationBuilder} object which triggered this event (must not be <strong>null</strong>)
  56.      * @param evType the type of this event (must not be <strong>null</strong>)
  57.      * @param createdConfiguration the newly created {@code ImmutableConfiguration} object (must not be <strong>null</strong>)
  58.      * @throws IllegalArgumentException if a required parameter is null
  59.      */
  60.     public ConfigurationBuilderResultCreatedEvent(final ConfigurationBuilder<?> source,
  61.         final EventType<? extends ConfigurationBuilderResultCreatedEvent> evType, final ImmutableConfiguration createdConfiguration) {
  62.         super(source, evType);
  63.         if (createdConfiguration == null) {
  64.             throw new IllegalArgumentException("Configuration must not be null!");
  65.         }
  66.         configuration = createdConfiguration;
  67.     }

  68.     /**
  69.      * Gets the newly created {@code ImmutableConfiguration} object.
  70.      *
  71.      * @return the newly created {@code ImmutableConfiguration}
  72.      */
  73.     public ImmutableConfiguration getConfiguration() {
  74.         return configuration;
  75.     }
  76. }