    001// Licensed under the Apache License, Version 2.0 (the "License");
    002// you may not use this file except in compliance with the License.
    003// You may obtain a copy of the License at
    004//
    005// http://www.apache.org/licenses/LICENSE-2.0
    006//
    007// Unless required by applicable law or agreed to in writing, software
    008// distributed under the License is distributed on an "AS IS" BASIS,
    009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    010// See the License for the specific language governing permissions and
    011// limitations under the License.
    012
    013package org.apache.tapestry5.ioc;
    014
    015/**
    016 * Object passed into a service contributor method that allows the method provide contributed values to the service's
    017 * configuration.
    018 *
    019 * A service can <em>collect</em> contributions in three different ways:
    020 * <ul>
    021 * <li>As an un-ordered collection of values</li>
    022 * <li>As an ordered list of values (where each value has a unique id, pre-requisites and post-requisites)</li>
    023 * <li>As a map of keys and values
    024 * </ul>
    025 *
    026 * The service defines the <em>type</em> of contribution, in terms of a base class or service interface. Contributions
    027 * must be compatible with the type.
    028 */
    029public interface MappedConfiguration<K, V>
    030{
    031
    032    /**
    033     * Adds a keyed object to the service's contribution.
    034     *
    035     * @param key
    036     *            unique id for the value
    037     * @param value
    038     *            to contribute
    039     * @throws IllegalArgumentException
    040     *             if key is not unique
    041     */
    042    void add(K key, V value);
    043
    044    /**
    045     * Overrides an existing contribution by its key.
    046     *
    047     * @param key
    048     *            unique id of value to override
    049     * @param value
    050     *            new value, or null to remove the key entirely
    051     * @since 5.1.0.0
    052     */
    053    void override(K key, V value);
    054
    055    /**
    056     * Adds a keyed object as an instantiated instance (with dependencies injected) of a class. When the value
    057     * type is an interface and the class to be contributed is a local file,
    058     * then a reloadable proxy for the value class will be created and contributed.
    059     *
    060     * @param key
    061     *            unique id for the value
    062     * @param clazz
    063     *            class to instantiate and contribute
    064     * @since 5.1.0.0
    065     */
    066    void addInstance(K key, Class<? extends V> clazz);
    067
    068    /**
    069     * Overrides an existing contribution with a new instance. When the value
    070     * type is an interface and the class to be contributed is a local file,
    071     * then a reloadable proxy for the value class will be created and contributed.
    072     *
    073     * @param key
    074     *            unique id of value to override
    075     * @param clazz
    076     *            class to instantiate as override
    077     */
    078    void overrideInstance(K key, Class<? extends V> clazz);
    079}