@
#include "TrafficLight-sharedFunctions.cws"

function generateJavaClass(strategy : node) {
    @class @strategy.name@ extends TrafficLightStrategy {
    public @strategy.name@() {}

    public bool start() {
        return @strategy.start@;
    }

    public int executeRules() {
        int iTriggeredRules = 0;
        if (bActive_) {
@
    incrementIndentLevel();
    foreach i in strategy.rules {
        @        if (executeRule@i.key()@()) ++iTriggeredRules;
@
    }
    @    }
    return iTriggeredRules;
}

@

    foreach i in strategy.rules {
        @private bool executeRule@i.key()@() {
    if (@convertAntecedent2Cpp(i.condition)@ == false) {
        return false;
    }
@
        foreach j in i.actions {
            writeAction<j>(j, "Java");
        }
        @    return true;
}

@
    }
    decrementIndentLevel();
    @}

@
}

if getMarkupKey() == "strategies" {
    // the current markup key is worth "strategies":
    // generate the implementation of each strategy
    // class, coming from ".tlc" files
    foreach strategy in this.strategies {
        generateJavaClass(strategy);
    }
} else if startString(getMarkupKey(), "DSL: ") {
    // the current markup key embeds strategies written
    // directly into the Java file
    if subString(getMarkupKey(), 5) != "TrafficLight" {
        error("only one DSL recognized for the moment: 'TrafficLight'!");
    }

    // parsing of the strategies attached to the markup: the function
    // 'getMarkupValue()' returns data embedded in the markup
    local theParseTree;
    parseStringAsBNF("TrafficLight.cwp", theParseTree, getMarkupValue());

    @*/
@
    foreach strategy in theParseTree.strategies {
        generateJavaClass(strategy);
    }
    @/*
@
}

Generated by CodeWorker v3.11.0.1 from CWscript2HTML.cwp.