|
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean class="com.wazeegroup.physhun.framework.ConcreteState" id="stateModel.NewTransaction">
<property name="initialState">
<value>true</value>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteState" id="stateModel.TransactionInProgress"/>
<bean class="com.wazeegroup.physhun.framework.ConcreteState" id="stateModel.TransactionComplete">
<property name="terminationState">
<value>true</value>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteState" id="stateModel.TransactionCancelled">
<property name="terminationState">
<value>true</value>
</property>
</bean>
<bean class="com.wazeegroup.physhun.generic.condition.Default" id="stateModel.DefaultCondition"/>
<bean class="com.wazeegroup.physhun.generic.condition.TriggeredDefault" id="stateModel.DefaultTriggeredCondition"/>
<bean class="com.wazeegroup.physhun.framework.ConcreteTransition" id="stateModel.tNew-InProgress">
<property name="fromState">
<ref bean="stateModel.NewTransaction"/>
</property>
<property name="toState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="condition">
<ref bean="stateModel.DefaultTriggeredCondition"/>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteTransition" id="stateModel.selfTransition-FundsAdded">
<property name="fromState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="toState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="condition">
<bean class="com.wazeegroup.physhun.generic.condition.InlineGroovyTriggeredCondition" id="stateModel.selfTransition-FundsAdded-condition">
<property name="code">
<value>if (triggerEvent instanceof soda.events.FundsAdded) {
return true;
}
else {
//some other type of event
return false;
}</value>
</property>
</bean>
</property>
<property name="action">
<bean class="com.wazeegroup.physhun.generic.action.InlineGroovyAction" id="stateModel.selfTransition-FundsAdded-action">
<property name="code">
<value>System.out.println("funds added!");
//Cast the process object and trigger event to make them easier to use.
soda.events.FundsAdded fundsAdded =
(soda.events.FundsAdded)triggerEvent;
soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
//Add the appropriate funds to the transaction
float newFunds = sodaTransaction.getFunds() + fundsAdded.getHowMuch();
sodaTransaction.setFunds(newFunds);</value>
</property>
</bean>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteTransition" id="stateModel.transitionSelectionOutOfStock">
<property name="fromState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="toState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="action">
<bean class="com.wazeegroup.physhun.generic.action.InlineGroovyAction" id="stateModel.transitionSelectionOutOfStock-action">
<property name="code">
<value>soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
System.out.println("Sold Out!");
sodaTransaction.setLastMessage("Sold Out!");</value>
</property>
</bean>
</property>
<property name="condition">
<bean class="com.wazeegroup.physhun.generic.condition.InlineGroovyTriggeredCondition" id="stateModel.transitionSelectionOutOfStock-condition">
<property name="code">
<value>if (! (triggerEvent instanceof soda.events.SelectionButtonPressed)) {
//it's not a button press event
return false;
}
//Cast the process object and trigger event to make them easier to use.
soda.events.SelectionButtonPressed buttonPressed =
(soda.events.SelectionButtonPressed)triggerEvent;
soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
//In this example, we'll just hardcode Orange Crush as out of stock and all others in stock
if (buttonPressed.getSelection().equals("Orange Crush")) {
return true;
}
else {
return false;
}</value>
</property>
</bean>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteTransition" id="stateModel.transitionPriceExceedsFunds">
<property name="fromState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="toState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="condition">
<bean class="com.wazeegroup.physhun.generic.condition.InlineGroovyTriggeredCondition" id="stateModel.transitionPriceExceedsFunds-condition">
<property name="code">
<value>if (! (triggerEvent instanceof soda.events.SelectionButtonPressed)) {
//it's not a button press event
return false;
}
//Cast the process object and trigger event to make them easier to use.
soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
//In this example, we'll just hardcode all prices to $0.50
if (sodaTransaction.getFunds() < 0.5f) {
return true;
}
else {
return false;
}</value>
</property>
</bean>
</property>
<property name="action">
<bean class="com.wazeegroup.physhun.generic.action.InlineGroovyAction" id="stateModel.transitionPriceExceedsFunds-action">
<property name="code">
<value>soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
System.out.println("Price: \$0.50");
sodaTransaction.setLastMessage("Price: \$0.50");</value>
</property>
</bean>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteTransition" id="stateModel.TransactionInProgress-TransactionCancelled">
<property name="fromState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="toState">
<ref bean="stateModel.TransactionCancelled"/>
</property>
<property name="condition">
<bean class="com.wazeegroup.physhun.generic.condition.InlineGroovyTriggeredCondition" id="stateModel.TransactionInProgress-TransactionCancelled-condition">
<property name="code">
<value>if (triggerEvent instanceof soda.events.CoinReturnPressed) {
return true;
}
else {
return false;
}</value>
</property>
</bean>
</property>
<property name="action">
<bean class="com.wazeegroup.physhun.generic.action.InlineGroovyAction" id="stateModel.TransactionInProgress-TransactionCancelled-action">
<property name="code">
<value>//Cast the process object to make it easier to use.
soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
//remove funds from holding
float fundsToRefund = sodaTransaction.getFunds();
sodaTransaction.setFunds(0f);
//refund the user's money
System.out.println(fundsToRefund + " returned");
sodaTransaction.setLastMessage(fundsToRefund + " returned");</value>
</property>
</bean>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteTransition" id="stateModel.TransactionInProgress-TransactionComplete">
<property name="fromState">
<ref bean="stateModel.TransactionInProgress"/>
</property>
<property name="toState">
<ref bean="stateModel.TransactionComplete"/>
</property>
<property name="action">
<bean class="com.wazeegroup.physhun.generic.action.InlineGroovyAction" id="stateModel.TransactionInProgress-TransactionComplete-action">
<property name="code">
<value>//cast the processObject and triggerEvent for usability
soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
soda.events.SelectionButtonPressed buttonPress =
(soda.events.SelectionButtonPressed)triggerEvent;
//in a real scenario, we'd interface with the machine hardware to vend the selected soda.
System.out.println(buttonPress.getSelection() + " vended!");
sodaTransaction.setLastMessage(buttonPress.getSelection() + " vended!");
//in a real scenario, we'd interface with the machine hardware to commit the transaction funds.
sodaTransaction.setFunds(0f);</value>
</property>
</bean>
</property>
<property name="condition">
<bean class="com.wazeegroup.physhun.generic.condition.InlineGroovyTriggeredCondition" id="stateModel.TransactionInProgress-TransactionComplete-condition">
<property name="code">
<value>if (! (triggerEvent instanceof soda.events.SelectionButtonPressed)) {
//not a ButtonPress event
return false;
}
//Cast the process object and trigger event to make them easier to use.
soda.events.SelectionButtonPressed buttonPressed =
(soda.events.SelectionButtonPressed)triggerEvent;
soda.SodaTransaction sodaTransaction =
(soda.SodaTransaction)processObject;
//In this example, we'll just hardcode all prices to $0.50
if (sodaTransaction.getFunds() < 0.5f) {
return false;
}
//In this example, we'll just hardcode Orange Crush as out of stock and all others in stock
if (buttonPressed.getSelection().equals("Orange Crush")) {
return false;
}
return true;</value>
</property>
</bean>
</property>
</bean>
<bean class="com.wazeegroup.physhun.framework.ConcreteStateModel" id="stateModel">
<property name="states">
<list>
<ref bean="stateModel.NewTransaction"/>
<ref bean="stateModel.TransactionInProgress"/>
<ref bean="stateModel.TransactionComplete"/>
<ref bean="stateModel.TransactionCancelled"/>
</list>
</property>
<property name="transitions">
<list>
<ref bean="stateModel.tNew-InProgress"/>
<ref bean="stateModel.selfTransition-FundsAdded"/>
<ref bean="stateModel.transitionSelectionOutOfStock"/>
<ref bean="stateModel.transitionPriceExceedsFunds"/>
<ref bean="stateModel.TransactionInProgress-TransactionCancelled"/>
<ref bean="stateModel.TransactionInProgress-TransactionComplete"/>
</list>
</property>
</bean>
</beans>
©2005-2008 Wazee Group, LLC
|