Package org.apache.tapestry

Source Code of org.apache.tapestry.AbstractComponent

/* $$ 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;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import ognl.OgnlRuntime;

import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Messages;
import org.apache.hivemind.impl.BaseLocatable;
import org.apache.hivemind.util.PropertyUtils;
import org.apache.tapestry.bean.BeanProvider;
import org.apache.tapestry.bean.BeanProviderPropertyAccessor;
import org.apache.tapestry.engine.IPageLoader;
import org.apache.tapestry.event.ChangeObserver;
import org.apache.tapestry.event.PageDetachListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.event.PageRenderListener;
import org.apache.tapestry.event.PageValidateListener;
import org.apache.tapestry.listener.ListenerMap;
import org.apache.tapestry.param.ParameterManager;
import org.apache.tapestry.spec.IComponentSpecification;

/**
* Abstract base class implementing the {@link IComponent}interface.
*
* @author Howard Lewis Ship
*/

public abstract class AbstractComponent extends BaseLocatable implements IComponent
{public static com.cortexeb.tools.clover.d __CLOVER_0_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);
    /**
     * Used to check that subclasses invoke this implementation of prepareForRender().
     *
     * @see Tapestry#checkMethodInvocation(Object, String, Object)
     * @since 3.0
     */
    private final static String PREPAREFORRENDER_METHOD_ID = "AbstractComponent.prepareForRender()";

    /**
     * Used to check that subclasses invoke this implementation of cleanupAfterRender().
     *
     * @see Tapestry#checkMethodInvocation(Object, String, Object)
     * @since 3.0
     */

    private final static String CLEANUPAFTERRENDER_METHOD_ID = "AbstractComponent.cleanupAfterRender()";

    static
    {
        // Register the BeanProviderHelper to provide access to the
        // beans of a bean provider as named properties.
        // TODO: move this into some kind of HiveMind configuration.

        __CLOVER_0_0.S[11625]++;OgnlRuntime.setPropertyAccessor(IBeanProvider.class, new BeanProviderPropertyAccessor());
    }

    /**
     * The specification used to originally build the component.
     */

    private IComponentSpecification _specification;

    /**
     * The page that contains the component, possibly itself (if the component is in fact, a page).
     */

    private IPage _page;

    /**
     * The component which contains the component. This will only be null if the component is
     * actually a page.
     */

    private IComponent _container;

    /**
     * The simple id of this component.
     */

    private String _id;

    /**
     * The fully qualified id of this component. This is calculated the first time it is needed,
     * then cached for later.
     */

    private String _idPath;

    private static final int MAP_SIZE = 5;

    /**
     * A {@link Map}of all bindings (for which there isn't a corresponding JavaBeans property); the
     * keys are the names of formal and informal parameters.
     */

    private Map _bindings;

    private Map _components;

    private static final int BODY_INIT_SIZE = 5;

    private INamespace _namespace;

    /**
     * Used in place of JDK 1.3's Collections.EMPTY_MAP (which is not available in JDK 1.2).
     */

    private static final Map EMPTY_MAP = Collections.unmodifiableMap(new HashMap(1));

    /**
     * The number of {@link IRender}objects in the body of this component.
     */

    private int _bodyCount = 0;

    /**
     * An aray of elements in the body of this component.
     */

    private IRender[] _body;

    /**
     * The components' asset map.
     */

    private Map _assets;

    /**
     * A mapping that allows public instance methods to be dressed up as {@link IActionListener}
     * listener objects.
     *
     * @since 1.0.2
     */

    private ListenerMap _listeners;

    /**
     * A bean provider; these are lazily created as needed.
     *
     * @since 1.0.4
     */

    private IBeanProvider _beans;

    /**
     * Manages setting and clearing parameter properties for the component.
     *
     * @since 2.0.3
     */

    private ParameterManager _parameterManager;

    /**
     * Provides access to localized Strings for this component.
     *
     * @since 2.0.4
     */

    private Messages _strings;

    public void addAsset(String name, IAsset asset)
    {try { __CLOVER_0_0.M[2826]++;
        __CLOVER_0_0.S[11626]++;if ((((_assets == null) && (++__CLOVER_0_0.CT[1986] != 0)) || (++__CLOVER_0_0.CF[1986] == 0))){
            __CLOVER_0_0.S[11627]++;_assets = new HashMap(MAP_SIZE);}

        __CLOVER_0_0.S[11628]++;_assets.put(name, asset);
    } finally { }}

    public void addComponent(IComponent component)
    {try { __CLOVER_0_0.M[2827]++;
        __CLOVER_0_0.S[11629]++;if ((((_components == null) && (++__CLOVER_0_0.CT[1987] != 0)) || (++__CLOVER_0_0.CF[1987] == 0))){
            __CLOVER_0_0.S[11630]++;_components = new HashMap(MAP_SIZE);}

        __CLOVER_0_0.S[11631]++;_components.put(component.getId(), component);
    } finally { }}

    /**
     * Adds an element (which may be static text or a component) as a body element of this
     * component. Such elements are rendered by {@link #renderBody(IMarkupWriter, IRequestCycle)}.
     *
     * @since 2.2
     */

    public void addBody(IRender element)
    {try { __CLOVER_0_0.M[2828]++;
        // Should check the specification to see if this component
        // allows body. Curently, this is checked by the component
        // in render(), which is silly.

        __CLOVER_0_0.S[11632]++;if ((((_body == null) && (++__CLOVER_0_0.CT[1988] != 0)) || (++__CLOVER_0_0.CF[1988] == 0))){
        {
            __CLOVER_0_0.S[11633]++;_body = new IRender[BODY_INIT_SIZE];
            __CLOVER_0_0.S[11634]++;_body[0] = element;

            __CLOVER_0_0.S[11635]++;_bodyCount = 1;
            __CLOVER_0_0.S[11636]++;return;
        }}

        // No more room? Make the array bigger.

        __CLOVER_0_0.S[11637]++;if ((((_bodyCount == _body.length) && (++__CLOVER_0_0.CT[1989] != 0)) || (++__CLOVER_0_0.CF[1989] == 0))){
        {
            __CLOVER_0_0.S[11638]++;IRender[] newWrapped;

            __CLOVER_0_0.S[11639]++;newWrapped = new IRender[_body.length * 2];

            __CLOVER_0_0.S[11640]++;System.arraycopy(_body, 0, newWrapped, 0, _bodyCount);

            __CLOVER_0_0.S[11641]++;_body = newWrapped;
        }}

        __CLOVER_0_0.S[11642]++;_body[_bodyCount++] = element;
    } finally { }}

    /**
     * Registers this component as a listener of the page if it implements
     * {@link org.apache.tapestry.event.PageDetachListener}or
     * {@link org.apache.tapestry.event.PageRenderListener}.
     * <p>
     * Invokes {@link #finishLoad()}. Subclasses may overide as needed, but must invoke this
     * implementation. {@link BaseComponent}loads its HTML template.
     */

    public void finishLoad(IRequestCycle cycle, IPageLoader loader,
            IComponentSpecification specification)
    {try { __CLOVER_0_0.M[2829]++;
        __CLOVER_0_0.S[11643]++;if ((((this instanceof PageDetachListener) && (++__CLOVER_0_0.CT[1990] != 0)) || (++__CLOVER_0_0.CF[1990] == 0))){
            __CLOVER_0_0.S[11644]++;_page.addPageDetachListener((PageDetachListener) this);}

        __CLOVER_0_0.S[11645]++;if ((((this instanceof PageRenderListener) && (++__CLOVER_0_0.CT[1991] != 0)) || (++__CLOVER_0_0.CF[1991] == 0))){
            __CLOVER_0_0.S[11646]++;_page.addPageRenderListener((PageRenderListener) this);}

        __CLOVER_0_0.S[11647]++;if ((((this instanceof PageValidateListener) && (++__CLOVER_0_0.CT[1992] != 0)) || (++__CLOVER_0_0.CF[1992] == 0))){
            __CLOVER_0_0.S[11648]++;_page.addPageValidateListener((PageValidateListener) this);}

        __CLOVER_0_0.S[11649]++;finishLoad();
    } finally { }}

    /**
     * Converts informal parameters into additional attributes on the curently open tag.
     * <p>
     * Invoked from subclasses to allow additional attributes to be specified within a tag (this
     * works best when there is a one-to-one corespondence between an {@link IComponent}and a HTML
     * element.
     * <p>
     * Iterates through the bindings for this component. Filters out bindings when the name matches
     * a formal parameter (as of 1.0.5, informal bindings are weeded out at page load / template
     * load time, if they match a formal parameter, or a specificied reserved name). For the most
     * part, all the bindings here are either informal parameter, or formal parameter without a
     * corresponding JavaBeans property.
     * <p>
     * For each acceptible key, the value is extracted using {@link IBinding#getObject()}. If the
     * value is null, no attribute is written.
     * <p>
     * If the value is an instance of {@link IAsset}, then {@link IAsset#buildURL(IRequestCycle)}
     * is invoked to convert the asset to a URL.
     * <p>
     * Finally, {@link IMarkupWriter#attribute(String,String)}is invoked with the value (or the
     * URL).
     * <p>
     * The most common use for informal parameters is to support the HTML class attribute (for use
     * with cascading style sheets) and to specify JavaScript event handlers.
     * <p>
     * Components are only required to generate attributes on the result phase; this can be skipped
     * during the rewind phase.
     */

    protected void renderInformalParameters(IMarkupWriter writer, IRequestCycle cycle)
    {try { __CLOVER_0_0.M[2830]++;
        __CLOVER_0_0.S[11650]++;String attribute;

        __CLOVER_0_0.S[11651]++;if ((((_bindings == null) && (++__CLOVER_0_0.CT[1993] != 0)) || (++__CLOVER_0_0.CF[1993] == 0))){
            __CLOVER_0_0.S[11652]++;return;}

        __CLOVER_0_0.S[11653]++;Iterator i = _bindings.entrySet().iterator();

        __CLOVER_0_0.S[11654]++;while ((((i.hasNext()) && (++__CLOVER_0_0.CT[1994] != 0)) || (++__CLOVER_0_0.CF[1994] == 0))){
        {
            __CLOVER_0_0.S[11655]++;Map.Entry entry = (Map.Entry) i.next();
            __CLOVER_0_0.S[11656]++;String name = (String) entry.getKey();

            __CLOVER_0_0.S[11657]++;IBinding binding = (IBinding) entry.getValue();

            __CLOVER_0_0.S[11658]++;Object value = binding.getObject();
            __CLOVER_0_0.S[11659]++;if ((((value == null) && (++__CLOVER_0_0.CT[1995] != 0)) || (++__CLOVER_0_0.CF[1995] == 0))){
                __CLOVER_0_0.S[11660]++;continue;}

            __CLOVER_0_0.S[11661]++;if ((((value instanceof IAsset) && (++__CLOVER_0_0.CT[1996] != 0)) || (++__CLOVER_0_0.CF[1996] == 0))){
            {
                __CLOVER_0_0.S[11662]++;IAsset asset = (IAsset) value;

                // Get the URL of the asset and insert that.

                __CLOVER_0_0.S[11663]++;attribute = asset.buildURL(cycle);
            }}
            else{
                __CLOVER_0_0.S[11664]++;attribute = value.toString();}

            __CLOVER_0_0.S[11665]++;writer.attribute(name, attribute);
        }}

    } finally { }}

    /**
     * Returns an object used to resolve classes.
     *
     * @since 3.0
     */
    private ClassResolver getClassResolver()
    {try { __CLOVER_0_0.M[2831]++;
        __CLOVER_0_0.S[11666]++;return getPage().getEngine().getClassResolver();
    } finally { }}

    /**
     * Returns the named binding, or null if it doesn't exist.
     * <p>
     * This method looks for a JavaBeans property with an appropriate name, of type {@link IBinding}.
     * The property should be named <code><i>name</i>Binding</code>. If it exists and is both
     * readable and writable, then it is accessor method is invoked. Components which implement such
     * methods can access their own binding through their instance variables instead of invoking
     * this method, a performance optimization.
     *
     * @see #setBinding(String,IBinding)
     */

    public IBinding getBinding(String name)
    {try { __CLOVER_0_0.M[2832]++;
        __CLOVER_0_0.S[11667]++;String bindingPropertyName = name + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;

        __CLOVER_0_0.S[11668]++;if ((((PropertyUtils.isReadable(this, bindingPropertyName)
                && PropertyUtils.getPropertyType(this, bindingPropertyName).equals(IBinding.class)) && (++__CLOVER_0_0.CT[1997] != 0)) || (++__CLOVER_0_0.CF[1997] == 0))){
        {
            __CLOVER_0_0.S[11669]++;return (IBinding) PropertyUtils.read(this, bindingPropertyName);
        }}

        __CLOVER_0_0.S[11670]++;if ((((_bindings == null) && (++__CLOVER_0_0.CT[1998] != 0)) || (++__CLOVER_0_0.CF[1998] == 0))){
            __CLOVER_0_0.S[11671]++;return null;}

        __CLOVER_0_0.S[11672]++;return (IBinding) _bindings.get(name);
    } finally { }}

    /**
     * Return's the page's change observer. In practical terms, this will be an
     * {@link org.apache.tapestry.engine.IPageRecorder}.
     *
     * @see IPage#getChangeObserver()
     * @deprecated To be removed in 3.1; use {@link IPage#getChangeObserver()}.
     */

    public ChangeObserver getChangeObserver()
    {try { __CLOVER_0_0.M[2833]++;
        __CLOVER_0_0.S[11673]++;return _page.getChangeObserver();
    } finally { }}

    public IComponent getComponent(String id)
    {try { __CLOVER_0_0.M[2834]++;
        __CLOVER_0_0.S[11674]++;IComponent result = null;

        __CLOVER_0_0.S[11675]++;if ((((_components != null) && (++__CLOVER_0_0.CT[1999] != 0)) || (++__CLOVER_0_0.CF[1999] == 0))){
            __CLOVER_0_0.S[11676]++;result = (IComponent) _components.get(id);}

        __CLOVER_0_0.S[11677]++;if ((((result == null) && (++__CLOVER_0_0.CT[2000] != 0)) || (++__CLOVER_0_0.CF[2000] == 0))){
            __CLOVER_0_0.S[11678]++;throw new ApplicationRuntimeException(Tapestry.format("no-such-component", this, id),
                    this, null, null);}

        __CLOVER_0_0.S[11679]++;return result;
    } finally { }}

    public IComponent getContainer()
    {try { __CLOVER_0_0.M[2835]++;
        __CLOVER_0_0.S[11680]++;return _container;
    } finally { }}

    public void setContainer(IComponent value)
    {try { __CLOVER_0_0.M[2836]++;
        __CLOVER_0_0.S[11681]++;if ((((_container != null) && (++__CLOVER_0_0.CT[2001] != 0)) || (++__CLOVER_0_0.CF[2001] == 0))){
            __CLOVER_0_0.S[11682]++;throw new ApplicationRuntimeException(Tapestry
                    .getMessage("AbstractComponent.attempt-to-change-container"));}

        __CLOVER_0_0.S[11683]++;_container = value;
    } finally { }}

    /**
     * Returns the name of the page, a slash, and this component's id path. Pages are different,
     * they simply return their name.
     *
     * @see #getIdPath()
     */

    public String getExtendedId()
    {try { __CLOVER_0_0.M[2837]++;
        __CLOVER_0_0.S[11684]++;if ((((_page == null) && (++__CLOVER_0_0.CT[2002] != 0)) || (++__CLOVER_0_0.CF[2002] == 0))){
            __CLOVER_0_0.S[11685]++;return null;}

        __CLOVER_0_0.S[11686]++;return _page.getPageName() + "/" + getIdPath();
    } finally { }}

    public String getId()
    {try { __CLOVER_0_0.M[2838]++;
        __CLOVER_0_0.S[11687]++;return _id;
    } finally { }}

    public void setId(String value)
    {try { __CLOVER_0_0.M[2839]++;
        __CLOVER_0_0.S[11688]++;if ((((_id != null) && (++__CLOVER_0_0.CT[2003] != 0)) || (++__CLOVER_0_0.CF[2003] == 0))){
            __CLOVER_0_0.S[11689]++;throw new ApplicationRuntimeException(Tapestry
                    .getMessage("AbstractComponent.attempt-to-change-component-id"));}

        __CLOVER_0_0.S[11690]++;_id = value;
    } finally { }}

    public String getIdPath()
    {try { __CLOVER_0_0.M[2840]++;
        __CLOVER_0_0.S[11691]++;String containerIdPath;

        __CLOVER_0_0.S[11692]++;if ((((_container == null) && (++__CLOVER_0_0.CT[2004] != 0)) || (++__CLOVER_0_0.CF[2004] == 0))){
            __CLOVER_0_0.S[11693]++;throw new NullPointerException(Tapestry
                    .format("AbstractComponent.null-container", this));}

        __CLOVER_0_0.S[11694]++;containerIdPath = _container.getIdPath();

        __CLOVER_0_0.S[11695]++;if ((((containerIdPath == null) && (++__CLOVER_0_0.CT[2005] != 0)) || (++__CLOVER_0_0.CF[2005] == 0))){
            __CLOVER_0_0.S[11696]++;_idPath = _id;}
        else{
            __CLOVER_0_0.S[11697]++;_idPath = containerIdPath + "." + _id;}

        __CLOVER_0_0.S[11698]++;return _idPath;
    } finally { }}

    public IPage getPage()
    {try { __CLOVER_0_0.M[2841]++;
        __CLOVER_0_0.S[11699]++;return _page;
    } finally { }}

    public void setPage(IPage value)
    {try { __CLOVER_0_0.M[2842]++;
        __CLOVER_0_0.S[11700]++;if ((((_page != null) && (++__CLOVER_0_0.CT[2006] != 0)) || (++__CLOVER_0_0.CF[2006] == 0))){
            __CLOVER_0_0.S[11701]++;throw new ApplicationRuntimeException(Tapestry
                    .getMessage("AbstractComponent.attempt-to-change-page"));}

        __CLOVER_0_0.S[11702]++;_page = value;
    } finally { }}

    public IComponentSpecification getSpecification()
    {try { __CLOVER_0_0.M[2843]++;
        __CLOVER_0_0.S[11703]++;return _specification;
    } finally { }}

    public void setSpecification(IComponentSpecification value)
    {try { __CLOVER_0_0.M[2844]++;
        __CLOVER_0_0.S[11704]++;if ((((_specification != null) && (++__CLOVER_0_0.CT[2007] != 0)) || (++__CLOVER_0_0.CF[2007] == 0))){
            __CLOVER_0_0.S[11705]++;throw new ApplicationRuntimeException(Tapestry
                    .getMessage("AbstractComponent.attempt-to-change-spec"));}

        __CLOVER_0_0.S[11706]++;_specification = value;
    } finally { }}

    /**
     * Renders all elements wrapped by the receiver.
     */

    public void renderBody(IMarkupWriter writer, IRequestCycle cycle)
    {try { __CLOVER_0_0.M[2845]++;
        __CLOVER_0_0.S[11707]++;for (int i = 0; (((i < _bodyCount) && (++__CLOVER_0_0.CT[2008] != 0)) || (++__CLOVER_0_0.CF[2008] == 0)); i++){
            __CLOVER_0_0.S[11708]++;_body[i].render(writer, cycle);}
    } finally { }}

    /**
     * Adds the binding with the given name, replacing any existing binding with that name.
     * <p>
     * This method checks to see if a matching JavaBeans property (with a name of
     * <code><i>name</i>Binding</code> and a type of {@link IBinding}) exists. If so, that
     * property is updated. An optimized component can simply implement accessor and mutator methods
     * and then access its bindings via its own instance variables, rather than going through {@link
     * #getBinding(String)}.
     * <p>
     * Informal parameters should <em>not</em> be stored in instance variables if {@link
     * #renderInformalParameters(IMarkupWriter, IRequestCycle)} is to be used. It relies on using
     * the collection of bindings (to store informal parameters).
     */

    public void setBinding(String name, IBinding binding)
    {try { __CLOVER_0_0.M[2846]++;
        __CLOVER_0_0.S[11709]++;String bindingPropertyName = name + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;

        __CLOVER_0_0.S[11710]++;if ((((PropertyUtils.isWritable(this, bindingPropertyName)
                && PropertyUtils.getPropertyType(this, bindingPropertyName).equals(IBinding.class)) && (++__CLOVER_0_0.CT[2009] != 0)) || (++__CLOVER_0_0.CF[2009] == 0))){
        {
            __CLOVER_0_0.S[11711]++;PropertyUtils.write(this, bindingPropertyName, binding);
            __CLOVER_0_0.S[11712]++;return;
        }}

        __CLOVER_0_0.S[11713]++;if ((((_bindings == null) && (++__CLOVER_0_0.CT[2010] != 0)) || (++__CLOVER_0_0.CF[2010] == 0))){
            __CLOVER_0_0.S[11714]++;_bindings = new HashMap(MAP_SIZE);}

        __CLOVER_0_0.S[11715]++;_bindings.put(name, binding);
    } finally { }}

    public String toString()
    {try { __CLOVER_0_0.M[2847]++;
        __CLOVER_0_0.S[11716]++;StringBuffer buffer;

        __CLOVER_0_0.S[11717]++;buffer = new StringBuffer(super.toString());

        __CLOVER_0_0.S[11718]++;buffer.append('[');

        __CLOVER_0_0.S[11719]++;buffer.append(getExtendedId());

        __CLOVER_0_0.S[11720]++;buffer.append(']');

        __CLOVER_0_0.S[11721]++;return buffer.toString();
    } finally { }}

    /**
     * Returns an unmodifiable {@link Map}of components, keyed on component id. Never returns null,
     * but may return an empty map. The returned map is immutable.
     */

    public Map getComponents()
    {try { __CLOVER_0_0.M[2848]++;
        __CLOVER_0_0.S[11722]++;if ((((_components == null) && (++__CLOVER_0_0.CT[2011] != 0)) || (++__CLOVER_0_0.CF[2011] == 0))){
            __CLOVER_0_0.S[11723]++;return EMPTY_MAP;}

        __CLOVER_0_0.S[11724]++;return Collections.unmodifiableMap(_components);

    } finally { }}

    public Map getAssets()
    {try { __CLOVER_0_0.M[2849]++;
        __CLOVER_0_0.S[11725]++;if ((((_assets == null) && (++__CLOVER_0_0.CT[2012] != 0)) || (++__CLOVER_0_0.CF[2012] == 0))){
            __CLOVER_0_0.S[11726]++;return EMPTY_MAP;}

        __CLOVER_0_0.S[11727]++;return Collections.unmodifiableMap(_assets);
    } finally { }}

    public IAsset getAsset(String name)
    {try { __CLOVER_0_0.M[2850]++;
        __CLOVER_0_0.S[11728]++;if ((((_assets == null) && (++__CLOVER_0_0.CT[2013] != 0)) || (++__CLOVER_0_0.CF[2013] == 0))){
            __CLOVER_0_0.S[11729]++;return null;}

        __CLOVER_0_0.S[11730]++;return (IAsset) _assets.get(name);
    } finally { }}

    public Collection getBindingNames()
    {try { __CLOVER_0_0.M[2851]++;
        // If no conainer, i.e. a page, then no bindings.

        __CLOVER_0_0.S[11731]++;if ((((_container == null) && (++__CLOVER_0_0.CT[2014] != 0)) || (++__CLOVER_0_0.CF[2014] == 0))){
            __CLOVER_0_0.S[11732]++;return null;}

        __CLOVER_0_0.S[11733]++;HashSet result = new HashSet();

        // All the informal bindings go into the bindings Map.

        __CLOVER_0_0.S[11734]++;if ((((_bindings != null) && (++__CLOVER_0_0.CT[2015] != 0)) || (++__CLOVER_0_0.CF[2015] == 0))){
            __CLOVER_0_0.S[11735]++;result.addAll(_bindings.keySet());}

        // Now, iterate over the formal parameters and add the formal parameters
        // that have a binding.

        __CLOVER_0_0.S[11736]++;List names = _specification.getParameterNames();

        __CLOVER_0_0.S[11737]++;int count = names.size();

        __CLOVER_0_0.S[11738]++;for (int i = 0; (((i < count) && (++__CLOVER_0_0.CT[2016] != 0)) || (++__CLOVER_0_0.CF[2016] == 0)); i++){
        {
            __CLOVER_0_0.S[11739]++;String name = (String) names.get(i);

            __CLOVER_0_0.S[11740]++;if ((((result.contains(name)) && (++__CLOVER_0_0.CT[2017] != 0)) || (++__CLOVER_0_0.CF[2017] == 0))){
                __CLOVER_0_0.S[11741]++;continue;}

            __CLOVER_0_0.S[11742]++;if ((((getBinding(name) != null) && (++__CLOVER_0_0.CT[2018] != 0)) || (++__CLOVER_0_0.CF[2018] == 0))){
                __CLOVER_0_0.S[11743]++;result.add(name);}
        }}

        __CLOVER_0_0.S[11744]++;return result;
    } finally { }}

    /**
     * Returns a {@link Map}of all bindings for this component. This implementation is expensive,
     * since it has to merge the disassociated bindings (informal parameters, and parameters without
     * a JavaBeans property) with the associated bindings (formal parameters with a JavaBeans
     * property).
     *
     * @since 1.0.5
     */

    public Map getBindings()
    {try { __CLOVER_0_0.M[2852]++;
        __CLOVER_0_0.S[11745]++;Map result = new HashMap();

        // Add any informal parameters.

        __CLOVER_0_0.S[11746]++;if ((((_bindings != null) && (++__CLOVER_0_0.CT[2019] != 0)) || (++__CLOVER_0_0.CF[2019] == 0))){
            __CLOVER_0_0.S[11747]++;result.putAll(_bindings);}

        // Now work on the formal parameters

        __CLOVER_0_0.S[11748]++;Iterator i = _specification.getParameterNames().iterator();
        __CLOVER_0_0.S[11749]++;while ((((i.hasNext()) && (++__CLOVER_0_0.CT[2020] != 0)) || (++__CLOVER_0_0.CF[2020] == 0))){
        {
            __CLOVER_0_0.S[11750]++;String name = (String) i.next();

            __CLOVER_0_0.S[11751]++;if ((((result.containsKey(name)) && (++__CLOVER_0_0.CT[2021] != 0)) || (++__CLOVER_0_0.CF[2021] == 0))){
                __CLOVER_0_0.S[11752]++;continue;}

            __CLOVER_0_0.S[11753]++;IBinding binding = getBinding(name);

            __CLOVER_0_0.S[11754]++;if ((((binding != null) && (++__CLOVER_0_0.CT[2022] != 0)) || (++__CLOVER_0_0.CF[2022] == 0))){
                __CLOVER_0_0.S[11755]++;result.put(name, binding);}
        }}

        __CLOVER_0_0.S[11756]++;return result;
    } finally { }}

    /**
     * Returns a {@link ListenerMap}for the component. A {@link ListenerMap}contains a number of
     * synthetic read-only properties that implement the {@link IActionListener}interface, but in
     * fact, cause public instance methods to be invoked.
     *
     * @since 1.0.2
     */

    public ListenerMap getListeners()
    {try { __CLOVER_0_0.M[2853]++;
        __CLOVER_0_0.S[11757]++;if ((((_listeners == null) && (++__CLOVER_0_0.CT[2023] != 0)) || (++__CLOVER_0_0.CF[2023] == 0))){
            __CLOVER_0_0.S[11758]++;_listeners = new ListenerMap(this);}

        __CLOVER_0_0.S[11759]++;return _listeners;
    } finally { }}

    /**
     * Returns the {@link IBeanProvider}for this component. This is lazily created the first time
     * it is needed.
     *
     * @since 1.0.4
     */

    public IBeanProvider getBeans()
    {try { __CLOVER_0_0.M[2854]++;
        __CLOVER_0_0.S[11760]++;if ((((_beans == null) && (++__CLOVER_0_0.CT[2024] != 0)) || (++__CLOVER_0_0.CF[2024] == 0))){
            __CLOVER_0_0.S[11761]++;_beans = new BeanProvider(this);}

        __CLOVER_0_0.S[11762]++;return _beans;
    } finally { }}

    /**
     * Invoked, as a convienience, from
     * {@link #finishLoad(IRequestCycle, IPageLoader, IComponentSpecification)}. This implemenation
     * does nothing. Subclasses may override without invoking this implementation.
     *
     * @since 1.0.5
     */

    protected void finishLoad()
    {try { __CLOVER_0_0.M[2855]++;
    } finally { }}

    /**
     * The main method used to render the component. Invokes
     * {@link #prepareForRender(IRequestCycle)}, then
     * {@link #renderComponent(IMarkupWriter, IRequestCycle)}.
     * {@link #cleanupAfterRender(IRequestCycle)}is invoked in a <code>finally</code> block.
     * <p>
     * Subclasses should not override this method; instead they will implement
     * {@link #renderComponent(IMarkupWriter, IRequestCycle)}.
     *
     * @since 2.0.3
     */

    public final void render(IMarkupWriter writer, IRequestCycle cycle)
    {try { __CLOVER_0_0.M[2856]++;
        __CLOVER_0_0.S[11763]++;try
        {
            __CLOVER_0_0.S[11764]++;Tapestry.clearMethodInvocations();

            __CLOVER_0_0.S[11765]++;prepareForRender(cycle);

            __CLOVER_0_0.S[11766]++;Tapestry.checkMethodInvocation(PREPAREFORRENDER_METHOD_ID, "prepareForRender()", this);

            __CLOVER_0_0.S[11767]++;renderComponent(writer, cycle);
        }
        finally
        {
            __CLOVER_0_0.S[11768]++;Tapestry.clearMethodInvocations();

            __CLOVER_0_0.S[11769]++;cleanupAfterRender(cycle);

            __CLOVER_0_0.S[11770]++;Tapestry.checkMethodInvocation(
                    CLEANUPAFTERRENDER_METHOD_ID,
                    "cleanupAfterRender()",
                    this);
        }
    } finally { }}

    /**
     * Invoked by {@link #render(IMarkupWriter, IRequestCycle)}to prepare the component to render.
     * This implementation sets JavaBeans properties from matching bound parameters. Subclasses that
     * override this method must invoke this implementation as well.
     *
     * @since 2.0.3
     */

    protected void prepareForRender(IRequestCycle cycle)
    {try { __CLOVER_0_0.M[2857]++;
        __CLOVER_0_0.S[11771]++;Tapestry.addMethodInvocation(PREPAREFORRENDER_METHOD_ID);

        __CLOVER_0_0.S[11772]++;if ((((_parameterManager == null) && (++__CLOVER_0_0.CT[2025] != 0)) || (++__CLOVER_0_0.CF[2025] == 0))){
        {
            // Pages inherit from this class too, but pages (by definition)
            // never have parameters.

            __CLOVER_0_0.S[11773]++;if ((((getSpecification().isPageSpecification()) && (++__CLOVER_0_0.CT[2026] != 0)) || (++__CLOVER_0_0.CF[2026] == 0))){
                __CLOVER_0_0.S[11774]++;return;}

            __CLOVER_0_0.S[11775]++;_parameterManager = new ParameterManager(this);
        }}

        __CLOVER_0_0.S[11776]++;_parameterManager.setParameters(cycle);
    } finally { }}

    /**
     * Invoked by {@link #render(IMarkupWriter, IRequestCycle)}to actually render the component
     * (with any parameter values already set). This is the method that subclasses must implement.
     *
     * @since 2.0.3
     */

    protected abstract void renderComponent(IMarkupWriter writer, IRequestCycle cycle);

    /**
     * Invoked by {@link #render(IMarkupWriter, IRequestCycle)}after the component renders, to
     * clear any parameters back to null (or 0, or false, or whatever the correct default is).
     * Primarily, this is used to ensure that the component doesn't hold onto any objects that could
     * otherwise be garbage collected.
     * <p>
     * Subclasses may override this implementation, but must also invoke it.
     *
     * @since 2.0.3
     */

    protected void cleanupAfterRender(IRequestCycle cycle)
    {try { __CLOVER_0_0.M[2858]++;
        __CLOVER_0_0.S[11777]++;Tapestry.addMethodInvocation(CLEANUPAFTERRENDER_METHOD_ID);

        __CLOVER_0_0.S[11778]++;if ((((_parameterManager != null) && (++__CLOVER_0_0.CT[2027] != 0)) || (++__CLOVER_0_0.CF[2027] == 0))){
            __CLOVER_0_0.S[11779]++;_parameterManager.resetParameters(cycle);}
    } finally { }}

    /** @since 3.0 * */

    public Messages getMessages()
    {try { __CLOVER_0_0.M[2859]++;
        __CLOVER_0_0.S[11780]++;if ((((_strings == null) && (++__CLOVER_0_0.CT[2028] != 0)) || (++__CLOVER_0_0.CF[2028] == 0))){
            __CLOVER_0_0.S[11781]++;_strings = getPage().getEngine().getComponentMessagesSource().getMessages(this);}

        __CLOVER_0_0.S[11782]++;return _strings;
    } finally { }}

    /**
     * Obtains the {@link IMessages}for this component (if necessary), and gets the string from it.
     */

    public String getString(String key)
    {try { __CLOVER_0_0.M[2860]++;
        __CLOVER_0_0.S[11783]++;return getMessages().getMessage(key);
    } finally { }}

    public String getMessage(String key)
    {try { __CLOVER_0_0.M[2861]++;
        // Invoke the deprecated implementation (for code coverage reasons).
        // In 3.1, remove getString() and move its implementation
        // here.

        __CLOVER_0_0.S[11784]++;return getString(key);
    } finally { }}

    /**
     * Formats a message string, using
     * {@link IMessages#format(java.lang.String, java.lang.Object[])}.
     *
     * @param key
     *            the key used to obtain a localized pattern using {@link #getString(String)}
     * @param arguments
     *            passed to the formatter
     * @since 2.2
     * @deprecated To be removed in 3.1. Use {@link #format(String, Object[])}instead.
     */

    public String formatString(String key, Object[] arguments)
    {try { __CLOVER_0_0.M[2862]++;
        __CLOVER_0_0.S[11785]++;return getMessages().format(key, arguments);
    } finally { }}

    /**
     * Formats a localized message string, using
     * {@link IMessages#format(java.lang.String, java.lang.Object[])}.
     *
     * @param key
     *            the key used to obtain a localized pattern using {@link #getString(String)}
     * @param arguments
     *            passed to the formatter
     * @since 3.0
     */

    public String format(String key, Object[] arguments)
    {try { __CLOVER_0_0.M[2863]++;
        // SOP: New name invokes deprecated method (consistency and
        // code coverage); in 3.1 we move the implementation here.

        __CLOVER_0_0.S[11786]++;return formatString(key, arguments);
    } finally { }}

    /**
     * Convienience method for invoking {@link IMessages#format(String, Object[])}
     *
     * @since 2.2
     * @deprecated To be removed in 3.1. Use {@link #format(String, Object)}instead.
     */

    public String formatString(String key, Object argument)
    {try { __CLOVER_0_0.M[2864]++;
        __CLOVER_0_0.S[11787]++;return getMessages().format(key, argument);
    } finally { }}

    /**
     * Convienience method for invoking {@link IMessages#format(String, Object)}
     *
     * @since 3.0
     */

    public String format(String key, Object argument)
    {try { __CLOVER_0_0.M[2865]++;
        __CLOVER_0_0.S[11788]++;return formatString(key, argument);
    } finally { }}

    /**
     * Convienience method for invoking {@link IMessages#format(String, Object, Object)}.
     *
     * @since 2.2
     * @deprecated To be removed in 3.1. Use {@link #format(String, Object, Object)}instead.
     */

    public String formatString(String key, Object argument1, Object argument2)
    {try { __CLOVER_0_0.M[2866]++;
        __CLOVER_0_0.S[11789]++;return getMessages().format(key, argument1, argument2);
    } finally { }}

    /**
     * Convienience method for invoking {@link IMessages#format(String, Object, Object)}.
     *
     * @since 3.0
     */

    public String format(String key, Object argument1, Object argument2)
    {try { __CLOVER_0_0.M[2867]++;
        __CLOVER_0_0.S[11790]++;return formatString(key, argument1, argument2);
    } finally { }}

    /**
     * Convienience method for {@link IMessages#format(String, Object, Object, Object)}.
     *
     * @since 2.2
     * @deprecated To be removed in 3.1. Use {@link #format(String, Object, Object, Object)}
     *             instead.
     */

    public String formatString(String key, Object argument1, Object argument2, Object argument3)
    {try { __CLOVER_0_0.M[2868]++;
        __CLOVER_0_0.S[11791]++;return getMessages().format(key, argument1, argument2, argument3);
    } finally { }}

    /**
     * Convienience method for {@link IMessages#format(String, Object, Object, Object)}.
     *
     * @since 3.0
     */

    public String format(String key, Object argument1, Object argument2, Object argument3)
    {try { __CLOVER_0_0.M[2869]++;
        __CLOVER_0_0.S[11792]++;return formatString(key, argument1, argument2, argument3);
    } finally { }}

    public INamespace getNamespace()
    {try { __CLOVER_0_0.M[2870]++;
        __CLOVER_0_0.S[11793]++;return _namespace;
    } finally { }}

    public void setNamespace(INamespace namespace)
    {try { __CLOVER_0_0.M[2871]++;
        __CLOVER_0_0.S[11794]++;_namespace = namespace;
    } finally { }}

    /**
     * Returns the body of the component, the element (which may be static HTML or components) that
     * the component immediately wraps. May return null. Do not modify the returned array. The array
     * may be padded with nulls.
     *
     * @since 2.3
     * @see #getBodyCount()
     */

    public IRender[] getBody()
    {try { __CLOVER_0_0.M[2872]++;
        __CLOVER_0_0.S[11795]++;return _body;
    } finally { }}

    /**
     * Returns the active number of elements in the the body, which may be zero.
     *
     * @since 2.3
     * @see #getBody()
     */

    public int getBodyCount()
    {try { __CLOVER_0_0.M[2873]++;
        __CLOVER_0_0.S[11796]++;return _bodyCount;
    } finally { }}

    /**
     * Empty implementation of
     * {@link org.apache.tapestry.event.PageRenderListener#pageEndRender(PageEvent)}. This allows
     * classes to implement {@link org.apache.tapestry.event.PageRenderListener}and only implement
     * the {@link org.apache.tapestry.event.PageRenderListener#pageBeginRender(PageEvent)}method.
     *
     * @since 3.0
     */

    public void pageEndRender(PageEvent event)
    {try { __CLOVER_0_0.M[2874]++;
    } finally { }}

    /**
     * Sets a property of a component.
     *
     * @see IComponent
     * @since 3.0
     */
    public void setProperty(String propertyName, Object value)
    {try { __CLOVER_0_0.M[2875]++;
        __CLOVER_0_0.S[11797]++;PropertyUtils.write(this, propertyName, value);
    } finally { }}

    /**
     * Gets a property of a component.
     *
     * @see IComponent
     * @since 3.0
     */
    public Object getProperty(String propertyName)
    {try { __CLOVER_0_0.M[2876]++;
        __CLOVER_0_0.S[11798]++;return PropertyUtils.read(this, propertyName);
    } finally { }}
}
TOP

Related Classes of org.apache.tapestry.AbstractComponent

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.