org.ckkloverdos.util
Class ClassUtil

java.lang.Object
  extended by org.ckkloverdos.util.ClassUtil

public final class ClassUtil
extends java.lang.Object

Provides utility methods related to class

Author:
Christos KK Loverdos

Method Summary
static java.lang.Class forName(java.lang.String name, java.net.URL[] urls)
          Tries to load the class first by calling loadClass(String) and, if this fails, then by using a URLClassLoader constructed with the provided urls.
static java.lang.ClassLoader getContextClassLoader()
          Returns the context class loader of the current thread.
static java.net.URL getContextResource(java.lang.String name)
          Returns the resource, obtained from the context class loader.
static java.net.URL getFileOrResource(java.lang.String name)
          Retrieves either the file or the context resource with the given name, whichever is found first.
static java.io.InputStream getFileOrResourceAsStream(java.lang.String name)
          Convenience method that calls getFileOrResource(String).
static java.lang.String getShortClassName(java.lang.Class c)
          Returns only the name part after the last dot.
static java.lang.String getShortClassName(java.lang.Object o)
          Returns only the name part after the last dot.
static java.lang.String getShortClassName(java.lang.String name)
          Returns only the name part after the last dot.
static java.lang.String identity(java.lang.Class c)
          Returns a unique name representing this class.
static java.lang.Class loadClass(java.lang.String name)
          Tries to load the class first by using the context class loader and then by calling Class.forName(String).
static java.lang.Class loadClass(java.lang.String name, java.lang.ClassLoader loader)
          Tries to load the class from the provided class loader.
static java.lang.Object newInstance(java.lang.Class c)
           
static java.lang.Object newInstance(java.lang.String className)
           
static java.lang.Object newInstance(java.lang.String className, java.lang.ClassLoader cl)
           
static java.lang.String normalizeClassName(java.lang.Class c)
          If the class is an array, returns its name with [] appended.
static java.lang.String normalizeClassName(java.lang.String name)
          If the class is an array, returns its name with [] appended.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

identity

public static java.lang.String identity(java.lang.Class c)
Returns a unique name representing this class. The class' loader is taken into account.

Parameters:
c -

getContextClassLoader

public static java.lang.ClassLoader getContextClassLoader()
Returns the context class loader of the current thread.


getContextResource

public static java.net.URL getContextResource(java.lang.String name)
Returns the resource, obtained from the context class loader.

Parameters:
name -
Returns:
null if not found.

getFileOrResource

public static java.net.URL getFileOrResource(java.lang.String name)
Retrieves either the file or the context resource with the given name, whichever is found first.

Parameters:
name -
Returns:
null if not found.

getFileOrResourceAsStream

public static java.io.InputStream getFileOrResourceAsStream(java.lang.String name)
                                                     throws java.io.IOException
Convenience method that calls getFileOrResource(String).

Parameters:
name -
Returns:
null if not found.
Throws:
java.io.IOException

loadClass

public static java.lang.Class loadClass(java.lang.String name)
Tries to load the class first by using the context class loader and then by calling Class.forName(String).

Parameters:
name -
Returns:
null if not found.

newInstance

public static java.lang.Object newInstance(java.lang.Class c)

newInstance

public static java.lang.Object newInstance(java.lang.String className)

newInstance

public static java.lang.Object newInstance(java.lang.String className,
                                           java.lang.ClassLoader cl)

loadClass

public static java.lang.Class loadClass(java.lang.String name,
                                        java.lang.ClassLoader loader)
Tries to load the class from the provided class loader. If the loader is null, then loadClass(String) is called.

Parameters:
name -
loader -
Returns:
the class or null if not found.

forName

public static java.lang.Class forName(java.lang.String name,
                                      java.net.URL[] urls)
Tries to load the class first by calling loadClass(String) and, if this fails, then by using a URLClassLoader constructed with the provided urls.

Parameters:
name -
urls -
Returns:
null if not found.

getShortClassName

public static java.lang.String getShortClassName(java.lang.Class c)
Returns only the name part after the last dot.

Parameters:
c -

getShortClassName

public static java.lang.String getShortClassName(java.lang.String name)
Returns only the name part after the last dot.


getShortClassName

public static java.lang.String getShortClassName(java.lang.Object o)
Returns only the name part after the last dot.


normalizeClassName

public static java.lang.String normalizeClassName(java.lang.Class c)
If the class is an array, returns its name with [] appended.

Parameters:
c -

normalizeClassName

public static java.lang.String normalizeClassName(java.lang.String name)
If the class is an array, returns its name with [] appended. Names in the form [I and [Ljava.lang.Integer; can be handled correctly.



Copyright © 1999-2007 Christos KK Loverdos. All Rights Reserved.