RegisterCarTypeController.java

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

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.ServiceLocator;
import org.andromda.samples.carrental.admins.web.main.AdministrationController;
import org.andromda.samples.carrental.inventory.InventoryService;

/**
 * <p>
 * This controller allows to register a new Car type. It calls the Inventory Service on the server
 * side.
 * </p>
 * <p>
 * @author Carlos Cuenca
 * </p>
 */
public abstract class RegisterCarTypeController
    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 RegisterCarTypeController instance()
    {
        return (RegisterCarTypeController)JsfUtils.resolveVariable("registerCarTypeController");
    }
    
    /**
     * 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/inventory/web/registerCarType/create-new-car-type.jsf".equals(forward))
        {
            RegisterCarTypeViewPopulator.populateForm(sourceForm,this.getCreateNewCarTypeCreateForm());
        }
        ControllerBase.getUseCaseScope().put(CURRENT_PAGE_VARIABLES_KEY, pageVariables);
    }
    
    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.inventory.web.registerCarType.createCarType
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void createCarType(CreateCarTypeForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.inventory.web.registerCarType.searchAllCarTypes
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void searchAllCarTypes(SearchAllCarTypesForm form)
        throws Throwable;


    /**
     * Retrieves the {@link CreateNewCarTypeCreateFormImpl} form instance 
     *
     * @return CreateNewCarTypeCreateFormImpl
     */
    protected CreateNewCarTypeCreateFormImpl getCreateNewCarTypeCreateForm()
    {
        return (CreateNewCarTypeCreateFormImpl)JsfUtils.resolveVariable("registerCarTypeCreateNewCarTypeCreateForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for create
     * </p>
     * This method is called when 'create' is triggered in the view 'create new car type'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _createNewCarType_create(CreateNewCarTypeCreateFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves createNewCarTypeCreate()
     *    
     * @return createNewCarTypeCreate
     * @throws Throwable
     */
    public String createNewCarTypeCreate()
        throws Throwable
    {
        this.setLastPostedFormClientId("registerCarTypeCreateNewCarTypeCreateForm");
        
        String forward=null;
        final CreateNewCarTypeCreateFormImpl form =
            this.getCreateNewCarTypeCreateForm();
            
        //trigger method execution
        _createNewCarType_create(form);

        forward = _saveCar(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/inventory/web/registerCarType/create-new-car-type.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/inventory/web/registerCarType/create-new-car-type.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for save car
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _saveCar(final CreateNewCarTypeCreateFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        createCarType(form);
        forward = ((AdministrationController)JsfUtils.resolveVariable("administrationController")).startUseCase();
        return forward;
    }

    /**
     * Retrieves the {@link RegisterCarTypeFormImpl} form instance 
     *
     * @return RegisterCarTypeFormImpl
     */
    protected RegisterCarTypeFormImpl getRegisterCarTypeForm()
    {
        return (RegisterCarTypeFormImpl)JsfUtils.resolveVariable("registerCarTypeRegisterCarTypeForm");
    }

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

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

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

    /**
     * <p>
     * TODO: Model Documentation for search car types
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _searchCarTypes(final RegisterCarTypeFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        searchAllCarTypes(form);
        forward = "/org/andromda/samples/carrental/inventory/web/registerCarType/create-new-car-type.jsf";
        return forward;
    }

    /**
     * Returns a reference to the InventoryService back-end service.
     *
     * @return ServiceLocator.instance().getInventoryService()
     */
    protected final InventoryService getInventoryService()
    {
        try
        {
            return ServiceLocator.instance().getInventoryService();
        }
        catch (final Throwable throwable)
        {
            throw new RuntimeException(throwable);
        }
    }


}