1 28 29 package com.idaremedia.antx.init; 30 31 import java.io.File ; 32 import java.net.URL ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 import org.apache.tools.ant.taskdefs.AntlibDefinition; 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.AntXFixture; 45 import com.idaremedia.antx.FixtureInitializer; 46 import com.idaremedia.antx.UISMContext; 47 import com.idaremedia.antx.apis.AntLibFriendly; 48 import com.idaremedia.antx.apis.ProblemHandler; 49 import com.idaremedia.antx.apis.Requester; 50 import com.idaremedia.antx.apis.Responses; 51 import com.idaremedia.antx.helpers.Strings; 52 import com.idaremedia.antx.helpers.Tk; 53 import com.idaremedia.antx.ownhelpers.DefinitionLoader; 54 import com.idaremedia.antx.parameters.CustomLoaderEnabled; 55 56 87 88 public final class InitUISMTask extends AntlibDefinition 89 implements UISMSource, CustomLoaderEnabled, AntLibFriendly, FixtureInitializer 90 { 91 96 public static final String OP_INSTALL_DEFAULT = "install-default"; 97 98 103 public static final String OP_UNINSTALL_DEFAULT = "uninstall-default"; 104 105 110 public static final String OP_INSTALL_ROOT = "install-root"; 111 112 117 public static final String OP_UNINSTALL_ROOT = "uninstall-root"; 118 119 120 121 124 public InitUISMTask() 125 { 126 } 127 128 129 134 public void init() 135 { 136 super.init(); 137 m_boobooResponse = new Requester.ForComponent(this); 138 m_bundle.setController(new DefinitionLoader(this)); 139 } 140 141 142 146 public void setProject(Project P) 147 { 148 super.setProject(P); 149 m_bundle.setProject(P); 150 } 151 152 153 154 160 public void setMustExist(boolean mustExist) 161 { 162 m_bundle.setMustExist(mustExist); 163 } 164 165 166 167 171 public void setBundleId(Reference reference) 172 { 173 m_bundle.setRefid(reference); 174 } 175 176 177 183 public void setURL(String url) 184 { 185 m_bundle.setURL(url); 186 } 187 188 189 193 194 public URL getURL() 195 { 196 return m_bundle.getURL(); 197 } 198 199 200 205 public void setFile(String filepath) 206 { 207 m_bundle.setFile(filepath); 208 } 209 210 211 215 public File getFile() 216 { 217 return m_bundle.getFile(); 218 } 219 220 221 225 public void setResource(String rsrc) 226 { 227 m_bundle.setResource(rsrc); 228 } 229 230 231 235 public String getResource() 236 { 237 return m_bundle.getResource(); 238 } 239 240 241 245 public Path getClassPath() 246 { 247 return m_bundle.getClassPath(); 248 } 249 250 251 255 public Path createClassPath() 256 { 257 return m_bundle.createClassPath(); 258 } 259 260 261 265 public void setClassPath(Path classpath) 266 { 267 m_bundle.setClassPath(classpath); 268 } 269 270 271 276 public void setClassPathRef(Reference reference) 277 { 278 m_bundle.setClassPathRef(reference); 279 } 280 281 282 287 public void setLoaderRef(Reference r) 288 { 289 m_bundle.setLoaderRef(r); 290 } 291 292 293 297 public String getLoaderRefId() 298 { 299 return m_bundle.getLoaderRefId(); 300 } 301 302 303 308 public void setAction(String op) 309 { 310 m_Op = Tk.lowercaseFrom(op); 311 } 312 313 314 317 private UIStringManager getUISM() 318 { 319 return new BundleStringManager 320 (m_bundle.newPropertyBundle(m_boobooResponse),null); 321 } 322 323 324 329 private void installRootSM() throws BuildException 330 { 331 UIStringManager alreadyInstalled = UISMContext.installStringManager(getUISM(),null); 332 if (alreadyInstalled!=null) { UISMContext.unwindStringManager(null); 334 String ermsg = AntX.uistrs().get("task.uism.err.too.many.root.bundles"); 335 log(ermsg, Project.MSG_ERR); 336 throw new BuildException(ermsg,getLocation()); 337 } 338 log("Installed root UIStringManager from URL="+getURL(),Project.MSG_DEBUG); 339 } 340 341 342 347 private void installDefaultSM() 348 { 349 boolean alreadyInstalled = !UISMContext.isDefaultUndefined(); 350 UISMContext.setDefaultStringManager(getUISM()); 351 if (alreadyInstalled) { 352 String ermsg = AntX.uistrs().get("task.uism.warn.repl.dflt.bundle"); 353 log(ermsg, Project.MSG_WARN); 354 } else { 355 log("Installed default UIStringManager from URL="+getURL(),Project.MSG_DEBUG); 356 } 357 } 358 359 360 361 367 public void execute() 368 throws BuildException 369 { 370 if (getAntlibClassLoader()!=null) { if (m_Op!=null && m_Op.startsWith("uninstall")) { 373 String ermsg = AntX.uistrs().get 374 ("task.manager.err.illegal.operation",m_Op); 375 log(ermsg,Project.MSG_ERR); 376 throw new BuildException(ermsg,getLocation()); 377 } 378 } 379 380 synchronized(m_bundle) { 382 if (m_Op==null || OP_INSTALL_DEFAULT.equals(m_Op)) { 383 installDefaultSM(); 384 } 385 else if (OP_INSTALL_ROOT.equals(m_Op) || 386 Strings.INSTALL.equals(m_Op)) { 387 installRootSM(); 388 } 389 else if (OP_UNINSTALL_ROOT.equals(m_Op) || 390 Strings.UNINSTALL.equals(m_Op)) { 391 log("Trying to uninstall the active root UIStringManager", 392 Project.MSG_DEBUG); 393 UISMContext.unwindStringManager(m_boobooResponse); 394 } 395 else if (OP_UNINSTALL_DEFAULT.equals(m_Op)) { 396 if (!UISMContext.isDefaultUndefined()) { 397 log("Trying to uninstall the default UIStringManager", 398 Project.MSG_DEBUG); 399 AntXFixture.reset(UISMContext.FXID,Strings.DEFAULT,m_boobooResponse); 400 } 401 } 402 else { 403 String ermsg = AntX.uistrs().get 404 ("task.manager.err.unknown.operation",m_Op); 405 log(ermsg,Project.MSG_WARN); 406 } 407 } 408 } 409 410 private UISMBundle m_bundle= new UISMBundle(true); private String m_Op; private ProblemHandler m_boobooResponse = Responses.ERROR; 413 } 414 415 416 | Popular Tags |