Package org.apache.tapestry.pageload

Source Code of org.apache.tapestry.pageload.PageLoader

/* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry.pageload;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import javax.servlet.ServletContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
import org.apache.hivemind.util.ClasspathResource;
import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IBinding;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.INamespace;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.ITemplateComponent;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.asset.ContextAsset;
import org.apache.tapestry.asset.ExternalAsset;
import org.apache.tapestry.asset.PrivateAsset;
import org.apache.tapestry.binding.ExpressionBinding;
import org.apache.tapestry.binding.ListenerBinding;
import org.apache.tapestry.engine.IComponentClassEnhancer;
import org.apache.tapestry.engine.IPageLoader;
import org.apache.tapestry.engine.ISpecificationSource;
import org.apache.tapestry.event.ChangeObserver;
import org.apache.tapestry.event.PageDetachListener;
import org.apache.tapestry.resolver.ComponentSpecificationResolver;
import org.apache.tapestry.resource.ContextResource;
import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.ComponentTemplateLoader;
import org.apache.tapestry.services.ExpressionEvaluator;
import org.apache.tapestry.services.TemplateSource;
import org.apache.tapestry.spec.AssetType;
import org.apache.tapestry.spec.BindingType;
import org.apache.tapestry.spec.IAssetSpecification;
import org.apache.tapestry.spec.IBindingSpecification;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.IContainedComponent;
import org.apache.tapestry.spec.IListenerBindingSpecification;
import org.apache.tapestry.spec.IPropertySpecification;

/**
* Runs the process of building the component hierarchy for an entire page.
* <p>
* This implementation is not threadsafe, therefore the threaded service model must be used.
*
* @author Howard Lewis Ship
*/

public class PageLoader implements IPageLoader
{public static com.cortexeb.tools.clover.d __CLOVER_194_0 = com.cortexeb.tools.clover.aq.getRecorder(new char[] {67,58,92,119,111,114,107,115,112,97,99,101,92,106,97,107,97,114,116,97,45,116,97,112,101,115,116,114,121,92,102,114,97,109,101,119,111,114,107,92,116,97,114,103,101,116,92,99,108,111,118,101,114,45,100,98},1097439627296L);
    private Log _log = LogFactory.getLog(PageLoader.class);

    private ClassResolver _classResolver;

    private IComponentClassEnhancer _enhancer;

    /** @since 3.1 */

    private ComponentSpecificationResolver _componentResolver;

    /** @since 3.1 */

    private ServletContext _context;

    /** @since 3.1 */

    private String _defaultPageClassName;

    /** @since 3.1 */

    private String _defaultScriptLanguage;

    /** @since 3.1 */

    private BindingSource _bindingSource;

    /** @since 3.1 */

    private ComponentTemplateLoader _componentTemplateLoader;

    private IEngine _engine;

    private List _inheritedBindingQueue = new ArrayList();

    private List _propertyInitializers = new ArrayList();

    /** @since 3.1 */
    private IComponentVisitor _establishDefaultParameterValuesVisitor;

    private ComponentTreeWalker _establishDefaultParameterValuesWalker;

    private ComponentTreeWalker _verifyRequiredParametersWalker;
   
    /** @since 3.1 */
    private ExpressionEvaluator _expressionEvaluator;

    /**
     * The locale of the application, which is also the locale of the page being loaded.
     */

    private Locale _locale;

    /**
     * Number of components instantiated, excluding the page itself.
     */

    private int _count;

    /**
     * The recursion depth. A page with no components is zero. A component on a page is one.
     */

    private int _depth;

    /**
     * The maximum depth reached while building the page.
     */

    private int _maxDepth;

    /**
     * Used to figure relative paths for context assets.
     */

    private Resource _applicationRoot;

    public void initializeService()
    {try { __CLOVER_194_0.M[3070]++;
        __CLOVER_194_0.S[12664]++;_applicationRoot = new ContextResource(_context, "/");

        // Create the mechanisms for walking the component tree when it is
        // complete
        __CLOVER_194_0.S[12665]++;IComponentVisitor verifyRequiredParametersVisitor = new VerifyRequiredParametersVisitor();
        __CLOVER_194_0.S[12666]++;_verifyRequiredParametersWalker = new ComponentTreeWalker(new IComponentVisitor[]
        { verifyRequiredParametersVisitor });

        __CLOVER_194_0.S[12667]++;_establishDefaultParameterValuesWalker = new ComponentTreeWalker(new IComponentVisitor[]
        { _establishDefaultParameterValuesVisitor });
    } finally { }}

