org.apache.wiki.util
Class ClassUtil

java.lang.Object
  extended by org.apache.wiki.util.ClassUtil

public final class ClassUtil
extends Object

Contains useful utilities for class file manipulation. This is a static class, so there is no need to instantiate it.

Since:
2.1.29.

Field Summary
static String MAPPINGS
          The location of the classmappings.xml document.
 
Method Summary
static List<String> classpathEntriesUnder(String rootPackage)
          Lists all the files in classpath under a given package.
static Class<?> findClass(List<String> packages, List<String> externaljars, String className)
          Attempts to find a class from a collection of packages.
static Class<?> findClass(String packageName, 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 Object getMappedObject(String requestedClass)
          This method is used to locate and instantiate a mapped class.
static Object getMappedObject(String requestedClass, Object... initargs)
          This method is used to locate and instantiate a mapped class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAPPINGS

public static final String MAPPINGS
The location of the classmappings.xml document. It will be searched for in the classpath. It's value is ""ini/classmappings.xml"".

See Also:
Constant Field Values
Method Detail

findClass

public static Class<?> findClass(List<String> packages,
                                 List<String> externaljars,
                                 String className)
                          throws ClassNotFoundException
Attempts to find a class from a collection of packages. This will first attempt to find the class based on just the className parameter, but should that fail, will iterate through the "packages" -list, prefixes the package name to the className, and then tries to find the class again.

Parameters:
packages - A List of Strings, containing different package names.
className - The name of the class to find.
Returns:
The class, if it was found.
Throws:
ClassNotFoundException - if this particular class cannot be found from the list.

findClass

public static Class<?> findClass(String packageName,
                                 String className)
                          throws ClassNotFoundException
It will first attempt to instantiate the class directly from the className, and will then try to prefix it with the packageName.

Parameters:
packageName - A package name (such as "org.apache.wiki.plugins").
className - The class name to find.
Returns:
The class, if it was found.
Throws:
ClassNotFoundException - if this particular class cannot be found.

classpathEntriesUnder

public static List<String> classpathEntriesUnder(String rootPackage)
Lists all the files in classpath under a given package.

Parameters:
rootPackage - the base package. Can be {code null}.
Returns:
all files entries in classpath under the given package

getMappedObject

public static Object getMappedObject(String requestedClass)
                              throws WikiException
This method is used to locate and instantiate a mapped class. You may redefine anything in the resource file which is located in your classpath under the name 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.

Parameters:
requestedClass - The name of the class you wish to instantiate.
Returns:
An instantiated Object.
Throws:
WikiException - If the class cannot be found or instantiated.
Since:
2.5.40

getMappedObject

public static Object getMappedObject(String requestedClass,
                                     Object... initargs)
                              throws WikiException
This method is used to locate and instantiate a mapped class. You may redefine anything in the resource file which is located in your classpath under the name "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.

Parameters:
requestedClass - The name of the class you wish to instantiate.
initargs - The parameters to be passed to the constructor. May be null.
Returns:
An instantiated Object.
Throws:
WikiException - If the class cannot be found or instantiated. The error is logged.
Since:
2.5.40


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.