Facts are nothing but plain old java objects (POJO). This article provides an overview on "How to create DROOLS Facts" in eclipse with the help of an example. A sample fact about a "Room" is as given below. Room have 4 properties. They are Room Name, Height , Width and Alarm Status. Value of alarm status will be true when alarm occurs due to fire or short circuit. When in normal condition, value of alarm status to be False.
public class Room { private String roomName; private String ROOM_WIDTH; private String ROOM_HEIGHT; private boolean alarmStatus; public String getRoomName() { return roomName; } public void setRoomName(String roomName) { this.roomName = roomName; } public String getROOM_WIDTH() { return ROOM_WIDTH; } public void setROOM_WIDTH(String rOOM_WIDTH) { ROOM_WIDTH = rOOM_WIDTH; } public String getROOM_HEIGHT() { return ROOM_HEIGHT; } public void setROOM_HEIGHT(String rOOM_HEIGHT) { ROOM_HEIGHT = rOOM_HEIGHT; } public boolean isAlarmStatus() { return alarmStatus; } public void setAlarmStatus(boolean alarmStatus) { this.alarmStatus = alarmStatus; } }
If you look at the above fact you can see that , variables "roomName", "alarmStatus" starts with a small letter. Variables ROOM_WIDTH, ROOM_HEIGHT are capital. Reason behind it is that, drools wont allow variables starting with capital letter preceded by small letter. Fully capitalized words are accepted by DROOLS.
Another aspect of defining variables is that , access modifier should be private. There should be getters and setters to access the variable. In the above DROOLS example, variable "roomName" is accessed using "getRoomName" and "setRoomName" methods. If Get and Set methods are not available DROOLS throws exception "Unable to create Field Extractor for 'roomName' "
No comments:
Post a Comment