1 28 29 package com.idaremedia.antx.condition; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.taskdefs.condition.Condition; 34 35 import com.idaremedia.antx.AntX; 36 import com.idaremedia.antx.AssertableProjectComponent; 37 import com.idaremedia.antx.FlexString; 38 import com.idaremedia.antx.helpers.Tk; 39 import com.idaremedia.antx.parameters.FlexValueSupport; 40 41 54 55 public abstract class FlexCondition extends AssertableProjectComponent 56 implements Condition, FlexValueSupport 57 { 58 61 protected FlexCondition() 62 { 63 super(AntX.conditions); 64 } 65 66 67 71 protected FlexCondition(String iam) 72 { 73 super(iam); 74 } 75 76 77 78 83 public final String getFlexValue() 84 { 85 return getValueHelper().get(); 86 } 87 88 89 90 96 public final String getResolvedFlexValue() 97 { 98 return getValueHelper().sourceString(getProject()); 99 } 100 101 102 103 109 public void setProperty(String property) 110 { 111 setLiteral(property); 112 getValueHelper().setIsProperty(true); 113 } 114 115 116 120 public final boolean isProperty() 121 { 122 return getValueHelper().isProperty(); 123 } 124 125 126 130 public final String getProperty() 131 { 132 return isProperty() ? getValueHelper().get() : null; 133 } 134 135 136 137 142 public void setVariable(String exportedproperty) 143 { 144 setLiteral(exportedproperty); 145 getValueHelper().setIsExported(true); 146 } 147 148 149 152 public final void setVar(String exportedproperty) 153 { 154 setVariable(exportedproperty); 155 } 156 157 158 162 public final boolean isVariable() 163 { 164 return getValueHelper().isExported(); 165 } 166 167 168 174 public final String getVariable() 175 { 176 return isVariable() ? getValueHelper().get() : null; 177 } 178 179 180 181 187 public void setReference(String refid) 188 { 189 setLiteral(refid); 190 getValueHelper().setIsReference(true); 191 } 192 193 194 198 public final boolean isReference() 199 { 200 return getValueHelper().isReference(); 201 } 202 203 204 208 public final String getReference() 209 { 210 return isReference() ? getValueHelper().get() : null; 211 } 212 213 214 215 221 public void setLiteral(String rawvalue) 222 { 223 getValueHelper().set(rawvalue); 224 getValueHelper().setIsLiteral(); } 226 227 228 232 public final boolean isLiteral() 233 { 234 return getValueHelper().isLiteral(); 235 } 236 237 238 243 public final String getLiteral() 244 { 245 return isLiteral() ? getValueHelper().get() : null; 246 } 247 248 249 250 257 protected void verifyIsDefined_(String required) 258 { 259 if (getValueHelper().isUndefined()) { 260 if (required==null) { 261 required="property|variable|reference"; 262 } 263 String ermsg = uistrs().get("task.needs.this.attr", 264 getTypicalName(),required); 265 log(ermsg,Project.MSG_ERR); 266 throw new BuildException(ermsg); 267 } 268 } 269 270 271 272 280 protected void verifyCanEvaluate_(String calr) 281 { 282 verifyInProject_(calr); 283 verifyIsDefined_(null); 284 } 285 286 287 288 292 protected abstract FlexString getValueHelper(); 293 294 295 302 protected String getTypicalName() 303 { 304 return Tk.lowercaseFrom(Tk.leafNameFrom(getClass())); 305 } 306 } 307 308 309 | Popular Tags |