Package org.apache.tapestry.engine

Source Code of org.apache.tapestry.engine.BaseEngine

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

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.record.SessionPageRecorder;

/**
*  Concrete implementation of {@link org.apache.tapestry.IEngine} used for ordinary
*  applications.  All page state information is maintained in
*  the {@link javax.servlet.http.HttpSession} using
*  instances of {@link org.apache.tapestry.record.SessionPageRecorder}.
*
@author Howard Lewis Ship
*
**/

public class BaseEngine extends AbstractEngine
{public static com.cortexeb.tools.clover.d __CLOVER_74_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 long serialVersionUID = -7051050643746333380L;

    private final static int MAP_SIZE = 3;

    private transient Map _recorders;

    private transient Set _activePageNames;

    /**
     *  Removes all page recorders that contain no changes, or
     *  are marked for discard.  Subclasses
     *  should invoke this implementation in addition to providing
     *  thier own.
     *
     **/

    protected void cleanupAfterRequest(IRequestCycle cycle)
    {try { __CLOVER_74_0.M[434]++;
        __CLOVER_74_0.S[1866]++;if ((((Tapestry.isEmpty(_recorders)) && (++__CLOVER_74_0.CT[348] != 0)) || (++__CLOVER_74_0.CF[348] == 0))){
            __CLOVER_74_0.S[1867]++;return;}

    __CLOVER_74_0.S[1868]++;boolean markDirty = false;
        __CLOVER_74_0.S[1869]++;Iterator i = _recorders.entrySet().iterator();

        __CLOVER_74_0.S[1870]++;while ((((i.hasNext()) && (++__CLOVER_74_0.CT[349] != 0)) || (++__CLOVER_74_0.CF[349] == 0))){
        {
            __CLOVER_74_0.S[1871]++;Map.Entry entry = (Map.Entry) i.next();
            __CLOVER_74_0.S[1872]++;String pageName = (String) entry.getKey();
            __CLOVER_74_0.S[1873]++;IPageRecorder recorder = (IPageRecorder) entry.getValue();

            __CLOVER_74_0.S[1874]++;if ((((!recorder.getHasChanges() || recorder.isMarkedForDiscard()) && (++__CLOVER_74_0.CT[350] != 0)) || (++__CLOVER_74_0.CF[350] == 0))){
            {
                __CLOVER_74_0.S[1875]++;recorder.discard();

                __CLOVER_74_0.S[1876]++;i.remove();

                __CLOVER_74_0.S[1877]++;_activePageNames.remove(pageName);
       
            __CLOVER_74_0.S[1878]++;markDirty = true;
            }}
        }}
       
        __CLOVER_74_0.S[1879]++;if ((((markDirty) && (++__CLOVER_74_0.CT[351] != 0)) || (++__CLOVER_74_0.CF[351] == 0))){
          __CLOVER_74_0.S[1880]++;markDirty();}
    } finally { }}

    public void forgetPage(String name)
    {try { __CLOVER_74_0.M[435]++;
        __CLOVER_74_0.S[1881]++;if ((((_recorders == null) && (++__CLOVER_74_0.CT[352] != 0)) || (++__CLOVER_74_0.CF[352] == 0))){
            __CLOVER_74_0.S[1882]++;return;}

        __CLOVER_74_0.S[1883]++;IPageRecorder recorder = (IPageRecorder) _recorders.get(name);
        __CLOVER_74_0.S[1884]++;if ((((recorder == null) && (++__CLOVER_74_0.CT[353] != 0)) || (++__CLOVER_74_0.CF[353] == 0))){
            __CLOVER_74_0.S[1885]++;return;}

        __CLOVER_74_0.S[1886]++;if ((((recorder.isDirty()) && (++__CLOVER_74_0.CT[354] != 0)) || (++__CLOVER_74_0.CF[354] == 0))){
            __CLOVER_74_0.S[1887]++;throw new ApplicationRuntimeException(
                Tapestry.format("BaseEngine.recorder-has-uncommited-changes", name));}

        __CLOVER_74_0.S[1888]++;recorder.discard();
        __CLOVER_74_0.S[1889]++;_recorders.remove(name);
        __CLOVER_74_0.S[1890]++;_activePageNames.remove(name);
       
        __CLOVER_74_0.S[1891]++;markDirty();
    } finally { }}

    /**
     *  Returns an unmodifiable {@link Collection} of the page names for which
     *  {@link IPageRecorder} instances exist.
     *
     *
     **/

    public Collection getActivePageNames()
    {try { __CLOVER_74_0.M[436]++;
        __CLOVER_74_0.S[1892]++;if ((((_activePageNames == null) && (++__CLOVER_74_0.CT[355] != 0)) || (++__CLOVER_74_0.CF[355] == 0))){
            __CLOVER_74_0.S[1893]++;return Collections.EMPTY_LIST;}

        __CLOVER_74_0.S[1894]++;return Collections.unmodifiableCollection(_activePageNames);
    } finally { }}

