FileDocCategorySizeDatePackage
ASClassLoaderUtil.javaAPI DocGlassfish v2 API10504Mon Jul 30 07:52:18 BST 2007com.sun.appserv.server.util

ASClassLoaderUtil

public class ASClassLoaderUtil extends Object

Fields Summary
private static final Logger
_logger
private static String
sharedClasspathForWebModule
Constructors Summary
Methods Summary
private static com.sun.enterprise.config.serverbeans.ApplicationsgetApplications()

        ConfigContext serverConfigCtx =  ApplicationServer.getServerContext().getConfigContext();
        Domain domain = ((Domain)serverConfigCtx.getRootConfigBean());
        return domain.getApplications();
    
public static java.net.URL[]getLibraries(java.lang.String librariesStr)
Utility method to obtain a resolved list of URLs representing the libraries specified for an application using the libraries application deploy-time attribute

param
librariesStr The deploy-time libraries attribute as specified by the deployer for an application
return
A list of URLs representing the libraries specified for the application

        if(librariesStr == null)
            return null;
        
        String [] librariesStrArray = librariesStr.split(",");
        if(librariesStrArray == null)
            return null;
        
        final URL [] urls = new URL[librariesStrArray.length];
        //Using the string from lib and applibs requires admin which is 
        //built after appserv-core.
        final String appLibsDir = System.getProperty(
                        SystemPropertyConstants.INSTANCE_ROOT_PROPERTY) 
                        + File.separator + "lib" 
                        + File.separator  + "applibs";
        
        int i=0;
        for(final String libraryStr:librariesStrArray){
            try {
                File f = new File(libraryStr);
                if(!f.isAbsolute())
                    f = new File(appLibsDir, libraryStr);
                URL url = f.toURL();
                urls[i++] = url;
            } catch (MalformedURLException malEx) {
                _logger.log(Level.WARNING,
                        "loader.cannot_convert_classpath_into_url",
                        libraryStr);
                _logger.log(Level.WARNING,"loader.exception", malEx);
            }
        }
        return urls;
    
public static java.lang.StringgetLibrariesForEJBJars(java.lang.String moduleId)
Gets the deploy-time "libraries" attribute specified for an EJB module [EJB Jars]

param
moduleId The module id of the EJB module
return
A comma separated list representing the libraries specified by the deployer.

        EjbModule app = null;
        try {
            app = getApplications().getEjbModuleByName(moduleId);
            if(app == null) return null;
        } catch(ConfigException malEx) {
            _logger.log(Level.WARNING, "loader.cannot_convert_classpath_into_url",
                                                                                           moduleId);
            _logger.log(Level.WARNING,"loader.exception", malEx);            
        }
        return app.getLibraries();
    
public static java.lang.StringgetLibrariesForJ2EEApplication(java.lang.String moduleId)
Gets the deploy-time "libraries" attribute specified for a J2EE application (.ear file)

param
moduleId The module id of the J2EE application
return
A comma separated list representing the libraries specified by the deployer.

        J2eeApplication app = null;
        try {
            app = getApplications().getJ2eeApplicationByName(moduleId);
            if(app == null) return null;
        } catch(ConfigException malEx) {
            _logger.log(Level.WARNING, "loader.cannot_convert_classpath_into_url",
                                                                                           moduleId);
            _logger.log(Level.WARNING,"loader.exception", malEx);            
        }
        return app.getLibraries();
    
public static java.lang.StringgetLibrariesForWebModule(java.lang.String moduleId)
Gets the deploy-time "libraries" attribute specified for a web module (.war file)

param
moduleId The module id of the web module
return
A comma separated list representing the libraries specified by the deployer.

        WebModule app = null;
        try {
            app = getApplications().getWebModuleByName(moduleId);
            if(app == null) return null;
        } catch(ConfigException malEx) {
            _logger.log(Level.WARNING, "loader.cannot_convert_classpath_into_url",
                                                                                           moduleId);
            _logger.log(Level.WARNING,"loader.exception", malEx);            
        }

        String librariesStr  = app.getLibraries();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "app = " +  app + " library = " + librariesStr);
        }
        return librariesStr;
    
public static synchronized java.lang.ClassLoadergetSharedClassLoader()
Returns the shared class loader

return
ClassLoader

        return ApplicationServer.getServerContext().getSharedClassLoader();
    
public static java.lang.StringgetWebModuleClassPath(java.lang.String moduleId)
Gets the classpath associated with a web module, suffixing libraries defined [if any] for the application

param
moduleId Module id of the web module
return
A File.pathSeparator separated list of classpaths for the passed in web module, including the module specified "libraries" defined for the web module.

    
                                                         
         
            if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "ASClassLoaderUtil.getWebModuleClassPath " +
            		"for module Id : " + moduleId);
            }

        synchronized(ASClassLoaderUtil.class) {
            if (sharedClasspathForWebModule == null) {
            	final StringBuilder tmpString = new StringBuilder();
            if (Boolean.getBoolean(PELaunch.USE_NEW_CLASSLOADER_PROPERTY)) {
    	        	final List<String> tmpList = new ArrayList<String>();
    	            tmpList.addAll(PELaunch.getSharedClasspath());
                //include addon jars as well now that they are not part of shared classpath. 
    	            tmpList.addAll(PELaunch.getAddOnsClasspath());
                
    	            for(final String s:tmpList){
    	                tmpString.append(s);
    	                tmpString.append(File.pathSeparatorChar);
                }
            } else {
    	            tmpString.append(System.getProperty("java.class.path"));
    	        }
    	        //set sharedClasspathForWebModule so that it doesn't need to be recomputed
    	        //for every other invocation
    	        sharedClasspathForWebModule = tmpString.toString();
            }
            }

        StringBuilder classpath = new StringBuilder(sharedClasspathForWebModule);
            
            if (moduleId != null) {
            final String specifiedLibraries = getLibrariesForWebModule(moduleId);
            final URL[] libs = getLibraries(specifiedLibraries);
                if (libs == null)  {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "classpath: " + classpath.toString());
                    }
                    return classpath.toString();
                }
  
                for (final URL u : libs) {
                    classpath.append(u + File.pathSeparator);
                }
            }

            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Final classpath: " + classpath.toString());    
            }
        
            return classpath.toString();