1 28 29 package com.idaremedia.antx.flowcontrol.match; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.types.Reference; 34 35 import com.idaremedia.antx.AntX; 36 import com.idaremedia.antx.FlexString; 37 import com.idaremedia.antx.apis.Requester; 38 import com.idaremedia.antx.condition.solo.RulesTk; 39 import com.idaremedia.antx.helpers.GenericParameters; 40 import com.idaremedia.antx.ownhelpers.ScopedProperties; 41 42 56 57 public class MatchCondition extends ChoiceTask 58 { 59 62 public MatchCondition() 63 { 64 super(AntX.flow+"switch"); 65 } 66 67 68 69 76 protected MatchCondition(String iam, boolean delayConfiguration) 77 { 78 super(iam,delayConfiguration); 79 } 80 81 82 83 87 public void setProject(Project P) 88 { 89 super.setProject(P); 90 m_conditionId.setProject(P); 91 } 92 93 94 95 100 public String getFlexValue() 101 { 102 return m_conditionId.get(); 103 } 104 105 106 107 110 public boolean isUndefined() 111 { 112 return m_conditionId.isUndefined(); 113 } 114 115 116 117 123 public String getVUT() 124 { 125 return m_conditionId.getValue(getProject()); 126 } 127 128 129 130 134 private void setFlexValue(String id) 135 { 136 m_conditionId.set(id); 137 m_conditionId.setIsLiteral(); 138 } 139 140 141 142 147 public void setCriteria(Reference condition) 148 { 149 require_(condition!=null,"setTest- nonzro reference"); 150 setFlexValue(condition.getRefId()); 151 } 152 153 154 155 160 public final void setTest(Reference condition) 161 { 162 setCriteria(condition); 163 } 164 165 166 167 172 public final String getCriteria() 173 { 174 return m_conditionId.isLiteral() ? m_conditionId.get() : null; 175 } 176 177 178 179 183 public void setProperty(String property) 184 { 185 require_(property!=null,"setProperty- nonzro name"); 186 setFlexValue(property); 187 m_conditionId.setIsProperty(true); 188 } 189 190 191 192 196 public void setVariable(String variable) 197 { 198 require_(variable!=null,"setVariable- nonzro name"); 199 setFlexValue(variable); 200 m_conditionId.setIsExported(true); 201 } 202 203 204 205 209 public void setReference(String reference) 210 { 211 require_(reference!=null,"setReference- nonzro name"); 212 setFlexValue(reference); 213 m_conditionId.setIsReference(true); 214 } 215 216 217 218 222 private void installOverlay(String vut, Reference context) 223 { 224 Project P= getProject(); 225 226 if (context!=null) { 228 Object o = P.getReference(context.getRefId()); 229 if (o instanceof GenericParameters) { 230 m_overlay = new ScopedProperties(P,true); 231 m_overlay.put((GenericParameters)o); 232 } 233 } 234 if (vut!=null) { 235 if (m_overlay==null) { 236 m_overlay = new ScopedProperties(P,true); 237 } 238 m_overlay.put("switch.value",vut); 239 } 240 if (m_overlay!=null) { 241 m_overlay.install(); 242 } 243 } 244 245 246 247 248 251 private void uninstallOverlay() 252 { 253 if (m_overlay!=null) { 254 m_overlay.uninstall(null); 255 m_overlay=null; 256 } 257 } 258 259 260 261 267 protected void verifyCanExecute_(String calr) 268 { 269 super.verifyCanExecute_(calr); 270 271 String testId = m_conditionId.getValue(); 272 RulesTk.verifyTest(testId,m_rqlink); 273 } 274 275 276 277 285 public boolean eval(String vut, Reference context) 286 throws BuildException 287 { 288 verifyCanExecute_("eval"); 289 installOverlay(vut, context); 290 try { 291 String testId = m_conditionId.getValue(); 292 return RulesTk.evalTest(testId, m_rqlink); 293 } finally { 294 uninstallOverlay(); 295 } 296 } 297 298 299 private FlexString m_conditionId = new FlexString(); 300 private ScopedProperties m_overlay; private Requester m_rqlink = new Requester.ForComponent(this); 302 } 303 304 | Popular Tags |