SOURCECODE |
How to... define a Gate
Description:
Gates are a part of SalesProcesses. If you want to implement user interaction, use UIGates. Normal Gates are preferably used to decide at which UIGate the Process continues. They are also very suitable for the implementation of background Processes. If you need data to prepared before the Gate goes into action, implement a Transition to the Gate.
(See also: HowTo..incorporate a SaleProcess, HowTo..define a UIGate, HowTo..define a Transition )
ToDo's:
- Select SaleProcess where you want to realize a Gate without user interaction.
- Define global instance of the new Gate.
- Instanciate the Gate, therefore implement
public Transition getNextTransition(SaleProcess pOwner, User usr)
method.
(It is also possible to subclass Gate and use the constuctor instead of an anonymous class, but unnecessary in most cases.)
- Decide which Gate should be the next and add return statement with the fitting Gate or Transition.
Uses:
Gate UIGate SaleProcess Transition GateChangeTransition
// mainly imports
import sale.Gate;
import sale.Transition;
import sale.GateChangeTransition;
import sale.SaleProcess;
import users.User;
1
// Main Class
public class RentProcess extends SaleProcess
{
2
// global instance of the not user interactive Gate
protected Gate decisionGate;
// Main Method
protected void setupMachine()
{
3
// The DecisionGate is defined
// It is a normal Gate without user interaction
decisionGate =
// the Gate as anonymous class
new Gate()
{
// getNextTransition method is to be implemented
public Transition getNextTransition(SaleProcess pOwner, User usr)
throws InterruptedException
{
// main task of this method is to decide which Gate has to be next
// therefore you could return certain Gates or Transitions
if (videoCatalog.size(dataBasket) == 0)
4
// the Process will be finished after committing
return GateChangeTransition.CHANGE_TO_COMMIT_GATE;
else
4
// the StartGate will be the next Gate
return new GateChangeTransition(startGate);
}
};
}
}