1 19 package org.netbeans.modules.j2ee.jboss4; 20 import java.util.Collections ; 21 import java.util.Map ; 22 import java.util.WeakHashMap ; 23 import javax.naming.NameNotFoundException ; 24 import javax.naming.NamingException ; 25 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 26 import org.netbeans.modules.j2ee.jboss4.config.WarDeploymentConfiguration; 27 import org.netbeans.modules.j2ee.jboss4.util.JBProperties; 28 import org.netbeans.modules.j2ee.jboss4.ide.JBJ2eePlatformFactory; 29 import java.io.File ; 30 import java.io.InputStream ; 31 import java.net.URLClassLoader ; 32 import java.util.Hashtable ; 33 import java.util.Locale ; 34 import javax.enterprise.deploy.model.DeployableObject ; 35 import javax.enterprise.deploy.shared.DConfigBeanVersionType ; 36 import javax.enterprise.deploy.shared.ModuleType ; 37 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 38 import javax.enterprise.deploy.spi.DeploymentManager ; 39 import javax.enterprise.deploy.spi.Target ; 40 import javax.enterprise.deploy.spi.TargetModuleID ; 41 import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException ; 42 import javax.enterprise.deploy.spi.exceptions.InvalidModuleException ; 43 import javax.enterprise.deploy.spi.exceptions.TargetException ; 44 import javax.enterprise.deploy.spi.status.ProgressObject ; 45 import javax.management.MBeanServerConnection ; 46 import javax.naming.Context ; 47 import javax.naming.InitialContext ; 48 import org.netbeans.modules.j2ee.jboss4.config.CarDeploymentConfiguration; 49 import org.netbeans.modules.j2ee.jboss4.config.EarDeploymentConfiguration; 50 import org.netbeans.modules.j2ee.jboss4.config.EjbDeploymentConfiguration; 51 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; 52 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; 53 54 58 public class JBDeploymentManager implements DeploymentManager { 59 60 private DeploymentManager dm; 61 private String realUri; 62 private MBeanServerConnection rmiServer; 63 64 private int debuggingPort = 8787; 65 66 private InstanceProperties instanceProperties; 67 68 73 private static Map propertiesToIsRunning = Collections.synchronizedMap(new WeakHashMap ()); 74 75 76 public JBDeploymentManager(DeploymentManager dm, String uri, String username, String password) { 77 realUri = uri; 78 this.dm = dm; 79 rmiServer = null; 80 } 81 82 public String getHost() { 86 String host = InstanceProperties.getInstanceProperties(realUri). 87 getProperty(JBPluginProperties.PROPERTY_HOST); 88 return host; 89 } 90 91 public int getPort() { 92 String port = InstanceProperties.getInstanceProperties(realUri). 93 getProperty(JBPluginProperties.PROPERTY_PORT); 94 return new Integer (port).intValue(); 95 } 96 97 public int getDebuggingPort() { 98 return debuggingPort; 99 } 100 101 public String getUrl() { 102 return realUri; 103 } 104 105 106 public InstanceProperties getInstanceProperties() { 107 if (instanceProperties == null) 108 instanceProperties = InstanceProperties.getInstanceProperties(realUri); 109 110 return instanceProperties; 111 } 112 113 public synchronized MBeanServerConnection getRMIServer() { 114 if(rmiServer == null) { 115 ClassLoader oldLoader = null; 116 117 try { 118 oldLoader = Thread.currentThread().getContextClassLoader(); 119 InstanceProperties ip = this.getInstanceProperties(); 120 URLClassLoader loader = JBDeploymentFactory.getJBClassLoader(ip.getProperty(JBPluginProperties.PROPERTY_ROOT_DIR), 121 ip.getProperty(JBPluginProperties.PROPERTY_SERVER_DIR)); 122 Thread.currentThread().setContextClassLoader(loader); 123 124 JBProperties props = getProperties(); 125 Hashtable env = new Hashtable (); 126 127 env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory"); 129 env.put(Context.PROVIDER_URL, "jnp://localhost:"+JBPluginUtils.getJnpPort(ip.getProperty(JBPluginProperties.PROPERTY_SERVER_DIR))); 130 env.put(Context.OBJECT_FACTORIES, "org.jboss.naming"); 131 env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" ); 132 env.put("jnp.disableDiscovery", Boolean.TRUE); 133 134 final String JAVA_SEC_AUTH_LOGIN_CONF = "java.security.auth.login.config"; String oldAuthConf = System.getProperty(JAVA_SEC_AUTH_LOGIN_CONF); 136 137 File securityConf = new File (props.getRootDir(), "/client/auth.conf"); 138 if (securityConf.exists()) { 139 env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.LoginInitialContextFactory"); 140 env.put(Context.SECURITY_PRINCIPAL, props.getUsername()); 141 env.put(Context.SECURITY_CREDENTIALS, props.getPassword()); 142 System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, securityConf.getAbsolutePath()); } 144 145 InitialContext ctx = new InitialContext (env); 147 148 if (oldAuthConf != null) { 150 System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, oldAuthConf); 151 } else { 152 System.clearProperty(JAVA_SEC_AUTH_LOGIN_CONF); 153 } 154 155 rmiServer = (MBeanServerConnection )ctx.lookup("/jmx/invoker/RMIAdaptor"); 157 } catch (NameNotFoundException ex) { 158 } catch (NamingException ex) { 159 } finally { 161 if (oldLoader != null) 162 Thread.currentThread().setContextClassLoader(oldLoader); 163 } 164 } 165 166 return rmiServer; 167 } 168 169 public synchronized MBeanServerConnection refreshRMIServer() { 170 rmiServer = null; 171 return getRMIServer(); 172 } 173 174 181 public static boolean isRunningLastCheck(InstanceProperties ip) { 182 boolean isRunning = propertiesToIsRunning.containsKey(ip) && propertiesToIsRunning.get(ip).equals(Boolean.TRUE); 183 return isRunning; 184 } 185 186 189 public static void setRunningLastCheck(InstanceProperties ip, Boolean isRunning) { 190 assert(ip != null); 191 propertiesToIsRunning.put(ip, isRunning); 192 } 193 194 public ProgressObject distribute(Target [] target, File file, File file2) throws IllegalStateException { 198 return new JBDeployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); 199 } 200 201 public DeploymentConfiguration createConfiguration(DeployableObject deployableObject) throws InvalidModuleException { 202 ModuleType type = deployableObject.getType(); 203 if (type == ModuleType.WAR) { 204 return new WarDeploymentConfiguration(deployableObject); 205 } else if (type == ModuleType.EAR) { 206 return new EarDeploymentConfiguration(deployableObject); 207 } else if (type == ModuleType.EJB) { 208 return new EjbDeploymentConfiguration(deployableObject); 209 } else if (type == ModuleType.CAR) { 210 return new CarDeploymentConfiguration(deployableObject); 211 } else { 212 throw new InvalidModuleException ("Unsupported module type: " + type.toString()); } 214 } 215 216 public ProgressObject redeploy(TargetModuleID [] targetModuleID, InputStream inputStream, InputStream inputStream2) throws UnsupportedOperationException , IllegalStateException { 217 return dm.redeploy(targetModuleID, inputStream, inputStream2); 218 } 219 220 public ProgressObject distribute(Target [] target, InputStream inputStream, InputStream inputStream2) throws IllegalStateException { 221 return dm.distribute(target, inputStream, inputStream2); 222 } 223 224 public ProgressObject distribute(Target [] target, ModuleType moduleType, InputStream inputStream, InputStream inputStream0) throws IllegalStateException { 225 return distribute(target, inputStream, inputStream0); 226 } 227 228 public ProgressObject undeploy(TargetModuleID [] targetModuleID) throws IllegalStateException { 229 return dm.undeploy(targetModuleID); 230 } 231 232 public ProgressObject stop(TargetModuleID [] targetModuleID) throws IllegalStateException { 233 return dm.stop(targetModuleID); 234 } 235 236 public ProgressObject start(TargetModuleID [] targetModuleID) throws IllegalStateException { 237 return dm.start(targetModuleID); 238 } 239 240 public void setLocale(Locale locale) throws UnsupportedOperationException { 241 dm.setLocale(locale); 242 } 243 244 public boolean isLocaleSupported(Locale locale) { 245 return dm.isLocaleSupported(locale); 246 } 247 248 public TargetModuleID [] getAvailableModules(ModuleType moduleType, Target [] target) throws TargetException , IllegalStateException { 249 return new TargetModuleID []{}; 251 } 252 253 public TargetModuleID [] getNonRunningModules(ModuleType moduleType, Target [] target) throws TargetException , IllegalStateException { 254 return new TargetModuleID []{}; 256 } 257 258 public TargetModuleID [] getRunningModules(ModuleType moduleType, Target [] target) throws TargetException , IllegalStateException { 259 return dm.getRunningModules(moduleType, target); 260 } 261 262 public ProgressObject redeploy(TargetModuleID [] targetModuleID, File file, File file2) throws UnsupportedOperationException , IllegalStateException { 263 return new JBDeployer(realUri, this).redeploy(targetModuleID, file, file2); 264 } 265 266 public void setDConfigBeanVersion(DConfigBeanVersionType dConfigBeanVersionType) throws DConfigBeanVersionUnsupportedException { 267 dm.setDConfigBeanVersion(dConfigBeanVersionType); 268 } 269 270 public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType dConfigBeanVersionType) { 271 return dm.isDConfigBeanVersionSupported(dConfigBeanVersionType); 272 } 273 274 public void release() { 275 if (dm != null) { 276 dm.release(); 277 } 278 } 279 280 public boolean isRedeploySupported() { 281 return dm.isRedeploySupported(); 282 } 283 284 public Locale getCurrentLocale() { 285 return dm.getCurrentLocale(); 286 } 287 288 public DConfigBeanVersionType getDConfigBeanVersion() { 289 return dm.getDConfigBeanVersion(); 290 } 291 292 public Locale getDefaultLocale() { 293 return dm.getDefaultLocale(); 294 } 295 296 public Locale [] getSupportedLocales() { 297 return dm.getSupportedLocales(); 298 } 299 300 public Target [] getTargets() throws IllegalStateException { 301 return dm.getTargets(); 302 } 303 304 private JBJ2eePlatformFactory.J2eePlatformImplImpl jbPlatform; 305 306 public JBJ2eePlatformFactory.J2eePlatformImplImpl getJBPlatform() { 307 if (jbPlatform == null) { 308 jbPlatform = (JBJ2eePlatformFactory.J2eePlatformImplImpl) new JBJ2eePlatformFactory().getJ2eePlatformImpl(this); 309 } 310 return jbPlatform; 311 } 312 313 public JBProperties getProperties() { 314 return new JBProperties(this); 315 } 316 317 } 318 | Popular Tags |