1 23 24 package com.sun.enterprise.instance; 25 26 import java.net.InetAddress ; 28 import java.net.UnknownHostException ; 29 30 import com.sun.enterprise.util.OS; 32 import com.sun.enterprise.util.StringUtils; 33 import com.sun.enterprise.config.*; 34 import com.sun.enterprise.config.serverbeans.ServerTags; 35 import com.sun.enterprise.config.serverbeans.JmsService; 36 import com.sun.enterprise.config.serverbeans.ElementProperty; 37 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 38 import com.sun.enterprise.server.Constants; 39 40 44 45 50 51 public class InstanceDefinition 52 { 53 public static final int DEFAULT_PORT = 80; 54 public static final int DEFAULT_JMS_PORT = 7676; 55 56 public static final String DEFAULT_JMS_USER = "admin"; 57 public static final String DEFAULT_JMS_PW = "admin"; 58 59 public static final String SPACE = " "; 60 public static final String WINDOWS_BIN_EXT = ".exe"; 61 public static final String BIN_DIR_NAME = "bin"; 62 public static final String LIB_DIR_NAME = "lib"; 63 64 private String mJavaHome = System.getProperty("java.home"); 65 private String mImqHome = null; 66 private String mServerName = null; 67 private int mHttpPort = DEFAULT_PORT; 68 private String mIdentifier = null; 69 private String mMailHost = null; 70 private String mUser = null; 71 private String mDocRoot = null; 72 private String mPortString = null; 73 74 private int mJMSPort = DEFAULT_JMS_PORT; 75 private String mJMSPortString = null; 76 private String mJMSUser = null; 77 private String mJMSPasswd = null; 78 79 88 89 public static final String UNIX_START_COMMAND_NAME = "startserv"; 90 public static final String UNIX_STOP_COMMAND_NAME = "stopserv"; 91 public static final String UNIX_GETTOKENS_COMMAND_NAME = "gettokens"; 92 public static final String UNIX_RESTART_COMMAND_NAME = "restartserv"; 93 94 95 107 public static final String WIN_START_COMMAND_NAME = "startsec.exe"; 108 public static final String WIN_STOP_COMMAND_NAME = "stopserv.bat"; 109 public static final String WIN_GETTOKENS_COMMAND_NAME = "gettokens.exe"; 110 111 public final String JMS_NODE_PATH = ServerXPathHelper.XPATH_JMS_SERVICE; 112 113 125 126 public InstanceDefinition(String serverName, int httpPort, 127 String identifier, String mailHost, String user, String docRoot, 128 int jmsPort, String jmsUser, String jmsPasswd) { 129 initialize(serverName, httpPort, identifier, mailHost, user, docRoot, 130 jmsPort, jmsUser, jmsPasswd); 131 } 132 133 141 public InstanceDefinition (String id, int port) { 142 if (id == null || port <= 0) 143 throw new IllegalArgumentException (Localizer.getValue(ExceptionType.ILLEGAL_PORT)); 144 String serverName = createLocalHostName(); 145 String mailHost = createLocalHostName(); 146 String user = System.getProperty("user.name"); 147 String docRoot = ServerManager.INSTANCE_CFG_ROOT 148 + "/" + ServerManager.DOC_DIR_NAME; 149 initialize(serverName, port, id, mailHost, user, docRoot, 150 DEFAULT_JMS_PORT, DEFAULT_JMS_USER, DEFAULT_JMS_PW); 151 } 152 153 private void initialize(String serverName, int httpPort, String identifier, 154 String mailHost, String user, String docRoot, int jmsPort, 155 String jmsUser, String jmsPasswd) { 156 if (serverName == null|| identifier == null|| 157 mailHost == null|| user == null|| 158 user == null|| docRoot == null|| 159 jmsUser == null|| jmsPasswd == null ) { 160 throw new IllegalArgumentException (); 161 } 162 if (httpPort <= 0 || jmsPort <= 0) { 163 throw new IllegalArgumentException (); 164 } 165 mServerName = serverName; 166 mHttpPort = httpPort; 167 mIdentifier = identifier; 168 mMailHost = mailHost; 169 mUser = user; 170 mDocRoot = docRoot; 171 mPortString = "" + mHttpPort; 172 mJMSPort = jmsPort; 173 mJMSPortString = jmsPort +""; 174 mJMSUser = jmsUser; 175 mJMSPasswd = jmsPasswd; 176 } 177 178 public String getID() { 179 return mIdentifier; 180 } 181 182 public int getPort() { 183 return mHttpPort; 184 } 185 186 public String getServerName() { 187 return mServerName; 188 } 189 190 public String getAdminJavaHome() throws ConfigException { 191 ConfigContext configContext; 192 InstanceEnvironment instanceEnvironment = 193 new InstanceEnvironment(ServerManager.ADMINSERVER_ID); 194 String fileUrl = instanceEnvironment.getConfigFilePath(); 195 configContext = ConfigFactory.createConfigContext(fileUrl); 196 ConfigBean configbean = ConfigBeansFactory.getConfigBeanByXPath( 197 configContext, ServerXPathHelper.XPATH_JAVACONFIG); 198 mJavaHome = configbean.getAttributeValue(ServerTags.JAVA_HOME); 199 return mJavaHome; 200 } 201 202 public String getDocRoot() 203 { 204 return ( mDocRoot ); 205 } 206 207 213 private String createLocalHostName() { 214 try { 215 return InetAddress.getLocalHost().getHostName(); 216 } 217 catch(UnknownHostException ue) { 218 return "localhost"; 219 } 220 } 221 222 223 230 231 public String [] getStartCommand() { 232 String [] startCommand = null; 233 237 if (OS.isWindows()) { 238 startCommand = getCompleteWindowsStartCommand(); 239 } 240 else { 241 245 startCommand = getCompleteNonWindowsStartCommand(); 246 } 247 return ( startCommand ); 248 } 249 250 254 private String [] getCompleteWindowsStartCommand() 255 { 256 257 String [] names = new String [] { 258 System.getProperty(Constants.INSTALL_ROOT), 259 BIN_DIR_NAME, 260 WIN_START_COMMAND_NAME 261 }; 262 String programName = StringUtils.makeFilePath(names, false); 263 264 265 266 return ( new String [] { 267 programName, 268 mIdentifier, 269 System.getProperty(Constants.IAS_ROOT), 270 } ); 271 } 272 273 274 277 private String [] getCompleteNonWindowsStartCommand() 278 { 279 String [] names = new String [] { 280 System.getProperty(Constants.IAS_ROOT), 281 BIN_DIR_NAME, 282 UNIX_START_COMMAND_NAME 283 }; 284 String programName = StringUtils.makeFilePath(names, false); 285 286 return ( new String []{programName} ); 287 } 288 296 297 public String [] getGetSecurityTokensCommand() { 298 String [] command = null; 299 String onlyCommand = null; 300 if (OS.isWindows()) { 301 onlyCommand = getWindowsSecTokensCommand(); 302 } 303 else { 304 onlyCommand = getNonWindowsSecTokensCommand(); 305 } 306 307 command = new String [] { 308 onlyCommand, 309 mIdentifier, 310 System.getProperty(Constants.IAS_ROOT), 311 }; 312 return ( command ); 313 } 314 315 317 private String getWindowsSecTokensCommand() 318 { 319 String [] names = new String [] { 320 System.getProperty(Constants.INSTALL_ROOT), 321 BIN_DIR_NAME, 322 WIN_GETTOKENS_COMMAND_NAME 323 }; 324 325 return ( StringUtils.makeFilePath(names, false) ); 326 } 327 329 330 private String getNonWindowsSecTokensCommand() 331 { 332 String [] names = new String [] { 333 System.getProperty(Constants.INSTALL_ROOT), 334 LIB_DIR_NAME, 335 UNIX_GETTOKENS_COMMAND_NAME 336 }; 337 338 return ( StringUtils.makeFilePath(names, false) ); 339 } 340 341 348 349 public String [] getStopCommand() { 350 String [] stopCommand = new String [1]; 351 352 String command = null; 353 if (OS.isWindows()) { 354 command = WIN_STOP_COMMAND_NAME; 355 } 356 else { 357 command = UNIX_STOP_COMMAND_NAME; 358 } 359 String [] names = new String [] { 360 System.getProperty(Constants.IAS_ROOT), 361 BIN_DIR_NAME, 362 command 363 }; 364 365 stopCommand[0] = StringUtils.makeFilePath(names, false); 366 367 return ( stopCommand ); 368 } 369 370 378 379 public String [] getRestartCommand() { 380 if (OS.isWindows()) { 381 throw new UnsupportedOperationException (Localizer.getValue(ExceptionType.ILLEGAL_RESTART)); 382 } 383 String [] restartCommand = new String [1]; 384 385 String [] names = new String [] { 386 System.getProperty(Constants.IAS_ROOT), 387 BIN_DIR_NAME, 388 UNIX_RESTART_COMMAND_NAME 389 }; 390 restartCommand[0] = StringUtils.makeFilePath(names, false); 391 392 return ( restartCommand ); 393 } 394 395 400 401 public String toString() { 402 StringBuffer sb = new StringBuffer (); 403 sb.append(mServerName); 404 sb.append(SPACE + mPortString); 405 sb.append(SPACE + mIdentifier); 406 sb.append(SPACE + mMailHost); 407 sb.append(SPACE + mUser); 408 sb.append(SPACE + mDocRoot); 409 410 return ( sb.toString() ); 411 } 412 413 416 public void setUser(String user) 417 { 418 if ((user != null) && (user.length() > 0)) 419 { 420 mUser = user; 421 } 422 } 423 424 427 public String getUser() 428 { 429 return mUser; 430 } 431 } 432 | Popular Tags |