    /**
     * Binds properties of the component as defined by the container's specification.
     * <p>
     * This implementation is very simple, we will need a lot more sanity checking and eror checking
     * in the final version.
     *
     * @param container
     *            The containing component. For a dynamic binding ({@link ExpressionBinding}) the
     *            property name is evaluated with the container as the root.
     * @param component
     *            The contained component being bound.
     * @param spec
     *            The specification of the contained component.
     * @param contained
     *            The contained component specification (from the container's
     *            {@link IComponentSpecification}).
     */

    private void bind(IComponent container, IComponent component, IContainedComponent contained)
    {try { __CLOVER_194_0.M[3071]++;
        __CLOVER_194_0.S[12668]++;IComponentSpecification spec = component.getSpecification();
        __CLOVER_194_0.S[12669]++;boolean formalOnly = !spec.getAllowInformalParameters();

        __CLOVER_194_0.S[12670]++;IComponentSpecification containerSpec = container.getSpecification();
        __CLOVER_194_0.S[12671]++;boolean containerFormalOnly = !containerSpec.getAllowInformalParameters();

        __CLOVER_194_0.S[12672]++;if ((((contained.getInheritInformalParameters()) && (++__CLOVER_194_0.CT[2163] != 0)) || (++__CLOVER_194_0.CF[2163] == 0))){
        {
            __CLOVER_194_0.S[12673]++;if ((((formalOnly) && (++__CLOVER_194_0.CT[2164] != 0)) || (++__CLOVER_194_0.CF[2164] == 0))){
                __CLOVER_194_0.S[12674]++;throw new ApplicationRuntimeException(PageloadMessages
                        .inheritInformalInvalidComponentFormalOnly(component), component, contained
                        .getLocation(), null);}

            __CLOVER_194_0.S[12675]++;if ((((containerFormalOnly) && (++__CLOVER_194_0.CT[2165] != 0)) || (++__CLOVER_194_0.CF[2165] == 0))){
                __CLOVER_194_0.S[12676]++;throw new ApplicationRuntimeException(PageloadMessages
                        .inheritInformalInvalidContainerFormalOnly(container, component),
                        component, contained.getLocation(), null);}

            __CLOVER_194_0.S[12677]++;IQueuedInheritedBinding queued = new QueuedInheritInformalBindings(component);
            __CLOVER_194_0.S[12678]++;_inheritedBindingQueue.add(queued);
        }}

        __CLOVER_194_0.S[12679]++;Iterator i = contained.getBindingNames().iterator();

        __CLOVER_194_0.S[12680]++;while ((((i.hasNext()) && (++__CLOVER_194_0.CT[2166] != 0)) || (++__CLOVER_194_0.CF[2166] == 0))){
        {
            __CLOVER_194_0.S[12681]++;String name = (String) i.next();

            __CLOVER_194_0.S[12682]++;boolean isFormal = spec.getParameter(name) != null;

            __CLOVER_194_0.S[12683]++;IBindingSpecification bspec = contained.getBinding(name);

            // If not allowing informal parameters, check that each binding
            // matches
            // a formal parameter.

            __CLOVER_194_0.S[12684]++;if ((((formalOnly && !isFormal) && (++__CLOVER_194_0.CT[2167] != 0)) || (++__CLOVER_194_0.CF[2167] == 0))){
                __CLOVER_194_0.S[12685]++;throw new ApplicationRuntimeException(PageloadMessages.formalParametersOnly(
                        component,
                        name), component, bspec.getLocation(), null);}

            // If an informal parameter that conflicts with a reserved name,
            // then
            // skip it.

            __CLOVER_194_0.S[12686]++;if ((((!isFormal && spec.isReservedParameterName(name)) && (++__CLOVER_194_0.CT[2168] != 0)) || (++__CLOVER_194_0.CF[2168] == 0))){
                __CLOVER_194_0.S[12687]++;continue;}

            // The type determines how to interpret the value:
            // As a simple static String
            // As a nested property name (relative to the component)
            // As the name of a binding inherited from the containing component.
            // As the name of a public field
            // As a script for a listener

            __CLOVER_194_0.S[12688]++;BindingType type = bspec.getType();

            // For inherited bindings, defer until later. This gives components
            // a chance to setup bindings from static values and expressions in
            // the
            // template. The order of operations is tricky, template bindings
            // come
            // later.

            __CLOVER_194_0.S[12689]++;if ((((type == BindingType.INHERITED) && (++__CLOVER_194_0.CT[2169] != 0)) || (++__CLOVER_194_0.CF[2169] == 0))){
            {
                __CLOVER_194_0.S[12690]++;QueuedInheritedBinding queued = new QueuedInheritedBinding(component, bspec
                        .getValue(), name);
                __CLOVER_194_0.S[12691]++;_inheritedBindingQueue.add(queued);
                __CLOVER_194_0.S[12692]++;continue;
            }}

            __CLOVER_194_0.S[12693]++;if ((((type == BindingType.LISTENER) && (++__CLOVER_194_0.CT[2170] != 0)) || (++__CLOVER_194_0.CF[2170] == 0))){
            {
                __CLOVER_194_0.S[12694]++;constructListenerBinding(component, name, (IListenerBindingSpecification) bspec);
                __CLOVER_194_0.S[12695]++;continue;
            }}

            __CLOVER_194_0.S[12696]++;IBinding binding = convert(container, bspec);

            __CLOVER_194_0.S[12697]++;if ((((binding != null) && (++__CLOVER_194_0.CT[2171] != 0)) || (++__CLOVER_194_0.CF[2171] == 0))){
                __CLOVER_194_0.S[12698]++;component.setBinding(name, binding);}
        }}
    } finally { }}

