All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.configuration2.builder.EventListenerParameters Maven / Gradle / Ivy

Go to download

Tools to assist in the reading of configuration/preferences files in various formats

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

import java.util.Collections;
import java.util.Map;

import org.apache.commons.configuration2.event.Event;
import org.apache.commons.configuration2.event.EventListener;
import org.apache.commons.configuration2.event.EventListenerList;
import org.apache.commons.configuration2.event.EventListenerRegistrationData;
import org.apache.commons.configuration2.event.EventType;

/**
 * 

* A specialized parameters implementation for {@link BasicConfigurationBuilder} * which allows for a convenient event listener initialization. *

*

* This class offers a fluent interface for registering event listeners. A fully * initialized instance can be passed to the * {@link BasicConfigurationBuilder#configure(BuilderParameters...)} method. All * event listeners which have been registered at the instance are then copied * over to the configuration builder. *

*

* The code fragment below shows a typical usage scenario: *

* *
 * BasicConfigurationBuilder<Configuration> builder =
 *         new BasicConfigurationBuilder<Configuration>(
 *                 PropertiesConfiguration.class)
 *                 .configure(new EventListenerParameters().addEventListener(
 *                         ConfigurationEvent.ANY, myListener));
 * 
* *

* In order to support a configuration builder's {@code configure()} method, * this class implements the {@code BuilderParameters} interface. However, this * is just a dummy implementation; no parameters are propagated to the builder. *

* * @version $Id: EventListenerParameters.java 1679772 2015-05-16 17:41:17Z oheger $ * @since 2.0 */ public class EventListenerParameters implements BuilderParameters, EventListenerProvider { /** Stores the event listener registrations added to this object. */ private final EventListenerList eventListeners; /** * Creates a new instance of {@code EventListenerParameters}. */ public EventListenerParameters() { eventListeners = new EventListenerList(); } /** * Adds an event listener of the specified event type to this object. * * @param eventType the event type object * @param listener the event listener * @param the event type * @return a reference to this object for method chaining */ public EventListenerParameters addEventListener( EventType eventType, EventListener listener) { eventListeners.addEventListener(eventType, listener); return this; } /** * Adds the specified {@code EventListenerRegistrationData} instance to this * object. * * @param registrationData the registration object to be added * @param the event type of the contained event listener * @return a reference to this object for method chaining */ public EventListenerParameters addEventListener( EventListenerRegistrationData registrationData) { eventListeners.addEventListener(registrationData); return this; } /** * {@inheritDoc} This implementation returns an empty map. */ @Override public Map getParameters() { return Collections.emptyMap(); } @Override public EventListenerList getListeners() { return eventListeners; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy