Example of Using a Static and Dynamic Wrapper

The following example illustrates the use of static and dynamic wrappers:

public class Tutorial1Main {

public interface Tutorial1Rules {

void hello1(int i);

}

public static void main(String[] args)

{

out.println("\n* OpenL Tutorial 1\n");

out.println("Working using static wrapper...\n");

callRulesWithStaticWrapper();

out.println("\nWorking using dynamic wrapper...\n");

callRulesWithDynamicWrapper();

}

private static void callRulesWithStaticWrapper() {

//Get current hour

Calendar calendar = Calendar.getInstance();

int hour = calendar.get(Calendar.HOUR_OF_DAY);

//Creates new instance of Java Wrapper for our lesson

Tutorial_1Wrapper tut1 = new Tutorial_1Wrapper();

//Step 1

out.println("* Executing OpenL rules...\n");

// Call the method wrapping Decision Table "hello1"

tut1.hello1(hour);

}

private static void callRulesWithDynamicWrapper(){

// Creates new instance of OpenL Rules Factory

RuleEngineFactory<Tutorial1Rules> rulesFactory = new RuleEngineFactory<Tutorial1Rules>("rules/Tutorial_1.xls", Tutorial1Rules.class);

//Creates new instance of dynamic Java Wrapper for our lesson

Tutorial1Rules rules = rulesFactory.newInstance();

//Get current hour

Calendar calendar = Calendar.getInstance();

int hour = calendar.get(Calendar.HOUR_OF_DAY);

out.println("* Executing OpenL rules...\n");

rules.hello1(hour);

}

}