Package org.apache.tapestry

Source Code of org.apache.tapestry.AbstractPage

/* $$ 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.io.OutputStream;
import java.util.EventListener;
import java.util.Locale;

import javax.swing.event.EventListenerList;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
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.util.StringSplitter;

/**
*  Abstract base class implementing the {@link IPage} interface.
*
@author Howard Lewis Ship, David Solis
@since 0.2.9
*
**/

public abstract class AbstractPage extends BaseComponent implements IPage
{public static com.cortexeb.tools.clover.d __CLOVER_2_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 static final Log LOG = LogFactory.getLog(AbstractPage.class);

    /**
     *  Object to be notified when a observered property changes.  Observered
     *  properties are the ones that will be persisted between request cycles.
     *  Unobserved properties are reconstructed.
     *
     **/

    private ChangeObserver _changeObserver;

    /**
     *  The {@link IEngine} the page is currently attached to.
     *
     **/

    private IEngine _engine;

    /**
     *  The visit object, if any, for the application.  Set inside
     *  {@link #attach(IEngine)} and cleared
     *  by {@link #detach()}.
     *
     **/

    private Object _visit;

    /**
     *  The qualified name of the page, which may be prefixed by the
     *  namespace.
     *
     *  @since 2.3
     *
     **/

    private String _pageName;

    /**
     *  Set when the page is attached to the engine.
     *
     **/

    private IRequestCycle _requestCycle;

    /**
     *  The locale of the page, initially determined from the {@link IEngine engine}.
     *
     **/

    private Locale _locale;

    /**
     *  A list of listeners for the page.
     *  @see PageRenderListener
     *  @see PageDetachListener
     *
     *  @since 1.0.5
     **/

    private EventListenerList _listenerList;
   
   
    /**
     *  The output encoding to be used when rendering this page.
     *  This value is cached from the engine.
     *
     *  @since 3.0
     **/
    private String _outputEncoding;

    /**
     *  Standard constructor; invokes {@link #initialize()}
     *  to configure initial values for properties
     *  of the page.
     *
     *  @since 2.2
     *
     **/

    public AbstractPage()
    {try { __CLOVER_2_0.M[93]++;
        __CLOVER_2_0.S[361]++;initialize();
    } finally { }}

    /**
     *  Implemented in subclasses to provide a particular kind of
     *  response writer (and therefore, a particular kind of
     *  content).
     *
     **/

    abstract public IMarkupWriter getResponseWriter(OutputStream out);

    /**
     *  Prepares the page to be returned to the pool.
     *  <ul>
     <li>Clears the changeObserved property
     *  <li>Invokes {@link PageDetachListener#pageDetached(PageEvent)} on all listeners
     *  <li>Invokes {@link #initialize()} to clear/reset any properties 
     * <li>Clears the engine, visit and requestCycle properties
     *  </ul>
     *
     *  <p>Subclasses may override this method, but must invoke this
     *  implementation (usually, last).
     *
     **/

    public void detach()
    {try { __CLOVER_2_0.M[94]++;
      __CLOVER_2_0.S[362]++;Tapestry.addMethodInvocation(Tapestry.ABSTRACTPAGE_DETACH_METHOD_ID);
     
        // Do this first,so that any changes to persistent properties do not
        // cause errors.

        __CLOVER_2_0.S[363]++;_changeObserver = null;

        __CLOVER_2_0.S[364]++;firePageDetached();

        __CLOVER_2_0.S[365]++;initialize();

        __CLOVER_2_0.S[366]++;_engine = null;
        __CLOVER_2_0.S[367]++;_visit = null;
        __CLOVER_2_0.S[368]++;_requestCycle = null;
    } finally { }}

    /**
     *  Method invoked from the constructor, and from
     *  {@link #detach()} to (re-)initialize properties
     *  of the page.  This is most useful when
     *  properties have non-null initial values.
     *
     *  <p>Subclasses may override this implementation
     *  (which is empty).
     *
     *  @since 2.2
     *
     **/

    protected void initialize()
    {try { __CLOVER_2_0.M[95]++;
        // Does nothing.
    } finally { }}

    public IEngine getEngine()
    {try { __CLOVER_2_0.M[96]++;
        __CLOVER_2_0.S[369]++;return _engine;
    } finally { }}

    public ChangeObserver getChangeObserver()
    {try { __CLOVER_2_0.M[97]++;
        __CLOVER_2_0.S[370]++;return _changeObserver;
    } finally { }}

