public final class ClassUtil extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MAPPINGS
The location of the classmappings.xml document.
|
static java.lang.String |
MAPPINGS_EXTRA
The location of the classmappings-extra.xml document.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
assignable(java.lang.String srcClassName,
java.lang.String parentClassName)
checks if
srcClassName is a subclass of parentClassname. |
static <T> T |
buildInstance(java.lang.Class<T> from)
This method is used to instantiate a given class.
|
static <T> T |
buildInstance(java.lang.Class<T> from,
java.lang.Object... initArgs)
This method is used to instantiate a given class.
|
static <T> T |
buildInstance(java.lang.String className)
This method is used to instantiate a given class.
|
static <T> T |
buildInstance(java.lang.String packageName,
java.lang.String className)
This method is used to instantiate a given class.
|
static java.util.List<java.lang.String> |
classpathEntriesUnder(java.lang.String rootPackage)
Lists all the files in classpath under a given package.
|
static boolean |
exists(java.lang.String className)
Checks if a given class exists in classpath.
|
static <T> java.lang.Class<T> |
findClass(java.util.List<java.lang.String> packages,
java.util.List<java.lang.String> externaljars,
java.lang.String className)
Attempts to find a class from a collection of packages.
|
static <T> java.lang.Class<T> |
findClass(java.lang.String packageName,
java.lang.String className)
It will first attempt to instantiate the class directly from the className, and will then try to prefix it with the packageName.
|
static java.util.Map<java.lang.String,java.lang.String> |
getExtraClassMappings() |
static java.lang.Class<?> |
getMappedClass(java.lang.String requestedClass)
Finds a mapped class from the c_classMappings list.
|
static <T> T |
getMappedObject(java.lang.String requestedClass)
This method is used to locate and instantiate a mapped class.
|
static <T> T |
getMappedObject(java.lang.String requestedClass,
java.lang.Object... initargs)
This method is used to locate and instantiate a mapped class.
|
public static final java.lang.String MAPPINGS
public static final java.lang.String MAPPINGS_EXTRA
public static <T> java.lang.Class<T> findClass(java.util.List<java.lang.String> packages, java.util.List<java.lang.String> externaljars, java.lang.String className) throws java.lang.ClassNotFoundException
packages - A List of Strings, containing different package names.className - The name of the class to find.java.lang.ClassNotFoundException - if this particular class cannot be found from the list.public static <T> java.lang.Class<T> findClass(java.lang.String packageName, java.lang.String className) throws java.lang.ClassNotFoundException
packageName - A package name (such as "org.apache.wiki.plugins").className - The class name to find.java.lang.ClassNotFoundException - if this particular class cannot be found.public static java.util.List<java.lang.String> classpathEntriesUnder(java.lang.String rootPackage)
rootPackage - the base package. Can be {code null}.public static <T> T getMappedObject(java.lang.String requestedClass) throws java.lang.ReflectiveOperationException, java.lang.IllegalArgumentException
ClassUtil.MAPPINGS ("ini/classmappings.xml").
This is an extremely powerful system, which allows you to remap many of
the JSPWiki core classes to your own class. Please read the documentation
included in the default "ini/classmappings.xml" file to see
how this method works.
requestedClass - The name of the class you wish to instantiate.java.lang.IllegalArgumentException - If the class cannot be found or instantiated.java.lang.ReflectiveOperationException - If the class cannot be found or instantiated.public static <T> T getMappedObject(java.lang.String requestedClass, java.lang.Object... initargs) throws java.lang.ReflectiveOperationException, java.lang.IllegalArgumentException
"ini/classmappings.xml".
This is an extremely powerful system, which allows you to remap many of
the JSPWiki core classes to your own class. Please read the documentation
included in the default "ini/classmappings.xml" file to see
how this method works.
This method takes in an object array for the constructor arguments for classes which have more than two constructors.
requestedClass - The name of the class you wish to instantiate.initargs - The parameters to be passed to the constructor. May be null.java.lang.IllegalArgumentException - If the class cannot be found or instantiated.java.lang.ReflectiveOperationException - If the class cannot be found or instantiated.public static java.lang.Class<?> getMappedClass(java.lang.String requestedClass) throws java.lang.ClassNotFoundException
requestedClass - requested class.java.lang.ClassNotFoundException - if the class is not found.public static boolean assignable(java.lang.String srcClassName, java.lang.String parentClassName)
srcClassName is a subclass of parentClassname.srcClassName - expected subclass.parentClassName - expected parent class.true if srcClassName is a subclass of parentClassname, false otherwise.public static boolean exists(java.lang.String className)
className - the class to check for existence.true if it exists, false otherwise.public static java.util.Map<java.lang.String,java.lang.String> getExtraClassMappings()
public static <T> T buildInstance(java.lang.String className) throws java.lang.ReflectiveOperationException
className - The name of the class you wish to instantiate.java.lang.ReflectiveOperationException - If the class cannot be found or instantiated.public static <T> T buildInstance(java.lang.String packageName, java.lang.String className) throws java.lang.ReflectiveOperationException
* It will first attempt to instantiate the class directly from the className, and will then try to prefix it with the packageName.
packageName - A package name (such as "org.apache.wiki.plugins").className - The class name to find.java.lang.ReflectiveOperationException - If the class cannot be found or instantiated.public static <T> T buildInstance(java.lang.Class<T> from) throws java.lang.ReflectiveOperationException
from - The name of the class you wish to instantiate.java.lang.ReflectiveOperationException - If the class cannot be found or instantiated.public static <T> T buildInstance(java.lang.Class<T> from, java.lang.Object... initArgs) throws java.lang.ReflectiveOperationException
This method takes in an object array for the constructor arguments for classes which have more than two constructors.
from - The name of the class you wish to instantiate.initArgs - The parameters to be passed to the constructor. May be null.java.lang.ReflectiveOperationException - If the class cannot be found or instantiated.Copyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.