001    // Copyright 2004, 2005 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.tapestry.services.impl;
016    
017    import org.apache.commons.logging.Log;
018    import org.apache.tapestry.IRequestCycle;
019    import org.apache.tapestry.ITemplateComponent;
020    import org.apache.tapestry.binding.BindingSource;
021    import org.apache.tapestry.engine.IPageLoader;
022    import org.apache.tapestry.parse.ComponentTemplate;
023    import org.apache.tapestry.services.ComponentTemplateLoader;
024    import org.apache.tapestry.services.TemplateSource;
025    
026    /**
027     * Utility service, <code>tapestry.page.ComponentTemplateLoader</code>, which will process the
028     * component's {@link org.apache.tapestry.parse.ComponentTemplate template}, which involves working
029     * through the nested structure of the template and hooking the various static template blocks and
030     * components together using {@link org.apache.tapestry.IComponent#addBody(IRender)}and
031     * {@link org.apache.tapestry.ITemplateComponent#addOuter(IRender)}.
032     * <p>
033     * Because this service must be reentrant, it acts as a factory for a
034     * {@link org.apache.tapestry.services.impl.ComponentTemplateLoaderLogic}that is created (and
035     * discarded) for each component whose template is loaded.
036     * 
037     * @author Howard Lewis Ship
038     * @since 3.0
039     */
040    
041    public class ComponentTemplateLoaderImpl implements ComponentTemplateLoader
042    {
043        private Log _log;
044    
045        private IPageLoader _pageLoader;
046    
047        private TemplateSource _templateSource;
048    
049        /** @since 4.0 */
050    
051        private BindingSource _bindingSource;
052    
053        public void loadTemplate(IRequestCycle requestCycle, ITemplateComponent loadComponent)
054        {
055            ComponentTemplate template = _templateSource.getTemplate(requestCycle, loadComponent);
056    
057            ComponentTemplateLoaderLogic logic = new ComponentTemplateLoaderLogic(_log, _pageLoader,
058                    _bindingSource);
059    
060            logic.loadTemplate(requestCycle, loadComponent, template);
061        }
062    
063        /** @since 4.0 */
064    
065        public void setPageLoader(IPageLoader pageLoader)
066        {
067            _pageLoader = pageLoader;
068        }
069    
070        /** @since 4.0 */
071    
072        public void setLog(Log log)
073        {
074            _log = log;
075        }
076    
077        /**
078         * @since 4.0
079         */
080    
081        public void setTemplateSource(TemplateSource templateSource)
082        {
083            _templateSource = templateSource;
084        }
085    
086        /**
087         * @since 4.0
088         */
089    
090        public void setBindingSource(BindingSource bindingSource)
091        {
092            _bindingSource = bindingSource;
093        }
094    }