    /**
     *  Returns the name of the page.
     *
     **/

    public String getExtendedId()
    {try { __CLOVER_2_0.M[98]++;
        __CLOVER_2_0.S[371]++;return _pageName;
    } finally { }}

    /**
     *  Pages always return null for idPath.
     *
     **/

    public String getIdPath()
    {try { __CLOVER_2_0.M[99]++;
        __CLOVER_2_0.S[372]++;return null;
    } finally { }}

    /**
     *  Returns the locale for the page, which may be null if the
     *  locale is not known (null corresponds to the "default locale").
     *
     **/

    public Locale getLocale()
    {try { __CLOVER_2_0.M[100]++;
        __CLOVER_2_0.S[373]++;return _locale;
    } finally { }}

    public void setLocale(Locale value)
    {try { __CLOVER_2_0.M[101]++;
        __CLOVER_2_0.S[374]++;if ((((_locale != null) && (++__CLOVER_2_0.CT[79] != 0)) || (++__CLOVER_2_0.CF[79] == 0))){
            __CLOVER_2_0.S[375]++;throw new ApplicationRuntimeException(
                Tapestry.getMessage("AbstractPage.attempt-to-change-locale"));}

        __CLOVER_2_0.S[376]++;_locale = value;
    } finally { }}

    public IComponent getNestedComponent(String path)
    {try { __CLOVER_2_0.M[102]++;
        __CLOVER_2_0.S[377]++;StringSplitter splitter;
        __CLOVER_2_0.S[378]++;IComponent current;
        __CLOVER_2_0.S[379]++;String[] elements;
        __CLOVER_2_0.S[380]++;int i;

        __CLOVER_2_0.S[381]++;if ((((path == null) && (++__CLOVER_2_0.CT[80] != 0)) || (++__CLOVER_2_0.CF[80] == 0))){
            __CLOVER_2_0.S[382]++;return this;}

        __CLOVER_2_0.S[383]++;splitter = new StringSplitter('.');
        __CLOVER_2_0.S[384]++;current = this;

        __CLOVER_2_0.S[385]++;elements = splitter.splitToArray(path);
        __CLOVER_2_0.S[386]++;for (i = 0; (((i < elements.length) && (++__CLOVER_2_0.CT[81] != 0)) || (++__CLOVER_2_0.CF[81] == 0)); i++){
        {
            __CLOVER_2_0.S[387]++;current = current.getComponent(elements[i]);
        }}

        __CLOVER_2_0.S[388]++;return current;

    } finally { }}

    /**
     *  Called by the {@link IEngine engine} to attach the page
     *  to itself.  Does
     *  <em>not</em> change the locale, but since a page is selected
     *  from the {@link org.apache.tapestry.engine.IPageSource} pool based on its
     *  locale matching the engine's locale, they should match
     *  anyway.
     *
     **/

    public void attach(IEngine value)
    {try { __CLOVER_2_0.M[103]++;
        __CLOVER_2_0.S[389]++;if ((((_engine != null) && (++__CLOVER_2_0.CT[82] != 0)) || (++__CLOVER_2_0.CF[82] == 0))){
            __CLOVER_2_0.S[390]++;LOG.error(this +" attach(" + value + "), but engine = " + _engine);}

        __CLOVER_2_0.S[391]++;_engine = value;
    } finally { }}

    /**
     *
     * <ul>
     <li>Invokes {@link PageRenderListener#pageBeginRender(PageEvent)}
     <li>Invokes {@link #beginResponse(IMarkupWriter, IRequestCycle)}
     <li>Invokes {@link IRequestCycle#commitPageChanges()} (if not rewinding)
     *  <li>Invokes {@link #render(IMarkupWriter, IRequestCycle)}
     <li>Invokes {@link PageRenderListener#pageEndRender(PageEvent)} (this occurs
     *  even if a previous step throws an exception)
     *
     **/

    public void renderPage(IMarkupWriter writer, IRequestCycle cycle)
    {try { __CLOVER_2_0.M[104]++;
        __CLOVER_2_0.S[392]++;try
        {
            __CLOVER_2_0.S[393]++;firePageBeginRender();

            __CLOVER_2_0.S[394]++;beginResponse(writer, cycle);

            __CLOVER_2_0.S[395]++;if ((((!cycle.isRewinding()) && (++__CLOVER_2_0.CT[83] != 0)) || (++__CLOVER_2_0.CF[83] == 0))){
                __CLOVER_2_0.S[396]++;cycle.commitPageChanges();}

            __CLOVER_2_0.S[397]++;render(writer, cycle);
        }
        finally
        {
            __CLOVER_2_0.S[398]++;firePageEndRender();
        }
    } finally { }}

