1 19 package org.netbeans.modules.j2ee.weblogic9; 20 21 22 import java.io.*; 23 import java.util.*; 24 25 import javax.enterprise.deploy.model.*; 26 import javax.enterprise.deploy.shared.*; 27 import javax.enterprise.deploy.spi.*; 28 import javax.enterprise.deploy.spi.exceptions.*; 29 import javax.enterprise.deploy.spi.status.*; 30 import org.netbeans.modules.j2ee.deployment.plugins.api.*; 31 import org.netbeans.modules.j2ee.weblogic9.config.EarDeploymentConfiguration; 32 import org.netbeans.modules.j2ee.weblogic9.config.EjbDeploymentConfiguration; 33 import org.netbeans.modules.j2ee.weblogic9.config.WarDeploymentConfiguration; 34 35 import org.netbeans.modules.j2ee.weblogic9.util.WLDebug; 36 import org.openide.ErrorManager; 37 38 39 47 public class WLDeploymentManager implements DeploymentManager { 48 49 private DeploymentManager dm; 50 private InstanceProperties instanceProperties; 51 private String uri; 52 private String username; 53 private String password; 54 private boolean isConnected; 55 private String host; 56 private String port; 57 58 59 private Process process; 60 61 62 public WLDeploymentManager(DeploymentManager dm, String uri, String username, String password, String host, String port) { 63 this.dm = dm; 64 this.uri = uri; 65 this.username = username; 66 this.password = password; 67 this.host = host; 68 this.port = port; 69 this.isConnected = true; 70 } 71 72 73 public WLDeploymentManager(DeploymentManager dm, String uri, String host, String port) { 74 this.dm = dm; 75 this.uri = uri; 76 this.host = host; 77 this.port = port; 78 this.isConnected = false; 79 } 80 81 85 public boolean isConnected() { 86 return isConnected; 87 } 88 89 92 public String getURI() { 93 return this.uri; 94 } 95 96 99 public String getHost() { 100 return host; 101 } 102 103 public String getUsername () { 104 return getInstanceProperties().getProperty(InstanceProperties.USERNAME_ATTR); 105 } 106 107 public String getPassword () { 108 return getInstanceProperties().getProperty(InstanceProperties.PASSWORD_ATTR); 109 } 110 111 114 public String getPort() { 115 return port; 116 } 117 118 public boolean isLocal () { 119 return new Boolean (getInstanceProperties().getProperty(WLPluginProperties.IS_LOCAL_ATTR)).booleanValue(); 120 } 121 124 public InstanceProperties getInstanceProperties() { 125 if (instanceProperties == null) { 126 this.instanceProperties = InstanceProperties.getInstanceProperties(uri); 127 128 } 129 return instanceProperties; 130 } 131 132 137 public synchronized void setServerProcess(Process process) { 138 this.process = process; 139 } 140 141 147 public synchronized Process getServerProcess() { 148 return process; 149 } 150 151 public ProgressObject distribute(Target[] target, File file, File file2) 152 throws IllegalStateException { 153 if (WLDebug.isEnabled()) WLDebug.notify(getClass(), "distribute(" + target + ", " + file + ", " + file2 + ")"); 157 if (isLocal()) { 158 return new WLDeployer(uri).deploy(target, file, file2, getHost(), getPort()); 160 } else { 161 modifiedLoader(); 163 try { 164 return new DelegatingProgressObject(dm.distribute(target, file, file2)); 165 } finally { 166 originalLoader(); 167 } 168 } 169 } 170 171 public ProgressObject distribute(Target[] target, ModuleType moduleType, InputStream inputStream, InputStream inputStream0) throws IllegalStateException { 172 return distribute(target, inputStream, inputStream0); 173 } 174 175 private ClassLoader swapLoader; 176 177 private void modifiedLoader() { 178 swapLoader = Thread.currentThread().getContextClassLoader(); 179 String serverRoot = getInstanceProperties().getProperty(WLPluginProperties.SERVER_ROOT_ATTR); 180 if (serverRoot == null) 184 serverRoot = WLPluginProperties.getInstance().getInstallLocation(); 185 186 Thread.currentThread().setContextClassLoader(WLDeploymentFactory.getWLClassLoader(serverRoot)); 187 } 188 private void originalLoader() { 189 Thread.currentThread().setContextClassLoader(swapLoader); 190 } 191 192 199 public DeploymentConfiguration createConfiguration( 200 DeployableObject deployableObject) throws InvalidModuleException { 201 ModuleType type = deployableObject.getType(); 202 if (type == ModuleType.WAR) { 203 return new WarDeploymentConfiguration(deployableObject); 204 } else if (type == ModuleType.EAR) { 205 return new EarDeploymentConfiguration(deployableObject); 206 } else if (type == ModuleType.EJB) { 207 return new EjbDeploymentConfiguration(deployableObject); 208 } else { 209 throw new InvalidModuleException("Unsupported module type: " + type.toString()); } 211 } 212 213 218 public ProgressObject redeploy(TargetModuleID[] targetModuleID, 219 InputStream inputStream, InputStream inputStream2) 220 throws UnsupportedOperationException , IllegalStateException { 221 if (WLDebug.isEnabled()) WLDebug.notify("redeploy(" + targetModuleID + ", " + inputStream + ", " + inputStream2 + ")"); modifiedLoader(); 225 try { 226 return new DelegatingProgressObject(dm.redeploy(targetModuleID, inputStream, inputStream2)); 227 } finally { 228 originalLoader(); 229 } 230 } 231 232 237 public ProgressObject distribute(Target[] target, InputStream inputStream, 238 InputStream inputStream2) throws IllegalStateException { 239 if (WLDebug.isEnabled()) WLDebug.notify("distribute(" + target + ", " + inputStream + ", " + inputStream2 + ")"); modifiedLoader(); 243 try { 244 return new DelegatingProgressObject(dm.distribute(target, inputStream, inputStream2)); 245 } finally { 246 originalLoader(); 247 } 248 } 249 250 255 public ProgressObject undeploy(TargetModuleID[] targetModuleID) 256 throws IllegalStateException { 257 if (WLDebug.isEnabled()) WLDebug.notify("undeploy(" + targetModuleID + ")"); modifiedLoader(); 260 try { 261 return new DelegatingProgressObject(dm.undeploy(targetModuleID)); 262 } finally { 263 originalLoader(); 264 } 265 } 266 267 272 public ProgressObject stop(TargetModuleID[] targetModuleID) 273 throws IllegalStateException { 274 if (WLDebug.isEnabled()) WLDebug.notify("stop(" + targetModuleID + ")"); 277 modifiedLoader(); 278 try { 279 return new DelegatingProgressObject(dm.stop(targetModuleID)); 280 } finally { 281 originalLoader(); 282 } 283 } 284 285 290 public ProgressObject start(TargetModuleID[] targetModuleID) 291 throws IllegalStateException { 292 if (WLDebug.isEnabled()) WLDebug.notify("start(" + targetModuleID + ")"); 295 modifiedLoader(); 296 try { 297 return new DelegatingProgressObject(dm.start(targetModuleID)); 298 } finally { 299 originalLoader(); 300 } 301 } 302 303 308 public TargetModuleID[] getAvailableModules(ModuleType moduleType, 309 Target[] target) throws TargetException, IllegalStateException { 310 if (WLDebug.isEnabled()) WLDebug.notify("getAvailableModules(" + moduleType + ", " + target + ")"); 314 modifiedLoader(); 315 try { 316 TargetModuleID t[] = dm.getAvailableModules(moduleType, target); 317 return t; 318 } finally { 319 originalLoader(); 320 } 321 } 322 323 328 public TargetModuleID[] getNonRunningModules(ModuleType moduleType, 329 Target[] target) throws TargetException, IllegalStateException { 330 if (WLDebug.isEnabled()) WLDebug.notify("getNonRunningModules(" + moduleType + ", " + target + ")"); 334 modifiedLoader(); 335 try { 336 TargetModuleID t[] = dm.getNonRunningModules(moduleType, target); 337 for (int i=0; i < t.length; i++) { 338 System.out.println("non running module:" + t[i]); 339 } 340 return t; 341 } finally { 342 originalLoader(); 343 } 344 } 345 346 351 public TargetModuleID[] getRunningModules(ModuleType moduleType, 352 Target[] target) throws TargetException, IllegalStateException { 353 if (WLDebug.isEnabled()) WLDebug.notify("getRunningModules(" + moduleType + ", " + target + ")"); 357 modifiedLoader(); 358 try { 359 TargetModuleID t[] = dm.getRunningModules(moduleType, target); 360 for (int i=0; i < t.length; i++) { 361 System.out.println("running module:" + t[i]); 362 } 363 return t; 364 } finally { 365 originalLoader(); 366 } 367 } 368 369 374 public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, 375 File file2) throws UnsupportedOperationException , 376 IllegalStateException { 377 if (WLDebug.isEnabled()) WLDebug.notify("redeploy(" + targetModuleID + ", " + file + ", " + file2 + ")"); 381 modifiedLoader(); 382 try { 383 return new DelegatingProgressObject(dm.redeploy(targetModuleID, file, file2)); 384 } finally { 385 originalLoader(); 386 } 387 } 388 389 394 public void setLocale(Locale locale) throws UnsupportedOperationException { 395 if (WLDebug.isEnabled()) WLDebug.notify("setLocale(" + locale + ")"); 398 modifiedLoader(); 399 try { 400 dm.setLocale(locale); 401 } finally { 402 originalLoader(); 403 } 404 } 405 406 411 public boolean isLocaleSupported(Locale locale) { 412 if (WLDebug.isEnabled()) WLDebug.notify("isLocaleSupported(" + locale + ")"); 415 modifiedLoader(); 416 try { 417 return dm.isLocaleSupported(locale); 418 } finally { 419 originalLoader(); 420 } 421 } 422 423 428 public void setDConfigBeanVersion( 429 DConfigBeanVersionType dConfigBeanVersionType) 430 throws DConfigBeanVersionUnsupportedException { 431 if (WLDebug.isEnabled()) WLDebug.notify("setDConfigBeanVersion(" + dConfigBeanVersionType + ")"); 435 modifiedLoader(); 436 try { 437 dm.setDConfigBeanVersion(dConfigBeanVersionType); 438 } finally { 439 originalLoader(); 440 } 441 } 442 443 448 public boolean isDConfigBeanVersionSupported( 449 DConfigBeanVersionType dConfigBeanVersionType) { 450 if (WLDebug.isEnabled()) WLDebug.notify("isDConfigBeanVersionSupported(" + dConfigBeanVersionType + ")"); 454 modifiedLoader(); 455 try { 456 return dm.isDConfigBeanVersionSupported(dConfigBeanVersionType); 457 } finally { 458 originalLoader(); 459 } 460 } 461 462 467 public void release() { 468 if (WLDebug.isEnabled()) WLDebug.notify("release()"); 471 modifiedLoader(); 472 try { 473 if (dm != null) { 474 try { 476 dm.release(); 477 } 478 catch (Exception e) { 479 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 480 } 481 finally { 482 dm = null; 483 } 484 } 485 } finally { 486 originalLoader(); 487 } 488 } 489 490 495 public boolean isRedeploySupported() { 496 if (WLDebug.isEnabled()) WLDebug.notify("isRedeploySupported()"); 499 modifiedLoader(); 500 try { 501 return dm.isRedeploySupported(); 502 } finally { 503 originalLoader(); 504 } 505 } 506 507 512 public Locale getCurrentLocale() { 513 if (WLDebug.isEnabled()) WLDebug.notify("getCurrentLocale()"); 516 modifiedLoader(); 517 try { 518 return dm.getCurrentLocale(); 519 } finally { 520 originalLoader(); 521 } 522 } 523 524 529 public DConfigBeanVersionType getDConfigBeanVersion() { 530 if (WLDebug.isEnabled()) WLDebug.notify("getDConfigBeanVersion()"); 533 modifiedLoader(); 534 try { 535 return dm.getDConfigBeanVersion(); 536 } finally { 537 originalLoader(); 538 } 539 } 540 541 546 public Locale getDefaultLocale() { 547 if (WLDebug.isEnabled()) WLDebug.notify("getDefaultLocale()"); 550 modifiedLoader(); 551 try { 552 return dm.getDefaultLocale(); 553 } finally { 554 originalLoader(); 555 } 556 } 557 558 563 public Locale[] getSupportedLocales() { 564 if (WLDebug.isEnabled()) WLDebug.notify("getSupportedLocales()"); 567 modifiedLoader(); 568 try { 569 return dm.getSupportedLocales(); 570 } finally { 571 originalLoader(); 572 } 573 } 574 575 580 public Target[] getTargets() throws IllegalStateException { 581 if (WLDebug.isEnabled()) WLDebug.notify("getTargets()"); 584 modifiedLoader(); 585 try { 586 return dm.getTargets(); 587 } finally { 588 originalLoader(); 589 } 590 } 591 592 static class DelegatingProgressObject implements ProgressObject, ProgressListener { 593 ProgressObject original; 594 private Vector listeners = new Vector(); 595 DelegatingProgressObject (ProgressObject original) { 596 this.original = original; 597 original.addProgressListener(this); 598 } 599 600 public DeploymentStatus getDeploymentStatus() { 601 return original.getDeploymentStatus(); 602 } 603 604 public TargetModuleID[] getResultTargetModuleIDs() { 605 return original.getResultTargetModuleIDs(); 606 } 607 608 public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) { 609 return getClientConfiguration(targetModuleID); 610 } 611 612 public boolean isCancelSupported() { 613 return original.isCancelSupported(); 614 } 615 616 public void cancel() throws OperationUnsupportedException { 617 original.cancel(); 618 } 619 620 public boolean isStopSupported() { 621 return original.isStopSupported(); 622 } 623 624 public void stop() throws OperationUnsupportedException { 625 original.stop(); 626 } 627 628 public void addProgressListener(ProgressListener progressListener) { 629 listeners.add(progressListener); 630 } 631 632 public void removeProgressListener(ProgressListener progressListener) { 633 listeners.remove(progressListener); 634 } 635 636 public void handleProgressEvent(ProgressEvent progressEvent) { 637 java.util.Vector targets = null; 638 synchronized (this) { 639 if (listeners != null) { 640 targets = (java.util.Vector ) listeners.clone(); 641 } 642 } 643 644 if (targets != null) { 645 for (int i = 0; i < targets.size(); i++) { 646 ProgressListener target = (ProgressListener)targets.elementAt(i); 647 target.handleProgressEvent(progressEvent); 648 } 649 } 650 } 651 652 } 653 } | Popular Tags |