1 28 29 package com.idaremedia.antx; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.taskdefs.AntlibDefinition; 34 35 import com.idaremedia.apis.UIStringManager; 36 37 import com.idaremedia.antx.apis.AntLibFriendly; 38 import com.idaremedia.antx.apis.ProjectDependent; 39 import com.idaremedia.antx.apis.ScriptLocatable; 40 import com.idaremedia.antx.helpers.Tk; 41 42 55 56 public abstract class AssertableLibDefinition extends AntlibDefinition 57 implements ProjectDependent, ScriptLocatable, AntLibFriendly 58 { 59 62 protected AssertableLibDefinition() 63 { 64 super(); 65 Iam_=""; 66 } 67 68 69 70 74 protected AssertableLibDefinition(String iam) 75 { 76 super(); 77 Iam_= Tk.cvlabelFrom(iam); 78 } 79 80 81 82 89 public void init() 90 { 91 super.init(); 92 93 if (!m_initedOnce) { 94 initonce(); 95 m_initedOnce=true; 96 } 97 } 98 99 100 101 108 protected void initonce() 109 { 110 } 111 112 113 114 115 121 public void execute() 122 { 123 verifyCanExecute_("exec"); 124 super.execute(); 125 } 126 127 128 129 130 135 public final UIStringManager uistrs() 136 { 137 return Iteration.uistrs(); 138 } 139 140 141 145 148 public void log(String msg, int msgLevel) 149 { 150 if (getProject()!=null) { 151 getProject().log(this,msg,msgLevel); 152 } else { 153 if (msgLevel >= Project.MSG_INFO) { System.err.println(msg); 155 } 156 } 157 } 158 159 163 164 167 public final String cvlabel_() 168 { 169 return Iam_; 170 } 171 172 173 179 protected final void require_(boolean c, String msg) 180 { 181 if (!c) { 182 String ermsg = uistrs().get("cv.require",Iam_,msg); 183 log(ermsg, Project.MSG_ERR); 184 throw new IllegalArgumentException (ermsg); 185 } 186 } 187 188 189 196 protected final void ensure_(boolean c, String msg) 197 { 198 if (!c) { 199 String ermsg = uistrs().get("cv.ensure",Iam_,msg); 200 log(ermsg, Project.MSG_ERR); 201 throw new IllegalStateException (ermsg); 202 } 203 } 204 205 206 213 protected final void verify_(boolean c, String msg) 214 { 215 if (!c) { 216 String ermsg = uistrs().get("cv.verify",Iam_,msg); 217 log(ermsg, Project.MSG_ERR); 218 throw new IllegalStateException (ermsg); 219 } 220 } 221 222 223 229 protected final void unexpected_(Throwable t, String msg) 230 { 231 String ermsg = uistrs().get("cv.unexpected",Iam_,msg,t); 232 log(ermsg, Project.MSG_WARN); 233 } 234 235 236 240 protected final void verifyInProject_(String calr) 241 { 242 if (getProject()==null) { 243 String ermsg = uistrs().get("cv.verifyInP",Iam_,calr); 244 log(ermsg, Project.MSG_ERR); 245 throw new IllegalStateException (ermsg); 246 } 247 } 248 249 250 255 protected final void verifyInTarget_(String calr) 256 { 257 if (getOwningTarget()==null) { 258 String ermsg = uistrs().get("cv.verifyInT",Iam_,calr); 259 log(ermsg, Project.MSG_ERR); 260 throw new IllegalStateException (ermsg); 261 } 262 verifyInProject_(calr); 263 } 264 265 266 275 protected void verifyCanExecute_(String calr) 276 throws BuildException 277 { 278 verifyInProject_(calr); 279 } 280 281 282 283 private final String Iam_; 284 private boolean m_initedOnce; 285 } 286 287 288 | Popular Tags |