    public void setChangeObserver(ChangeObserver value)
    {try { __CLOVER_2_0.M[105]++;
        __CLOVER_2_0.S[399]++;_changeObserver = value;
    } finally { }}

    /** @since 3.0 **/

    public void setPageName(String pageName)
    {try { __CLOVER_2_0.M[106]++;
        __CLOVER_2_0.S[400]++;if ((((_pageName != null) && (++__CLOVER_2_0.CT[84] != 0)) || (++__CLOVER_2_0.CF[84] == 0))){
            __CLOVER_2_0.S[401]++;throw new ApplicationRuntimeException(
                Tapestry.getMessage("AbstractPage.attempt-to-change-name"));}

        __CLOVER_2_0.S[402]++;_pageName = pageName;
    } finally { }}

    /**
     *  By default, pages are not protected and this method does nothing.
     *
     **/

    public void validate(IRequestCycle cycle)
    {try { __CLOVER_2_0.M[107]++;
        __CLOVER_2_0.S[403]++;Tapestry.addMethodInvocation(Tapestry.ABSTRACTPAGE_VALIDATE_METHOD_ID);

        __CLOVER_2_0.S[404]++;firePageValidate();
    } finally { }}

    /**
     *  Does nothing, subclasses may override as needed.
     *
     * @deprecated To be removed in 3.1.  Implement
     * {@link PageRenderListener} instead.
     *
     **/

    public void beginResponse(IMarkupWriter writer, IRequestCycle cycle)
    {try { __CLOVER_2_0.M[108]++;
    } finally { }}

    public IRequestCycle getRequestCycle()
    {try { __CLOVER_2_0.M[109]++;
        __CLOVER_2_0.S[405]++;return _requestCycle;
    } finally { }}

    public void setRequestCycle(IRequestCycle value)
    {try { __CLOVER_2_0.M[110]++;
        __CLOVER_2_0.S[406]++;_requestCycle = value;
    } finally { }}

    /**
     *  Returns the visit object obtained from the engine via
     *  {@link IEngine#getVisit(IRequestCycle)}.
     *
     **/

    public Object getVisit()
    {try { __CLOVER_2_0.M[111]++;
        __CLOVER_2_0.S[407]++;if ((((_visit == null) && (++__CLOVER_2_0.CT[85] != 0)) || (++__CLOVER_2_0.CF[85] == 0))){
            __CLOVER_2_0.S[408]++;_visit = _engine.getVisit(_requestCycle);}

        __CLOVER_2_0.S[409]++;return _visit;
    } finally { }}

    /**
     *  Convienience methods, simply invokes
     *  {@link IEngine#getGlobal()}.
     *
     *  @since 2.3
     *
     **/

    public Object getGlobal()
    {try { __CLOVER_2_0.M[112]++;
        __CLOVER_2_0.S[410]++;return _engine.getGlobal();
    } finally { }}

    public void addPageDetachListener(PageDetachListener listener)
    {try { __CLOVER_2_0.M[113]++;
        __CLOVER_2_0.S[411]++;addListener(PageDetachListener.class, listener);
    } finally { }}

    private void addListener(Class listenerClass, EventListener listener)
    {try { __CLOVER_2_0.M[114]++;
        __CLOVER_2_0.S[412]++;if ((((_listenerList == null) && (++__CLOVER_2_0.CT[86] != 0)) || (++__CLOVER_2_0.CF[86] == 0))){
            __CLOVER_2_0.S[413]++;_listenerList = new EventListenerList();}

        __CLOVER_2_0.S[414]++;_listenerList.add(listenerClass, listener);
    } finally { }}

    /**
     *  @since 2.1-beta-2
     *
     **/

    private void removeListener(Class listenerClass, EventListener listener)
    {try { __CLOVER_2_0.M[115]++;
        __CLOVER_2_0.S[415]++;if ((((_listenerList != null) && (++__CLOVER_2_0.CT[87] != 0)) || (++__CLOVER_2_0.CF[87] == 0))){
            __CLOVER_2_0.S[416]++;_listenerList.remove(listenerClass, listener);}
    } finally { }}

