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"); }}