1 23 24 28 package com.sun.enterprise.deployment.backend; 29 30 import com.sun.enterprise.config.ConfigException; 31 import com.sun.enterprise.deployment.Application; 32 import com.sun.enterprise.deployment.BundleDescriptor; 33 import com.sun.enterprise.deployment.archivist.ArchivistFactory; 34 import com.sun.enterprise.deployment.archivist.AppClientArchivist; 35 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 36 import com.sun.enterprise.deployment.archivist.Archivist; 37 import com.sun.enterprise.deployment.archivist.ConnectorArchivist; 38 import com.sun.enterprise.deployment.archivist.EjbArchivist; 39 import com.sun.enterprise.deployment.archivist.WebArchivist; 40 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 41 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 42 import com.sun.enterprise.instance.AppclientModulesManager; 43 import com.sun.enterprise.instance.AppsManager; 44 import com.sun.enterprise.instance.BaseManager; 45 import com.sun.enterprise.instance.ConnectorModulesManager; 46 import com.sun.enterprise.instance.EjbModulesManager; 47 import com.sun.enterprise.instance.InstanceEnvironment; 48 import com.sun.enterprise.instance.WebModulesManager; 49 import com.sun.enterprise.loader.ClassLoaderUtils; 50 import com.sun.enterprise.loader.EJBClassLoader; 51 import com.sun.enterprise.server.Constants; 52 import com.sun.enterprise.util.io.FileUtils; 53 54 import java.io.File ; 55 import java.io.IOException ; 56 import java.util.logging.Level ; 57 import java.util.logging.Logger ; 58 import java.util.*; 59 60 66 public class DeploymentUtils { 67 68 private static Logger _logger = DeploymentLogger.get(); 69 70 80 static void setParentClassLoader(ClassLoader bootStrap, BaseManager baseMgr, 81 DeploymentRequest req) throws ConfigException, IOException { 82 83 List allClassPaths = new ArrayList(); 84 85 List systemClasspath = baseMgr.getSystemCPathPrefixNSuffix(); 87 if (systemClasspath.size() > 0) { 88 allClassPaths.addAll(systemClasspath); 89 } 90 91 List commonClassPath = getCommonClasspath(baseMgr); 93 if (commonClassPath.size() > 0) { 94 allClassPaths.addAll(commonClassPath); 95 } 96 97 boolean resolveConnectorClassPath = false; 109 String target = null; 110 if (req.isVerifying()) { resolveConnectorClassPath = true; 112 String targetString = req.getResourceTargetList(); 113 target = (new java.util.StringTokenizer (targetString)).nextToken(); 116 } 117 118 List sharedClassPath = 119 baseMgr.getSharedClasspath(resolveConnectorClassPath, target); 120 if (sharedClassPath.size() > 0) { 121 allClassPaths.addAll(sharedClassPath); 122 } 123 124 ClassLoader parentClassLoader = 125 getClassLoader(allClassPaths, bootStrap, null); 126 127 req.setParentClassLoader(parentClassLoader); 129 130 req.setParentClasspath(allClassPaths); 132 } 133 134 145 static EJBClassLoader getClassLoader(List paths, ClassLoader parent, 146 File other) throws IOException { 147 148 EJBClassLoader ejbCl = null; 149 150 if (parent != null) { 151 ejbCl = new EJBClassLoader(parent); 152 } else { 153 ejbCl = new EJBClassLoader(); 154 } 155 156 final int LIST_SZ = paths.size(); 157 for (int i=0; i<LIST_SZ; i++) { 158 String path = (String ) paths.get(i); 159 ejbCl.appendURL(new File (path)); 160 } 161 162 if (other != null) { 163 ejbCl.appendURL(other); 164 } 165 166 return ejbCl; 167 } 168 169 175 static List getCommonClasspath(BaseManager mgr) throws IOException { 176 177 InstanceEnvironment env = mgr.getInstanceEnvironment(); 178 String dir = env.getLibClassesPath(); 179 String jarDir = env.getLibPath(); 180 181 return ClassLoaderUtils.getUrlList(new File [] {new File (dir)}, 182 new File [] {new File (jarDir)}); 183 } 184 185 protected static String getSystemPropertyIgnoreCase(final String key) 186 { 187 Properties p = System.getProperties(); 188 Set set = p.entrySet(); 189 190 for(Iterator it = set.iterator(); it.hasNext(); ) 191 { 192 Map.Entry me = (Map.Entry)it.next(); 193 String propKey = (String )me.getKey(); 194 195 if(key.compareToIgnoreCase(propKey) == 0) 196 return (String )me.getValue(); 197 } 198 199 return null; 200 } 201 202 218 static Application getAppDescriptor(String appDir) throws IASDeploymentException 219 { 220 return getAppDescriptor(appDir, false); 221 } 222 223 238 static Application getAppDescriptor(String appDir, boolean annotationProcessing) 239 throws IASDeploymentException 240 { 241 try { 242 FileArchive archive = new FileArchive(); 243 archive.open(appDir); 244 245 ApplicationArchivist archivist = new ApplicationArchivist(); 246 archivist.setAnnotationProcessingRequested(annotationProcessing); 247 archivist.setXMLValidation(false); 248 249 return (Application) archivist.open(archive); 250 } catch(Throwable t) { 251 throw new IASDeploymentException(t); 252 } 253 } 254 255 259 static Application getModuleDescriptor(String appDir) throws IASDeploymentException 260 { 261 return getModuleDescriptor(appDir, false); 262 } 263 264 static Application getModuleDescriptor(String appDir, boolean annotationProcessing) 265 throws IASDeploymentException 266 { 267 try { 268 FileArchive archive = new FileArchive(); 269 archive.open(appDir); 270 271 Archivist archivist = 272 ArchivistFactory.getArchivistForArchive(archive); 273 274 archivist.setAnnotationProcessingRequested(annotationProcessing); 275 archivist.setXMLValidation(false); 276 277 return (Application) ApplicationArchivist.openArchive(archivist, archive, true); 278 } catch(Throwable t) { 279 throw new IASDeploymentException(t); 280 } 281 } 282 283 298 public static RootDeploymentDescriptor getDescriptor( 299 String appId, BaseManager manager) throws IASDeploymentException { 300 Application application = manager.getRegisteredDescriptor(appId); 301 if (application != null) { 302 if (application.isVirtual()) { 303 return application.getStandaloneBundleDescriptor(); 304 } else { 305 return application; 306 } 307 } 308 309 FileArchive in = new FileArchive(); 311 try { 312 String appDir = manager.getLocation(appId); 313 if (manager.isSystemAdmin(appId)) { 318 in.open(appDir); 319 } else { 320 String xmlDir = manager.getGeneratedXMLLocation(appId); 321 if (FileUtils.safeIsDirectory(xmlDir)) { 322 in.open(xmlDir); 323 } else { 324 _logger.log(Level.WARNING, 326 "enterprise.deployment.backend.no_generated_xmldir", 327 new Object []{appId, xmlDir, appDir}); 328 in.open(appDir); 329 } 330 } 331 332 Archivist archivist = null; 333 if (manager instanceof AppsManager) { 334 archivist = new ApplicationArchivist(); 335 } else if (manager instanceof EjbModulesManager) { 336 archivist = new EjbArchivist(); 337 } else if (manager instanceof WebModulesManager) { 338 archivist = new WebArchivist(); 339 } else if (manager instanceof AppclientModulesManager) { 340 archivist = new AppClientArchivist(); 341 } else if (manager instanceof ConnectorModulesManager) { 342 archivist = new ConnectorArchivist(); 343 } 344 345 archivist.setAnnotationProcessingRequested(false); 346 archivist.setXMLValidation(false); 347 Application desc = ApplicationArchivist.openArchive( 348 appId, archivist, in, true); 349 350 if (!desc.isVirtual()) { 353 archivist.setHandleRuntimeInfo(false); 354 ((ApplicationArchivist) 355 archivist).readModulesDescriptors(desc, in); 356 archivist.setHandleRuntimeInfo(true); 358 archivist.readRuntimeDeploymentDescriptor(in, desc); 359 } else { 360 return (BundleDescriptor) 361 desc.getBundleDescriptors().iterator().next(); 362 } 363 return desc; 364 } catch (Exception ex) { 365 _logger.log(Level.SEVERE, 366 "enterprise.deployment.backend.get_descriptor_failed", 367 new Object []{appId}); 368 IASDeploymentException de = new IASDeploymentException(ex.getMessage()); 369 de.initCause(ex); 370 throw de; 371 } finally { 372 try { 373 in.close(); 374 } catch (Exception ex) {} 375 } 376 } 377 } 378 | Popular Tags |