Integrating It All
[ 318 ]
' ',' ',' ',
' ',' ',' '
]
def TicTacToeEngineSession() {
super()
page = new WelcomePage(this)
}
}
The TicTacToeEngineSession class will be generated based on the state
variables declared in the state block of the DSL. The session class extends a
PersistableSession class, which has methods for marshaling the current session
variables to and from a map. It also creates a unique session ID from a UUID:
class PersistableSession {
def sessionId
def page
def PersistableSession() {
sessionId = UUID.randomUUID().toString()
}
def restoreSession(Map saved) {
saved.each { var ->
if (this.properties.containsKey(var.key)) {
if (var.key == 'page') {
page = Class.forName("${saved.page.capitalize()}Page")
.getDeclaredConstructor(Object.class)
.newInstance(this)
} else {
this."${var.key}" = var.value
}
}
}
}
Map asMap() {
Map theMap = this.properties.clone()
theMap.remove('class')
theMap['page'] = this.page.toString()
theMap
}
}
http://www.ebook3000.com