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 * https://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
19 import org.apache.commons.configuration2.ImmutableConfiguration;
20 import org.apache.commons.configuration2.event.EventType;
21
22 /**
23 * <p>
24 * A specialized event class which is generated by a {@link ConfigurationBuilder} when a result configuration has been
25 * created.
26 * </p>
27 * <p>
28 * Events of this type are fired in the {@code getConfiguration()} method of a configuration builder each time a new
29 * result object is created. At the time the event is fired, no lock is held. The newly created
30 * {@code ImmutableConfiguration} object is available as a property of this event.
31 * </p>
32 * <p>
33 * A use case for this event is to perform special initializations on newly created configuration objects. It is also an
34 * indication that a builder is now fully initialized; i.e. the managed configuration is available.
35 * </p>
36 *
37 * @since 2.0
38 */
39 public class ConfigurationBuilderResultCreatedEvent extends ConfigurationBuilderEvent {
40
41 /**
42 * The specialized event type for a newly created result configuration. Events of this type are generated by a
43 * configuration builder when a result configuration has been created.
44 */
45 public static final EventType<ConfigurationBuilderResultCreatedEvent> RESULT_CREATED = new EventType<>(ANY, "RESULT_CREATED");
46
47 // SpotBugs
48 // [ERROR] Medium: Class org.apache.commons.configuration2.builder.ConfigurationBuilderResultCreatedEvent defines
49 // non-transient non-serializable instance field configuration
50 // [org.apache.commons.configuration2.builder.ConfigurationBuilderResultCreatedEvent] In
51 // ConfigurationBuilderResultCreatedEvent.java SE_BAD_FIELD
52 //
53 // private static final long serialVersionUID = 1L;
54
55 /** The newly created configuration object. */
56 private final ImmutableConfiguration configuration;
57
58 /**
59 * Creates a new instance of {@code ConfigurationBuilderResultCreatedEvent} and initializes its properties.
60 *
61 * @param source the {@code ConfigurationBuilder} object which triggered this event (must not be <strong>null</strong>)
62 * @param evType the type of this event (must not be <strong>null</strong>)
63 * @param createdConfiguration the newly created {@code ImmutableConfiguration} object (must not be <strong>null</strong>)
64 * @throws IllegalArgumentException if a required parameter is null
65 */
66 public ConfigurationBuilderResultCreatedEvent(final ConfigurationBuilder<?> source,
67 final EventType<? extends ConfigurationBuilderResultCreatedEvent> evType, final ImmutableConfiguration createdConfiguration) {
68 super(source, evType);
69 if (createdConfiguration == null) {
70 throw new IllegalArgumentException("Configuration must not be null!");
71 }
72 configuration = createdConfiguration;
73 }
74
75 /**
76 * Gets the newly created {@code ImmutableConfiguration} object.
77 *
78 * @return the newly created {@code ImmutableConfiguration}
79 */
80 public ImmutableConfiguration getConfiguration() {
81 return configuration;
82 }
83 }