    public void addPageRenderListener(PageRenderListener listener)
    {try { __CLOVER_2_0.M[116]++;
        __CLOVER_2_0.S[417]++;addListener(PageRenderListener.class, listener);
    } finally { }}

    /**
     *  @since 1.0.5
     *
     **/

    protected void firePageDetached()
    {try { __CLOVER_2_0.M[117]++;
        __CLOVER_2_0.S[418]++;if ((((_listenerList == null) && (++__CLOVER_2_0.CT[88] != 0)) || (++__CLOVER_2_0.CF[88] == 0))){
            __CLOVER_2_0.S[419]++;return;}

        __CLOVER_2_0.S[420]++;PageEvent event = null;
        __CLOVER_2_0.S[421]++;Object[] listeners = _listenerList.getListenerList();

        __CLOVER_2_0.S[422]++;for (int i = 0; (((i < listeners.length) && (++__CLOVER_2_0.CT[89] != 0)) || (++__CLOVER_2_0.CF[89] == 0)); i += 2){
        {
            __CLOVER_2_0.S[423]++;if ((((listeners[i] == PageDetachListener.class) && (++__CLOVER_2_0.CT[90] != 0)) || (++__CLOVER_2_0.CF[90] == 0))){
            {
                __CLOVER_2_0.S[424]++;PageDetachListener l = (PageDetachListener) listeners[i + 1];

                __CLOVER_2_0.S[425]++;if ((((event == null) && (++__CLOVER_2_0.CT[91] != 0)) || (++__CLOVER_2_0.CF[91] == 0))){
                    __CLOVER_2_0.S[426]++;event = new PageEvent(this, _requestCycle);}

                __CLOVER_2_0.S[427]++;l.pageDetached(event);
            }}
        }}
    } finally { }}

    /**
     *  @since 1.0.5
     *
     **/

    protected void firePageBeginRender()
    {try { __CLOVER_2_0.M[118]++;
        __CLOVER_2_0.S[428]++;if ((((_listenerList == null) && (++__CLOVER_2_0.CT[92] != 0)) || (++__CLOVER_2_0.CF[92] == 0))){
            __CLOVER_2_0.S[429]++;return;}

        __CLOVER_2_0.S[430]++;PageEvent event = null;
        __CLOVER_2_0.S[431]++;Object[] listeners = _listenerList.getListenerList();

        __CLOVER_2_0.S[432]++;for (int i = 0; (((i < listeners.length) && (++__CLOVER_2_0.CT[93] != 0)) || (++__CLOVER_2_0.CF[93] == 0)); i += 2){
        {
            __CLOVER_2_0.S[433]++;if ((((listeners[i] == PageRenderListener.class) && (++__CLOVER_2_0.CT[94] != 0)) || (++__CLOVER_2_0.CF[94] == 0))){
            {
                __CLOVER_2_0.S[434]++;PageRenderListener l = (PageRenderListener) listeners[i + 1];

                __CLOVER_2_0.S[435]++;if ((((event == null) && (++__CLOVER_2_0.CT[95] != 0)) || (++__CLOVER_2_0.CF[95] == 0))){
                    __CLOVER_2_0.S[436]++;event = new PageEvent(this, _requestCycle);}

                __CLOVER_2_0.S[437]++;l.pageBeginRender(event);
            }}
        }}
    } finally { }}

    /**
     *  @since 1.0.5
     *
     **/

    protected void firePageEndRender()
    {try { __CLOVER_2_0.M[119]++;
        __CLOVER_2_0.S[438]++;if ((((_listenerList == null) && (++__CLOVER_2_0.CT[96] != 0)) || (++__CLOVER_2_0.CF[96] == 0))){
            __CLOVER_2_0.S[439]++;return;}

        __CLOVER_2_0.S[440]++;PageEvent event = null;
        __CLOVER_2_0.S[441]++;Object[] listeners = _listenerList.getListenerList();

        __CLOVER_2_0.S[442]++;for (int i = 0; (((i < listeners.length) && (++__CLOVER_2_0.CT[97] != 0)) || (++__CLOVER_2_0.CF[97] == 0)); i += 2){
        {
            __CLOVER_2_0.S[443]++;if ((((listeners[i] == PageRenderListener.class) && (++__CLOVER_2_0.CT[98] != 0)) || (++__CLOVER_2_0.CF[98] == 0))){
            {
                __CLOVER_2_0.S[444]++;PageRenderListener l = (PageRenderListener) listeners[i + 1];

                __CLOVER_2_0.S[445]++;if ((((event == null) && (++__CLOVER_2_0.CT[99] != 0)) || (++__CLOVER_2_0.CF[99] == 0))){
                    __CLOVER_2_0.S[446]++;event = new PageEvent(this, _requestCycle);}

                __CLOVER_2_0.S[447]++;l.pageEndRender(event);
            }}
        }}
    } finally { }}

