| 1 28 29 package com.idaremedia.antx.condition.solo; 30 31 import java.util.Iterator ; 32 import java.util.Stack ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 import org.apache.tools.ant.taskdefs.Available; 37 import org.apache.tools.ant.taskdefs.Checksum; 38 import org.apache.tools.ant.taskdefs.UpToDate; 39 import org.apache.tools.ant.taskdefs.condition.Condition; 40 import org.apache.tools.ant.types.Reference; 41 42 import com.idaremedia.antx.AntX; 43 import com.idaremedia.antx.NoiseLevel; 44 import com.idaremedia.antx.apis.Requester; 45 import com.idaremedia.antx.condition.AllSet; 46 import com.idaremedia.antx.condition.AllSetTrue; 47 import com.idaremedia.antx.condition.AnySet; 48 import com.idaremedia.antx.condition.AnySetTrue; 49 import com.idaremedia.antx.condition.FileNotEmpty; 50 import com.idaremedia.antx.condition.IsAntVersion; 51 import com.idaremedia.antx.condition.IsClass; 52 import com.idaremedia.antx.condition.IsResource; 53 import com.idaremedia.antx.condition.NoneSet; 54 55 95 96 public class TallySet extends RuleType implements FreeformRule 97 { 98 101 public TallySet() 102 { 103 super(AntX.rules+"tally"); 104 setStopQuickEvaluation(false); 105 } 106 107 108 112 public TallySet(String iam) 113 { 114 super(iam); 115 setStopQuickEvaluation(false); 116 } 117 118 119 123 public Object clone() 124 { 125 if (isReference()) { 126 return getReference().clone(); 127 } 128 return super.clone(); 129 } 130 131 132 138 public void setRefId(Reference r) 139 { 140 require_(r!=null,"setRefId- nonzro ref"); 141 checkModify("setRefId"); 142 if (!isEmpty()) { 143 throw new BuildException(uistrs().get("task.too.many.attrs",getId())); 144 } 145 m_ref = r; 146 } 147 148 149 153 public final Reference getRefId() 154 { 155 return m_ref; 156 } 157 158 159 163 public boolean isReference() 164 { 165 return getRefId()!=null; 166 } 167 168 169 173 public NoiseLevel getFailureEffect() 174 { 175 return NoiseLevel.WARNING; 176 } 177 178 179 183 189 public void addConfigured(Condition c) 190 { 191 require_(c!=null,"add- nonzro condition"); 192 xaddCondition(c); 193 } 194 195 196 199 public void addTallyset(TallySet tt) 200 { 201 xaddCondition(tt); 202 } 203 204 205 208 public void addIsClass(IsClass isc) 209 { 210 xaddCondition(isc); 211 } 212 213 214 217 public void addIsResource(IsResource isr) 218 { 219 xaddCondition(isr); 220 } 221 222 223 226 public void addFileNotEmpty(FileNotEmpty fne) 227 { 228 xaddCondition(fne); 229 } 230 231 232 235 public void addAllSet(AllSet allset) 236 { 237 xaddCondition(allset); 238 } 239 240 241 245 public void addAllSetTrue(AllSetTrue allset) 246 { 247 xaddCondition(allset); 248 } 249 250 251 254 public void addAnySet(AnySet anyset) 255 { 256 xaddCondition(anyset); 257 } 258 259 260 264 public void addAnySetTrue(AnySetTrue anyset) 265 { 266 xaddCondition(anyset); 267 } 268 269 270 273 public void addNoneSet(NoneSet noneset) 274 { 275 xaddCondition(noneset); 276 } 277 278 279 283 public void addIsMatch(MatchesTask matches) 284 { 285 xaddCondition(matches); 286 } 287 288 289 292 public void addAvailable(Available av) 293 { 294 xaddCondition(av); 295 } 296 297 298 301 public void addChecksum(Checksum cs) 302 { 303 xaddCondition(cs); 304 } 305 306 307 310 public void addUpToDate(UpToDate up) 311 { 312 xaddCondition(up); 313 } 314 315 316 320 public void addAntVersion(IsAntVersion vc) 321 { 322 xaddCondition(vc); 323 } 324 325 329 334 public void xaddCondition(Condition c) 335 { 336 if (isReference()) { 337 throw new BuildException(uistrs().get("task.too.many.attrs",getId())); 338 } 339 super.xaddCondition(c); 340 } 341 342 343 349 public boolean xaddRootCondition(Condition c) 350 { 351 if (isReference()) { 352 throw new BuildException(uistrs().get("task.too.many.attrs",getId())); 353 } 354 return super.xaddRootCondition(c); 355 } 356 357 358 362 protected final TallySet getReference() 363 { 364 verify_(m_ref!=null,"getReference- has refid"); 365 Object robj = m_ref.getReferencedObject(getProject()); 366 367 if (!(robj instanceof TallySet)) { 368 String ermsg = uistrs().get("brul.bad.ruleid",m_ref.getRefId()); 369 log(ermsg,Project.MSG_ERR); 370 throw new BuildException(ermsg); 371 } 372 return (TallySet)robj; 373 } 374 375 376 380 381 390 public void verifyNoCircularDependency(Stack stk, Requester clnt) 391 { 392 if (!m_circularityChecked) { 393 if (isReference()) { 394 Object robj = m_ref.getReferencedObject(getProject()); 395 if (stk.contains(robj)) { 396 String ermsg = uistrs().get("brul.circular.referals",m_ref.getRefId()); 397 clnt.problem(ermsg,Project.MSG_ERR); 398 throw new BuildException(ermsg,clnt.getLocation()); 399 } 400 if (robj instanceof BooleanRule) { 401 stk.push(robj); 402 ((BooleanRule)robj).verifyNoCircularDependency(stk,clnt); 403 stk.pop(); 404 } 405 m_circularityChecked = true; 406 } 407 else if (!isEmpty()) { 408 Stack itemstk= new Stack (); 409 Iterator itr= getConditions().iterator(); 410 int I=0; 411 while (itr.hasNext()) { 412 Object oc = itr.next(); 413 I++; 414 if (oc instanceof BooleanRule) { 415 if (stk.contains(oc)) { 416 String posI = getId()+"["+String.valueOf(I)+"]"; 417 String ermsg = uistrs().get("brul.circular.referals",posI); 418 clnt.problem(ermsg,Project.MSG_ERR); 419 throw new BuildException(ermsg,clnt.getLocation()); 420 } 421 itemstk.addAll(stk); 422 itemstk.push(oc); 423 ((BooleanRule)oc).verifyNoCircularDependency(itemstk,clnt); 424 itemstk.clear(); 425 } 426 } 427 m_circularityChecked = true; 428 } 429 } } 431 432 433 438 public boolean eval(ShareableConditionUser calr) 439 throws BuildException 440 { 441 if (isReference()) { 442 return getReference().eval(calr); 443 } 444 return super.eval(calr); 445 } 446 447 448 454 public boolean eval() 455 throws BuildException 456 { 457 if (isReference()) { 458 return getReference().eval(); 459 } 460 return super.eval(); 461 } 462 463 464 468 protected void setEvalResult(boolean istrue, String listing) 469 { 470 if (istrue) { 471 log("TallySet ("+getId()+") evaluates TRUE",Project.MSG_DEBUG); 472 } else { 473 log("TallySet ("+getId()+") evaluates FALSE; condition in order "+listing, 474 Project.MSG_DEBUG); 475 } 476 } 477 478 479 private Reference m_ref; 480 } 481 482 483 | Popular Tags |