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.internal.pageload.DefaultComponentRequestSelectorAnalyzer;
017import org.apache.tapestry5.internal.pageload.DefaultComponentResourceLocator;
018import org.apache.tapestry5.internal.pageload.PagePreloaderImpl;
019import org.apache.tapestry5.internal.services.ComponentTemplateSource;
020import org.apache.tapestry5.internal.services.ComponentTemplateSourceImpl;
021import org.apache.tapestry5.ioc.ServiceBinder;
022import org.apache.tapestry5.ioc.annotations.Marker;
023import org.apache.tapestry5.ioc.annotations.Startup;
024import org.apache.tapestry5.ioc.annotations.Symbol;
025import org.apache.tapestry5.services.Core;
026import org.apache.tapestry5.services.pageload.ComponentRequestSelectorAnalyzer;
027import org.apache.tapestry5.services.pageload.ComponentResourceLocator;
028import org.apache.tapestry5.services.pageload.PagePreloader;
029import org.apache.tapestry5.services.pageload.PreloaderMode;
030
031/**
032 * @since 5.3
033 */
034@Marker(Core.class)
035public class PageLoadModule
036{
037    public static void bind(ServiceBinder binder)
038    {
039        binder.bind(ComponentRequestSelectorAnalyzer.class, DefaultComponentRequestSelectorAnalyzer.class);
040        binder.bind(ComponentResourceLocator.class, DefaultComponentResourceLocator.class);
041        binder.bind(ComponentTemplateSource.class, ComponentTemplateSourceImpl.class);
042        binder.bind(PagePreloader.class, PagePreloaderImpl.class);
043    }
044
045    @Startup
046    public static void preloadPages(PagePreloader preloader,
047                                    @Symbol(SymbolConstants.PRELOADER_MODE)
048                                    PreloaderMode mode,
049                                    @Symbol(SymbolConstants.PRODUCTION_MODE)
050                                    boolean productionMode)
051    {
052        if (mode.isEnabledFor(productionMode))
053        {
054            preloader.preloadPages();
055        }
056    }
057}