Reputation: 13405
I've got a class WorldGodsVoice
class WorldGodsVoice extends Thread implements IThreadable {
def innerId
boolean isSequenced
long wait
def messages = []
volatile isEternal = true
def seq_id = 0
....
}
I WorldGodsVoice
wrap with another class
class GodsVoiceSubsystem extends Subsystem {
def component = new WorldGodsVoice()
def activate() {
component.start()
}
def disable() {
component.stopThread()
}
String toString() {
component
}
}
And keep that wrapped class inside some global object LifeFramework
@Component
class LifeFramework extends ComplexFramework {
static final service_config = "config/service-config.xml";
def file
{
file = Gdx.files.internal(service_config).file
loaders << [ "godsVoice" : new WorldGodsVoiceConfigLoader() ]
subsystems << [ "godsVoice" : new GodsVoiceSubsystem() ]
}
def initSubsystems() {
loaders.each { k, v -> v.load(file, subsystems[k]) }
subsystems.each { k, v ->
v.activate()
}
}
def destroySubsystems() {
subsystems.each { k, v ->
v.disable()
}
}
def accessSubsystem(id) {
subsystems[id]
}
}
ComplexFramework
is just an abstract class with methods and loaders, subsystems
fields.
Configuration for WorldGodsVoice
I keep in the xml
file
<?xml version="1.0"?>
<services>
<service id="godsVoice">
<innerId>GOD_S_VOICE</innerId>
<wait>1000</wait>
<messages sequenced="false">
The world is living...Without a hero!
The world is filled with life!
The world is eternal!
</messages>
</service>
</services>
I process xml
like this
abstract class XmlConfigSubsystemLoader {
def load(file, subsystem) {
def xml = new ServiceConfigLoader().load(file) // new XmlSlurper().parse(file)
processXml(xml.'*'.find { node -> node.@id == subsystemId() }, subsystem)
}
abstract subsystemId()
abstract processXml(xml, subsystem)
}
And abstract methods looks like this
class WorldGodsVoiceConfigLoader extends XmlConfigSubsystemLoader {
def subsystemId() { "godsVoice" }
def processXml(xml, subsystem) {
subsystem.component.innerId = xml.innerId.text()
subsystem.component.wait = xml.wait.text() as Long
subsystem.component.messages = xml.messages.text().trim().split("!").collect { it.trim() } as String[]
subsystem.component.isSequenced = xml.messages.@sequenced
println "${ xml.messages.@sequenced }" // false
println "${ subsystem.component.isSequenced }" // true
}
}
The problem is that despite having all other fields set - it does not want to set isSequenced
field for the object. It always returns for isSequenced
either default or set inside object (like boolean isSequenced = true
) value.
What is the problem?
Upvotes: 0
Views: 29
Reputation: 171144
Groovy truth says that any non-empty non-null string is true
You need
subsystem.component.isSequenced = Boolean.valueOf(xml.messages.@sequenced)
Upvotes: 1