AdministratorLoginController.java

// license-header java merge-point
// Generated by andromda-jsf cartridge (controllers\Controller.java.vsl) DO NOT EDIT!
package org.andromda.samples.carrental.admins.web.login;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.andromda.samples.carrental.ControllerBase;
import org.andromda.samples.carrental.JsfUtils;
import org.andromda.samples.carrental.admins.web.main.AdministrationController;

/**
 * <p>
 * TODO: Model Documentation for
 * org.andromda.samples.carrental.admins.web.login.AdministratorLoginController
 * </p>
 */
public abstract class AdministratorLoginController
    extends ControllerBase
    implements Serializable
{
    /**
     * The serial version UID of this class. Needed for serialization.
     */
    private static final long serialVersionUID = 1L;

    /**
     * Returns an instance from the JSF context
     *
     */
    public static AdministratorLoginController instance()
    {
        return (AdministratorLoginController)JsfUtils.resolveVariable("administratorLoginController");
    }
    
    /**
     * Populate action form and page variables
     *
     * @param currentView the current view
     * @param forward the forward view
     * @param sourceForm the source form
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     * @throws NoSuchMethodException
     */
    private void populateActionFormsAndPageVariables(final String currentView, String forward, final Object sourceForm) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
    {
        if(forward == null)
        {
            forward=currentView;
        }
        
        final Map<String,Object> pageVariables=this.getPageVariables(forward);
        if("/org/andromda/samples/carrental/admins/web/login/adminstrator-login.jsf".equals(forward))
        {
            AdministratorLoginViewPopulator.populateForm(sourceForm,this.getAdminstratorLoginSubmitForm());
        }
        ControllerBase.getUseCaseScope().put(CURRENT_PAGE_VARIABLES_KEY, pageVariables);
    }
    
    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.admins.web.login.authenticateAsAdministrator
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract String authenticateAsAdministrator(AuthenticateAsAdministratorForm form)
        throws Throwable;


    /**
     * Retrieves the {@link AdminstratorLoginSubmitFormImpl} form instance 
     *
     * @return AdminstratorLoginSubmitFormImpl
     */
    protected AdminstratorLoginSubmitFormImpl getAdminstratorLoginSubmitForm()
    {
        return (AdminstratorLoginSubmitFormImpl)JsfUtils.resolveVariable("administratorLoginAdminstratorLoginSubmitForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for submit
     * </p>
     * This method is called when 'submit' is triggered in the view 'Adminstrator Login'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _adminstratorLogin_submit(AdminstratorLoginSubmitFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves adminstratorLoginSubmit()
     *    
     * @return adminstratorLoginSubmit
     * @throws Throwable
     */
    public String adminstratorLoginSubmit()
        throws Throwable
    {
        this.setLastPostedFormClientId("administratorLoginAdminstratorLoginSubmitForm");
        
        String forward=null;
        final AdminstratorLoginSubmitFormImpl form =
            this.getAdminstratorLoginSubmitForm();
            
        //trigger method execution
        _adminstratorLogin_submit(form);

        forward = _validate(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/admins/web/login/adminstrator-login.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/admins/web/login/adminstrator-login.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for Validate
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _validate(final AdminstratorLoginSubmitFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        authenticateAsAdministrator(form);
        forward = __authenticateAsAdministrator(form);
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for Begin Admin Login
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _beginAdminLogin(final AdminstratorLoginSubmitFormImpl form)
        throws Throwable
    {
        String forward = null;
        forward = "/org/andromda/samples/carrental/admins/web/login/adminstrator-login.jsf";
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for org.andromda.samples.carrental.admins.web.login.check
     * </p>
     *
     * @return a transition
     */
    protected String __authenticateAsAdministrator(final AdminstratorLoginSubmitFormImpl form)
        throws Throwable
    {
        final String value = String.valueOf(authenticateAsAdministrator(form));
        String forward = null;
        if (value.equals("succeed"))
        {
            forward = ((AdministrationController)JsfUtils.resolveVariable("administrationController")).startUseCase();
        }
        if (value.equals("fail"))
        {
            forward = _beginAdminLogin(form);
        }
        if (forward == null)
        {
            // throw exception in case we have an invalid return value from the controller
            throw new RuntimeException("Runtime model error: no valid path selected. Selected path="+value);
        }
        else
        {
            return forward;
        }
    }

    /**
     * Retrieves the {@link AdministratorLoginFormImpl} form instance 
     *
     * @return AdministratorLoginFormImpl
     */
    protected AdministratorLoginFormImpl getAdministratorLoginForm()
    {
        return (AdministratorLoginFormImpl)JsfUtils.resolveVariable("administratorLoginAdministratorLoginForm");
    }

    /**
     * This method is called when the use case 'Administrator Login' starts.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _administratorLogin_started(AdministratorLoginFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves the internal start use case
     *    
     * @return administratorLogin
     * @throws Throwable
     */
    protected String internalStartUseCase(Map<String,Object> useCaseParameters)
        throws Throwable
    {
        this.setLastPostedFormClientId("administratorLoginAdministratorLoginForm");
        
        String forward=null;
        final AdministratorLoginFormImpl form =
            this.getAdministratorLoginForm();
            
        //copy parameters form caller use case
        form.copyFrom(useCaseParameters);
        
        //trigger method execution
        _administratorLogin_started(form);

        forward = _beginAdminLogin(form);
        populateActionFormsAndPageVariables(null,forward,form);
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for Begin Admin Login
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _beginAdminLogin(final AdministratorLoginFormImpl form)
        throws Throwable
    {
        String forward = null;
        forward = "/org/andromda/samples/carrental/admins/web/login/adminstrator-login.jsf";
        return forward;
    }


}