1 28 29 package com.idaremedia.antx.condition.solo; 30 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.taskdefs.condition.Condition; 33 import org.apache.tools.ant.types.Reference; 34 35 import com.idaremedia.antx.AntX; 36 import com.idaremedia.antx.ExportedProperties; 37 import com.idaremedia.antx.helpers.Strings; 38 import com.idaremedia.antx.parameters.TrueFalsePropertySetter; 39 40 88 89 public class TallyTask extends CompoundRuleTask 90 implements FreeformRule, TrueFalsePropertySetter 91 { 92 95 public TallyTask() 96 { 97 super(AntX.rules+"tally"); 98 } 99 100 101 104 public TallyTask(String iam) 105 { 106 super(iam); 107 } 108 109 110 114 protected TallyTask(String iam, boolean embedded) 115 { 116 super(iam,embedded); 117 } 118 119 120 124 135 public final void setLogic(BooleanRule.Operator logic) 136 { 137 setDefaultCombineOperator(logic); 138 } 139 140 141 146 public final BooleanRule.Operator getLogic() 147 { 148 return getDefaultCombineOperator(); 149 } 150 151 152 159 public void setAll(boolean evaluateAll) 160 { 161 setStopQuickEvaluation(!evaluateAll); 162 } 163 164 165 171 public final boolean willEvaluateAll() 172 { 173 return !isStopQuickEvaluation(); 174 } 175 176 177 182 public void setFalseProperty(String property) 183 { 184 require_(property!=null,"setFalsP- nonzro nam"); 185 checkModify("setFalsProp"); 186 m_falseProperty = property; 187 m_varMask &= ~F_VAR; 188 } 189 190 191 195 public final String getFalseProperty() 196 { 197 return (m_varMask&F_VAR)==F_VAR ? null : m_falseProperty; 198 } 199 200 201 207 public void setFalseVariable(String variable) 208 { 209 require_(variable!=null,"setFalsV- nonzro nam"); 210 checkModify("setFalsVar"); 211 m_falseProperty = variable; 212 m_varMask |= F_VAR; 213 } 214 215 216 221 public final String getFalseVariable() 222 { 223 return (m_varMask&F_VAR)==F_VAR ? m_falseProperty : null; 224 } 225 226 227 232 public void setTrueProperty(String property) 233 { 234 require_(property!=null,"setTrueP- nonzro nam"); 235 checkModify("setTrueProp"); 236 m_trueProperty = property; 237 } 238 239 240 244 public final String getTrueProperty() 245 { 246 return m_trueProperty; 247 } 248 249 250 256 public void setTrueVariable(String variable) 257 { 258 require_(variable!=null,"setTrueV- nonzro nam"); 259 checkModify("setTrueVar"); 260 m_trueProperty = variable; 261 m_varMask |= T_VAR; 262 } 263 264 265 270 public final String getTrueVariable() 271 { 272 return (m_varMask&T_VAR)==T_VAR ? m_trueProperty : null; 273 } 274 275 276 284 public void setRuleId(Reference ruleId) 285 { 286 setReferralReference(ruleId); 287 } 288 289 290 294 public void setId(String id) 295 { 296 m_Id= id; 297 } 298 299 300 303 public final String getId() 304 { 305 if (m_Id!=null) { 306 return m_Id; 307 } 308 return super.getId(); 309 } 310 311 312 315 public void addTally(TallyTask tt) 316 { 317 xaddCondition(tt); 318 } 319 320 321 324 public final void addPrefer(PreferTask pt) 325 { 326 xaddCondition(pt); 327 } 328 329 330 333 public final void addAssert(AssertTask at) 334 { 335 xaddCondition(at); 336 } 337 338 342 348 public void addConfigured(Condition c) 349 { 350 require_(c!=null,"add- nonzro condition"); 351 xaddCondition(c); 352 } 353 354 358 361 public boolean eval() 362 { 363 boolean istrue; 364 365 if (runReferral()) { 366 istrue= getReferral().eval(new Referee()); 367 } else { 368 verifyCanExecute_("eval"); 369 istrue= defaultMultipleConditionEval(); 370 } 371 372 375 if (istrue && getTrueProperty()!=null) { 376 String prop = getTrueProperty(); 377 log("Tally was true; setting true-property '"+prop+"' property", 378 Project.MSG_DEBUG); 379 if ((m_varMask&T_VAR)==T_VAR) { 380 ExportedProperties.set(prop,Strings.TRUE); 381 } else { 382 checkIfProperty_(prop,true); 383 getProject().setNewProperty(prop,Strings.TRUE); 384 } 385 } 386 if (!istrue && getFalseProperty()!=null) { 387 String prop = getFalseProperty(); 388 log("Tally was false; setting false-property '"+prop+"' property", 389 Project.MSG_DEBUG); 390 if ((m_varMask&F_VAR)==F_VAR) { 391 ExportedProperties.set(prop,Strings.TRUE); 392 } else { 393 checkIfProperty_(prop,true); 394 getProject().setNewProperty(prop,Strings.TRUE); 395 } 396 } 397 398 return istrue; 399 } 400 401 402 406 protected boolean isIncompatibleReferral(ShareableCondition rule) 407 { 408 return false; 409 } 410 411 412 private static final int T_VAR=0x02; 413 private static final int F_VAR=0x04; 414 415 private String m_Id; 416 private String m_falseProperty; 417 private String m_trueProperty; 418 private int m_varMask; 419 } 420 421 422 | Popular Tags |