    001    // Copyright 2007 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.services;
    016
    017    import org.apache.tapestry5.annotations.Environmental;
    018    import org.apache.tapestry5.ioc.services.PropertyShadowBuilder;
    019
    020    /**
    021     * Much like {@link PropertyShadowBuilder}, except that instead of accessing a property of some other service, it
    022     * accesses a value from within the {@link Environment} service. This is useful for defining a new service that can be
    023     * injected into other services (whereas the {@link Environmental} annotation may only be used within component
    024     * classes).
    025     */
    026    public interface EnvironmentalShadowBuilder
    027    {
    028        /**
    029         * Returns a proxy that delegates all methods to an object obtained from {@link Environment#peekRequired(Class)}.
    030         * Note that at the time this method is invoked, the Environment service may still be virtual, and will often not
    031         * yet have been loaded with values, and that's OK, the resolution is deferred to the instant a method is invoked.
    032         *
    033         * @param <T>
    034         * @param serviceType the service type, which is used to obtained the delegate instance
    035         * @return a proxy to the service
    036         */
    037        <T> T build(Class<T> serviceType);
    038    }