GuessController.java
// license-header java merge-point
// Generated by andromda-jsf cartridge (controllers\Controller.java.vsl) DO NOT EDIT!
package org.andromda.samples.animalquiz.guess;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.andromda.samples.animalquiz.ControllerBase;
import org.andromda.samples.animalquiz.JsfUtils;
import org.andromda.samples.animalquiz.Messages;
import org.andromda.samples.animalquiz.ServiceLocator;
import org.andromda.samples.animalquiz.decisiontree.DecisionService;
/**
* <p>
* TODO: Model Documentation for GuessController
* </p>
*/
public abstract class GuessController
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 GuessController instance()
{
return (GuessController)JsfUtils.resolveVariable("guessController");
}
/**
* 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/animalquiz/guess/confirm-animal-in-mind.jsf".equals(forward))
{
GuessViewPopulator.populateForm(sourceForm,this.getConfirmAnimalInMindGotOneForm());
}
else
if("/org/andromda/samples/animalquiz/guess/answer-question.jsf".equals(forward))
{
GuessViewPopulator.populateForm(sourceForm,this.getAnswerQuestionYesForm());
GuessViewPopulator.populateForm(sourceForm,this.getAnswerQuestionNoForm());
GuessViewPopulator.populateAnswerQuestionPageVariables(sourceForm,pageVariables);
}
else
if("/org/andromda/samples/animalquiz/guess/reveal-animal.jsf".equals(forward))
{
GuessViewPopulator.populateForm(sourceForm,this.getRevealAnimalThisIsTheAnimalForm());
}
else
if("/org/andromda/samples/animalquiz/guess/enter-a-question.jsf".equals(forward))
{
GuessViewPopulator.populateForm(sourceForm,this.getEnterAQuestionThisIsTheQuestionForm());
}
ControllerBase.getUseCaseScope().put(CURRENT_PAGE_VARIABLES_KEY, pageVariables);
}
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.getFirstQuestion
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract void getFirstQuestion(GetFirstQuestionForm form)
throws Throwable;
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.nextDecisionItemAvailable
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract String nextDecisionItemAvailable(NextDecisionItemAvailableForm form)
throws Throwable;
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.rememberAnimal
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract void rememberAnimal(RememberAnimalForm form)
throws Throwable;
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.rememberQuestion
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract void rememberQuestion(RememberQuestionForm form)
throws Throwable;
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.lastAnswerWasYes
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract boolean lastAnswerWasYes()
throws Throwable;
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.rememberPositiveAnswer
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract void rememberPositiveAnswer()
throws Throwable;
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.rememberNegativeAnswer
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract void rememberNegativeAnswer()
throws Throwable;
/**
* <p>
* Sets up the session for the user, initializing objects that will be used and need to be
* created in advance (such as the GuessSessionState).
* </p>
*
* @param form the associated form
* @throws Throwable
*/
public abstract void initializeSession()
throws Throwable;
/**
* Retrieves the {@link ConfirmAnimalInMindGotOneFormImpl} form instance
*
* @return ConfirmAnimalInMindGotOneFormImpl
*/
protected ConfirmAnimalInMindGotOneFormImpl getConfirmAnimalInMindGotOneForm()
{
return (ConfirmAnimalInMindGotOneFormImpl)JsfUtils.resolveVariable("guessConfirmAnimalInMindGotOneForm");
}
/**
* <p>
* TODO: Model Documentation for got one
* </p>
* This method is called when 'got one' is triggered in the view 'confirm animal in mind'.
* It can be safely overridden in descendant classes.
*
* @param form the associated form
*/
protected void _confirmAnimalInMind_gotOne(ConfirmAnimalInMindGotOneFormImpl form)
{
//this method can be overridden
}
/**
* Retrieves confirmAnimalInMindGotOne()
*
* @return confirmAnimalInMindGotOne
* @throws Throwable
*/
public String confirmAnimalInMindGotOne()
throws Throwable
{
this.setLastPostedFormClientId("guessConfirmAnimalInMindGotOneForm");
String forward=null;
final ConfirmAnimalInMindGotOneFormImpl form =
this.getConfirmAnimalInMindGotOneForm();
//trigger method execution
_confirmAnimalInMind_gotOne(form);
forward = _getTheFirstQuestion(form);
populateActionFormsAndPageVariables("/org/andromda/samples/animalquiz/guess/confirm-animal-in-mind.jsf",forward,form);
if(forward != null)
{
if("/org/andromda/samples/animalquiz/guess/confirm-animal-in-mind.jsf".equals(forward))
{
forward = null; //the destination form is the same, stay on the current view
}
}
return forward;
}
/**
* <p>
* TODO: Model Documentation for get the first question
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _getTheFirstQuestion(final ConfirmAnimalInMindGotOneFormImpl form)
throws Throwable
{
String forward = null;
getFirstQuestion(form);
forward = _promptTheUser(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for prompt the user
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _promptTheUser(final ConfirmAnimalInMindGotOneFormImpl form)
throws Throwable
{
String forward = null;
forward = "/org/andromda/samples/animalquiz/guess/answer-question.jsf";
return forward;
}
/**
* Retrieves the {@link AnswerQuestionYesFormImpl} form instance
*
* @return AnswerQuestionYesFormImpl
*/
protected AnswerQuestionYesFormImpl getAnswerQuestionYesForm()
{
return (AnswerQuestionYesFormImpl)JsfUtils.resolveVariable("guessAnswerQuestionYesForm");
}
/**
* <p>
* TODO: Model Documentation for yes
* </p>
* This method is called when 'yes' is triggered in the view 'answer question'.
* It can be safely overridden in descendant classes.
*
* @param form the associated form
*/
protected void _answerQuestion_yes(AnswerQuestionYesFormImpl form)
{
//this method can be overridden
}
/**
* Retrieves answerQuestionYes()
*
* @return answerQuestionYes
* @throws Throwable
*/
public String answerQuestionYes()
throws Throwable
{
this.setLastPostedFormClientId("guessAnswerQuestionYesForm");
String forward=null;
final AnswerQuestionYesFormImpl form =
this.getAnswerQuestionYesForm();
//trigger method execution
_answerQuestion_yes(form);
forward = _rememberPositiveAnswer(form);
populateActionFormsAndPageVariables("/org/andromda/samples/animalquiz/guess/answer-question.jsf",forward,form);
if(forward != null)
{
if("/org/andromda/samples/animalquiz/guess/answer-question.jsf".equals(forward))
{
forward = null; //the destination form is the same, stay on the current view
}
}
return forward;
}
/**
* <p>
* TODO: Model Documentation for remember positive answer
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _rememberPositiveAnswer(final AnswerQuestionYesFormImpl form)
throws Throwable
{
String forward = null;
rememberPositiveAnswer();
forward = _getNextDecisionItem(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for get next decision item
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _getNextDecisionItem(final AnswerQuestionYesFormImpl form)
throws Throwable
{
String forward = null;
forward = __nextDecisionItemAvailable(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for get last answer
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _getLastAnswer(final AnswerQuestionYesFormImpl form)
throws Throwable
{
String forward = null;
forward = __lastAnswerWasYes(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for ask for animal
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _askForAnimal(final AnswerQuestionYesFormImpl form)
throws Throwable
{
String forward = null;
forward = "/org/andromda/samples/animalquiz/guess/reveal-animal.jsf";
return forward;
}
/**
* <p>
* TODO: Model Documentation for prompt the user
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _promptTheUser(final AnswerQuestionYesFormImpl form)
throws Throwable
{
String forward = null;
forward = "/org/andromda/samples/animalquiz/guess/answer-question.jsf";
return forward;
}
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.unknown
* </p>
*
* @return a transition
*/
protected String __nextDecisionItemAvailable(final AnswerQuestionYesFormImpl form)
throws Throwable
{
final String value = String.valueOf(nextDecisionItemAvailable(form));
String forward = null;
if (value.equals("no"))
{
forward = _getLastAnswer(form);
}
if (value.equals("yes"))
{
forward = _promptTheUser(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;
}
}
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.unknown
* </p>
*
* @return a transition
*/
protected String __lastAnswerWasYes(final AnswerQuestionYesFormImpl form)
throws Throwable
{
final String value = String.valueOf(lastAnswerWasYes());
String forward = null;
if (value.equals("true"))
{
forward = "/org/andromda/samples/animalquiz/guess/i-win-continue.jsf";
}
if (value.equals("false"))
{
forward = _askForAnimal(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 AnswerQuestionNoFormImpl} form instance
*
* @return AnswerQuestionNoFormImpl
*/
protected AnswerQuestionNoFormImpl getAnswerQuestionNoForm()
{
return (AnswerQuestionNoFormImpl)JsfUtils.resolveVariable("guessAnswerQuestionNoForm");
}
/**
* <p>
* TODO: Model Documentation for no
* </p>
* This method is called when 'no' is triggered in the view 'answer question'.
* It can be safely overridden in descendant classes.
*
* @param form the associated form
*/
protected void _answerQuestion_no(AnswerQuestionNoFormImpl form)
{
//this method can be overridden
}
/**
* Retrieves answerQuestionNo()
*
* @return answerQuestionNo
* @throws Throwable
*/
public String answerQuestionNo()
throws Throwable
{
this.setLastPostedFormClientId("guessAnswerQuestionNoForm");
String forward=null;
final AnswerQuestionNoFormImpl form =
this.getAnswerQuestionNoForm();
//trigger method execution
_answerQuestion_no(form);
forward = _rememberNegativeAnswer(form);
populateActionFormsAndPageVariables("/org/andromda/samples/animalquiz/guess/answer-question.jsf",forward,form);
if(forward != null)
{
if("/org/andromda/samples/animalquiz/guess/answer-question.jsf".equals(forward))
{
forward = null; //the destination form is the same, stay on the current view
}
}
return forward;
}
/**
* <p>
* TODO: Model Documentation for remember negative answer
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _rememberNegativeAnswer(final AnswerQuestionNoFormImpl form)
throws Throwable
{
String forward = null;
rememberNegativeAnswer();
forward = _getNextDecisionItem(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for get next decision item
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _getNextDecisionItem(final AnswerQuestionNoFormImpl form)
throws Throwable
{
String forward = null;
forward = __nextDecisionItemAvailable(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for get last answer
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _getLastAnswer(final AnswerQuestionNoFormImpl form)
throws Throwable
{
String forward = null;
forward = __lastAnswerWasYes(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for ask for animal
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _askForAnimal(final AnswerQuestionNoFormImpl form)
throws Throwable
{
String forward = null;
forward = "/org/andromda/samples/animalquiz/guess/reveal-animal.jsf";
return forward;
}
/**
* <p>
* TODO: Model Documentation for prompt the user
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _promptTheUser(final AnswerQuestionNoFormImpl form)
throws Throwable
{
String forward = null;
forward = "/org/andromda/samples/animalquiz/guess/answer-question.jsf";
return forward;
}
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.unknown
* </p>
*
* @return a transition
*/
protected String __nextDecisionItemAvailable(final AnswerQuestionNoFormImpl form)
throws Throwable
{
final String value = String.valueOf(nextDecisionItemAvailable(form));
String forward = null;
if (value.equals("no"))
{
forward = _getLastAnswer(form);
}
if (value.equals("yes"))
{
forward = _promptTheUser(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;
}
}
/**
* <p>
* TODO: Model Documentation for org.andromda.samples.animalquiz.guess.unknown
* </p>
*
* @return a transition
*/
protected String __lastAnswerWasYes(final AnswerQuestionNoFormImpl form)
throws Throwable
{
final String value = String.valueOf(lastAnswerWasYes());
String forward = null;
if (value.equals("true"))
{
forward = "/org/andromda/samples/animalquiz/guess/i-win-continue.jsf";
}
if (value.equals("false"))
{
forward = _askForAnimal(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 RevealAnimalThisIsTheAnimalFormImpl} form instance
*
* @return RevealAnimalThisIsTheAnimalFormImpl
*/
protected RevealAnimalThisIsTheAnimalFormImpl getRevealAnimalThisIsTheAnimalForm()
{
return (RevealAnimalThisIsTheAnimalFormImpl)JsfUtils.resolveVariable("guessRevealAnimalThisIsTheAnimalForm");
}
/**
* <p>
* TODO: Model Documentation for this is the animal
* </p>
* This method is called when 'this is the animal' is triggered in the view 'reveal animal'.
* It can be safely overridden in descendant classes.
*
* @param form the associated form
*/
protected void _revealAnimal_thisIsTheAnimal(RevealAnimalThisIsTheAnimalFormImpl form)
{
//this method can be overridden
}
/**
* Retrieves revealAnimalThisIsTheAnimal()
*
* @return revealAnimalThisIsTheAnimal
* @throws Throwable
*/
public String revealAnimalThisIsTheAnimal()
throws Throwable
{
this.setLastPostedFormClientId("guessRevealAnimalThisIsTheAnimalForm");
String forward=null;
final RevealAnimalThisIsTheAnimalFormImpl form =
this.getRevealAnimalThisIsTheAnimalForm();
//trigger method execution
_revealAnimal_thisIsTheAnimal(form);
forward = _rememberAnimal(form);
populateActionFormsAndPageVariables("/org/andromda/samples/animalquiz/guess/reveal-animal.jsf",forward,form);
if(forward != null)
{
if("/org/andromda/samples/animalquiz/guess/reveal-animal.jsf".equals(forward))
{
forward = null; //the destination form is the same, stay on the current view
}
}
return forward;
}
/**
* <p>
* TODO: Model Documentation for remember animal
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _rememberAnimal(final RevealAnimalThisIsTheAnimalFormImpl form)
throws Throwable
{
String forward = null;
rememberAnimal(form);
forward = _askForAQuestion(form);
return forward;
}
/**
* <p>
* TODO: Model Documentation for ask for a question
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _askForAQuestion(final RevealAnimalThisIsTheAnimalFormImpl form)
throws Throwable
{
String forward = null;
forward = "/org/andromda/samples/animalquiz/guess/enter-a-question.jsf";
return forward;
}
/**
* Retrieves the {@link EnterAQuestionThisIsTheQuestionFormImpl} form instance
*
* @return EnterAQuestionThisIsTheQuestionFormImpl
*/
protected EnterAQuestionThisIsTheQuestionFormImpl getEnterAQuestionThisIsTheQuestionForm()
{
return (EnterAQuestionThisIsTheQuestionFormImpl)JsfUtils.resolveVariable("guessEnterAQuestionThisIsTheQuestionForm");
}
/**
* <p>
* TODO: Model Documentation for this is the question
* </p>
* This method is called when 'this is the question' is triggered in the view 'enter a question'.
* It can be safely overridden in descendant classes.
*
* @param form the associated form
*/
protected void _enterAQuestion_thisIsTheQuestion(EnterAQuestionThisIsTheQuestionFormImpl form)
{
//this method can be overridden
}
/**
* Retrieves enterAQuestionThisIsTheQuestion()
*
* @return enterAQuestionThisIsTheQuestion
* @throws Throwable
*/
public String enterAQuestionThisIsTheQuestion()
throws Throwable
{
this.setLastPostedFormClientId("guessEnterAQuestionThisIsTheQuestionForm");
String forward=null;
final EnterAQuestionThisIsTheQuestionFormImpl form =
this.getEnterAQuestionThisIsTheQuestionForm();
//trigger method execution
_enterAQuestion_thisIsTheQuestion(form);
forward = _rememberQuestion(form);
JsfUtils.addInfoMessage(Messages.get("true", (Object[])null));
populateActionFormsAndPageVariables("/org/andromda/samples/animalquiz/guess/enter-a-question.jsf",forward,form);
if(forward != null)
{
if("/org/andromda/samples/animalquiz/guess/enter-a-question.jsf".equals(forward))
{
forward = null; //the destination form is the same, stay on the current view
}
}
return forward;
}
/**
* <p>
* TODO: Model Documentation for remember question
* </p>
*
* @param form the associated form
* @return the forward view
* @throws Throwable
*/
protected String _rememberQuestion(final EnterAQuestionThisIsTheQuestionFormImpl form)
throws Throwable
{
String forward = null;
rememberQuestion(form);
forward = ((GuessController)JsfUtils.resolveVariable("guessController")).startUseCase();
return forward;
}
/**
* <p>
* TODO: Model Documentation for continue
* </p>
* This method is called when 'continue' is triggered in the view 'I win, continue ?'.
* It can be safely overridden in descendant classes.
*/
protected void _iWinContinue_continue()
{
//this method can be overridden
}
/**
* Retrieves iWinContinueContinue()
*
* @return iWinContinueContinue
* @throws Throwable
*/
public String iWinContinueContinue()
throws Throwable
{
this.setLastPostedFormClientId("guessIWinContinueContinueForm");
String forward=null;
forward=((GuessController)JsfUtils.resolveVariable("guessController")).startUseCase();
return forward;
}
/**
* This method is called when the use case 'Guess' starts.
* It can be safely overridden in descendant classes.
*/
protected void _guess_started()
{
//this method can be overridden
}
/**
* Retrieves the internal start use case
*
* @return guess
* @throws Throwable
*/
protected String internalStartUseCase(Map<String,Object> useCaseParameters)
throws Throwable
{
this.setLastPostedFormClientId("guessGuessForm");
String forward=null;
//trigger method execution
_guess_started();
forward = _askUserToThinkOfAnAnimal();
return forward;
}
/**
* <p>
* TODO: Model Documentation for ask user to think of an animal
* </p>
*
* @return the forward view
* @throws Throwable
*/
protected String _askUserToThinkOfAnAnimal()
throws Throwable
{
String forward = null;
initializeSession();
forward = "/org/andromda/samples/animalquiz/guess/confirm-animal-in-mind.jsf";
return forward;
}
/**
* Returns a reference to the DecisionService back-end service.
*
* @return ServiceLocator.instance().getDecisionService()
*/
protected final DecisionService getDecisionService()
{
try
{
return ServiceLocator.instance().getDecisionService();
}
catch (final Throwable throwable)
{
throw new RuntimeException(throwable);
}
}
/**
* Returns the current GuessSessionState from the session found in the argument request.
* <p/>
* In case an object was found in the session but it was not of the correct type, this method
* will return <code>null</code>.
* <p/>
* If there is no session, it will be created; if the session does not contain the session-object
* the object will be instantiated and subsequently stored in the session.
*
* @return read description
*/
protected final GuessSessionState getGuessSessionState()
{
GuessSessionState object = null;
final HttpSession session = JsfUtils.getSession(true);
Object attribute = session.getAttribute("guessSessionState");
if (attribute instanceof GuessSessionState)
{
object = (GuessSessionState)attribute;
}
else if (attribute == null)
{
object = new GuessSessionState();
setGuessSessionState(object);
}
return object;
}
/**
* Set the argument org.andromda.cartridges.jsf2.metafacades.JSFSessionObjectLogicImpl[GuessSessionState] .name object in the session corresponding with the argument request.
* If the session does not exist it will be created.
*
* @param object the object
*/
protected final void setGuessSessionState(final GuessSessionState object)
{
this.setGuessSessionState(object, true);
}
/**
* Set the argument GuessSessionState object in the session corresponding with the argument request.
* Any existing object will be overwritten.
*
* @param object the object
* @param createSession denotes whether or not the session should be created automatically in case it
* would not yet exist
*/
protected final void setGuessSessionState(GuessSessionState object, boolean createSession)
{
final HttpSession session = JsfUtils.getSession(createSession);
if (session != null)
{
session.setAttribute("guessSessionState", object);
}
}
/**
* Removes the argument GuessSessionState object from the session corresponding with the argument request.
* In any of the following cases this method will do nothing:
* <ul>
* <li>No session corresponds to the argument request</li>
* <li>No GuessSessionState object could be found in the request</li>
* <li>The object is not of the correct type</li>
* </ul>
*/
protected final void removeGuessSessionState()
{
final HttpSession session = JsfUtils.getSession(false);
if (session != null)
{
Object attribute = session.getAttribute("guessSessionState");
if (attribute instanceof GuessSessionState)
{
session.removeAttribute("guessSessionState");
}
}
}
}