ReturnCarController.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.returnCar;
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.contracts.ContractService;
import org.andromda.samples.carrental.contracts.web.registerAccident.RegisterAccidentController;
/**
* <p>
* This controller allows the user to return a car that has been previously rented. It calls the
* Contract Service on the server side
* </p>
* <p>
* @author Carlos Cuenca
* </p>
*/
public abstract class ReturnCarController
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 ReturnCarController instance()
{
return (ReturnCarController)JsfUtils.resolveVariable("returnCarController");
}
/**
* 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/returnCar/select-contract.jsf".equals(forward))
{
ReturnACarViewPopulator.populateForm(sourceForm,this.getSelectContractReturnForm());
ReturnACarViewPopulator.populateSelectContractPageVariables(sourceForm,pageVariables);
}
ControllerBase.getUseCaseScope().put(CURRENT_PAGE_VARIABLES_KEY, pageVariables);
}
/**
* <p>
* TODO: Model Documentation for
* org.andromda.samples.carrental.contracts.web.returnCar.returnCar
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract String returnCar(ReturnCarForm form)
throws Throwable;
/**
* <p>
* TODO: Model Documentation for
* org.andromda.samples.carrental.contracts.web.returnCar.searchForContractsOfCustomer
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract void searchForContractsOfCustomer(SearchForContractsOfCustomerForm form)
throws Throwable;
/**
* <p>
* TODO: Model Documentation for
* org.andromda.samples.carrental.contracts.web.returnCar.hadAccident
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract String hadAccident(HadAccidentForm form)
throws Throwable;
/**
* Retrieves the {@link SelectContractReturnFormImpl} form instance
*
* @return SelectContractReturnFormImpl
*/
protected SelectContractReturnFormImpl getSelectContractReturnForm()
{
return (SelectContractReturnFormImpl)JsfUtils.resolveVariable("returnACarSelectContractReturnForm");
}
/**
* <p>
* TODO: Model Documentation for return
* </p>
* This method is called when 'return' is triggered in the view 'Select Contract'.
* It can be safely overridden in descendant classes.
*
* @param form the associated form
*/
protected void _selectContract_return(SelectContractReturnFormImpl form)
{
//this method can be overridden
}
/**
* Retrieves selectContractReturn()
*
* @return selectContractReturn
* @throws Throwable
*/
public String selectContractReturn()
throws Throwable
{
this.setLastPostedFormClientId("returnACarSelectContractReturnForm");
String forward=null;
final SelectContractReturnFormImpl form =
this.getSelectContractReturnForm();
//trigger method execution
_selectContract_return(form);
forward = _accidentHappened(form);
populateActionFormsAndPageVariables("/org/andromda/samples/carrental/contracts/web/returnCar/select-contract.jsf",forward,form);
if(forward != null)
{
if("/org/andromda/samples/carrental/contracts/web/returnCar/select-contract.jsf".equals(forward))
{
forward = null; //the destination form is the same, stay on the current view
}
}
return forward;
}
/**
* <p>
* TODO: Model Documentation for Accident Happened
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _accidentHappened(final SelectContractReturnFormImpl form)
throws Throwable
{
String forward = null;
forward = __hadAccident(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for Returning Car
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _returningCar(final SelectContractReturnFormImpl form)
throws Throwable
{
String forward = null;
returnCar(form);
forward = ((AdministrationController)JsfUtils.resolveVariable("administrationController")).startUseCase();
return forward;
}
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.carrental.contracts.web.returnCar.accident
* </p>
*
* @return a transition
*/
protected String __hadAccident(final SelectContractReturnFormImpl form)
throws Throwable
{
final String value = String.valueOf(hadAccident(form));
String forward = null;
if (value.equals("yes"))
{
forward = ((RegisterAccidentController)JsfUtils.resolveVariable("registerAccidentController")).startUseCase();
}
if (value.equals("no"))
{
forward = _returningCar(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 ReturnACarFormImpl} form instance
*
* @return ReturnACarFormImpl
*/
protected ReturnACarFormImpl getReturnACarForm()
{
return (ReturnACarFormImpl)JsfUtils.resolveVariable("returnACarReturnACarForm");
}
/**
* This method is called when the use case 'ReturnACar' starts.
* It can be safely overridden in descendant classes.
*
* @param form the associated form
*/
protected void _returnACar_started(ReturnACarFormImpl form)
{
//this method can be overridden
}
/**
* Retrieves the internal start use case
*
* @return returnACar
* @throws Throwable
*/
protected String internalStartUseCase(Map<String,Object> useCaseParameters)
throws Throwable
{
this.setLastPostedFormClientId("returnACarReturnACarForm");
String forward=null;
final ReturnACarFormImpl form =
this.getReturnACarForm();
//copy parameters form caller use case
form.copyFrom(useCaseParameters);
//trigger method execution
_returnACar_started(form);
forward = _searchForContracts(form);
populateActionFormsAndPageVariables(null,forward,form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for search for contracts
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _searchForContracts(final ReturnACarFormImpl form)
throws Throwable
{
String forward = null;
searchForContractsOfCustomer(form);
forward = "/org/andromda/samples/carrental/contracts/web/returnCar/select-contract.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);
}
}
}