All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.portal.kernel.util.ClassLoaderPool Maven / Gradle / Ivy

Go to download

Contains interfaces for the portal services. Interfaces are only loaded by the global class loader and are shared by all plugins.

There is a newer version: 156.0.0
Show newest version
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.portal.kernel.util;

import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Maps servlet context names to/from the servlet context's class loader.
 *
 * @author Shuyang Zhou
 */
public class ClassLoaderPool {

	/**
	 * Returns the class loader associated with the context name.
	 *
	 * 

* If no class loader is found for the context name, the thread's context * class loader is returned as a fallback. *

* * @param contextName the servlet context's name * @return the class loader associated with the context name */ public static ClassLoader getClassLoader(String contextName) { PortalRuntimePermission.checkGetBeanProperty(ClassLoaderPool.class); ClassLoader classLoader = null; if ((contextName != null) && !contextName.equals(StringPool.NULL)) { classLoader = _classLoaders.get(contextName); } if (classLoader == null) { Thread currentThread = Thread.currentThread(); classLoader = currentThread.getContextClassLoader(); } return classLoader; } /** * Returns the context name associated with the class loader. * *

* If the class loader is null or if no context name is * associated with the class loader, {@link * com.liferay.portal.kernel.util.StringPool#NULL} is returned. *

* * @param classLoader the class loader * @return the context name associated with the class loader */ public static String getContextName(ClassLoader classLoader) { if (classLoader == null) { return StringPool.NULL; } String contextName = _contextNames.get(classLoader); if (contextName == null) { contextName = StringPool.NULL; } return contextName; } public static void register(String contextName, ClassLoader classLoader) { PortalRuntimePermission.checkGetBeanProperty(ClassLoaderPool.class); _classLoaders.put(contextName, classLoader); _contextNames.put(classLoader, contextName); } public static void unregister(ClassLoader classLoader) { PortalRuntimePermission.checkGetBeanProperty(ClassLoaderPool.class); String contextName = _contextNames.remove(classLoader); if (contextName != null) { _classLoaders.remove(contextName); } } public static void unregister(String contextName) { PortalRuntimePermission.checkGetBeanProperty(ClassLoaderPool.class); ClassLoader classLoader = _classLoaders.remove(contextName); if (classLoader != null) { _contextNames.remove(classLoader); } } private static final Map _classLoaders = new ConcurrentHashMap<>(); private static final Map _contextNames = new ConcurrentHashMap<>(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy