1 19 20 package org.netbeans.modules.j2ee.deployment.devmodules.api; 21 22 import java.awt.event.WindowAdapter ; 23 import java.awt.event.WindowEvent ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Map ; 29 import java.util.Set ; 30 import java.util.WeakHashMap ; 31 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; 32 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 33 import org.netbeans.modules.j2ee.deployment.impl.*; 34 import org.netbeans.modules.j2ee.deployment.impl.projects.*; 35 import org.netbeans.modules.j2ee.deployment.impl.ui.*; 36 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 37 import org.openide.ErrorManager; 38 import org.openide.util.NbBundle; 39 40 44 public final class Deployment { 45 46 private static boolean alsoStartTargets = true; 48 private static Deployment instance = null; 49 50 public static synchronized Deployment getDefault () { 51 if (instance == null) { 52 instance = new Deployment (); 53 } 54 return instance; 55 } 56 57 private Deployment () { 58 } 59 60 68 public String deploy (J2eeModuleProvider jmp, boolean debugmode, String clientModuleUrl, String clientUrlPart, boolean forceRedeploy) throws DeploymentException { 69 return deploy(jmp, debugmode, clientModuleUrl, clientUrlPart, forceRedeploy, null); 70 } 71 72 public String deploy (J2eeModuleProvider jmp, boolean debugmode, String clientModuleUrl, String clientUrlPart, boolean forceRedeploy, Logger logger) throws DeploymentException { 73 74 DeploymentTargetImpl target = new DeploymentTargetImpl(jmp, clientModuleUrl); 75 TargetModule[] modules = null; 76 final J2eeModule module = target.getModule(); 77 78 String title = NbBundle.getMessage(Deployment.class, "LBL_Deploying", jmp.getDeploymentName()); 79 ProgressUI progress = new ProgressUI(title, false, logger); 80 81 try { 82 progress.start(); 83 84 ServerString server = target.getServer(); 86 if (module == null) { 87 String msg = NbBundle.getMessage (Deployment.class, "MSG_NoJ2eeModule"); 88 throw new DeploymentException(msg); 89 } 90 if (server == null || server.getServerInstance() == null) { 91 String msg = NbBundle.getMessage (Deployment.class, "MSG_NoTargetServer"); 92 throw new DeploymentException(msg); 93 } 94 95 boolean serverReady = false; 96 TargetServer targetserver = new TargetServer(target); 97 98 if (alsoStartTargets || debugmode) { 99 targetserver.startTargets(debugmode, progress); 100 } else { server.getServerInstance().start(progress); 102 } 103 104 jmp.deployDatasources(); 105 106 modules = targetserver.deploy(progress, forceRedeploy); 107 targetserver.notifyIncrementalDeployment(modules); 110 111 if (modules != null && modules.length > 0) { 112 target.setTargetModules(modules); 113 } else { 114 String msg = NbBundle.getMessage(Deployment.class, "MSG_ModuleNotDeployed"); 115 throw new DeploymentException (msg); 116 } 117 return target.getClientUrl(clientUrlPart); 118 } catch (Exception ex) { 119 String msg = NbBundle.getMessage (Deployment.class, "MSG_DeployFailed", ex.getLocalizedMessage ()); 120 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 121 throw new DeploymentException(msg, ex); 122 } finally { 123 if (progress != null) { 124 progress.finish(); 125 } 126 } 127 } 128 129 public static final class DeploymentException extends Exception { 130 private DeploymentException (String msg) { 131 super (msg); 132 } 133 private DeploymentException (Throwable t) { 134 super (t); 135 } 136 private DeploymentException (String s, Throwable t) { 137 super (s, t); 138 } 139 144 public String toString() { 145 String s = getClass().getName(); 146 String message = getLocalizedMessage(); 147 return (message != null) ? (message) : s; 148 } 149 } 150 151 public String [] getServerInstanceIDs () { 152 return InstanceProperties.getInstanceList (); 153 } 154 155 165 public String [] getServerInstanceIDs(Object [] moduleTypes) { 166 return getServerInstanceIDs(moduleTypes, null, null); 167 } 168 169 180 public String [] getServerInstanceIDs(Object [] moduleTypes, String specVersion) { 181 return getServerInstanceIDs(moduleTypes, specVersion, null); 182 } 183 184 196 public String [] getServerInstanceIDs(Object [] moduleTypes, String specVersion, String [] tools) { 197 List result = new ArrayList (); 198 String [] serverInstanceIDs = getServerInstanceIDs(); 199 for (int i = 0; i < serverInstanceIDs.length; i++) { 200 J2eePlatform platform = getJ2eePlatform(serverInstanceIDs[i]); 201 if (platform != null) { 202 boolean isOk = true; 203 if (moduleTypes != null) { 204 Set platModuleTypes = platform.getSupportedModuleTypes(); 205 for (int j = 0; j < moduleTypes.length; j++) { 206 if (!platModuleTypes.contains(moduleTypes[j])) { 207 isOk = false; 208 } 209 } 210 } 211 if (isOk && specVersion != null) { 212 Set platSpecVers = platform.getSupportedSpecVersions(); 213 if (specVersion.equals(J2eeModule.J2EE_13)) { 214 isOk = platSpecVers.contains(J2eeModule.J2EE_13) 215 || platSpecVers.contains(J2eeModule.J2EE_14); 216 } else { 217 isOk = platSpecVers.contains(specVersion); 218 } 219 } 220 if (isOk && tools != null) { 221 for (int j = 0; j < tools.length; j++) { 222 if (!platform.isToolSupported(tools[j])) { 223 isOk = false; 224 } 225 } 226 } 227 if (isOk) { 228 result.add(serverInstanceIDs[i]); 229 } 230 } 231 } 232 return (String [])result.toArray(new String [result.size()]); 233 } 234 235 public String getServerInstanceDisplayName (String id) { 236 return ServerRegistry.getInstance ().getServerInstance (id).getDisplayName (); 237 } 238 239 public String getServerID (String instanceId) { 240 ServerInstance si = ServerRegistry.getInstance().getServerInstance(instanceId); 241 if (si != null) { 242 return si.getServer().getShortName(); 243 } 244 return null; 245 } 246 247 public String getDefaultServerInstanceID () { 248 ServerString defInst = ServerRegistry.getInstance ().getDefaultInstance (); 249 if (defInst != null) { 250 ServerInstance si = defInst.getServerInstance(); 251 if (si != null) { 252 return si.getUrl (); 253 } 254 } 255 return null; 256 } 257 258 public String [] getInstancesOfServer (String id) { 259 if (id != null) { 260 Server server = ServerRegistry.getInstance().getServer(id); 261 if (server != null) { 262 ServerInstance sis [] = ServerRegistry.getInstance ().getServer (id).getInstances (); 263 String ids [] = new String [sis.length]; 264 for (int i = 0; i < sis.length; i++) { 265 ids [i] = sis [i].getUrl (); 266 } 267 return ids; 268 } 269 } 270 return new String [0]; 271 } 272 273 public String [] getServerIDs () { 274 Collection c = ServerRegistry.getInstance ().getServers (); 275 String ids [] = new String [c.size ()]; 276 Iterator iter = c.iterator (); 277 for (int i = 0; i < c.size (); i++) { 278 Server s = (Server) iter.next (); 279 ids [i] = s.getShortName (); 280 } 281 return ids; 282 } 283 284 292 public J2eePlatform getJ2eePlatform(String serverInstanceID) { 293 ServerInstance serInst = ServerRegistry.getInstance().getServerInstance(serverInstanceID); 294 if (serInst == null) return null; 295 return J2eePlatform.create(serInst); 296 } 297 298 public String getServerDisplayName (String id) { 299 return ServerRegistry.getInstance ().getServer (id).getDisplayName(); 300 } 301 302 309 public final void addInstanceListener(InstanceListener l) { 310 ServerRegistry.getInstance ().addInstanceListener(l); 311 } 312 313 320 public final void removeInstanceListener(InstanceListener l) { 321 ServerRegistry.getInstance ().removeInstanceListener(l); 322 } 323 324 public static interface Logger { 325 public void log(String message); 326 } 327 } 328 | Popular Tags |