    private IBinding convert(IComponent container, IBindingSpecification spec)
    {try { __CLOVER_194_0.M[3072]++;
        __CLOVER_194_0.S[12699]++;Location location = spec.getLocation();
        __CLOVER_194_0.S[12700]++;String locator = spec.getValue();

        __CLOVER_194_0.S[12701]++;return _bindingSource.createBinding(container, locator, location);
    } finally { }}

    /**
     * Construct a {@link ListenerBinding}for the component, and add it.
     *
     * @since 3.0
     */

    private void constructListenerBinding(IComponent component, String bindingName,
            IListenerBindingSpecification spec)
    {try { __CLOVER_194_0.M[3073]++;
        __CLOVER_194_0.S[12702]++;String language = spec.getLanguage();

        // If not provided in the page or component specification, then
        // search for a default (factory default is "jython").

        __CLOVER_194_0.S[12703]++;if ((((Tapestry.isBlank(language)) && (++__CLOVER_194_0.CT[2172] != 0)) || (++__CLOVER_194_0.CF[2172] == 0))){
            __CLOVER_194_0.S[12704]++;language = _defaultScriptLanguage;}

        // Construct the binding. The first parameter is the compononent
        // (not the DirectLink or Form, but the page or component containing the
        // link or form).

        __CLOVER_194_0.S[12705]++;IBinding binding = new ListenerBinding(component.getContainer(), language,
                spec.getScript(), spec.getLocation());

        __CLOVER_194_0.S[12706]++;component.setBinding(bindingName, binding);
    } finally { }}

    /**
     * Sets up a component. This involves:
     * <ul>
     * <li>Instantiating any contained components.
     * <li>Add the contained components to the container.
     * <li>Setting up bindings between container and containees.
     * <li>Construct the containees recursively.
     * <li>Invoking
     * {@link IComponent#finishLoad(IRequestCycle, IPageLoader, IComponentSpecification)}
     * </ul>
     *
     * @param cycle
     *            the request cycle for which the page is being (initially) constructed
     * @param page
     *            The page on which the container exists.
     * @param container
     *            The component to be set up.
     * @param containerSpec
     *            The specification for the container.
     * @param the
     *            namespace of the container
     */

