Package org.apache.beehive.netui.compiler.model

Source Code of org.apache.beehive.netui.compiler.model.ForwardModel

/*
* 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.
*
* $Header:$
*/
package org.apache.beehive.netui.compiler.model;

import java.util.List;
import java.util.ArrayList;

import org.apache.beehive.netui.compiler.model.schema.struts11.ForwardDocument.Forward;
import org.apache.beehive.netui.compiler.model.schema.struts11.SetPropertyDocument.SetProperty;
import org.apache.beehive.netui.compiler.JpfLanguageConstants;

/**
* Represents an action forward in a Struts application.
*/
public class ForwardModel
        extends StrutsElementSupport
        implements JpfLanguageConstants
{
    private static final String JPF_ACTION_FWD_CLASSNAME = PAGEFLOW_PACKAGE + ".config.PageFlowActionForward";
   
    private boolean _isNestedReturn = false;
    private boolean _contextRelative = false;
    private String _name;  // required to be set
    private String _path;  // required to be set
    private boolean _redirect = false;
    private boolean _externalRedirect = false;
    private boolean _returnToPage = false;
    private boolean _returnToAction = false;
    private String _outputFormBeanType;
    private String _outputFormBeanMember;
    private boolean _hasExplicitRedirectValue = false;
    private List _actionOutputs = null;
    private boolean _restoreQueryString = false;
   

    protected ForwardModel( StrutsApp parent )
    {
        super( parent );
    }
   
    public ForwardModel( String name, String path, StrutsApp parent )
    {
        super( parent );
        _name = name;
        _path = path;
    }

    public void writeToXMLBean( Forward xb )
    {
        assert _name != null;

        xb.setName( _name );
       
        if ( xb.getPath() == null )
        {
            xb.setPath( _path == null ? "" : _path );
        }
       
        if ( xb.getContextRelative() == null && _contextRelative )
        {
            xb.setContextRelative( Forward.ContextRelative.TRUE );
        }
       
        if ( xb.getRedirect() == null && _redirect )
        {
            xb.setRedirect( Forward.Redirect.TRUE );
        }
       
        //
        // "externalRedirect" is set using set-property, to indicate that the redirect
        // is to another app.
        //
        if ( _externalRedirect ) addSetProperty( xb, "externalRedirect", "true" );
       
        //
        // "returnToPage" is set using set-property, which requires us to override the
        // ActionForward class.
        //
        if ( _returnToPage ) addSetProperty( xb, "returnToPage", "true" );

        //
        // "returnToAction" is set using set-property, which requires us to override the
        // ActionForward class.
        //
        if ( _returnToAction ) addSetProperty( xb, "returnToAction", "true" );

        if ( _hasExplicitRedirectValue ) addSetProperty( xb, "hasExplicitRedirectValue", "true" );

        if ( _restoreQueryString ) addSetProperty( xb, "restoreQueryString", "true" );
       
        if ( _actionOutputs != null && _actionOutputs.size() > 0 )
        {
            if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_FWD_CLASSNAME );

            int n = _actionOutputs.size();
            SetProperty countProp = xb.addNewSetProperty();
            countProp.setProperty( "actionOutputCount" );
            countProp.setValue( Integer.toString( n ) );
           
            for ( int i = 0; i < n; ++i )
            {
                ActionOutputModel pi = ( ActionOutputModel ) _actionOutputs.get( i );
                SetProperty prop = xb.addNewSetProperty();
                prop.setProperty( "actionOutput" + i );
                prop.setValue( pi.getType() + '|' + pi.getNullable() + '|' + pi.getName() );
            }
        }
       
        //
        // "nestedReturn" is set using set-property, which requires us to override the
        // ActionForward class.
        //
        if ( _isNestedReturn ) addSetProperty( xb, "nestedReturn", "true" );
        if ( _outputFormBeanType != null ) addSetProperty( xb, "returnFormType", _outputFormBeanType );
        if ( _outputFormBeanMember != null ) addSetProperty( xb, "returnFormMember", _outputFormBeanMember );
       
        addComment( xb );
    }   

    public boolean isReturnToPage()
    {
        return _returnToPage;
    }

    public void setReturnToPage( boolean returnToPage )
    {
        _returnToPage = returnToPage;
    }

    public boolean isReturnToAction()
    {
        return _returnToAction;
    }

    public void setReturnToAction( boolean returnToAction )
    {
        _returnToAction = returnToAction;
    }

    public void setIsNestedReturn( boolean nestedReturn )
    {
        _isNestedReturn = nestedReturn;
    }

    public String getOutputFormBeanType()
    {
        return _outputFormBeanType;
    }

    public void setOutputFormBeanType( String outputFormBeanType )
    {
        _outputFormBeanType = outputFormBeanType;
    }

    public String getOutputFormBeanMember()
    {
        return _outputFormBeanMember;
    }

    public void setOutputFormBeanMember( String outputFormBeanMember )
    {
        _outputFormBeanMember = outputFormBeanMember;
    }

    public boolean getContextRelative()
    {
        return _contextRelative;
    }

    public void setContextRelative( boolean contextRelative )
    {
        _contextRelative = contextRelative;
    }

    public String getName()
    {
        return _name;
    }

    public void setName( String name )
    {
        _name = name;
    }

    public String getPath()
    {
        return _path;
    }

    public void setPath( String path )
    {
        _path = path;
    }

    public boolean isRedirect()
    {
        return _redirect;
    }

    public void setRedirect( boolean redirect )
    {
        _redirect = redirect;
        _hasExplicitRedirectValue = redirect;
    }

    public boolean isExternalRedirect()
    {
        return _externalRedirect;
    }

    public void setExternalRedirect( boolean externalRedirect )
    {
        _externalRedirect = externalRedirect;
        if ( externalRedirect  ) setRedirect( externalRedirect );
    }

    public boolean isRestoreQueryString()
    {
        return _restoreQueryString;
    }

    public void setRestoreQueryString( boolean restore )
    {
        _restoreQueryString = restore;
    }

    /**
     * @deprecated
     * @see #forwardsToPage
     */
    public final boolean isPageForward()
    {
        return forwardsToPage();
    }

    public boolean forwardsToPage()
    {
        return ! _path.endsWith( ".do" ) && ! _path.endsWith( ".jpf" )// NOI18N
    }

    public boolean forwardsToAction()
    {
        return _path.endsWith( ".do" )// NOI18N
    }

    public final boolean forwardsToPageFlow()
    {
        return _path.endsWith( ".jpf" )// NOI18N
    }

    public String getPageName()
    {
        assert forwardsToPage() : "getPageName() called for non-page " + _path;  // NOI18N

        int slash = _path.lastIndexOf( '/' )// NOI18N
        return slash != -1 ? _path.substring( slash + 1 ) : _path;
    }

    public String getActionName()
    {
        assert forwardsToAction() : "getActionName() called for non-action" + _path;  // NOI18N

        int index = _path.indexOf( ".do" )// NOI18N
        assert index != -1;
        return _path.substring( 0, index );
    }

    public void addActionOutput( ActionOutputModel actionOutput )
    {
        if ( _actionOutputs == null ) _actionOutputs = new ArrayList();
        _actionOutputs.add( actionOutput );
    }
   
    public boolean isNestedReturn()
    {
        return _isNestedReturn;
    }
   
    private static void addSetProperty( Forward xb, String propertyName, String propertyValue )
    {
        SetProperty prop = xb.addNewSetProperty();
        prop.setProperty( propertyName );
        prop.setValue( propertyValue );
        if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_FWD_CLASSNAME );
    }
}
TOP

Related Classes of org.apache.beehive.netui.compiler.model.ForwardModel

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.