    /**
     *  @since 2.1-beta-2
     *
     **/

    public void removePageDetachListener(PageDetachListener listener)
    {try { __CLOVER_2_0.M[120]++;
        __CLOVER_2_0.S[448]++;removeListener(PageDetachListener.class, listener);
    } finally { }}

    public void removePageRenderListener(PageRenderListener listener)
    {try { __CLOVER_2_0.M[121]++;
        __CLOVER_2_0.S[449]++;removeListener(PageRenderListener.class, listener);
    } finally { }}

    /** @since 2.2 **/

    public void beginPageRender()
    {try { __CLOVER_2_0.M[122]++;
        __CLOVER_2_0.S[450]++;firePageBeginRender();
    } finally { }}

    /** @since 2.2 **/

    public void endPageRender()
    {try { __CLOVER_2_0.M[123]++;
        __CLOVER_2_0.S[451]++;firePageEndRender();
    } finally { }}

    /** @since 3.0 **/

    public String getPageName()
    {try { __CLOVER_2_0.M[124]++;
        __CLOVER_2_0.S[452]++;return _pageName;
    } finally { }}

    public void addPageValidateListener(PageValidateListener listener)
    {try { __CLOVER_2_0.M[125]++;
        __CLOVER_2_0.S[453]++;addListener(PageValidateListener.class, listener);
    } finally { }}

    public void removePageValidateListener(PageValidateListener listener)
    {try { __CLOVER_2_0.M[126]++;
        __CLOVER_2_0.S[454]++;removeListener(PageValidateListener.class, listener);
    } finally { }}

    protected void firePageValidate()
    {try { __CLOVER_2_0.M[127]++;
        __CLOVER_2_0.S[455]++;if ((((_listenerList == null) && (++__CLOVER_2_0.CT[100] != 0)) || (++__CLOVER_2_0.CF[100] == 0))){
            __CLOVER_2_0.S[456]++;return;}

        __CLOVER_2_0.S[457]++;PageEvent event = null;
        __CLOVER_2_0.S[458]++;Object[] listeners = _listenerList.getListenerList();

        __CLOVER_2_0.S[459]++;for (int i = 0; (((i < listeners.length) && (++__CLOVER_2_0.CT[101] != 0)) || (++__CLOVER_2_0.CF[101] == 0)); i += 2){
        {
            __CLOVER_2_0.S[460]++;if ((((listeners[i] == PageValidateListener.class) && (++__CLOVER_2_0.CT[102] != 0)) || (++__CLOVER_2_0.CF[102] == 0))){
            {
                __CLOVER_2_0.S[461]++;PageValidateListener l = (PageValidateListener) listeners[i + 1];

                __CLOVER_2_0.S[462]++;if ((((event == null) && (++__CLOVER_2_0.CT[103] != 0)) || (++__CLOVER_2_0.CF[103] == 0))){
                    __CLOVER_2_0.S[463]++;event = new PageEvent(this, _requestCycle);}

                __CLOVER_2_0.S[464]++;l.pageValidate(event);
            }}
        }}
    } finally { }}

    /**
     *  Returns the output encoding to be used when rendering this page.
     *  This value is usually cached from the Engine.
     *
     *  @since 3.0
     **/
    protected String getOutputEncoding()
    {try { __CLOVER_2_0.M[128]++;
        __CLOVER_2_0.S[465]++;if ((((_outputEncoding == null) && (++__CLOVER_2_0.CT[104] != 0)) || (++__CLOVER_2_0.CF[104] == 0))){
            __CLOVER_2_0.S[466]++;_outputEncoding = getEngine().getOutputEncoding();}
       
        __CLOVER_2_0.S[467]++;return _outputEncoding;
    } finally { }}
}
TOP

Related Classes of org.apache.tapestry.AbstractPage

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.