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