1 28 29 package com.idaremedia.antx.init; 30 31 import java.io.File ; 32 import java.net.URL ; 33 import java.text.MessageFormat ; 34 35 import org.apache.tools.ant.BuildException; 36 import org.apache.tools.ant.Project; 37 import org.apache.tools.ant.types.Path; 38 import org.apache.tools.ant.types.Reference; 39 40 import com.idaremedia.apis.BundleStringManager; 41 import com.idaremedia.apis.UIStringManager; 42 43 import com.idaremedia.antx.AntX; 44 import com.idaremedia.antx.FixtureOverlay; 45 import com.idaremedia.antx.UISMContext; 46 import com.idaremedia.antx.apis.BuildError; 47 import com.idaremedia.antx.apis.ProblemHandler; 48 import com.idaremedia.antx.apis.Responses; 49 import com.idaremedia.antx.starters.TaskSet; 50 51 66 67 public class UISMConfigureTask extends TaskSet 68 implements FixtureOverlay, UISMSource, UIStringManager 69 { 70 73 public UISMConfigureTask() 74 { 75 super(AntX.uism); 76 } 77 78 79 83 public UISMConfigureTask(String iam) 84 { 85 super(iam); 86 } 87 88 89 93 public void setProject(Project P) 94 { 95 super.setProject(P); 96 m_bundle.setProject(P); 97 } 98 99 100 104 public void init() 105 { 106 super.init(); 107 m_boobooNotify = new Responses.LogUsing(this); 108 } 109 110 111 116 public void setBundleId(Reference reference) 117 { 118 m_bundle.setRefid(reference); 119 } 120 121 125 public void setURL(String url) 126 { 127 m_bundle.setURL(url); 128 } 129 130 public URL getURL() 131 { 132 return m_bundle.getURL(); 133 } 134 135 public void setFile(String filepath) 136 { 137 m_bundle.setFile(filepath); 138 } 139 140 public File getFile() 141 { 142 return m_bundle.getFile(); 143 } 144 145 public void setResource(String rsrc) 146 { 147 m_bundle.setResource(rsrc); 148 } 149 150 public String getResource() 151 { 152 return m_bundle.getResource(); 153 } 154 155 156 160 166 public void setClassPath(Path classpath) 167 { 168 m_bundle.setClassPath(classpath); 169 } 170 171 172 177 public void setClassPathRef(Reference r) 178 { 179 m_bundle.setClassPathRef(r); 180 } 181 182 183 184 189 public Path getClassPath() 190 { 191 return m_bundle.getClassPath(); 192 } 193 194 195 201 public void setLoaderRef(Reference r) 202 { 203 m_bundle.setLoaderRef(r); 204 } 205 206 207 213 public String getLoaderRefId() 214 { 215 return m_bundle.getLoaderRefId(); 216 } 217 218 219 223 224 private static final String NOSTR= new String ("==_\\\""); 226 227 public String mget(String id, Object [] args, String defm) 228 { 229 BundleStringManager uism = getThisUISM(); 230 231 String msg = uism.mget(id,args,NOSTR); 232 233 if (NOSTR.equals(msg)) { 234 if (!ignoreAllInherited() && m_inheritedUISM!=null) { 235 msg = m_inheritedUISM.mget(id,args,defm); 236 } else if (defm!=null) { 237 msg = defm; 238 } else { 239 msg = uism.getDefaultString(); 240 } 241 } 242 return msg; 243 } 244 245 246 public String mget(MessageFormat mf, String id, Object [] args, String defm) 247 { 248 BundleStringManager uism = getThisUISM(); 249 250 String msg = uism.mget(mf,id,args,NOSTR); 251 if (NOSTR.equals(msg)) { 252 if (!ignoreAllInherited() && m_inheritedUISM!=null) { 253 msg = m_inheritedUISM.mget(mf,id,args,defm); 254 } else if (defm!=null) { 255 msg = defm; 256 } else { 257 msg = uism.getDefaultString(); 258 } 259 } 260 return msg; 261 } 262 263 264 public final String mget(String id, Object [] args) 265 { 266 return mget(id,args,null); 267 } 268 269 public final String get(String id) 270 { 271 return mget(id,(Object [])null,(String )null); 272 } 273 274 public final String dget(String id, String defm) 275 { 276 return mget(id,(Object [])null, defm); 277 } 278 279 public final String get(String id, Object arg1) 280 { 281 return mget(id, new Object []{arg1}, null); 282 } 283 284 public final String dget(String id, Object arg1, String defm) 285 { 286 return mget(id, new Object []{arg1}, defm); 287 } 288 289 public final String get(String id, Object arg1, Object arg2) 290 { 291 return mget(id, new Object []{arg1,arg2}, null); 292 } 293 294 public final String dget(String id, Object arg1, Object arg2, String defm) 295 { 296 return mget(id, new Object []{arg1,arg2}, defm); 297 } 298 299 public final String get(String id, Object arg1, Object arg2, Object arg3) 300 { 301 return mget(id, new Object []{arg1,arg2,arg3}, null); 302 } 303 304 public final String dget(String id, Object arg1, Object arg2, Object arg3, String defm) 305 { 306 return mget(id, new Object []{arg1,arg2,arg3}, defm); 307 } 308 309 public final String getDefaultString() 310 { 311 return getThisUISM().getDefaultString(); 312 } 313 314 318 323 protected final boolean ignoreAllInherited() 324 { 325 return m_noInherited; 326 } 327 328 329 335 public void setInheritance(boolean passthru) 336 { 337 m_noInherited = !passthru; 338 } 339 340 341 346 private BundleStringManager getThisUISM() 347 { 348 if (m_UISM==null) { 349 m_UISM = new BundleStringManager 350 (m_bundle.newPropertyBundle(m_boobooNotify),null); 351 } 352 return m_UISM; 353 } 354 355 356 364 protected void performNestedTasks() 365 throws BuildException 366 { 367 synchronized(m_runlock) { 368 boolean installed=false; 369 try { 370 m_inheritedUISM = UISMContext.installStringManager(this,m_boobooNotify); 371 installed= true; 372 getThisUISM(); 373 super.performNestedTasks(); 374 375 } finally { 376 if (installed) { 377 m_inheritedUISM = null; 378 UIStringManager uism = UISMContext.getStringManager(); 379 if (uism!=this) { 380 String ME= uistrs().dget("task.uism.whoami","UIStringManager"); 381 String ermsg = uistrs().get("context.stack.corrupted",ME); 382 log(ermsg, Project.MSG_ERR); 383 throw new BuildError(ermsg,getLocation()); 384 } 385 UISMContext.unwindStringManager(null); 386 } } 388 } 389 } 390 391 392 private boolean m_noInherited; private UIStringManager m_inheritedUISM; private UISMBundle m_bundle= new UISMBundle(); private BundleStringManager m_UISM; private Object m_runlock = new int[0]; private ProblemHandler m_boobooNotify;} 399 400 401 | Popular Tags |