Object Models for an Example Help Desk
public static class Problem { Note: Drools has problems dealing with Java 5
enums as match types so I use static integers here. In general, using enums
is much better. final public static int NONE = 0;
appliance types: final public static int REFRIGERATOR = 101;
final public static int MICROWAVE = 102; final public static int TV = 103;
final public static int DVD = 104; environmentalData possible values:
final public static int CIRCUIT_BREAKER_OFF = 1002; final public static int LIGHTS_OFF_IN_ROOM = 1003;
problemType possible values: final public static int NOT_RUNNING = 2001;
final public static int SMOKING = 2002; final public static int ON_FIRE = 2003;
final public static int MAKES_NOISE = 2004;
long serviceId = 0; unique ID for all problems dealing with customer problem
int applianceType = NONE; int problemType = NONE;
int environmentalData = NONE;
public Problemlong serviceId, int type { this.serviceId = serviceId;
this.applianceType = type; }
public String toString { return [Problem: + enumNames.getapplianceType +
problem type: + enumNames.getproblemType + environmental data: +
enumNames.getenvironmentalData + ]; }
public long getServiceId { return serviceId; } public int getEnvironmentalData {
return environmentalData; }
public int getProblemType { return problemType;
} static MapInteger, String enumNames =
92
new HashMapInteger, String; static {
enumNames.put0, NONE; enumNames.put1002, CIRCUIT_BREAKER_OFF;
enumNames.put1003, LIGHTS_OFF_IN_ROOM; enumNames.put2001, NOT_RUNNING;
enumNames.put2002, SMOKING; enumNames.put2003, ON_FIRE;
enumNames.put2004, MAKES_NOISE; enumNames.put101, REFRIGERATOR;
enumNames.put102, MICROWAVE; enumNames.put103, TV;
enumNames.put104, DVD;
} }
It is unfortunate that the current version of Drools does not work well with Java 5 enums – the P roblem class would have been about half as many lines of code no
need to map integers to meaningful descriptions for toString and the example
would also be more type safe. I used constant values like REFRIGERATOR and RUNNING to represent pos-
sible values for the member class attributes like applianceT ype, problemT ype, and environmentalData. There is obviously a tight binding from the Java POJO
classes like P roblem to the rules that use these classes to represent objects in work- ing memory. We will see a few example help desk rules in the next section.