1 19 20 package org.netbeans.modules.j2ee.oc4j.ide; 21 22 import java.util.Collections ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 import java.util.Vector ; 26 import javax.enterprise.deploy.shared.ActionType ; 27 import javax.enterprise.deploy.shared.CommandType ; 28 import javax.enterprise.deploy.shared.StateType ; 29 import javax.enterprise.deploy.spi.DeploymentManager ; 30 import javax.enterprise.deploy.spi.Target ; 31 import javax.enterprise.deploy.spi.TargetModuleID ; 32 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException ; 33 import javax.enterprise.deploy.spi.status.ClientConfiguration ; 34 import javax.enterprise.deploy.spi.status.DeploymentStatus ; 35 import javax.enterprise.deploy.spi.status.ProgressEvent ; 36 import javax.enterprise.deploy.spi.status.ProgressListener ; 37 import javax.enterprise.deploy.spi.status.ProgressObject ; 38 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 39 import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; 40 import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer; 41 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentManager; 42 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties; 43 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils; 44 import org.openide.util.NbBundle; 45 import org.openide.util.RequestProcessor; 46 47 51 public class OC4JStartServer extends StartServer implements ProgressObject { 52 53 static enum MODE { RUN, DEBUG }; 54 private MODE mode; 55 private DeploymentStatus deploymentStatus; 56 private OC4JDeploymentManager dm; 57 private String serverName; 58 private String serverHome; 59 private Vector <ProgressListener > listeners = new Vector <ProgressListener >(); 60 private InstanceProperties ip; 61 private static Map isDebugModeUri = Collections.synchronizedMap((Map )new HashMap (2,1)); 62 private String url; 63 64 public OC4JStartServer(DeploymentManager dm) { 65 if (!(dm instanceof OC4JDeploymentManager)) { 66 throw new IllegalArgumentException ("Only OC4JDeplomentManager is supported"); } 68 this.dm = (OC4JDeploymentManager) dm; 69 this.ip = ((OC4JDeploymentManager)dm).getProperties().getInstanceProperties(); 70 serverName = ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR); 71 serverHome = ip.getProperty(OC4JPluginProperties.PROPERTY_OC4J_HOME); 72 url = ip.getProperty(InstanceProperties.URL_ATTR); 73 } 74 75 public boolean supportsStartDebugging(Target target) { 76 return OC4JPluginUtils.isLocalServer(ip); 77 } 78 79 public InstanceProperties getInstanceProperties() { 80 return ip; 81 } 82 83 public ProgressObject startDebugging(Target target) { 84 mode = MODE.DEBUG; 85 String user = "oc4jadmin"; 86 String serverName = ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR); 87 fireHandleProgressEvent(null, new OC4JDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, 88 NbBundle.getMessage(OC4JStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName))); 90 if(!OC4JPluginUtils.isUserActivated(serverHome, user)) { 92 String password = null; 93 94 while(password == null || password.equals("")) { 95 password = OC4JPluginUtils.requestPassword(user); 96 } 97 98 if(!OC4JPluginUtils.activateUser(serverHome, user, password)) { 99 fireHandleProgressEvent(null, new OC4JDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.FAILED, 100 NbBundle.getMessage(OC4JStartServer.class, "MSG_START_SERVER_NOT_INITIALIZED", serverName))); 102 return this; 103 } 104 } 105 106 RequestProcessor.getDefault().post(new OC4JStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); 107 addDebugModeUri(); 108 return this; 109 } 110 111 private void addDebugModeUri() { 112 isDebugModeUri.put(url, new Object ()); 113 } 114 115 private void removeDebugModeUri() { 116 isDebugModeUri.remove(url); 117 } 118 119 private boolean existsDebugModeUri() { 120 return isDebugModeUri.containsKey(url); 121 } 122 123 public boolean isDebuggable(Target target) { 124 if (!existsDebugModeUri()) { 125 return false; 126 } 127 if (!isRunning()) { 128 return false; 129 } 130 return true; 131 } 132 133 public boolean isAlsoTargetServer(Target target) { 134 return true; 135 } 136 137 public ServerDebugInfo getDebugInfo(Target target) { 138 return new ServerDebugInfo(ip.getProperty(OC4JPluginProperties.PROPERTY_HOST), dm.getProperties().getDebugPort()); 139 } 140 141 public boolean supportsStartDeploymentManager() { 142 return OC4JPluginUtils.isLocalServer(ip); 143 } 144 145 public ProgressObject stopDeploymentManager() { 146 fireHandleProgressEvent(null, new OC4JDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, 147 NbBundle.getMessage(OC4JStartServer.class, "MSG_STOP_SERVER_IN_PROGRESS", serverName))); RequestProcessor.getDefault().post(new OC4JStopRunnable(dm, this), 0, Thread.NORM_PRIORITY); 149 removeDebugModeUri(); 150 return this; 151 } 152 153 public ProgressObject startDeploymentManager() { 155 mode = MODE.RUN; 156 String user = "oc4jadmin"; 157 String serverName = ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR); 158 fireHandleProgressEvent(null, new OC4JDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.RUNNING, 159 NbBundle.getMessage(OC4JStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName))); 161 if(!OC4JPluginUtils.isUserActivated(serverHome, user)) { 163 String password = null; 164 165 while(password == null || password.equals("")) { 166 password = OC4JPluginUtils.requestPassword(user); 167 } 168 169 if(!OC4JPluginUtils.activateUser(serverHome, user, password)) { 170 fireHandleProgressEvent(null, new OC4JDeploymentStatus(ActionType.EXECUTE, CommandType.START, StateType.FAILED, 171 NbBundle.getMessage(OC4JStartServer.class, "MSG_START_SERVER_NOT_INITIALIZED", serverName))); 173 return this; 174 } 175 } 176 177 RequestProcessor.getDefault().post(new OC4JStartRunnable(dm, this), 0, Thread.NORM_PRIORITY); 178 removeDebugModeUri(); 179 return this; 180 } 181 182 public boolean needsStartForTargetList() { 183 return false; 184 } 185 186 public boolean needsStartForConfigure() { 187 return false; 188 } 189 190 public boolean needsStartForAdminConfig() { 191 return false; 192 } 193 194 public boolean isRunning() { 195 return OC4JPluginProperties.isRunning(ip.getProperty(OC4JPluginProperties.PROPERTY_HOST), 196 ip.getProperty(InstanceProperties.HTTP_PORT_NUMBER)); 197 } 198 199 public DeploymentStatus getDeploymentStatus() { 200 return deploymentStatus; 201 } 202 203 public TargetModuleID [] getResultTargetModuleIDs() { 204 return null; 205 } 206 207 public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) { 208 return null; 209 } 210 211 public boolean isCancelSupported() { 212 return false; 213 } 214 215 public void cancel() throws OperationUnsupportedException { 216 } 217 218 public boolean isStopSupported() { 219 return OC4JPluginUtils.isLocalServer(ip); 220 } 221 222 public void stop() throws OperationUnsupportedException { 223 } 224 225 public void addProgressListener(ProgressListener progressListener) { 226 listeners.add(progressListener); 227 } 228 229 public void removeProgressListener(ProgressListener progressListener) { 230 listeners.remove(progressListener); 231 } 232 233 public void fireHandleProgressEvent(TargetModuleID targetModuleID, DeploymentStatus deploymentStatus) { 234 ProgressEvent evt = new ProgressEvent (this, targetModuleID, deploymentStatus); 235 this.deploymentStatus = deploymentStatus; 236 237 java.util.Vector targets = null; 238 synchronized (this) { 239 if (listeners != null) { 240 targets = (java.util.Vector ) listeners.clone(); 241 } 242 } 243 244 if (targets != null) { 245 for (int i = 0; i < targets.size(); i++) { 246 ProgressListener target = (ProgressListener )targets.elementAt(i); 247 target.handleProgressEvent(evt); 248 } 249 } 250 } 251 252 MODE getMode() { 253 return mode; 254 } 255 } | Popular Tags |