    private void constructComponent(IRequestCycle cycle, IPage page, IComponent container,
            IComponentSpecification containerSpec, INamespace namespace)
    {try { __CLOVER_194_0.M[3074]++;
        __CLOVER_194_0.S[12707]++;_depth++;
        __CLOVER_194_0.S[12708]++;if ((((_depth > _maxDepth) && (++__CLOVER_194_0.CT[2173] != 0)) || (++__CLOVER_194_0.CF[2173] == 0))){
            __CLOVER_194_0.S[12709]++;_maxDepth = _depth;}

        __CLOVER_194_0.S[12710]++;List ids = new ArrayList(containerSpec.getComponentIds());
        __CLOVER_194_0.S[12711]++;int count = ids.size();

        __CLOVER_194_0.S[12712]++;try
        {
            __CLOVER_194_0.S[12713]++;for (int i = 0; (((i < count) && (++__CLOVER_194_0.CT[2174] != 0)) || (++__CLOVER_194_0.CF[2174] == 0)); i++){
            {
                __CLOVER_194_0.S[12714]++;String id = (String) ids.get(i);

                // Get the sub-component specification from the
                // container's specification.

                __CLOVER_194_0.S[12715]++;IContainedComponent contained = containerSpec.getComponent(id);

                __CLOVER_194_0.S[12716]++;String type = contained.getType();
                __CLOVER_194_0.S[12717]++;Location location = contained.getLocation();

                __CLOVER_194_0.S[12718]++;_componentResolver.resolve(cycle, namespace, type, location);

                __CLOVER_194_0.S[12719]++;IComponentSpecification componentSpecification = _componentResolver
                        .getSpecification();
                __CLOVER_194_0.S[12720]++;INamespace componentNamespace = _componentResolver.getNamespace();

                // Instantiate the contained component.

                __CLOVER_194_0.S[12721]++;IComponent component = instantiateComponent(
                        page,
                        container,
                        id,
                        componentSpecification,
                        componentNamespace,
                        location);

                // Add it, by name, to the container.

                __CLOVER_194_0.S[12722]++;container.addComponent(component);

                // Set up any bindings in the IContainedComponent specification

                __CLOVER_194_0.S[12723]++;bind(container, component, contained);

                // Now construct the component recusively; it gets its chance
                // to create its subcomponents and set their bindings.

                __CLOVER_194_0.S[12724]++;constructComponent(
                        cycle,
                        page,
                        component,
                        componentSpecification,
                        componentNamespace);
            }}

            __CLOVER_194_0.S[12725]++;addAssets(container, containerSpec);

            // Finish the load of the component; most components (which
            // subclass BaseComponent) load their templates here.
            // That may cause yet more components to be created, and more
            // bindings to be set, so we defer some checking until
            // later.

            __CLOVER_194_0.S[12726]++;container.finishLoad(cycle, this, containerSpec);

            // Finally, we create an initializer for each
            // specified property.

            __CLOVER_194_0.S[12727]++;createPropertyInitializers(page, container, containerSpec);
        }
        catch (ApplicationRuntimeException ex)
        {
            __CLOVER_194_0.S[12728]++;throw ex;
        }
        catch (RuntimeException ex)
        {
            __CLOVER_194_0.S[12729]++;throw new ApplicationRuntimeException(PageloadMessages.unableToInstantiateComponent(
                    container,
                    ex), container, null, ex);
        }

        __CLOVER_194_0.S[12730]++;_depth--;
    } finally { }}

    /**
     * Invoked to create an implicit component (one which is defined in the containing component's
     * template, rather that in the containing component's specification).
     *
     * @see org.apache.tapestry.services.impl.ComponentTemplateLoaderImpl
     * @since 3.0
     */

    public IComponent createImplicitComponent(IRequestCycle cycle, IComponent container,
            String componentId, String componentType, Location location)
    {try { __CLOVER_194_0.M[3075]++;
        __CLOVER_194_0.S[12731]++;IPage page = container.getPage();

        __CLOVER_194_0.S[12732]++;_componentResolver.resolve(cycle, container.getNamespace(), componentType, location);

        __CLOVER_194_0.S[12733]++;INamespace componentNamespace = _componentResolver.getNamespace();
        __CLOVER_194_0.S[12734]++;IComponentSpecification spec = _componentResolver.getSpecification();

        __CLOVER_194_0.S[12735]++;IComponent result = instantiateComponent(
                page,
                container,
                componentId,
                spec,
                componentNamespace,
                location);

        __CLOVER_194_0.S[12736]++;container.addComponent(result);

        // Recusively build the component.

        __CLOVER_194_0.S[12737]++;constructComponent(cycle, page, result, spec, componentNamespace);

        __CLOVER_194_0.S[12738]++;return result;
    } finally { }}

    /**
     * Instantiates a component from its specification. We instantiate the component object, then
     * set its specification, page, container and id.
     *
     * @see AbstractComponent
     */

