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.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},1096998272901L);
    private Log _log = LogFactory.getLog(PageLoader.class);

    private ClassResolver _classResolver;

    private IComponentClassEnhancer _enhancer;

    private ISpecificationSource _specificationSource;

    /** @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();

    private ComponentTreeWalker _establishDefaultParameterValuesWalker;

    private ComponentTreeWalker _verifyRequiredParametersWalker;

    /**
     * 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[955]++;
        __CLOVER_194_0.S[4493]++;_applicationRoot = new ContextResource(_context, "/");

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

        __CLOVER_194_0.S[4496]++;IComponentVisitor establishDefaultParameterValuesVisitor = new EstablishDefaultParameterValuesVisitor(
                _classResolver);
        __CLOVER_194_0.S[4497]++;_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[956]++;
        __CLOVER_194_0.S[4498]++;IComponentSpecification spec = component.getSpecification();
        __CLOVER_194_0.S[4499]++;boolean formalOnly = !spec.getAllowInformalParameters();

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

        __CLOVER_194_0.S[4502]++;if ((((contained.getInheritInformalParameters()) && (++__CLOVER_194_0.CT[830] != 0)) || (++__CLOVER_194_0.CF[830] == 0))){
        {
            __CLOVER_194_0.S[4503]++;if ((((formalOnly) && (++__CLOVER_194_0.CT[831] != 0)) || (++__CLOVER_194_0.CF[831] == 0))){
                __CLOVER_194_0.S[4504]++;throw new ApplicationRuntimeException(PageloadMessages
                        .inheritInformalInvalidComponentFormalOnly(component), component, contained.getLocation(), null);}

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

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

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

        __CLOVER_194_0.S[4510]++;while ((((i.hasNext()) && (++__CLOVER_194_0.CT[833] != 0)) || (++__CLOVER_194_0.CF[833] == 0))){
        {
            __CLOVER_194_0.S[4511]++;String name = (String) i.next();

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

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

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

            __CLOVER_194_0.S[4514]++;if ((((formalOnly && !isFormal) && (++__CLOVER_194_0.CT[834] != 0)) || (++__CLOVER_194_0.CF[834] == 0))){
                __CLOVER_194_0.S[4515]++;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[4516]++;if ((((!isFormal && spec.isReservedParameterName(name)) && (++__CLOVER_194_0.CT[835] != 0)) || (++__CLOVER_194_0.CF[835] == 0))){
                __CLOVER_194_0.S[4517]++;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[4518]++;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[4519]++;if ((((type == BindingType.INHERITED) && (++__CLOVER_194_0.CT[836] != 0)) || (++__CLOVER_194_0.CF[836] == 0))){
            {
                __CLOVER_194_0.S[4520]++;QueuedInheritedBinding queued = new QueuedInheritedBinding(component, bspec.getValue(), name);
                __CLOVER_194_0.S[4521]++;_inheritedBindingQueue.add(queued);
                __CLOVER_194_0.S[4522]++;continue;
            }}

            __CLOVER_194_0.S[4523]++;if ((((type == BindingType.LISTENER) && (++__CLOVER_194_0.CT[837] != 0)) || (++__CLOVER_194_0.CF[837] == 0))){
            {
                __CLOVER_194_0.S[4524]++;constructListenerBinding(component, name, (IListenerBindingSpecification) bspec);
                __CLOVER_194_0.S[4525]++;continue;
            }}

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

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

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

        __CLOVER_194_0.S[4531]++;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[958]++;
        __CLOVER_194_0.S[4532]++;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[4533]++;if ((((Tapestry.isBlank(language)) && (++__CLOVER_194_0.CT[839] != 0)) || (++__CLOVER_194_0.CF[839] == 0))){
            __CLOVER_194_0.S[4534]++;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[4535]++;IBinding binding = new ListenerBinding(component.getContainer(), language, spec.getScript(), spec.getLocation());

        __CLOVER_194_0.S[4536]++;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[959]++;
        __CLOVER_194_0.S[4537]++;_depth++;
        __CLOVER_194_0.S[4538]++;if ((((_depth > _maxDepth) && (++__CLOVER_194_0.CT[840] != 0)) || (++__CLOVER_194_0.CF[840] == 0))){
            __CLOVER_194_0.S[4539]++;_maxDepth = _depth;}

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

        __CLOVER_194_0.S[4542]++;try
        {
            __CLOVER_194_0.S[4543]++;for (int i = 0; (((i < count) && (++__CLOVER_194_0.CT[841] != 0)) || (++__CLOVER_194_0.CF[841] == 0)); i++){
            {
                __CLOVER_194_0.S[4544]++;String id = (String) ids.get(i);

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

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

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

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

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

                // Instantiate the contained component.

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

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

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

                // Set up any bindings in the IContainedComponent specification

                __CLOVER_194_0.S[4553]++;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[4554]++;constructComponent(cycle, page, component, componentSpecification, componentNamespace);
            }}

            __CLOVER_194_0.S[4555]++;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[4556]++;container.finishLoad(cycle, this, containerSpec);

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

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

        __CLOVER_194_0.S[4560]++;_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[960]++;
        __CLOVER_194_0.S[4561]++;IPage page = container.getPage();

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

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

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

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

        // Recusively build the component.

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

        __CLOVER_194_0.S[4568]++;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[961]++;
        __CLOVER_194_0.S[4569]++;IComponent result = null;
        __CLOVER_194_0.S[4570]++;String className = spec.getComponentClassName();

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

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

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

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

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

        __CLOVER_194_0.S[4581]++;result.setNamespace(namespace);
        __CLOVER_194_0.S[4582]++;result.setSpecification(spec);
        __CLOVER_194_0.S[4583]++;result.setPage(page);
        __CLOVER_194_0.S[4584]++;result.setContainer(container);
        __CLOVER_194_0.S[4585]++;result.setId(id);
        __CLOVER_194_0.S[4586]++;result.setLocation(location);

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

        __CLOVER_194_0.S[4588]++;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[962]++;
        __CLOVER_194_0.S[4589]++;IPage result = null;

        __CLOVER_194_0.S[4590]++;String pageName = namespace.constructQualifiedName(name);
        __CLOVER_194_0.S[4591]++;String className = spec.getComponentClassName();
        __CLOVER_194_0.S[4592]++;Location location = spec.getLocation();

        __CLOVER_194_0.S[4593]++;if ((((Tapestry.isBlank(className)) && (++__CLOVER_194_0.CT[844] != 0)) || (++__CLOVER_194_0.CF[844] == 0))){
            __CLOVER_194_0.S[4594]++;className = _defaultPageClassName;}

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

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

            __CLOVER_194_0.S[4599]++;result.setNamespace(namespace);
            __CLOVER_194_0.S[4600]++;result.setSpecification(spec);
            __CLOVER_194_0.S[4601]++;result.setPageName(pageName);
            __CLOVER_194_0.S[4602]++;result.setPage(result);
            __CLOVER_194_0.S[4603]++;result.setLocale(_locale);
            __CLOVER_194_0.S[4604]++;result.setLocation(location);
        }
        catch (ClassCastException ex)
        {
            __CLOVER_194_0.S[4605]++;throw new ApplicationRuntimeException(PageloadMessages.classNotPage(enhancedClassName), location, ex);
        }
        catch (Exception ex)
        {
            __CLOVER_194_0.S[4606]++;throw new ApplicationRuntimeException(PageloadMessages.unableToInstantiate(enhancedClassName, ex),
                    location, ex);
        }

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

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

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

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

        __CLOVER_194_0.S[4611]++;_count = 0;
        __CLOVER_194_0.S[4612]++;_depth = 0;
        __CLOVER_194_0.S[4613]++;_maxDepth = 0;

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

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

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

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

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

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

            __CLOVER_194_0.S[4621]++;establishDefaultPropertyValues();
        }
        finally
        {
            __CLOVER_194_0.S[4622]++;_locale = null;
            __CLOVER_194_0.S[4623]++;_engine = null;
            __CLOVER_194_0.S[4624]++;_inheritedBindingQueue.clear();
            __CLOVER_194_0.S[4625]++;_propertyInitializers.clear();
        }

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

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

    /** @since 3.1 */
   
    public void loadTemplateForComponent(IRequestCycle cycle, ITemplateComponent component)
    {try { __CLOVER_194_0.M[964]++;
        __CLOVER_194_0.S[4629]++;_componentTemplateLoader.loadTemplate(cycle, component);
    } finally { }}

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

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

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

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

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

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

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

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

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

        __CLOVER_194_0.S[4641]++;if ((((names.isEmpty()) && (++__CLOVER_194_0.CT[848] != 0)) || (++__CLOVER_194_0.CF[848] == 0))){
            __CLOVER_194_0.S[4642]++;return;}

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

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

        __CLOVER_194_0.S[4645]++;while ((((i.hasNext()) && (++__CLOVER_194_0.CT[849] != 0)) || (++__CLOVER_194_0.CF[849] == 0))){
        {
            __CLOVER_194_0.S[4646]++;String name = (String) i.next();
            __CLOVER_194_0.S[4647]++;IAssetSpecification assetSpec = specification.getAsset(name);
            __CLOVER_194_0.S[4648]++;IAsset asset = convert(name, component, assetSpec, specLocation);

            __CLOVER_194_0.S[4649]++;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[968]++;
        __CLOVER_194_0.S[4650]++;List names = spec.getPropertySpecificationNames();
        __CLOVER_194_0.S[4651]++;int count = names.size();

        __CLOVER_194_0.S[4652]++;for (int i = 0; (((i < count) && (++__CLOVER_194_0.CT[850] != 0)) || (++__CLOVER_194_0.CF[850] == 0)); i++){
        {
            __CLOVER_194_0.S[4653]++;String name = (String) names.get(i);
            __CLOVER_194_0.S[4654]++;IPropertySpecification ps = spec.getPropertySpecification(name);
            __CLOVER_194_0.S[4655]++;String expression = ps.getInitialValue();

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

            __CLOVER_194_0.S[4657]++;_propertyInitializers.add(initializer);
            __CLOVER_194_0.S[4658]++;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[969]++;
        __CLOVER_194_0.S[4659]++;AssetType type = spec.getType();
        __CLOVER_194_0.S[4660]++;String path = spec.getPath();
        __CLOVER_194_0.S[4661]++;Location location = spec.getLocation();

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

        __CLOVER_194_0.S[4664]++;if ((((type == AssetType.PRIVATE) && (++__CLOVER_194_0.CT[852] != 0)) || (++__CLOVER_194_0.CF[852] == 0))){
        {
            __CLOVER_194_0.S[4665]++;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[4666]++;if ((((path.startsWith("/")) && (++__CLOVER_194_0.CT[853] != 0)) || (++__CLOVER_194_0.CF[853] == 0))){
            {
                __CLOVER_194_0.S[4667]++;baseLocation = new ClasspathResource(_classResolver, "/");
                __CLOVER_194_0.S[4668]++;path = path.substring(1);
            }}

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

        __CLOVER_194_0.S[4670]++;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[970]++;
        __CLOVER_194_0.S[4671]++;Resource assetLocation = baseLocation.getRelativeResource(path);
        __CLOVER_194_0.S[4672]++;Resource localizedLocation = assetLocation.getLocalization(_locale);

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

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

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

    /** @since 3.1 */

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

    /** @since 3.1 */

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

    /** @since 3.1 */

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

    /** @since 3.1 */

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

    /** @since 3.1 */

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

    /** @since 3.1 */

    public void setSpecificationSource(ISpecificationSource source)
    {try { __CLOVER_194_0.M[977]++;
        __CLOVER_194_0.S[4682]++;_specificationSource = source;
    } finally { }}

    /** @since 3.1 */

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

    /** @since 3.1 */

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

    /** @since 3.1 */

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

    /**
     * @since 3.1
     */
    public void setComponentTemplateLoader(ComponentTemplateLoader componentTemplateLoader)
    {try { __CLOVER_194_0.M[981]++;
        __CLOVER_194_0.S[4686]++;_componentTemplateLoader = componentTemplateLoader;
    } 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.