1 32 33 package com.knowgate.rules; 34 35 import java.util.Map ; 36 import java.util.Iterator ; 37 import java.util.HashMap ; 38 import java.util.Date ; 39 import java.math.BigDecimal ; 40 41 52 public abstract class RuleExecution { 53 54 private RuleEngine oRuleEngine; 55 56 private HashMap oParams; 57 private HashMap oAssrts; 58 59 63 public RuleExecution(RuleEngine oEngine) { 64 oRuleEngine = oEngine; 65 oParams = new HashMap (29); 66 oAssrts = new HashMap (29); 67 } 68 69 73 public RuleExecution(RuleExecution oRexec) { 74 oRuleEngine = oRexec.getRuleEngine(); 75 oParams = (HashMap ) oRexec.getParamMap().clone(); 76 oAssrts = (HashMap ) oRexec.getAssertMap().clone(); 77 } 78 79 82 public void clear() { 83 oParams.clear(); 84 oAssrts.clear(); 85 } 86 87 91 public RuleEngine getRuleEngine() { 92 return oRuleEngine; 93 } 94 95 100 public void setAssert(String sAssertKey, boolean bTrueOrFalse) { 101 if (oAssrts.containsKey(sAssertKey)) oAssrts.remove(sAssertKey); 102 oAssrts.put(sAssertKey, new Boolean (bTrueOrFalse)); 103 } 104 105 110 public boolean getAssert(String sAssertKey) { 111 Boolean bAssrt = (Boolean ) oAssrts.get(sAssertKey); 112 if (bAssrt==null) 113 return false; 114 else 115 return bAssrt.booleanValue(); 116 } 117 118 122 public HashMap getParamMap() { 123 return oParams; 124 } 125 126 130 public HashMap getAssertMap() { 131 return oAssrts; 132 } 133 134 141 public boolean isNull(String sKey) { 142 if (oParams.containsKey(sKey)) 143 return (null==oParams.get(sKey)); 144 else 145 return true; 146 } 147 148 153 public boolean isDefined(String sKey) { 154 return oParams.containsKey(sKey); 155 } 156 157 163 public void setParam(String sKey, Object oValue) { 164 if (oParams.containsKey(sKey)) oParams.remove(sKey); 165 oParams.put(sKey, oValue); 166 } 167 168 172 public void resetParam(String sKey) { 173 if (oParams.containsKey(sKey)) oParams.remove(sKey); 174 } 175 176 181 public void setParams(Map oMap) { 182 Iterator oKeys = oMap.keySet().iterator(); 183 while (oKeys.hasNext()) { 184 Object oKey = (String ) oKeys.next(); 185 if (oParams.containsKey(oKey)) oParams.remove(oKey); 186 oParams.put(oKey, oMap.get(oKey)); 187 } } 189 190 195 public Object getParam(String sKey) { 196 if (oParams.containsKey(sKey)) 197 return oParams.get(sKey); 198 else 199 return null; 200 } 201 202 208 public Object getParam(String sKey, Object oDefault) { 209 if (oParams.containsKey(sKey)) 210 return oParams.get(sKey); 211 else 212 return oDefault; 213 } 214 215 221 public String getParamStr(String sKey, String sDefault) { 222 Object oParam = oParams.get(sKey); 223 if (oParam==null) 224 return sDefault; 225 else 226 return oParam.toString(); 227 } 228 229 234 public String getParamStr(String sKey) { 235 return getParamStr(sKey, null); 236 } 237 238 245 public Date getParamDate(String sKey, Date dtDefault) 246 throws ClassCastException { 247 Object oParam = oParams.get(sKey); 248 if (oParam==null) 249 return dtDefault; 250 else 251 return (Date ) oParam; 252 } 253 254 260 public Date getParamDate(String sKey) 261 throws ClassCastException { 262 return getParamDate(sKey, null); 263 } 264 265 272 public BigDecimal getParamDec(String sKey, BigDecimal oDefault) 273 throws ClassCastException { 274 Object oParam = oParams.get(sKey); 275 if (oParam==null) 276 return oDefault; 277 else 278 return (BigDecimal ) oParam; 279 } 280 281 287 public BigDecimal getParamDec(String sKey) 288 throws ClassCastException { 289 return getParamDec(sKey, null); 290 } 291 292 299 public Integer getParamInt(String sKey, Integer iDefault) 300 throws ClassCastException { 301 Object oParam = oParams.get(sKey); 302 if (oParam==null) 303 return iDefault; 304 else 305 return (Integer ) oParam; 306 } 307 308 314 public Integer getParamInt(String sKey) 315 throws ClassCastException { 316 return getParamInt(sKey, null); 317 } 318 319 326 public abstract Object getResult() throws RuleExecutionException; 327 } 328 | Popular Tags |