CustomerReservesCarController.java

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

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.contracts.ContractService;
import org.andromda.samples.carrental.customers.CustomerService;
import org.andromda.samples.carrental.customers.web.login.CustomerLogInController;

/**
 * <p>
 * This controller register the reservation of a car. It calls the Contract Service on the server
 * Side
 * </p>
 * <p>
 * @author Carlos Cuenca
 * </p>
 */
public abstract class CustomerReservesCarController
    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 CustomerReservesCarController instance()
    {
        return (CustomerReservesCarController)JsfUtils.resolveVariable("customerReservesCarController");
    }
    
    /**
     * 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/contracts/web/reserveCar/reserve-a-car.jsf".equals(forward))
        {
            CustomerReservesCarViewPopulator.populateForm(sourceForm,this.getReserveACarReserveForm());
            CustomerReservesCarViewPopulator.populateForm(sourceForm,this.getReserveACarDeleteForm());
            CustomerReservesCarViewPopulator.populateReserveACarPageVariables(sourceForm,pageVariables);
        }
        ControllerBase.getUseCaseScope().put(CURRENT_PAGE_VARIABLES_KEY, pageVariables);
    }
    
    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.contracts.web.reserveCar.searchForReservations
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void searchForReservations(SearchForReservationsForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for org.andromda.samples.carrental.contracts.web.reserveCar.reserve
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void reserve(ReserveForm form)
        throws Throwable;

    /**
     * <p>
     * TODO: Model Documentation for
     * org.andromda.samples.carrental.contracts.web.reserveCar.deleteReservation
     * </p>
     *
     * @param form the associated form
     * @throws Throwable
     */
    public abstract void deleteReservation(DeleteReservationForm form)
        throws Throwable;


    /**
     * Retrieves the {@link ReserveACarReserveFormImpl} form instance 
     *
     * @return ReserveACarReserveFormImpl
     */
    protected ReserveACarReserveFormImpl getReserveACarReserveForm()
    {
        return (ReserveACarReserveFormImpl)JsfUtils.resolveVariable("customerReservesCarReserveACarReserveForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for reserve
     * </p>
     * This method is called when 'reserve' is triggered in the view 'Reserve a Car'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _reserveACar_reserve(ReserveACarReserveFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves reserveACarReserve()
     *    
     * @return reserveACarReserve
     * @throws Throwable
     */
    public String reserveACarReserve()
        throws Throwable
    {
        this.setLastPostedFormClientId("customerReservesCarReserveACarReserveForm");
        
        String forward=null;
        final ReserveACarReserveFormImpl form =
            this.getReserveACarReserveForm();
            
        //trigger method execution
        _reserveACar_reserve(form);

        forward = _saveReservation(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/contracts/web/reserveCar/reserve-a-car.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/contracts/web/reserveCar/reserve-a-car.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for Save Reservation
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _saveReservation(final ReserveACarReserveFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        reserve(form);
        forward = ((CustomerLogInController)JsfUtils.resolveVariable("customerLogInController")).startUseCase();
        return forward;
    }

    /**
     * Retrieves the {@link ReserveACarDeleteFormImpl} form instance 
     *
     * @return ReserveACarDeleteFormImpl
     */
    protected ReserveACarDeleteFormImpl getReserveACarDeleteForm()
    {
        return (ReserveACarDeleteFormImpl)JsfUtils.resolveVariable("customerReservesCarReserveACarDeleteForm");
    }

    /**
     * <p>
     * TODO: Model Documentation for delete
     * </p>
     * This method is called when 'delete' is triggered in the view 'Reserve a Car'.
     * It can be safely overridden in descendant classes.
     *
     * @param form the associated form
     */
    protected void _reserveACar_delete(ReserveACarDeleteFormImpl form)
    {
        //this method can be overridden
    }

    /**
     * Retrieves reserveACarDelete()
     *    
     * @return reserveACarDelete
     * @throws Throwable
     */
    public String reserveACarDelete()
        throws Throwable
    {
        this.setLastPostedFormClientId("customerReservesCarReserveACarDeleteForm");
        
        String forward=null;
        final ReserveACarDeleteFormImpl form =
            this.getReserveACarDeleteForm();
            
        //trigger method execution
        _reserveACar_delete(form);

        forward = _deleteReservation(form);
        populateActionFormsAndPageVariables("/org/andromda/samples/carrental/contracts/web/reserveCar/reserve-a-car.jsf",forward,form);
        if(forward != null)
        {
            if("/org/andromda/samples/carrental/contracts/web/reserveCar/reserve-a-car.jsf".equals(forward))
            {
                forward = null; //the destination form is the same, stay on the current view
            }
        }
        
        return forward;
    }

    /**
     * <p>
     * TODO: Model Documentation for Delete Reservation
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _deleteReservation(final ReserveACarDeleteFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        deleteReservation(form);
        forward = ((CustomerLogInController)JsfUtils.resolveVariable("customerLogInController")).startUseCase();
        return forward;
    }

    /**
     * Retrieves the {@link CustomerReservesCarFormImpl} form instance 
     *
     * @return CustomerReservesCarFormImpl
     */
    protected CustomerReservesCarFormImpl getCustomerReservesCarForm()
    {
        return (CustomerReservesCarFormImpl)JsfUtils.resolveVariable("customerReservesCarCustomerReservesCarForm");
    }

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

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

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

    /**
     * <p>
     * TODO: Model Documentation for load reservations list
     * </p>
     *
     * @param form the associated form
     * @return the forward view
     * @throws Throwable
     */
    protected String _loadReservationsList(final CustomerReservesCarFormImpl form)
        throws Throwable
    {
        String forward = null;
    
        searchForReservations(form);
        forward = "/org/andromda/samples/carrental/contracts/web/reserveCar/reserve-a-car.jsf";
        return forward;
    }

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

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


}