Package com.axelor.common
Class ClassUtils
java.lang.Object
com.axelor.common.ClassUtils
Provides class utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
classToResourceName
(Class<?> klass) Get the resource path of the given class.static String
classToResourceName
(String klass) Convert the class name to '/' based resource path.static ClassLoader
Returns the context ClassLoader for this Thread.static ClassLoader
Returns the default ClassLoader.static <T> Class
<? super T> getRealClass
(Class<T> proxyClass) Get the real class of the given proxy class.static URL
getResource
(String location) Finds the resource from the class path with the given location using default ClassLoader.static URL
Resolve the given resource location to aURL
.static boolean
Check whether the given object is a CGLIB or ByteBuddy proxy.static boolean
isProxyClass
(Class<?> clazz) Check whether the given class is a CGLIB or ByteBuddy proxy class, assuming no custom proxy class naming is used.static boolean
isProxyClassName
(String className) Check whether the given class name is a CGLIB or ByteBuddy proxy class name, assuming no custom class naming is used.static String
resourceToClassName
(String resource) Convert the '/' based resource path to '.' based class name.static ClassLoader
setContextClassLoader
(ClassLoader classLoader) Override the context ClassLoader of this Thread.
-
Method Details
-
getContextClassLoader
Returns the context ClassLoader for this Thread.- Returns:
- the context ClassLoader for this Thread, or null indicating the system class loader.
- See Also:
-
setContextClassLoader
Override the context ClassLoader of this Thread.- Parameters:
classLoader
- the ClassLoader to override.- Returns:
- the previous context ClassLoader, or null if ClassLoader is not overriden.
-
getDefaultClassLoader
Returns the default ClassLoader.Generally, it is current Thread context ClassLoader. If not available, it will be the ClassLoader that loaded the
ClassUtils
.- Returns:
- the default ClassLoader, or null if system ClassLoader is not accessible.
-
resourceToClassName
Convert the '/' based resource path to '.' based class name.- Parameters:
resource
- the resource path- Returns:
- the corresponding fully qualified class name
-
classToResourceName
Convert the class name to '/' based resource path.- Parameters:
klass
- the fully qualified class name- Returns:
- the corresponding resource path
-
classToResourceName
Get the resource path of the given class.- Parameters:
klass
- the class- Returns:
- the corresponding resource path
-
isProxy
Check whether the given object is a CGLIB or ByteBuddy proxy.- Parameters:
object
- the object to check- Returns:
- true if object is proxy
-
isProxyClass
Check whether the given class is a CGLIB or ByteBuddy proxy class, assuming no custom proxy class naming is used.- Parameters:
clazz
- the class to check- Returns:
- true of given class is a proxy class
-
isProxyClassName
Check whether the given class name is a CGLIB or ByteBuddy proxy class name, assuming no custom class naming is used.- Parameters:
className
- the class name to check- Returns:
- true if class name is proxy class name
-
getRealClass
Get the real class of the given proxy class.- Parameters:
proxyClass
- the proxy class whose first real super class is required.- Returns:
- the real super class of the given proxy class, or itself if it's not a proxy class
-
getURL
Resolve the given resource location to aURL
.- Parameters:
location
- the resource location to resolve, either a pseudo 'classpath:' url, a 'file:' url or plain resource location.- Returns:
- a corresponding
URL
object - Throws:
FileNotFoundException
- if location can't be resolved.
-
getResource
Finds the resource from the class path with the given location using default ClassLoader.- Parameters:
location
- The resource location- Returns:
- an
URL
for reading the resource or null - See Also:
-