Drools 被設計為可插入式的語言實現。目前規則能用Java, Python和Groovy實現。更為重要的是,Drools提供了聲明式程序設計(Declarative PRogramming),并且使用域描述語言(Domain Specific Languages (DSL))-專為你的問題域定義了某種模式的xml, 它已經足夠靈活到可以用來描述你的問題域。DSLs包含的XML元素(Element)和屬性(Attribute)代表了問題域中各種要素。
import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import BusinessLayer;/** * Sample Struts action with Pseudocode * 使用偽代碼的Struts行為示例 */public class SampleStrutsAction extends Action{ /** * Standard Struts doPerfom method * 標準的Struts doPerform方法 */ public ActionForward doPerform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws InvalidEntryPointException {//Local Variables//本地變量 StocKOFfer userOffer =null; //Get any previous values from the session//從session取得以前的數據 userOffer=(StockOffer)request.getSession() .getAttribute("PREVIOUS_STOCK_OFFER"); //create this object if it is null//如為null則創建新對象 if (null==userOffer){ userOffer = new StockOffer(); }//Update with the incoming values //用上送的數據更新//These values match those on the form //這些數據是與form中的數據相對應的 userOffer.setStockName(request. getParameterValue("STOCK_NAME")); userOffer.setStockPrice(request .getParameterValue("STOCK_PRICE")); userOffer.setStockQuantity(request .getParameterValue("STOCK_QTY")); //Reset the output value//重置輸出數據 userOffer.setRecommendPurchase(null);//Call the Business Layer//調用商業層 BusinessLayer .evaluateStockPurchase(userOffer); //Forward to the appropriate page //轉向合適的頁面 if ("YES".equals( testOffer.getRecommendPurchase()){ return mapping.findForward("YES_WEB_PAGE"); } //otherwise default to the no page//否則指向無此頁面 return mapping.findForward("NO_WEB_PAGE"); }}