1 28 29 package com.idaremedia.antx.starters; 30 31 import com.idaremedia.antx.AntX; 32 import com.idaremedia.antx.AssertableTask; 33 import com.idaremedia.antx.MsgGetter; 34 import com.idaremedia.antx.NoiseLevel; 35 import com.idaremedia.antx.go.Iff; 36 import com.idaremedia.antx.go.Unless; 37 import com.idaremedia.antx.helpers.InnerString; 38 import com.idaremedia.antx.helpers.Tk; 39 import com.idaremedia.antx.parameters.Conditional; 40 41 64 65 public class MsgTask extends AssertableTask implements Conditional 66 { 67 70 public MsgTask() 71 { 72 super(AntX.starters); 73 } 74 75 76 80 public MsgTask(String iam) 81 { 82 super(iam); 83 } 84 85 86 92 public MsgTask(String iam, String defaultMsg) 93 { 94 super(iam); 95 require_(defaultMsg!=null,"ctor- nonzro dfltMsg"); 96 m_defaultMsgStr = defaultMsg; 97 } 98 99 100 104 public void setIf(String property) 105 { 106 m_ifProperty = (property==null) ? "" : property; 107 } 108 109 110 115 public String getIfProperty() 116 { 117 return m_ifProperty; 118 } 119 120 121 125 public void setUnless(String property) 126 { 127 m_unlessProperty = (property==null) ? "" : property; 128 } 129 130 131 136 public String getUnlessProperty() 137 { 138 return m_unlessProperty; 139 } 140 141 142 147 public void setMsgLevel(NoiseLevel level) 148 { 149 require_(level!=null,"setLvl- nonzro lvl"); 150 m_preferredMsgLevel = level; 151 } 152 153 154 160 public final void setLevel(NoiseLevel nl) 161 { 162 setMsgLevel(nl); 163 } 164 165 166 171 public final NoiseLevel getPreferredMsgLevel() 172 { 173 return m_preferredMsgLevel; 174 } 175 176 177 184 public final NoiseLevel getMsgLevel() 185 { 186 NoiseLevel nl= getPreferredMsgLevel(); 187 if (nl==null) { 188 nl= getDefaultMsgLevel(); 189 } 190 return nl; 191 } 192 193 194 200 public void addConfiguredDefaultMsg(InnerString defaultMsgStr) 201 { 202 require_(defaultMsgStr!=null,"addDfltMsg- nonzro str"); 203 m_defaultMsgStr= defaultMsgStr.toString(getProject()); 204 } 205 206 207 212 public final String getDefaultMsg() 213 { 214 return m_defaultMsgStr; 215 } 216 217 218 223 public void setMessage(String string) 224 { 225 require_(string!=null,"setMsg- nonzro string"); 226 addConfiguredDefaultMsg(new InnerString(string)); 227 } 228 229 230 235 public final void setMsgArg1(String arg1) 236 { 237 m_arg1= arg1; 238 } 239 240 241 245 public final String getMsgArg1() 246 { 247 return m_arg1; 248 } 249 250 251 256 public final void setMsgArg2(String arg2) 257 { 258 m_arg2= arg2; 259 } 260 261 262 266 public final String getMsgArg2() 267 { 268 return m_arg2; 269 } 270 271 272 278 public String getMsg() 279 { 280 String msg = null; 281 boolean chk = false; 282 283 if (m_arg1!=null) { 284 if (m_arg2!=null) { 285 msg= getMsg(newMsgGetter(m_arg1,m_arg2)); 286 } else { 287 msg= getMsg(newMsgGetter(m_arg1)); 288 } 289 } else if (m_arg2!=null) { 290 msg = getMsg(newMsgGetter("",m_arg2)); 291 } else { 292 msg = super.getMsg(); 293 chk = true; 294 } 295 296 if (chk) { 297 String dfltMsg = getDefaultMsg(); 298 if (Tk.isWhitespace(msg)) { 299 msg = dfltMsg; 300 } else if (msg.equals(getMsgId()) && !Tk.isWhitespace(dfltMsg)) { 301 msg = dfltMsg; 302 } 303 } 304 305 return msg; 306 } 307 308 309 314 public String getMsg(MsgGetter getr) 315 { 316 String msg = super.getMsg(getr); 317 318 if (Tk.isWhitespace(msg)) { 319 msg = getDefaultMsg(); 320 } 321 322 return msg; 323 } 324 325 326 332 protected final boolean testIfCondition() 333 { 334 return Iff.allowed(getIfProperty(), getProject()); 335 } 336 337 338 344 protected final boolean testUnlessCondition() 345 { 346 return Unless.allowed(getUnlessProperty(),getProject()); 347 } 348 349 350 354 public void execute() 355 { 356 verifyCanExecute_("execute"); 357 358 if (testIfCondition() && testUnlessCondition()) { 359 log(getMsg(), getMsgLevel().getNativeIndex()); 360 } 361 } 362 363 364 private NoiseLevel m_preferredMsgLevel; 365 private String m_defaultMsgStr=""; 366 private String m_arg1, m_arg2; private String m_ifProperty=""; 368 private String m_unlessProperty=""; 369 } 370 371 372 373 | Popular Tags |