001    // Copyright 2006, 2007, 2009 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.internal;
016    
017    import org.apache.tapestry5.ioc.ObjectCreator;
018    import org.apache.tapestry5.ioc.ServiceLifecycle;
019    import org.apache.tapestry5.ioc.ServiceResources;
020    
021    /**
022     * Wrapper around a lifecycle, a set of resources for a service, and an underlying {@link ObjectCreator} for a service
023     * that allows the service lifecycle to alter the way that the service is created (this is needed for the more advanced,
024     * non-singleton types of service lifecycles).
025     */
026    public class LifecycleWrappedServiceCreator implements ObjectCreator
027    {
028         private final ServiceLifecycle lifecycle;
029    
030        private final ServiceResources resources;
031    
032        private final ObjectCreator creator;
033    
034        public LifecycleWrappedServiceCreator(ServiceLifecycle lifecycle, ServiceResources resources, ObjectCreator creator)
035        {
036            this.lifecycle = lifecycle;
037            this.resources = resources;
038            this.creator = creator;
039        }
040    
041        /**
042         * Passes the resources and the service creator through the {@link org.apache.tapestry5.ioc.ServiceLifecycle}.
043         */
044        public Object createObject()
045        {
046            return lifecycle.createService(resources, creator);
047        }
048    
049    }