    private IComponent instantiateComponent(IPage page, IComponent container, String id,
            IComponentSpecification spec, INamespace namespace, Location location)
    {try { __CLOVER_194_0.M[3076]++;
        __CLOVER_194_0.S[12739]++;IComponent result = null;
        __CLOVER_194_0.S[12740]++;String className = spec.getComponentClassName();

        __CLOVER_194_0.S[12741]++;if ((((Tapestry.isBlank(className)) && (++__CLOVER_194_0.CT[2175] != 0)) || (++__CLOVER_194_0.CF[2175] == 0))){
            __CLOVER_194_0.S[12742]++;className = BaseComponent.class.getName();}

        __CLOVER_194_0.S[12743]++;Class componentClass = _enhancer.getEnhancedClass(spec, className);
        __CLOVER_194_0.S[12744]++;String enhancedClassName = componentClass.getName();

        __CLOVER_194_0.S[12745]++;try
        {
            __CLOVER_194_0.S[12746]++;result = (IComponent) componentClass.newInstance();

        }
        catch (ClassCastException ex)
        {
            __CLOVER_194_0.S[12747]++;throw new ApplicationRuntimeException(PageloadMessages
                    .classNotComponent(enhancedClassName), container, spec.getLocation(), ex);
        }
        catch (Throwable ex)
        {
            __CLOVER_194_0.S[12748]++;throw new ApplicationRuntimeException(PageloadMessages.unableToInstantiate(
                    enhancedClassName,
                    ex), container, spec.getLocation(), ex);
        }

        __CLOVER_194_0.S[12749]++;if ((((result instanceof IPage) && (++__CLOVER_194_0.CT[2176] != 0)) || (++__CLOVER_194_0.CF[2176] == 0))){
            __CLOVER_194_0.S[12750]++;throw new ApplicationRuntimeException(PageloadMessages.pageNotAllowed(result), result,
                    null, null);}

        __CLOVER_194_0.S[12751]++;result.setNamespace(namespace);
        __CLOVER_194_0.S[12752]++;result.setSpecification(spec);
        __CLOVER_194_0.S[12753]++;result.setPage(page);
        __CLOVER_194_0.S[12754]++;result.setContainer(container);
        __CLOVER_194_0.S[12755]++;result.setId(id);
        __CLOVER_194_0.S[12756]++;result.setLocation(location);

        __CLOVER_194_0.S[12757]++;_count++;

        __CLOVER_194_0.S[12758]++;return result;
    } finally { }}

    /**
     * Instantitates a page from its specification.
     *
     * @param name
     *            the unqualified, simple, name for the page
     * @param namespace
     *            the namespace containing the page's specification
     * @param spec
     *            the page's specification We instantiate the page object, then set its
     *            specification, names and locale.
     * @see IEngine
     * @see ChangeObserver
     */

    private IPage instantiatePage(String name, INamespace namespace, IComponentSpecification spec)
    {try { __CLOVER_194_0.M[3077]++;
        __CLOVER_194_0.S[12759]++;IPage result = null;

        __CLOVER_194_0.S[12760]++;String pageName = namespace.constructQualifiedName(name);
        __CLOVER_194_0.S[12761]++;String className = spec.getComponentClassName();
        __CLOVER_194_0.S[12762]++;Location location = spec.getLocation();

        __CLOVER_194_0.S[12763]++;if ((((Tapestry.isBlank(className)) && (++__CLOVER_194_0.CT[2177] != 0)) || (++__CLOVER_194_0.CF[2177] == 0))){
            __CLOVER_194_0.S[12764]++;className = _defaultPageClassName;}

        __CLOVER_194_0.S[12765]++;Class pageClass = _enhancer.getEnhancedClass(spec, className);
        __CLOVER_194_0.S[12766]++;String enhancedClassName = pageClass.getName();

        __CLOVER_194_0.S[12767]++;try
        {
            __CLOVER_194_0.S[12768]++;result = (IPage) pageClass.newInstance();

            __CLOVER_194_0.S[12769]++;result.setNamespace(namespace);
            __CLOVER_194_0.S[12770]++;result.setSpecification(spec);
            __CLOVER_194_0.S[12771]++;result.setPageName(pageName);
            __CLOVER_194_0.S[12772]++;result.setPage(result);
            __CLOVER_194_0.S[12773]++;result.setLocale(_locale);
            __CLOVER_194_0.S[12774]++;result.setLocation(location);
        }
        catch (ClassCastException ex)
        {
            __CLOVER_194_0.S[12775]++;throw new ApplicationRuntimeException(PageloadMessages.classNotPage(enhancedClassName),
                    location, ex);
        }
        catch (Exception ex)
        {
            __CLOVER_194_0.S[12776]++;throw new ApplicationRuntimeException(PageloadMessages.unableToInstantiate(
                    enhancedClassName,
                    ex), location, ex);
        }

        __CLOVER_194_0.S[12777]++;return result;
    } finally { }}

