Package org.jibx.binding
Class Loader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.jibx.binding.Loader
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
Loader.NondelegatingLoader
Binding classloader. This is intended to substitute for the System
classloader (i.e., the one used for loading user classes). It first processes
one or more binding definitions, caching the binary classes modified by the
bindings. It then uses these modified forms of the classes when they're
requested for loading.
- Author:
- Dennis M. Sosnoski
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Version of bind-on-demand loader which will not delegate handling of classes included in the binding definition. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Class
Find and load class by name.static URL[]
Method builds an array of URL for items in the class path.protected boolean
isBoundClass
(String name) Check if a class has been modified by a binding.void
loadBinding
(String fname, String sname, InputStream is, URL url) Load binding definition.void
loadFileBinding
(String path) Load binding definition from file path.void
loadResourceBinding
(String path) Load binding definition from file path.void
Process the binding definitions.void
reset()
Reset loader information.Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
m_bindings
Binding definitions used by loader. -
m_isBound
private boolean m_isBoundFlag for bindings compiled into class code. -
m_classMap
Map of classes modified by binding.
-
-
Constructor Details
-
Loader
Constructor with classpath URLs and parent classloader supplied. Sets up the paths for both actual classloading and finding classes to be bound.- Parameters:
paths
- array of classpath URLsparent
- classloader used for delegation loading
-
Loader
Constructor with classpath URLs supplied. This uses the supplied classpaths, delegating directly to the parent classloader of the normal System classloader.- Parameters:
paths
- array of classpath URLs
-
Loader
Default constructor. This reads the standard class path and uses it for locating classes used by the binding, delegating directly to the parent classloader of the normal System classloader.- Throws:
MalformedURLException
- on error in classpath URLs
-
-
Method Details
-
reset
public void reset()Reset loader information. This discards all prior bindings and clears the internal state in preparation for loading a different set of bindings. It is not possible to clear the loaded classes, though, so any new bindings must refer to different classes from those previously loaded. -
getClassPaths
Method builds an array of URL for items in the class path.- Returns:
- array of classpath URLs
- Throws:
MalformedURLException
-
loadBinding
public void loadBinding(String fname, String sname, InputStream is, URL url) throws JiBXException, IOException Load binding definition. This may be called multiple times to load multiple bindings, but only prior to the bindings being compiled. The reader form of the call is generally preferred, since the document encoding may not be properly interpreted from a stream.- Parameters:
fname
- binding definition full namesname
- short form of name to use as the default name of the bindingis
- input stream for binding definition documenturl
- URL for binding definition (null
if not available)- Throws:
IllegalStateException
- if called after bindings have been compiledIOException
- if error reading the bindingJiBXException
- if error in processing the binding definition
-
loadFileBinding
Load binding definition from file path. This may be called multiple times to load multiple bindings, but only prior to the bindings being compiled.- Parameters:
path
- binding definition file path- Throws:
IllegalStateException
- if called after bindings have been compiledIOException
- if error reading the fileJiBXException
- if error in processing the binding definition
-
loadResourceBinding
Load binding definition from file path. This may be called multiple times to load multiple bindings, but only prior to the bindings being compiled.- Parameters:
path
- binding definition file path- Throws:
IllegalStateException
- if called after bindings have been compiledIOException
- if error reading the fileJiBXException
- if error in processing the binding definition
-
processBindings
Process the binding definitions. This compiles the bindings into the classes, saving the modified classes for loading when needed.- Throws:
JiBXException
- if error in processing the binding definition
-
isBoundClass
Check if a class has been modified by a binding. If bindings haven't been compiled prior to this call they will be compiled automatically when this method is called.- Parameters:
name
- fully qualified package and class name to be found- Returns:
true
if class modified by binding,false
if not
-
findClass
Find and load class by name. If the named class has been modified by a binding this loads the modified binary class; otherwise, it just uses the base class implementation to do the loading. If bindings haven't been compiled prior to this call they will be compiled automatically when this method is called.- Overrides:
findClass
in classURLClassLoader
- Parameters:
name
- fully qualified package and class name to be found- Returns:
- the loaded class
- Throws:
ClassNotFoundException
- if the class cannot be found- See Also:
-