    public IPageRecorder getPageRecorder(String pageName, IRequestCycle cycle)
    {try { __CLOVER_74_0.M[437]++;
        __CLOVER_74_0.S[1895]++;if ((((_activePageNames == null || !_activePageNames.contains(pageName)) && (++__CLOVER_74_0.CT[356] != 0)) || (++__CLOVER_74_0.CF[356] == 0))){
            __CLOVER_74_0.S[1896]++;return null;}

        __CLOVER_74_0.S[1897]++;IPageRecorder result = null;

        __CLOVER_74_0.S[1898]++;if ((((_recorders != null) && (++__CLOVER_74_0.CT[357] != 0)) || (++__CLOVER_74_0.CF[357] == 0))){
            __CLOVER_74_0.S[1899]++;return result = (IPageRecorder) _recorders.get(pageName);}

        // So the page is active, but not in the cache of page recoders,
        // so (re-)create the page recorder.

        __CLOVER_74_0.S[1900]++;if ((((result == null) && (++__CLOVER_74_0.CT[358] != 0)) || (++__CLOVER_74_0.CF[358] == 0))){
            __CLOVER_74_0.S[1901]++;result = createPageRecorder(pageName, cycle);}

        __CLOVER_74_0.S[1902]++;return result;
    } finally { }}

    public IPageRecorder createPageRecorder(String pageName, IRequestCycle cycle)
    {try { __CLOVER_74_0.M[438]++;
        __CLOVER_74_0.S[1903]++;if ((((_recorders == null) && (++__CLOVER_74_0.CT[359] != 0)) || (++__CLOVER_74_0.CF[359] == 0))){
            __CLOVER_74_0.S[1904]++;_recorders = new HashMap(MAP_SIZE);}
        else{
        {
            __CLOVER_74_0.S[1905]++;if ((((_recorders.containsKey(pageName)) && (++__CLOVER_74_0.CT[360] != 0)) || (++__CLOVER_74_0.CF[360] == 0))){
                __CLOVER_74_0.S[1906]++;throw new ApplicationRuntimeException(
                    Tapestry.format("BaseEngine.duplicate-page-recorder", pageName));}
        }}

        // Force the creation of the HttpSession

        __CLOVER_74_0.S[1907]++;cycle.getRequestContext().createSession();
        __CLOVER_74_0.S[1908]++;setStateful();
      

        __CLOVER_74_0.S[1909]++;IPageRecorder result = new SessionPageRecorder();
        __CLOVER_74_0.S[1910]++;result.initialize(pageName, cycle);

        __CLOVER_74_0.S[1911]++;_recorders.put(pageName, result);

        __CLOVER_74_0.S[1912]++;if ((((_activePageNames == null) && (++__CLOVER_74_0.CT[361] != 0)) || (++__CLOVER_74_0.CF[361] == 0))){
            __CLOVER_74_0.S[1913]++;_activePageNames = new HashSet();}

        __CLOVER_74_0.S[1914]++;_activePageNames.add(pageName);
       
        __CLOVER_74_0.S[1915]++;markDirty();

        __CLOVER_74_0.S[1916]++;return result;
    } finally { }}

    /**
     *  Reconstructs the list of active page names
     *  written by {@link #writeExternal(ObjectOutput)}.
     *
     **/

    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {try { __CLOVER_74_0.M[439]++;
        __CLOVER_74_0.S[1917]++;super.readExternal(in);

        __CLOVER_74_0.S[1918]++;int count = in.readInt();

        __CLOVER_74_0.S[1919]++;if ((((count > 0) && (++__CLOVER_74_0.CT[362] != 0)) || (++__CLOVER_74_0.CF[362] == 0))){
            __CLOVER_74_0.S[1920]++;_activePageNames = new HashSet(count);}

        __CLOVER_74_0.S[1921]++;for (int i = 0; (((i < count) && (++__CLOVER_74_0.CT[363] != 0)) || (++__CLOVER_74_0.CF[363] == 0)); i++){
        {
            __CLOVER_74_0.S[1922]++;String name = in.readUTF();

            __CLOVER_74_0.S[1923]++;_activePageNames.add(name);
        }}

    } finally { }}

    /**
     *  Writes the engine's persistent state; this is simply the list of active page
     *  names.  For efficiency, this is written as a count followed by each name
     *  as a UTF String.
     *
     **/

    public void writeExternal(ObjectOutput out) throws IOException
    {try { __CLOVER_74_0.M[440]++;
        __CLOVER_74_0.S[1924]++;super.writeExternal(out);

        __CLOVER_74_0.S[1925]++;if ((((Tapestry.isEmpty(_activePageNames)) && (++__CLOVER_74_0.CT[364] != 0)) || (++__CLOVER_74_0.CF[364] == 0))){
        {
            __CLOVER_74_0.S[1926]++;out.writeInt(0);
            __CLOVER_74_0.S[1927]++;return;
        }}

        __CLOVER_74_0.S[1928]++;int count = _activePageNames.size();

        __CLOVER_74_0.S[1929]++;out.writeInt(count);

        __CLOVER_74_0.S[1930]++;Iterator i = _activePageNames.iterator();

        __CLOVER_74_0.S[1931]++;while ((((i.hasNext()) && (++__CLOVER_74_0.CT[365] != 0)) || (++__CLOVER_74_0.CF[365] == 0))){
        {
            __CLOVER_74_0.S[1932]++;String name = (String) i.next();

            __CLOVER_74_0.S[1933]++;out.writeUTF(name);
        }}
    } finally { }}

    public void extendDescription(ToStringBuilder builder)
    {try { __CLOVER_74_0.M[441]++;
    __CLOVER_74_0.S[1934]++;builder.append("activePageNames", _activePageNames);
    } finally { }}

}
TOP

Related Classes of org.apache.tapestry.engine.BaseEngine

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.