Package org.jibx.binding.classes
Class ClassCache
- java.lang.Object
-
- org.jibx.binding.classes.ClassCache
-
public class ClassCache extends java.lang.Object
Cache for class files being modified. Handles loading and saving of class files. Classes are loaded directly from the file system paths supplied on initialization in preference to the system class path.- Author:
- Dennis M. Sosnoski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClassCache.ClassCacheLocator
Locator using the cache.
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap
m_classMap
Map from class names to actual class information.private java.lang.String[]
m_paths
Paths to be searched for class files.private java.io.File[]
m_roots
Root directories corresponding to paths.private static ClassCache
s_instance
Singleton instance of class (created when paths set)private static java.util.HashSet
s_preserveClasses
Classes to be preserved without modification.
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassCache(java.lang.String[] paths)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static void
addClassFile(ClassFile cf)
Add created class information to cache.static void
addPreserveClass(java.lang.String name)
Add class name to set to be preserved without modification.static ClassFile
getClassFile(java.lang.String name)
Get class information.private ClassFile
getClassFileImpl(java.lang.String name)
Get class information.static java.io.File
getModifiablePath()
Return the first modifiable directory path from the classpath in use.static boolean
hasClassFile(java.lang.String name)
Check if class information has been loaded.static boolean
isPreserveClass(java.lang.String name)
Check if a class is to be preserved without modification.static ClassFile
requireClassFile(java.lang.String name)
Get required class information.static void
setPaths(java.lang.String[] paths)
Set class paths to be searched.
-
-
-
Field Detail
-
s_instance
private static ClassCache s_instance
Singleton instance of class (created when paths set)
-
s_preserveClasses
private static java.util.HashSet s_preserveClasses
Classes to be preserved without modification.
-
m_paths
private java.lang.String[] m_paths
Paths to be searched for class files.
-
m_roots
private java.io.File[] m_roots
Root directories corresponding to paths.
-
m_classMap
private java.util.HashMap m_classMap
Map from class names to actual class information.
-
-
Method Detail
-
getClassFileImpl
private ClassFile getClassFileImpl(java.lang.String name) throws JiBXException
Get class information. Looks up the class in cache, and if not already present tries to find it based on the class file search path list. If the class file is found it is loaded and this method calls itself recursively to load the whole hierarchy of superclasses.- Parameters:
name
- fully-qualified name of class to be found- Returns:
- class information, or
null
if class not found - Throws:
JiBXException
- on any error accessing class file
-
addPreserveClass
public static void addPreserveClass(java.lang.String name)
Add class name to set to be preserved without modification. If the class information has already been loaded, this forces the modifiable setting to unmodifiable.- Parameters:
name
- fully-qualified class name
-
isPreserveClass
public static boolean isPreserveClass(java.lang.String name)
Check if a class is to be preserved without modification.- Parameters:
name
- fully-qualified class name- Returns:
true
if to be preserved,false
if not
-
getClassFile
public static ClassFile getClassFile(java.lang.String name) throws JiBXException
Get class information. Looks up the class in cache, and if not already present tries to find it based on the class file search path list. If the class file is found it is loaded along with all superclasses.- Parameters:
name
- fully-qualified name of class to be found- Returns:
- class information, or
null
if class not found - Throws:
JiBXException
- on any error accessing class file
-
requireClassFile
public static ClassFile requireClassFile(java.lang.String name) throws JiBXException
Get required class information. Looks up the class in cache, and if not already present tries to find it based on the class file search path list. If the class is not found this throws a runtime exception.- Parameters:
name
- fully-qualified name of class to be found- Returns:
- class information, or
null
if class not found - Throws:
JiBXException
- on any error accessing class file
-
hasClassFile
public static boolean hasClassFile(java.lang.String name)
Check if class information has been loaded.- Parameters:
name
- full-qualified name of class to be checked- Returns:
true
if found
-
addClassFile
static void addClassFile(ClassFile cf)
Add created class information to cache.- Parameters:
cf
- information for class to be added
-
getModifiablePath
public static java.io.File getModifiablePath()
Return the first modifiable directory path from the classpath in use.- Returns:
- modifiable directory, or
null
if none
-
setPaths
public static void setPaths(java.lang.String[] paths)
Set class paths to be searched. Discards jar file paths and normalizes all other paths (except the empty path) to end with the system path separator character.- Parameters:
paths
- ordered set of paths to be searched for class files
-
-