1 19 20 package org.netbeans.modules.j2ee.jboss4.nodes.actions; 21 22 import java.io.File ; 23 import javax.enterprise.deploy.shared.ModuleType ; 24 import javax.management.MalformedObjectNameException ; 25 import javax.management.ObjectName ; 26 import org.netbeans.api.progress.ProgressHandle; 27 import org.netbeans.api.progress.ProgressHandleFactory; 28 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; 29 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; 30 import org.netbeans.modules.j2ee.jboss4.nodes.Util; 31 import org.openide.util.Lookup; 32 import org.openide.util.NbBundle; 33 import org.openide.util.RequestProcessor; 34 import org.openide.util.RequestProcessor.Task; 35 36 40 public class UndeployModuleCookieImpl implements UndeployModuleCookie { 41 42 private String fileName; 43 private Lookup lookup; 44 private ModuleType type; 45 private final boolean isEJB3; 46 private boolean isRunning; 47 48 public UndeployModuleCookieImpl(String fileName, ModuleType type, Lookup lookup) { 49 this(fileName, type, false, lookup); 50 } 51 52 public UndeployModuleCookieImpl(String fileName, Lookup lookup) { 53 this(fileName, ModuleType.EJB, true, lookup); 54 } 55 56 private UndeployModuleCookieImpl(String fileName, ModuleType type, boolean isEJB3, Lookup lookup) { 57 this.lookup = lookup; 58 this.fileName = fileName; 59 this.type = type; 60 this.isEJB3 = isEJB3; 61 this.isRunning = false; 62 } 63 64 public Task undeploy() { 65 final JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); 66 final String nameWoExt = fileName.substring(0, fileName.lastIndexOf('.')); 67 final ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(UndeployModuleCookieImpl.class, 68 "LBL_UndeployProgress", nameWoExt)); 69 70 Runnable r = new Runnable () { 71 public void run() { 72 isRunning = true; 73 String deployDir = dm.getInstanceProperties().getProperty(JBPluginProperties.PROPERTY_DEPLOY_DIR); 74 File file = new File (deployDir, fileName); 75 76 if(file.exists() && file.canWrite()) { 77 file.delete(); 78 79 try { 80 ObjectName searchPattern = null; 81 if (Util.isRemoteManagementSupported(lookup) && !isEJB3) { 82 searchPattern = new ObjectName ("jboss.management.local:"+(!type.equals(ModuleType.EAR) ? 83 "J2EEApplication=null," : "")+"j2eeType="+Util.getModuleTypeString(type)+",name=" + fileName + ",*"); 84 } 85 else { 86 if (type.equals(ModuleType.EAR)) { 87 searchPattern = new ObjectName ("jboss.j2ee:service=EARDeployment,url='" + fileName + "'"); } 89 else 90 if (type.equals(ModuleType.WAR)) { 91 searchPattern = new ObjectName ("jboss.web:j2eeType=WebModule,J2EEApplication=none,name=//localhost/" + nameWoExt + ",*"); } 93 else 94 if (type.equals(ModuleType.EJB)) { 95 searchPattern = new ObjectName ("jboss.j2ee:service=" + (isEJB3 ? "EJB3" : "EjbModule") + ",module=" + fileName); } 97 } 98 99 int time = 0; 100 while(dm.refreshRMIServer() != null && Util.isObjectDeployed(dm.getRMIServer(), searchPattern) && time < 30000) { 101 try { 102 Thread.sleep(2000); 103 time += 2000; 104 } catch (InterruptedException ex) { 105 } 107 } 108 } catch (MalformedObjectNameException ex) { 109 } catch (NullPointerException ex) { 110 } 112 } 113 114 handle.finish(); 115 isRunning = false; 116 } 117 }; 118 119 handle.start(); 120 return RequestProcessor.getDefault().post(r); 121 } 122 123 public boolean isRunning() { 124 return isRunning; 125 } 126 127 } | Popular Tags |