001    // Copyright 2006, 2008, 2009, 2010, 2011 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    
015    package 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, or be {@linkplain org.apache.tapestry5.ioc.services.TypeCoercer coercable} to the type.
030     *
031     * @see org.apache.tapestry5.ioc.annotations.Contribute
032     * @see org.apache.tapestry5.ioc.annotations.UsesConfiguration
033     */
034    public interface OrderedConfiguration<T>
035    {
036        /**
037         * Adds an ordered object to a service's contribution. Each object has an id (which must be unique). Optionally,
038         * pre-requisites (a list of ids that must precede this object) and post-requisites (ids that must follow) can be
039         * provided.
040         * <p/>
041         * <p>If no constraints are supplied, then an implicit constraint is supplied: after the previously
042         * contributed id <em>within the same contribution method</em>.
043         *
044         * @param id          a unique id for the object; the id will be fully qualified with the contributing module's id
045         * @param constraints used to order the object relative to other contributed objects
046         * @param object      to add to the service's configuration
047         */
048        void add(String id, T object, String... constraints);
049    
050        /**
051         * Overrides a normally contributed object. Each override must match a single normally contributed object.
052         *
053         * @param id          identifies object to override
054         * @param object      overriding object (may be null)
055         * @param constraints constraints for the overridden object, replacing constraints for the original object (even if
056         *                    omitted, in which case the override object will have no ordering constraints)
057         * @since 5.1.0.0
058         */
059        void override(String id, T object, String... constraints);
060    
061        /**
062         * Adds an ordered object by instantiating (with dependencies) the indicated class. When the configuration type is
063         * an interface and the class to be contributed is a local file,
064         * then a reloadable proxy for the class will be created and contributed.
065         *
066         * @param id          of contribution (used for ordering)
067         * @param clazz       class to instantiate
068         * @param constraints used to order the object relative to other contributed objects
069         * @since 5.1.0.0
070         */
071        void addInstance(String id, Class<? extends T> clazz, String... constraints);
072    
073        /**
074         * Instantiates an object and adds it as an override. When the configuration type is an interface and the class to
075         * be contributed is a local file, then a reloadable proxy for the class will be created and contributed.
076         *
077         * @param id          of object to override
078         * @param clazz       to instantiate
079         * @param constraints constraints for the overridden object, replacing constraints for the original object (even if
080         *                    omitted, in which case the override object will have no ordering constraints)
081         * @since 5.1.0.0
082         */
083        void overrideInstance(String id, Class<? extends T> clazz, String... constraints);
084    }