1 23 24 package com.sun.enterprise.admin.mbeans; 25 26 import com.sun.enterprise.admin.common.exception.ServerInstanceException; 27 import com.sun.enterprise.config.serverbeans.Applications; 28 import com.sun.enterprise.config.ConfigBeansFactory; 29 import com.sun.enterprise.config.ConfigContext; 30 import com.sun.enterprise.config.serverbeans.Applications; 31 import com.sun.enterprise.config.serverbeans.J2eeApplication; 32 import com.sun.enterprise.config.serverbeans.WebModule; 33 import com.sun.enterprise.config.serverbeans.EjbModule; 34 import com.sun.enterprise.config.serverbeans.ConnectorModule; 35 import com.sun.enterprise.config.serverbeans.AppclientModule; 36 import com.sun.enterprise.config.serverbeans.LifecycleModule; 37 import com.sun.enterprise.config.serverbeans.Mbean; 38 import javax.enterprise.deploy.shared.ModuleType ; 39 import com.sun.enterprise.deployment.backend.DeploymentUtils; 40 import com.sun.enterprise.deployment.util.XModuleType; 41 import com.sun.enterprise.instance.AppsManager; 42 import com.sun.enterprise.deployment.Application; 43 import com.sun.enterprise.deployment.BundleDescriptor; 44 import com.sun.enterprise.server.ApplicationServer; 45 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 46 import com.sun.enterprise.deployment.io.DescriptorConstants; 47 import com.sun.enterprise.admin.server.core.AdminService; 48 import java.util.Iterator ; 49 import java.io.File ; 50 import java.io.FileReader ; 51 import java.io.StringWriter ; 52 import java.io.EOFException ; 53 import java.io.FileNotFoundException ; 54 import java.io.IOException ; 55 import com.sun.enterprise.instance.InstanceFactory; 56 import com.sun.enterprise.util.io.FileUtils; 57 import java.util.logging.Level ; 58 import java.util.logging.Logger ; 59 import com.sun.enterprise.util.i18n.StringManager; 60 import com.sun.logging.LogDomains; 61 import com.sun.enterprise.util.RelativePathResolver; 62 63 70 71 public class J2EEModule { 72 73 private static final StringManager localStrings = 75 StringManager.getManager(J2EEModule.class); 76 private static final Logger sLogger = 77 Logger.getLogger(LogDomains.ADMIN_LOGGER); 78 79 private String standaloneModuleName = null; 81 private String subModuleName = null; 82 private ModuleType moduleType = null; 83 private String ddLocation = null; 84 85 88 public J2EEModule () { 89 } 90 91 94 public J2EEModule (String standaloneModuleName) 95 throws ServerInstanceException { 96 97 if ((standaloneModuleName == null) || 98 (standaloneModuleName.length() < 1)) { 99 sLogger.log(Level.WARNING, getLogMsg("invalid standAloneModuleName")); 100 throw new ServerInstanceException ( localStrings.getString( 101 "admin.mbeans.J2EEModule.invalidStandaloneModuleName")); 102 } 103 this.standaloneModuleName = standaloneModuleName; 104 } 105 106 109 public J2EEModule (String standaloneModuleName, String subModuleName) 110 throws ServerInstanceException { 111 112 this(standaloneModuleName); 113 114 if ((subModuleName == null) || 115 (subModuleName.length() < 1)) { 116 sLogger.log(Level.WARNING, 117 getLogMsg("invalid sub module for the given stand-alone module")); 118 throw new ServerInstanceException (localStrings.getString( 119 "admin.mbeans.J2EEModule.invalidSubModuleName")); 120 } 121 this.subModuleName = subModuleName; 122 } 123 124 135 public ModuleType getModuleType() throws ServerInstanceException { 136 137 if (moduleType != null) return moduleType; 138 139 if (subModuleName == null) { 140 moduleType = getModuleType(standaloneModuleName); 141 } else { 142 moduleType = getModuleType(standaloneModuleName, subModuleName); 143 } 144 145 return moduleType; 146 } 147 148 152 public String getDeploymentDescriptorsLocation() 153 throws ServerInstanceException { 154 155 if (ddLocation != null) { 156 ddLocation = RelativePathResolver.resolvePath(ddLocation); 157 return ddLocation; 158 } 159 160 if (subModuleName == null) { 161 ddLocation = getDDLocation(standaloneModuleName); 162 } else { 163 ddLocation = getDDLocation(standaloneModuleName, subModuleName); 164 } 165 166 if (ddLocation != null) { 167 ddLocation = RelativePathResolver.resolvePath(ddLocation); 168 } 169 170 return ddLocation; 171 } 172 173 176 ModuleType getModuleType(String standaloneModuleName) 177 throws ServerInstanceException { 178 179 sLogger.log(Level.FINE, 180 getLogMsg("getModuleType for standaloneModuleName" + 181 standaloneModuleName)); 182 183 185 ModuleType moduleType = null; 186 187 try { 188 189 Applications appsConfigBean = 191 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 192 AdminService.getAdminService().getAdminContext().getAdminConfigContext(), 193 ServerXPathHelper.XPATH_APPLICATIONS); 194 195 J2eeApplication[] j2eeApps = appsConfigBean.getJ2eeApplication(); 197 if (j2eeApps != null) { 198 for(int i=0; i<j2eeApps.length; i++) { 199 if ((j2eeApps[i].getName()).equals(standaloneModuleName)) { 200 ddLocation = j2eeApps[i].getLocation(); 201 return ModuleType.EAR; 202 } 203 } 204 } 205 206 EjbModule[] eModules = appsConfigBean.getEjbModule(); 208 if (eModules != null) { 209 for(int i=0; i<eModules.length; i++) { 210 if ((eModules[i].getName()).equals(standaloneModuleName)) { 211 ddLocation = eModules[i].getLocation(); 212 return ModuleType.EJB; 213 } 214 } 215 } 216 217 WebModule[] wModules = appsConfigBean.getWebModule(); 219 if (wModules != null) { 220 for(int i=0; i<wModules.length; i++) { 221 if ((wModules[i].getName()).equals(standaloneModuleName)) { 222 ddLocation = wModules[i].getLocation(); 223 return ModuleType.WAR; 224 } 225 } 226 } 227 228 ConnectorModule[] connectorConfigBeans = appsConfigBean.getConnectorModule(); 230 if (connectorConfigBeans != null) { 231 for(int i = 0; i < connectorConfigBeans.length; i++) { 232 if ((connectorConfigBeans[i].getName()).equals(standaloneModuleName)) { 233 ddLocation = connectorConfigBeans[i].getLocation(); 234 return ModuleType.RAR; 235 } 236 } 237 } 238 239 AppclientModule[] acModules = appsConfigBean.getAppclientModule(); 241 if (acModules != null) { 242 for(int i = 0; i < acModules.length; i++) { 243 if ((acModules[i].getName()).equals(standaloneModuleName)) { 244 ddLocation = acModules[i].getLocation(); 245 return ModuleType.CAR; 246 } 247 } 248 } 249 250 LifecycleModule[] lcModules = appsConfigBean.getLifecycleModule(); 252 if (lcModules != null) { 253 for(int i = 0; i < lcModules.length; i++) { 254 if ((lcModules[i].getName()).equals(standaloneModuleName)) { 255 return XModuleType.LCM; 256 } 257 } 258 } 259 260 Mbean[] mbModules = appsConfigBean.getMbean(); 262 if (mbModules != null) { 263 for(int i = 0; i < mbModules.length; i++) { 264 if ((mbModules[i].getName()).equals(standaloneModuleName)) { 265 return XModuleType.CMB; 266 } 267 } 268 } 269 270 } catch (Exception e) { 271 throw new ServerInstanceException(e.getLocalizedMessage()); 272 } 273 return moduleType; 274 } 275 276 280 ModuleType getModuleType(String standaloneModuleName, String subModuleName) 281 throws ServerInstanceException { 282 283 sLogger.log(Level.FINE, getLogMsg("getModuleType " + 284 "standaloneModuleName = " + standaloneModuleName + " " + 285 "subModuleName = " + subModuleName)); 286 287 ModuleType moduleType = null; 288 289 try { 290 292 AppsManager am = InstanceFactory.createAppsManager( 293 ApplicationServer.getServerContext().getInstanceName()); 294 295 Application appD = (Application) 296 DeploymentUtils.getDescriptor(standaloneModuleName, am); 297 298 301 BundleDescriptor bd = null; 302 java.util.Set bds = appD.getBundleDescriptors(); 303 for(Iterator it=bds.iterator(); it.hasNext(); ) { 304 bd = (BundleDescriptor)it.next(); 305 if ((bd.getModuleDescriptor().getArchiveUri()).equals(subModuleName) || 306 bd.getModuleID().equals(subModuleName) || 307 bd.getName().equals(subModuleName)) { 308 moduleType = bd.getModuleType(); 309 ddLocation = am.getLocation(standaloneModuleName) + 311 File.separator + 312 FileUtils.makeFriendlyFileName( 313 bd.getModuleDescriptor().getArchiveUri()); 314 break; 315 } 316 } 317 318 } catch (Exception e) { 319 throw new ServerInstanceException(e.getLocalizedMessage()); 320 } 321 322 return moduleType; 323 324 } 325 326 327 335 String getDDLocation(String standaloneModuleName) 336 throws ServerInstanceException { 337 sLogger.log(Level.FINE, getLogMsg( 338 "getDDLocation for standaloneModuleName " + standaloneModuleName)); 339 return ddLocation; 340 } 341 342 350 String getDDLocation(String standaloneModuleName, String subModuleName) 351 throws ServerInstanceException { 352 sLogger.log(Level.FINE, getLogMsg( 353 "getDDLocation for standaloneModuleName " + 354 standaloneModuleName + " " + 355 "subModuleName = " + subModuleName)); 356 return ddLocation; 357 } 358 359 360 361 365 public String getStringForDDxml(String fileName) 366 throws ServerInstanceException { 367 368 try { 369 return FileUtils.getFileContents(fileName); 370 } catch (FileNotFoundException fnfe) { 371 sLogger.log(Level.WARNING, getLogMsg( 372 "getStringForDDxml FileNotFoundException " + fileName)); 373 throw new ServerInstanceException(fnfe.getLocalizedMessage()); 374 } catch (IOException ioe) { 375 sLogger.log(Level.WARNING, getLogMsg( 376 "getStringForDDxml IOException " + fileName)); 377 throw new ServerInstanceException(ioe.getLocalizedMessage()); 378 } 379 } 380 381 385 private String getLogMsg(String str) { 386 return (this.getClass().getName() + ":" + 387 str); 388 } 389 390 } 391 | Popular Tags |