1 28 29 package com.idaremedia.antx.condition.solo; 30 31 import java.io.File ; 32 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.ProjectComponent; 35 import org.apache.tools.ant.RuntimeConfigurable; 36 import org.apache.tools.ant.taskdefs.Available; 37 import org.apache.tools.ant.taskdefs.condition.Condition; 38 import org.apache.tools.ant.taskdefs.condition.Http; 39 import org.apache.tools.ant.taskdefs.condition.IsFalse; 40 import org.apache.tools.ant.taskdefs.condition.IsTrue; 41 import org.apache.tools.ant.taskdefs.condition.Os; 42 import org.apache.tools.ant.types.Path; 43 import org.apache.tools.ant.types.Reference; 44 45 import com.idaremedia.antx.AssertableProjectComponent; 46 import com.idaremedia.antx.StringEquality; 47 48 import com.idaremedia.antx.condition.AllSet; 49 import com.idaremedia.antx.condition.AnySet; 50 import com.idaremedia.antx.condition.FlexCondition; 51 import com.idaremedia.antx.condition.IsAntVersion; 52 import com.idaremedia.antx.condition.IsBoolean; 53 import com.idaremedia.antx.condition.IsNotSet; 54 import com.idaremedia.antx.condition.IsNotWhitespace; 55 import com.idaremedia.antx.condition.IsNumeric; 56 import com.idaremedia.antx.condition.IsReference; 57 import com.idaremedia.antx.condition.IsSet; 58 import com.idaremedia.antx.condition.IsSetTrue; 59 import com.idaremedia.antx.condition.NoneSet; 60 import com.idaremedia.antx.condition.ShortHandConditions; 61 62 import com.idaremedia.antx.helpers.Strings; 63 import com.idaremedia.antx.helpers.Tk; 64 import com.idaremedia.antx.parameters.Handling; 65 import com.idaremedia.antx.parameters.IgnoreCaseEnabled; 66 import com.idaremedia.antx.parameters.IgnoreWhitespaceEnabled; 67 import com.idaremedia.antx.parameters.IsA; 68 import com.idaremedia.antx.parameters.MalformedCheckEnabled; 69 import com.idaremedia.antx.parameters.SynonymsEnabled; 70 import com.idaremedia.antx.parameters.TrimEnabled; 71 import com.idaremedia.antx.parameters.ValueMatchEnabled; 72 73 88 89 public final class ShortHandHelper extends AssertableProjectComponent 90 implements ShortHandConditions, ValueMatchEnabled 91 { 92 97 public ShortHandHelper(BooleanRule rule) 98 { 99 super(rule.cvlabel_()); 100 m_rule = rule; 101 } 102 103 104 110 public ShortHandHelper(String iam, BooleanRule rule) 111 { 112 super(iam); 113 require_(rule!=null,"ctor- nonzro rul"); 114 m_rule = rule; 115 } 116 117 118 122 public BooleanRule getOwningRule() 123 { 124 return m_rule; 125 } 126 127 128 133 public final boolean isActivated() 134 { 135 return m_isActivated; 136 } 137 138 139 145 public final void activateCondition(Condition c, String who) 146 { 147 boolean ok= m_rule.xaddRootCondition(c); 148 ensure_(ok,who+BooleanRule.ONLY_ONE); 149 applyPendingModifiers(c); 150 m_isActivated = true; } 152 153 154 158 private static final String tf(boolean b) 159 { 160 return b ? Strings.TRUE : Strings.FALSE; 161 } 162 163 164 168 public void setIsTrue(String value) 169 { 170 IsTrue t= new IsTrue(); 171 t.setProject(getProject()); 172 Boolean B = Tk.string2PosBool(value); 173 t.setValue(B==null ? false : B.booleanValue()); 174 activateCondition(t,"setIsTrue"); 175 } 176 177 178 public void setIsFalse(String value) 179 { 180 IsFalse f= new IsFalse(); 181 f.setProject(getProject()); 182 Boolean B = Tk.string2NegBool(value); 183 f.setValue(B==null ? false : B.booleanValue()); 184 activateCondition(f,"setIsFalse"); 185 } 186 187 188 public void setOSFamily(String family) 189 { 190 Os t= new Os(family); 191 activateCondition(t,"setOSFamily"); 192 } 193 194 195 public void setOS(String selector) 196 { 197 IsOS t= new IsOS(getProject()); 198 t.setSelector(selector); 199 activateCondition(t,"setOS"); 200 } 201 202 203 public void setHttpAlive(String url) 204 { 205 Http t= new Http(); 206 t.setProject(getProject()); 207 t.setUrl(url); 208 activateCondition(t,"setHttpAlive"); 209 } 210 211 212 public void setIsFile(File file) 213 { 214 Available t= getIsAvailableCondition(); 215 t.setFile(file); 216 Available.FileDir filetype= new Available.FileDir(); 217 Tk.initEnum(filetype,"file"); 218 t.setType(filetype); 219 activateCondition(t,"setIsFile"); 220 } 221 222 223 public void setIsDirectory(File dir) 224 { 225 Available t= getIsAvailableCondition(); 226 t.setFile(dir); 227 Available.FileDir dirtype= new Available.FileDir(); 228 Tk.initEnum(dirtype,"dir"); 229 t.setType(dirtype); 230 activateCondition(t,"setIsDirectory"); 231 } 232 233 234 public void setFilepath(Path filp) 235 { 236 m_rule.checkModify("setFilpath"); 237 Available t= getIsAvailableCondition(); 238 t.setFilepath(filp); 239 } 240 241 242 public void setIsResource(String resource) 243 { 244 Available t= getIsAvailableCondition(); 245 t.setResource(resource); 246 activateCondition(t,"setIsResource"); 247 } 248 249 250 public void setIsClass(String classname) 251 { 252 Available t= getIsAvailableCondition(); 253 t.setClassname(classname); 254 activateCondition(t,"setIsClass"); 255 } 256 257 258 public void setClasspath(Path clsp) 259 { 260 m_rule.checkModify("setClazpath"); 261 Available t= getIsAvailableCondition(); 262 t.setClasspath(clsp); 263 } 264 265 266 public void setClasspathRef(Reference cpr) 267 { 268 m_rule.checkModify("setClzpath"); 269 Available t= getIsAvailableCondition(); 270 t.setClasspathRef(cpr); 271 } 272 273 274 public void setSystemClasses(boolean included) 275 { 276 m_rule.checkModify("setSystemClazes"); 277 Available t= getIsAvailableCondition(); 278 t.setIgnoresystemclasses(!included); 279 } 280 281 285 290 public void setAntIs(String version) 291 { 292 IsAntVersion t= new IsAntVersion(); 293 t.setProject(getProject()); 294 t.setIs(version); 295 activateCondition(t,"setAntIs"); 296 } 297 298 303 public void setAntLike(String pattern) 304 { 305 IsAntVersion t= new IsAntVersion(); 306 t.setProject(getProject()); 307 t.setLike(pattern); 308 activateCondition(t,"setAntLike"); 309 } 310 311 312 316 public void setIsBoolean(String value) 317 { 318 IsBoolean t= (IsBoolean)getHalfBakedObject(IsBoolean.class); 319 t.setValue(value); 320 activateCondition(t,"setIsBoolean"); 321 } 322 323 324 public void setIsNotWhitespace(String value) 325 { 326 IsNotWhitespace t= (IsNotWhitespace)getHalfBakedObject(IsNotWhitespace.class); 327 t.setValue(value); 328 activateCondition(t,"setIsNotWSpc"); 329 } 330 331 332 public void setIsNumeric(String value) 333 { 334 IsNumeric t= (IsNumeric)getHalfBakedObject(IsNumeric.class); 335 t.setValue(value); 336 activateCondition(t,"setIsNumeric"); 337 } 338 339 340 345 public void setGT(String gt) 346 { 347 m_rule.checkModify("setGT"); 348 IsNumeric t = (IsNumeric)getHalfBakedObject("gt",gt); 349 if (t!=null) { 350 t.setGT(Tk.longFrom(gt,Tk.NO_NUM)); 351 } 352 } 353 354 355 360 public void setGTE(String gte) 361 { 362 m_rule.checkModify("setGTE"); 363 IsNumeric t = (IsNumeric)getHalfBakedObject("gte",gte); 364 if (t!=null) { 365 t.setGTE(Tk.longFrom(gte,Tk.NO_NUM)); 366 } 367 } 368 369 370 374 public void setLT(String lt) 375 { 376 m_rule.checkModify("setLT"); 377 IsNumeric t = (IsNumeric)getHalfBakedObject("lt",lt); 378 if (t!=null) { 379 t.setLT(Tk.longFrom(lt,Tk.NO_NUM)); 380 } 381 } 382 383 384 389 public void setLTE(String lte) 390 { 391 m_rule.checkModify("setLTE"); 392 IsNumeric t = (IsNumeric)getHalfBakedObject("lte",lte); 393 if (t!=null) { 394 t.setLTE(Tk.longFrom(lte,Tk.NO_NUM)); 395 } 396 } 397 398 402 public void setIsSet(String property) 403 { 404 IsSet t= (IsSet)getHalfBakedObject(IsSet.class); 405 t.setProperty(property); 406 activateCondition(t,"setIsSet"); 407 } 408 409 410 public void setIsSetTrue(String property) 411 { 412 IsSetTrue t= (IsSetTrue)getHalfBakedObject(IsSetTrue.class); 413 t.setProperty(property); 414 activateCondition(t,"setIsSetTrue"); 415 } 416 417 418 public void setIsNotSet(String property) 419 { 420 IsNotSet t= (IsNotSet)getHalfBakedObject(IsNotSet.class); 421 t.setProperty(property); 422 activateCondition(t,"setIsNotSet"); 423 } 424 425 426 430 public void setVarSet(String variable) 431 { 432 IsSet t= (IsSet)getHalfBakedObject(IsSet.class); 433 t.setVariable(variable); 434 disableIsA(); 435 activateCondition(t,"setVarSet"); 436 } 437 438 439 public void setVarSetTrue(String variable) 440 { 441 IsSetTrue t= (IsSetTrue)getHalfBakedObject(IsSetTrue.class); 442 t.setVariable(variable); 443 disableIsA(); 444 activateCondition(t,"setVarSetTrue"); 445 } 446 447 448 public void setVarNotSet(String variable) 449 { 450 IsNotSet t= (IsNotSet)getHalfBakedObject(IsNotSet.class); 451 t.setVariable(variable); 452 disableIsA(); 453 activateCondition(t,"setVarNotSet"); 454 } 455 456 457 461 462 465 public void setIsRef(String refId) 466 { 467 IsReference t= (IsReference)getHalfBakedObject(IsReference.class); 468 t.setName(refId); 469 activateCondition(t,"setIsRef"); 470 } 471 472 473 477 public void setIsNotRef(String refId) 478 { 479 IsReference t= (IsReference)getHalfBakedObject(IsReference.class); 480 t.setName(refId); 481 t.xsetNoExist(true); 482 activateCondition(t,"setIsNotRef"); 483 } 484 485 486 489 public void setClassName(String clzId) 490 { 491 m_rule.checkModify("setRefClaz"); 492 IsReference ref= getIsReferenceCondition(); 493 ref.setClassName(clzId); 494 } 495 496 497 500 public void setIsKindOf(boolean isKindOf) 501 { 502 m_rule.checkModify("setRefKndOf"); 503 IsReference ref= getIsReferenceCondition(); 504 ref.setKindOf(isKindOf); 505 } 506 507 508 512 public void setAnySet(String properties) 513 { 514 require_(!Tk.isWhitespace(properties),"setAnySet- propertylist"); 515 AnySet t= new AnySet(properties,getProject()); 516 setHalfBakedObject(t); 517 activateCondition(t,"setAnySet"); 518 } 519 520 521 public void setAllSet(String properties) 522 { 523 require_(!Tk.isWhitespace(properties),"setAllSet- propertylist"); 524 AllSet t= new AllSet(properties,getProject()); 525 setHalfBakedObject(t); 526 activateCondition(t,"setAllSet"); 527 } 528 529 530 536 public void setAllSetLike(String pattern) 537 { 538 require_(!Tk.isWhitespace(pattern),"setAllSetLike- pattern"); 539 AllSet t= new AllSet(); 540 t.setProject(getProject()); 541 t.setPropertiesLike(pattern); 542 setHalfBakedObject(t); 543 activateCondition(t,"setAllSetLike"); 544 } 545 546 547 public void setNoneSet(String properties) 548 { 549 require_(!Tk.isWhitespace(properties),"setNoneSet- propertylist"); 550 NoneSet t= new NoneSet(properties,getProject()); 551 setHalfBakedObject(t); 552 activateCondition(t,"setNoneSet"); 553 } 554 555 556 560 public void setMatches(String pattern) 561 { 562 StringEquality t= getEqualityCondition(); 563 t.setMatch(pattern); 564 activateCondition(t,"setMatches"); 565 } 566 567 568 public final void setMatch(String pattern) 569 { 570 setMatches(pattern); 571 } 572 573 574 public void setVariable(String variable) 575 { 576 m_rule.checkModify("setStrEqVar"); 577 StringEquality eqt = getEqualityCondition(); 578 eqt.setUnknownArg(variable); 579 eqt.getUnknownValueGetter().setIsExported(true); 580 } 581 582 583 public void setProperty(String property) 584 { 585 m_rule.checkModify("setStrEqProp"); 586 StringEquality eqt = getEqualityCondition(); 587 eqt.setUnknownArg(property); 588 eqt.getUnknownValueGetter().setIsProperty(true); 589 } 590 591 592 public void setReference(String reference) 593 { 594 m_rule.checkModify("setStrEqRef"); 595 StringEquality eqt = getEqualityCondition(); 596 eqt.setUnknownArg(reference); 597 eqt.getUnknownValueGetter().setIsReference(true); 598 } 599 600 601 public void setValue(String value) 602 { 603 m_rule.checkModify("setStrEqValu"); 604 Object t = getHalfBakedObject("value",value); 605 if (t!=null) { 606 ((ValueMatchEnabled)t).setValue(value); 607 } 608 } 609 610 614 public void setSynonyms(boolean allowAll) 615 { 616 m_rule.checkModify("setSynonyms"); 617 Object t = getHalfBakedObject("synonyms",tf(allowAll)); 618 if (t!=null) { 619 ((SynonymsEnabled)t).setSynonyms(allowAll); 620 } 621 } 622 623 624 public boolean allowSynonyms() 625 { 626 if (getHalfBakedObject() instanceof SynonymsEnabled) { 627 return ((SynonymsEnabled)getHalfBakedObject()).allowSynonyms(); 628 } 629 return true; } 631 632 633 public void setIgnoreCase(boolean ignore) 634 { 635 m_rule.checkModify("setIgnoreCase"); 636 Object t = getHalfBakedObject("ignorecase",tf(ignore)); 637 if (t!=null) { 638 ((IgnoreCaseEnabled)t).setIgnoreCase(ignore); 639 } 640 } 641 642 643 public boolean isIgnoreCase() 644 { 645 if (getHalfBakedObject() instanceof IgnoreCaseEnabled) { 646 return ((IgnoreCaseEnabled) 647 getHalfBakedObject()).isIgnoreCase(); 648 } 649 return false; 650 } 651 652 653 public void setTrim(boolean trim) 654 { 655 m_rule.checkModify("setTrim"); 656 Object t = getHalfBakedObject("trim",tf(trim)); 657 if (t!=null) { 658 ((TrimEnabled)t).setTrim(trim); 659 } 660 } 661 662 663 public boolean willTrim() 664 { 665 if (getHalfBakedObject() instanceof TrimEnabled) { 666 return ((TrimEnabled)getHalfBakedObject()).willTrim(); 667 } 668 return false; 669 } 670 671 672 public void setWhitespace(Handling response) 673 { 674 m_rule.checkModify("setWhtSpc"); 675 Object t = getHalfBakedObject("whitespace",response.getValue()); 676 if (t!=null) { 677 ((IgnoreWhitespaceEnabled)t).setWhitespace(response); 678 } 679 } 680 681 682 public boolean ignoreWhitespace() 683 { 684 if (getHalfBakedObject() instanceof IgnoreWhitespaceEnabled) { 685 return ((IgnoreWhitespaceEnabled) 686 getHalfBakedObject()).ignoreWhitespace(); 687 } 688 return false; 689 } 690 691 692 public void setMalformed(Handling response) 693 { 694 m_rule.checkModify("setMalformd"); 695 Object t = getHalfBakedObject("malformed",response.getValue()); 696 if (t!=null) { 697 ((MalformedCheckEnabled)t).setMalformed(response); 698 } 699 } 700 701 702 public Handling getMalformedHandling() 703 { 704 if (getHalfBakedObject() instanceof MalformedCheckEnabled) { 705 return ((MalformedCheckEnabled) 706 getHalfBakedObject()).getMalformedHandling(); 707 } 708 return null; 709 } 710 711 712 716 721 public void disableIsA() 722 { 723 m_disableIsA=true; 724 } 725 726 727 731 public boolean noIsA() 732 { 733 return m_disableIsA; 734 } 735 736 737 746 public void setIsA(IsA isa) 747 { 748 m_rule.checkModify("setIsA"); 749 750 require_(!noIsA(),"setIsA- Flex condition"); 751 752 Object t = getHalfBakedObject(); 753 if (t==null && m_delayedIsA==null) { m_delayedIsA = new IsAHandle(isa); 755 return; 756 } 757 758 require_((t instanceof FlexCondition),"setIsA- Flex condition"); 759 760 FlexCondition c = (FlexCondition)t; 761 762 switch (isa.getIndex()) { 763 case IsA.PROPERTY_INDEX: { 764 c.setProperty(c.getFlexValue()); 765 break; 766 } 767 case IsA.VARIABLE_INDEX: { 768 c.setVariable(c.getFlexValue()); 769 break; 770 } 771 case IsA.REFERENCE_INDEX:{ 772 c.setReference(c.getFlexValue()); 773 break; 774 } 775 default: { 776 c.setLiteral(c.getFlexValue()); 777 } 778 } 779 } 780 781 785 795 public final Object getHalfBakedObject(Class ofClass) 796 { 797 if (m_halfbakedObject==null) { 798 try { 799 m_halfbakedObject = ofClass.newInstance(); 800 } catch(Exception anyX) { 801 throw new BuildException(anyX,m_rule.getLocation()); 802 } 803 if (m_halfbakedObject instanceof ProjectComponent) { 804 ((ProjectComponent)m_halfbakedObject).setProject(getProject()); 805 } 806 } 807 else { 808 require_(ofClass.isInstance(m_halfbakedObject), 809 "construction of a single condition-type inline"); 810 } 811 return m_halfbakedObject; 812 } 813 814 815 819 public final Object getHalfBakedObject() 820 { 821 return m_halfbakedObject; 822 } 823 824 825 829 private Object getHalfBakedObject(String attr, String saved) 830 { 831 Object t = getHalfBakedObject(); 832 if (t==null) { 833 getPendingModifiers().setAttribute(attr,saved); 834 } 835 return t; 836 } 837 838 839 844 private void setHalfBakedObject(Object object) 845 { 846 m_halfbakedObject = object; 847 } 848 849 850 855 StringEquality getEqualityCondition() 856 { 857 return (StringEquality)getHalfBakedObject(StringEquality.class); 858 } 859 860 861 866 private Available getIsAvailableCondition() 867 { 868 return (Available)getHalfBakedObject(Available.class); 869 } 870 871 872 877 private IsReference getIsReferenceCondition() 878 { 879 return (IsReference)getHalfBakedObject(IsReference.class); 880 } 881 882 883 887 private static final Object NOTHIN= new int[0]; 888 889 890 897 public final boolean havePendingModifiers() 898 { 899 return m_delayedParams!=null || m_delayedIsA!=null; 900 } 901 902 903 909 public final void applyPendingModifiers(Object test) 910 { 911 require_(test!=null,"applyMods- nonzro condition"); 912 if (m_delayedParams!=null) { 913 m_delayedParams.setProxy(test); 914 RuntimeConfigurable helper = m_delayedParams; 915 m_delayedParams = null; 916 helper.reconfigure(getProject()); 917 helper = null; 918 } 919 if (m_delayedIsA!=null) { 920 setIsA(m_delayedIsA.get()); 921 m_delayedIsA = null; 922 } 923 } 924 925 926 932 private RuntimeConfigurable getPendingModifiers() 933 { 934 if (m_delayedParams==null) { 935 m_delayedParams = new RuntimeConfigurable(NOTHIN,"shh"); 936 } 937 return m_delayedParams; 938 } 939 940 941 945 private Object m_halfbakedObject; private final BooleanRule m_rule; 947 private boolean m_disableIsA; private boolean m_isActivated; private RuntimeConfigurable m_delayedParams; private IsAHandle m_delayedIsA;} 952 953 954 | Popular Tags |