    public IPage loadPage(String name, INamespace namespace, IRequestCycle cycle,
            IComponentSpecification specification)
    {try { __CLOVER_194_0.M[3078]++;
        __CLOVER_194_0.S[12778]++;IPage page = null;

        __CLOVER_194_0.S[12779]++;_engine = cycle.getEngine();

        __CLOVER_194_0.S[12780]++;_locale = _engine.getLocale();

        __CLOVER_194_0.S[12781]++;_count = 0;
        __CLOVER_194_0.S[12782]++;_depth = 0;
        __CLOVER_194_0.S[12783]++;_maxDepth = 0;

        __CLOVER_194_0.S[12784]++;try
        {
            __CLOVER_194_0.S[12785]++;page = instantiatePage(name, namespace, specification);

            __CLOVER_194_0.S[12786]++;page.attach(_engine);

            __CLOVER_194_0.S[12787]++;constructComponent(cycle, page, page, specification, namespace);

            // Walk through the complete component tree to set up the default
            // parameter values.
            __CLOVER_194_0.S[12788]++;_establishDefaultParameterValuesWalker.walkComponentTree(page);

            __CLOVER_194_0.S[12789]++;establishInheritedBindings();

            // Walk through the complete component tree to ensure that required
            // parameters are bound
            __CLOVER_194_0.S[12790]++;_verifyRequiredParametersWalker.walkComponentTree(page);

            __CLOVER_194_0.S[12791]++;establishDefaultPropertyValues();
        }
        finally
        {
            __CLOVER_194_0.S[12792]++;_locale = null;
            __CLOVER_194_0.S[12793]++;_engine = null;
            __CLOVER_194_0.S[12794]++;_inheritedBindingQueue.clear();
            __CLOVER_194_0.S[12795]++;_propertyInitializers.clear();
        }

        __CLOVER_194_0.S[12796]++;if ((((_log.isDebugEnabled()) && (++__CLOVER_194_0.CT[2178] != 0)) || (++__CLOVER_194_0.CF[2178] == 0))){
            __CLOVER_194_0.S[12797]++;_log.debug("Loaded page " + page + " with " + _count + " components (maximum depth "
                    + _maxDepth + ")");}

        __CLOVER_194_0.S[12798]++;return page;
    } finally { }}

    /** @since 3.1 */

    public void loadTemplateForComponent(IRequestCycle cycle, ITemplateComponent component)
    {try { __CLOVER_194_0.M[3079]++;
        __CLOVER_194_0.S[12799]++;_componentTemplateLoader.loadTemplate(cycle, component);
    } finally { }}

    private void establishInheritedBindings()
    {try { __CLOVER_194_0.M[3080]++;
        __CLOVER_194_0.S[12800]++;_log.debug("Establishing inherited bindings");

        __CLOVER_194_0.S[12801]++;int count = _inheritedBindingQueue.size();

        __CLOVER_194_0.S[12802]++;for (int i = 0; (((i < count) && (++__CLOVER_194_0.CT[2179] != 0)) || (++__CLOVER_194_0.CF[2179] == 0)); i++){
        {
            __CLOVER_194_0.S[12803]++;IQueuedInheritedBinding queued = (IQueuedInheritedBinding) _inheritedBindingQueue
                    .get(i);

            __CLOVER_194_0.S[12804]++;queued.connect();
        }}
    } finally { }}

    private void establishDefaultPropertyValues()
    {try { __CLOVER_194_0.M[3081]++;
        __CLOVER_194_0.S[12805]++;_log.debug("Setting default property values");

        __CLOVER_194_0.S[12806]++;int count = _propertyInitializers.size();

        __CLOVER_194_0.S[12807]++;for (int i = 0; (((i < count) && (++__CLOVER_194_0.CT[2180] != 0)) || (++__CLOVER_194_0.CF[2180] == 0)); i++){
        {
            __CLOVER_194_0.S[12808]++;PageDetachListener initializer = (PageDetachListener) _propertyInitializers.get(i);

            __CLOVER_194_0.S[12809]++;initializer.pageDetached(null);
        }}
    } finally { }}

