foundry-0.9.1

foundry.classutils
Class ClassUtilities

java.lang.Object
  |
  +--foundry.classutils.ClassUtilities

public final class ClassUtilities
extends Object

A collection of methods useful for Classes.

Version:
$Revision: 1.4 $
Author:
Laird Nelson

Constructor Summary
private ClassUtilities()
          Constructs a new ClassUtilities object.
 
Method Summary
static Set getAllFields(Class c)
          Returns all Fields in the supplied Class and all of its superclasses.
static Set getAllFields(Class c, Class stop)
          Returns all Fields in the supplied Class and all of its superclasses, up to but not including the superclass identified by the stop parameter.
static Set getAllFieldsWithReturnType(Class c, Class type, Class stop, boolean excludeStatics)
          Returns all Fields in the supplied Class (and all of its superclasses up to but not including the superclass identified by the stop parameter) that are of the supplied data type.
static URL getClasspathLocation(Class c)
          Returns the classpath URL from which the supplied Class was loaded.
private static URL getOfficialClasspathLocation(Class c)
          Returns the classpath URL from which the supplied Class was loaded, as computed using ProtectionDomains and CodeSources.
static void main(String[] args)
          Convenience method; allows use of the ClassUtilities class as a program.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

ClassUtilities

private ClassUtilities()
Constructs a new ClassUtilities object. Since all publicly accessible methods in this class are static, this method should never be called.
Method Detail

getOfficialClasspathLocation

private static final URL getOfficialClasspathLocation(Class c)
Returns the classpath URL from which the supplied Class was loaded, as computed using ProtectionDomains and CodeSources.
Parameters:
c - the Class whose classpath location is to be computed
Returns:
the classpath location, or null if the official classpath location could not be computed

getClasspathLocation

public static final URL getClasspathLocation(Class c)
Returns the classpath URL from which the supplied Class was loaded.
Parameters:
c - the Class whose classpath location is to be computed
Returns:
the classpath location, or null if the classpath location could not be determined

getAllFields

public static final Set getAllFields(Class c)
                              throws SecurityException
Returns all Fields in the supplied Class and all of its superclasses.
Parameters:
c - the Class whose Fields should be returned; must not be null
Returns:
a Set consisting of Field objects in an indeterminate order
Throws:
SecurityException - if the current SecurityManager determines that reflection is not allowed
See Also:
Class.getFields(), Class.getDeclaredFields()

getAllFields

public static final Set getAllFields(Class c,
                                     Class stop)
                              throws SecurityException
Returns all Fields in the supplied Class and all of its superclasses, up to but not including the superclass identified by the stop parameter.
Parameters:
c - the Class whose Fields should be returned; must not be null
stop - the superclass whose Fields (and whose ancestors' Fields) should not be included in the return value; if null then the entire superclass chain will be examined
Returns:
a Set consisting of Field objects in an indeterminate order
Throws:
SecurityException - if the current SecurityManager determines that reflection is not allowed
See Also:
Class.getFields(), Class.getDeclaredFields()

getAllFieldsWithReturnType

public static final Set getAllFieldsWithReturnType(Class c,
                                                   Class type,
                                                   Class stop,
                                                   boolean excludeStatics)
                                            throws SecurityException
Returns all Fields in the supplied Class (and all of its superclasses up to but not including the superclass identified by the stop parameter) that are of the supplied data type. Static fields can be excluded from the result.
Parameters:
c - the Class whose Fields should be returned; must not be null
type - the Class of the data type that the data type of all Fields to be returned must be instances of; if null then no data type filtering will be performed
stop - the superclass whose Fields (and whose ancestors' Fields) should not be included in the return value; if null then the entire superclass chain will be examined
excludeStatics - exclude static Fields from the result if true
Returns:
a Set consisting of Field objects in an indeterminate order
Throws:
SecurityException - if the current SecurityManager determines that reflection is not allowed
See Also:
Class.getFields(), Class.getDeclaredFields()

main

public static final void main(String[] args)
                       throws Exception
Convenience method; allows use of the ClassUtilities class as a program. For each class name supplied as an argument, prints the classpath location from which that class was loaded.
Parameters:
args - the command line arguments
Throws:
Exception - if an error was encountered

foundry-0.9.1

Copyright © 2000 - Laird Jarrett Nelson