Class X4OLanguageClassLoader
java.lang.Object
org.x4o.xml.lang.X4OLanguageClassLoader
X4OLanguageClassLoader is short hand for safe class loading.
- Version:
- 1.0 6 Aug 2012
- Author:
- Willem Cazander
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassLoaderGets the thread classloader or the normal classloader.static URLgetResource(String resourceName) Gets a resource from the classloader to an url.static InputStreamgetResourceAsStream(String resourceName) Gets a resource from the classloader to an inputstream.static Class<?> Loads a Class from the ContextClassLoader and if that is not set, then uses the class of the String className instance.static ObjectnewInstance(Class<?> clazz) Creates new instance of clazz.static ObjectnewInstance(String className) Creates new instance of className.
-
Method Details
-
getClassLoader
Gets the thread classloader or the normal classloader.- Returns:
- Returns the ClassLoader.
-
loadClass
Loads a Class from the ContextClassLoader and if that is not set, then uses the class of the String className instance.- Parameters:
className- The class name to load- Returns:
- The loaded class
- Throws:
ClassNotFoundException- if class not loaded.
-
newInstance
public static Object newInstance(Class<?> clazz) throws InstantiationException, IllegalAccessException Creates new instance of clazz.- Parameters:
clazz- The class to make object from.- Returns:
- The object of the clazz.
- Throws:
InstantiationException- When className has no default constructor.IllegalAccessException- When class loading has security error.
-
newInstance
public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException Creates new instance of className.- Parameters:
className- The className to create object from.- Returns:
- The object of the className.
- Throws:
ClassNotFoundException- When className is not found.InstantiationException- When className has no default constructor.IllegalAccessException- When class loading has security error.
-
getResource
-
getResourceAsStream
Gets a resource from the classloader to an inputstream.- Parameters:
resourceName- The resource to get from the classloader.- Returns:
- The inputstream to the resource or null if not found.
- See Also:
-