    private void addAssets(IComponent component, IComponentSpecification specification)
    {try { __CLOVER_194_0.M[3082]++;
        __CLOVER_194_0.S[12810]++;List names = specification.getAssetNames();

        __CLOVER_194_0.S[12811]++;if ((((names.isEmpty()) && (++__CLOVER_194_0.CT[2181] != 0)) || (++__CLOVER_194_0.CF[2181] == 0))){
            __CLOVER_194_0.S[12812]++;return;}

        __CLOVER_194_0.S[12813]++;Resource specLocation = specification.getSpecificationLocation();

        __CLOVER_194_0.S[12814]++;Iterator i = names.iterator();

        __CLOVER_194_0.S[12815]++;while ((((i.hasNext()) && (++__CLOVER_194_0.CT[2182] != 0)) || (++__CLOVER_194_0.CF[2182] == 0))){
        {
            __CLOVER_194_0.S[12816]++;String name = (String) i.next();
            __CLOVER_194_0.S[12817]++;IAssetSpecification assetSpec = specification.getAsset(name);
            __CLOVER_194_0.S[12818]++;IAsset asset = convert(name, component, assetSpec, specLocation);

            __CLOVER_194_0.S[12819]++;component.addAsset(name, asset);
        }}
    } finally { }}

    /**
     * Invoked from
     * {@link #constructComponent(IRequestCycle, IPage, IComponent, IComponentSpecification, INamespace)}
     * after {@link IComponent#finishLoad(IRequestCycle, IPageLoader, IComponentSpecification)}is
     * invoked. This iterates over any {@link org.apache.tapestry.spec.IPropertySpecification}s for
     * the component, create an initializer for each.
     */

    private void createPropertyInitializers(IPage page, IComponent component,
            IComponentSpecification spec)
    {try { __CLOVER_194_0.M[3083]++;
        __CLOVER_194_0.S[12820]++;List names = spec.getPropertySpecificationNames();
        __CLOVER_194_0.S[12821]++;int count = names.size();

        __CLOVER_194_0.S[12822]++;for (int i = 0; (((i < count) && (++__CLOVER_194_0.CT[2183] != 0)) || (++__CLOVER_194_0.CF[2183] == 0)); i++){
        {
            __CLOVER_194_0.S[12823]++;String name = (String) names.get(i);
            __CLOVER_194_0.S[12824]++;IPropertySpecification ps = spec.getPropertySpecification(name);
            __CLOVER_194_0.S[12825]++;String expression = ps.getInitialValue();

            __CLOVER_194_0.S[12826]++;PageDetachListener initializer = new PropertyInitializer(component, name, expression,
                    ps.getLocation(), _expressionEvaluator);

            __CLOVER_194_0.S[12827]++;_propertyInitializers.add(initializer);
            __CLOVER_194_0.S[12828]++;page.addPageDetachListener(initializer);
        }}

    } finally { }}

    /**
     * Builds an instance of {@link IAsset}from the specification.
     */

    private IAsset convert(String assetName, IComponent component, IAssetSpecification spec,
            Resource specificationLocation)
    {try { __CLOVER_194_0.M[3084]++;
        __CLOVER_194_0.S[12829]++;AssetType type = spec.getType();
        __CLOVER_194_0.S[12830]++;String path = spec.getPath();
        __CLOVER_194_0.S[12831]++;Location location = spec.getLocation();

        __CLOVER_194_0.S[12832]++;if ((((type == AssetType.EXTERNAL) && (++__CLOVER_194_0.CT[2184] != 0)) || (++__CLOVER_194_0.CF[2184] == 0))){
            __CLOVER_194_0.S[12833]++;return new ExternalAsset(path, location);}

        __CLOVER_194_0.S[12834]++;if ((((type == AssetType.PRIVATE) && (++__CLOVER_194_0.CT[2185] != 0)) || (++__CLOVER_194_0.CF[2185] == 0))){
        {
            __CLOVER_194_0.S[12835]++;Resource baseLocation = specificationLocation;

            // Fudge a special case for private assets with complete paths. The
            // specificationLocation
            // can't be used because it is often a ContextResourceLocation,
            // not a ClasspathResourceLocation.

            __CLOVER_194_0.S[12836]++;if ((((path.startsWith("/")) && (++__CLOVER_194_0.CT[2186] != 0)) || (++__CLOVER_194_0.CF[2186] == 0))){
            {
                __CLOVER_194_0.S[12837]++;baseLocation = new ClasspathResource(_classResolver, "/");
                __CLOVER_194_0.S[12838]++;path = path.substring(1);
            }}

            __CLOVER_194_0.S[12839]++;return new PrivateAsset((ClasspathResource) findAsset(
                    assetName,
                    component,
                    baseLocation,
                    path,
                    location), location);
        }}

        __CLOVER_194_0.S[12840]++;return new ContextAsset((ContextResource) findAsset(
                assetName,
                component,
                _applicationRoot,
                path,
                location), location);
    } finally { }}

