1 28 29 package com.idaremedia.antx.condition.solo; 30 31 import java.util.Iterator ; 32 import java.util.Stack ; 33 import java.util.Hashtable ; 34 35 import org.apache.tools.ant.BuildException; 36 import org.apache.tools.ant.Location; 37 import org.apache.tools.ant.taskdefs.condition.Condition; 38 39 import com.idaremedia.antx.AntX; 40 import com.idaremedia.antx.FixtureComponent; 41 import com.idaremedia.antx.NoiseLevel; 42 import com.idaremedia.antx.apis.BuildAssertionException; 43 import com.idaremedia.antx.apis.Requester; 44 import com.idaremedia.antx.starters.Quiet; 45 46 47 62 63 public abstract class RuleType extends BooleanRule 64 implements FixtureComponent, ShareableCondition, Quiet, Cloneable 65 { 66 67 71 protected RuleType(String iam) 72 { 73 super(iam,true); 74 } 75 76 77 81 public Object clone() 82 { 83 try { 84 RuleType copy = (RuleType)super.clone(); 85 cloneInternals(copy); 86 return copy; 87 } catch(CloneNotSupportedException clnx) { 88 throw new Error (uistrs().get(AntX.CLONE_BROKEN_MSGID)); 89 } 90 } 91 92 96 100 public void setId(String id) 101 { 102 m_Id= id; 103 } 104 105 106 112 public final String getId() 113 { 114 if (m_Id!=null) { 115 return m_Id; 116 } 117 return super.getId(); 118 } 119 120 121 126 public NoiseLevel getFailureEffect() 127 { 128 return null; 129 } 130 131 132 136 140 private static final Hashtable sm_updateJunkFactories= new Hashtable (11,0.9f); 141 142 private static final RuleUserHandle.Factory getUpdateJunkFactory(Class c) 143 { 144 if (c==null) { 145 throw new IllegalArgumentException ("getUPJFactory- NULL class"); 146 } 147 synchronized(c) { RuleUserHandle.Factory f= (RuleUserHandle.Factory) 149 sm_updateJunkFactories.get(c); 150 if (f==null) { 151 f = new RuleUserHandle.Factory(); 152 sm_updateJunkFactories.put(c,f); 153 } 154 return f; 155 } 156 } 157 158 159 165 private static final RuleUserHandle getUpdatePropertyJunkHandle(Class c) 166 { 167 return (RuleUserHandle)getUpdateJunkFactory(c).get(); 168 } 169 170 171 176 protected static final ShareableConditionUser getUpdatePropertyJunk(Class c) 177 { 178 return ((RuleUserHandle)getUpdateJunkFactory(c).get()).getCaller(); 179 } 180 181 182 186 public final String getMsgId() 187 { 188 ShareableConditionUser upj= getUpdatePropertyJunk(getClass()); 189 String msgid = upj!=null ? upj.getMsgId() : null; 190 return (msgid!=null) ? msgid : super.getMsgId(); 191 } 192 193 194 198 public final Location getLocation() 199 { 200 ShareableConditionUser upj= getUpdatePropertyJunk(getClass()); 201 Location l = upj!=null ? upj.getLocation() : null; 202 return (l!=null) ? l : super.getLocation(); 203 } 204 205 206 210 protected final String getUpdateProperty() 211 { 212 ShareableConditionUser upj= getUpdatePropertyJunk(getClass()); 213 return upj!=null ? upj.getUpdateProperty() : super.getUpdateProperty(); 214 } 215 216 217 221 protected final String getUpdatePropertyValue() 222 { 223 ShareableConditionUser upj= getUpdatePropertyJunk(getClass()); 224 String upv = upj!=null ? upj.getUpdateValue() : null; 225 return (upv==null) ? super.getUpdatePropertyValue() : upv; 226 } 227 228 229 233 protected final String getUpdateVariable() 234 { 235 ShareableConditionUser upj= getUpdatePropertyJunk(getClass()); 236 return upj!=null ? upj.getUpdateVariable() : super.getUpdateVariable(); 237 } 238 239 240 244 249 public final synchronized void freezeDefinition() 250 { 251 if (!isFrozen()) { 252 maybeConfigure(); 253 super.freezeDefinition(); 254 255 if (!m_circularityChecked) { 256 Stack stk = new Stack (); 257 stk.push(this); 258 verifyNoCircularDependency(stk, new Requester.ForComponent(this)); 259 m_circularityChecked=true; 260 } 261 } 262 } 263 264 265 270 protected boolean safeEvalImpl() 271 { 272 boolean stopQuik= isStopQuickEvaluation(); 273 boolean istrue= true; 274 int N= 0; 275 boolean stop= false; 277 if (!isEmpty()) { 278 Iterator itr= getConditions().iterator(); 279 while (!stop && itr.hasNext()) { 280 try { 281 boolean condTrue = ((Condition)itr.next()).eval(); 282 if (!condTrue) { 283 istrue = false; 284 if (stopQuik) { 285 stop = true; 286 } 287 } 288 } catch(BuildAssertionException aX) { 289 istrue = false; 290 stop = true; 291 } 292 N++; 293 } 294 } 295 296 setEvalResult(istrue,getConditionNames(N)); 297 return istrue; 298 } 299 300 301 308 public boolean eval(ShareableConditionUser calr) 309 throws BuildException 310 { 311 require_(calr!=null, "eval- nonzro calr information"); 312 313 freezeDefinition(); 315 316 RuleUserHandle upj = getUpdatePropertyJunkHandle(getClass()); 318 final ShareableConditionUser previous = upj.setCaller(calr); 319 320 try { 322 return safeEvalImpl(); 323 } 324 finally { 326 upj.setCaller(previous); 327 } 328 } 329 330 331 340 public boolean eval() 341 { 342 freezeDefinition(); 344 345 return safeEvalImpl(); 347 } 348 349 350 352 356 public final void execute() 357 { 358 } 360 361 362 protected boolean m_circularityChecked; private String m_Id;} 366 367 368 | Popular Tags |