org.apache.openjpa.lib.util
Class JavaVersions

java.lang.Object
  extended by org.apache.openjpa.lib.util.JavaVersions

public class JavaVersions
extends Object

Utilities for dealing with different Java spec versions.

Author:
Abe White

Field Summary
static int VERSION
          Java version; one of 2, 3, 4, 5, 6, or 7.
 
Constructor Summary
JavaVersions()
           
 
Method Summary
static Throwable getCause(Throwable ex)
          Return the cause of the given throwable.
static Class[] getParameterizedTypes(Field f)
          Collects the parameterized type declarations for a given field.
static Class[] getParameterizedTypes(Method meth)
          Collects the parameterized return type declarations for a given method.
static Class getVersionSpecificClass(Class base)
          Returns a version-specific instance of the specified class
static Class getVersionSpecificClass(String base)
          Obtains a subclass of the specific base class that is specific to the current version of Java in use.
static Throwable initCause(Throwable ex, Throwable cause)
          Set the cause of the given throwable.
static boolean isAnnotation(Class cls)
          Return true if the given type is an annotation.
static boolean isEnumeration(Class cls)
          Return true if the given type is an enumeration.
static void main(String[] args)
           
static boolean transferStackTrace(Throwable from, Throwable to)
          Transfer the stack from one throwable to another, or return false if it cannot be done, possibly due to an unsupported Java version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final int VERSION
Java version; one of 2, 3, 4, 5, 6, or 7.

Constructor Detail

JavaVersions

public JavaVersions()
Method Detail

getVersionSpecificClass

public static Class getVersionSpecificClass(Class base)
Returns a version-specific instance of the specified class

Parameters:
base - the base class to check
Returns:
the JDK-version-specific version of the class
See Also:
getVersionSpecificClass(String)

getVersionSpecificClass

public static Class getVersionSpecificClass(String base)
                                     throws ClassNotFoundException
Obtains a subclass of the specific base class that is specific to the current version of Java in use. The heuristic for the class name to load will be that OpenJPA first checks for the name of the class with the current setting of the VERSION field, then each number in decreasing order, until ending in the unqualified name. For example, if we are using JDK 1.5.1, and we want to load "org.apache.openjpa.lib.SomeClass", we will try to load the following classes in order and return the first one that is successfully found and loaded:
  1. org.apache.openjpa.lib.SomeClass5
  2. org.apache.openjpa.lib.SomeClass4
  3. org.apache.openjpa.lib.SomeClass3
  4. org.apache.openjpa.lib.SomeClass2
  5. org.apache.openjpa.lib.SomeClass1
  6. org.apache.openjpa.lib.SomeClass

Parameters:
base - the base name of the class to load
Returns:
the subclass appropriate for the current Java version
Throws:
ClassNotFoundException

isAnnotation

public static boolean isAnnotation(Class cls)
Return true if the given type is an annotation.


isEnumeration

public static boolean isEnumeration(Class cls)
Return true if the given type is an enumeration.


getParameterizedTypes

public static Class[] getParameterizedTypes(Field f)
Collects the parameterized type declarations for a given field.


getParameterizedTypes

public static Class[] getParameterizedTypes(Method meth)
Collects the parameterized return type declarations for a given method.


transferStackTrace

public static boolean transferStackTrace(Throwable from,
                                         Throwable to)
Transfer the stack from one throwable to another, or return false if it cannot be done, possibly due to an unsupported Java version.


getCause

public static Throwable getCause(Throwable ex)
Return the cause of the given throwable.


initCause

public static Throwable initCause(Throwable ex,
                                  Throwable cause)
Set the cause of the given throwable.


main

public static void main(String[] args)


Copyright © 2006-2007 Apache Software Foundation. All Rights Reserved.