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.IRender;
019 import org.apache.tapestry.IRequestCycle;
020 import org.apache.tapestry.ITemplateComponent;
021 import org.apache.tapestry.binding.BindingSource;
022 import org.apache.tapestry.engine.IPageLoader;
023 import org.apache.tapestry.parse.ComponentTemplate;
024 import org.apache.tapestry.services.ComponentTemplateLoader;
025 import org.apache.tapestry.services.TemplateSource;
026
027 /**
028 * Utility service, <code>tapestry.page.ComponentTemplateLoader</code>, which will process the
029 * component's {@link org.apache.tapestry.parse.ComponentTemplate template}, which involves working
030 * through the nested structure of the template and hooking the various static template blocks and
031 * components together using {@link org.apache.tapestry.IComponent#addBody(IRender)}and
032 * {@link org.apache.tapestry.ITemplateComponent#addOuter(IRender)}.
033 * <p>
034 * Because this service must be reentrant, it acts as a factory for a
035 * {@link org.apache.tapestry.services.impl.ComponentTemplateLoaderLogic}that is created (and
036 * discarded) for each component whose template is loaded.
037 *
038 * @author Howard Lewis Ship
039 * @since 3.0
040 */
041
042 public class ComponentTemplateLoaderImpl implements ComponentTemplateLoader
043 {
044 private Log _log;
045
046 private IPageLoader _pageLoader;
047
048 private TemplateSource _templateSource;
049
050 /** @since 4.0 */
051
052 private BindingSource _bindingSource;
053
054 public void loadTemplate(IRequestCycle requestCycle, ITemplateComponent loadComponent)
055 {
056 ComponentTemplate template = _templateSource.getTemplate(requestCycle, loadComponent);
057
058 ComponentTemplateLoaderLogic logic = new ComponentTemplateLoaderLogic(_log, _pageLoader, _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 }