    private Resource findAsset(String assetName, IComponent component, Resource baseLocation,
            String path, Location location)
    {try { __CLOVER_194_0.M[3085]++;
        __CLOVER_194_0.S[12841]++;Resource assetLocation = baseLocation.getRelativeResource(path);
        __CLOVER_194_0.S[12842]++;Resource localizedLocation = assetLocation.getLocalization(_locale);

        __CLOVER_194_0.S[12843]++;if ((((localizedLocation == null) && (++__CLOVER_194_0.CT[2187] != 0)) || (++__CLOVER_194_0.CF[2187] == 0))){
            __CLOVER_194_0.S[12844]++;throw new ApplicationRuntimeException(PageloadMessages.missingAsset(
                    assetName,
                    component), component, location, null);}

        __CLOVER_194_0.S[12845]++;return localizedLocation;
    } finally { }}

    public TemplateSource getTemplateSource()
    {try { __CLOVER_194_0.M[3086]++;
        __CLOVER_194_0.S[12846]++;return _engine.getTemplateSource();
    } finally { }}

    /** @since 3.1 */

    public void setClassResolver(ClassResolver resolver)
    {try { __CLOVER_194_0.M[3087]++;
        __CLOVER_194_0.S[12847]++;_classResolver = resolver;
    } finally { }}

    /** @since 3.1 */

    public void setLog(Log log)
    {try { __CLOVER_194_0.M[3088]++;
        __CLOVER_194_0.S[12848]++;_log = log;
    } finally { }}

    /** @since 3.1 */

    public void setEnhancer(IComponentClassEnhancer enhancer)
    {try { __CLOVER_194_0.M[3089]++;
        __CLOVER_194_0.S[12849]++;_enhancer = enhancer;
    } finally { }}

    /** @since 3.1 */

    public void setComponentResolver(ComponentSpecificationResolver resolver)
    {try { __CLOVER_194_0.M[3090]++;
        __CLOVER_194_0.S[12850]++;_componentResolver = resolver;
    } finally { }}

    /** @since 3.1 */

    public void setContext(ServletContext context)
    {try { __CLOVER_194_0.M[3091]++;
        __CLOVER_194_0.S[12851]++;_context = context;
    } finally { }}

    /** @since 3.1 */

    public void setDefaultPageClassName(String string)
    {try { __CLOVER_194_0.M[3092]++;
        __CLOVER_194_0.S[12852]++;_defaultPageClassName = string;
    } finally { }}

    /** @since 3.1 */

    public void setDefaultScriptLanguage(String string)
    {try { __CLOVER_194_0.M[3093]++;
        __CLOVER_194_0.S[12853]++;_defaultScriptLanguage = string;
    } finally { }}

    /** @since 3.1 */

    public void setBindingSource(BindingSource bindingSource)
    {try { __CLOVER_194_0.M[3094]++;
        __CLOVER_194_0.S[12854]++;_bindingSource = bindingSource;
    } finally { }}

    /**
     * @since 3.1
     */
    public void setComponentTemplateLoader(ComponentTemplateLoader componentTemplateLoader)
    {try { __CLOVER_194_0.M[3095]++;
        __CLOVER_194_0.S[12855]++;_componentTemplateLoader = componentTemplateLoader;
    } finally { }}

    /** @since 3.1 */
    public void setEstablishDefaultParameterValuesVisitor(
            IComponentVisitor establishDefaultParameterValuesVisitor)
    {try { __CLOVER_194_0.M[3096]++;
        __CLOVER_194_0.S[12856]++;_establishDefaultParameterValuesVisitor = establishDefaultParameterValuesVisitor;
    } finally { }}
   
    /** @since 3.1 */
    public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator)
    {try { __CLOVER_194_0.M[3097]++;
        __CLOVER_194_0.S[12857]++;_expressionEvaluator = expressionEvaluator;
    } finally { }}
}
TOP

Related Classes of org.apache.tapestry.pageload.PageLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.