001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005// http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.modules;
014
015import org.apache.tapestry5.SymbolConstants;
016import org.apache.tapestry5.http.TapestryHttpSymbolConstants;
017import org.apache.tapestry5.internal.pageload.DefaultComponentRequestSelectorAnalyzer;
018import org.apache.tapestry5.internal.pageload.DefaultComponentResourceLocator;
019import org.apache.tapestry5.internal.pageload.PagePreloaderImpl;
020import org.apache.tapestry5.internal.services.ComponentTemplateSource;
021import org.apache.tapestry5.internal.services.ComponentTemplateSourceImpl;
022import org.apache.tapestry5.ioc.ServiceBinder;
023import org.apache.tapestry5.ioc.annotations.Marker;
024import org.apache.tapestry5.ioc.annotations.Startup;
025import org.apache.tapestry5.ioc.annotations.Symbol;
026import org.apache.tapestry5.services.Core;
027import org.apache.tapestry5.services.pageload.ComponentRequestSelectorAnalyzer;
028import org.apache.tapestry5.services.pageload.ComponentResourceLocator;
029import org.apache.tapestry5.services.pageload.PagePreloader;
030import org.apache.tapestry5.services.pageload.PreloaderMode;
031
032/**
033 * @since 5.3
034 */
035@Marker(Core.class)
036public class PageLoadModule
037{
038    public static void bind(ServiceBinder binder)
039    {
040        binder.bind(ComponentRequestSelectorAnalyzer.class, DefaultComponentRequestSelectorAnalyzer.class);
041        binder.bind(ComponentResourceLocator.class, DefaultComponentResourceLocator.class);
042        binder.bind(ComponentTemplateSource.class, ComponentTemplateSourceImpl.class);
043        binder.bind(PagePreloader.class, PagePreloaderImpl.class);
044    }
045
046    @Startup
047    public static void preloadPages(PagePreloader preloader,
048                                    @Symbol(SymbolConstants.PRELOADER_MODE)
049                                    PreloaderMode mode,
050                                    @Symbol(TapestryHttpSymbolConstants.PRODUCTION_MODE)
051                                    boolean productionMode)
052    {
053        if (mode.isEnabledFor(productionMode))
054        {
055            preloader.preloadPages();
056        }
057    }
058}