Class Loader

  • All Implemented Interfaces:
    Closeable, AutoCloseable
    Direct Known Subclasses:
    Loader.NondelegatingLoader

    public class Loader
    extends URLClassLoader
    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
    • Constructor Detail

      • Loader

        public Loader​(URL[] paths,
                      ClassLoader parent)
        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 URLs
        parent - classloader used for delegation loading
      • Loader

        public Loader​(URL[] paths)
        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

        public Loader()
               throws MalformedURLException
        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 Detail

      • 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.
      • loadBinding

        public void loadBinding​(String fname,
                                String sname,
                                InputStream is,
                                URL url)
                         throws org.jibx.runtime.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 name
        sname - short form of name to use as the default name of the binding
        is - input stream for binding definition document
        url - URL for binding definition (null if not available)
        Throws:
        IllegalStateException - if called after bindings have been compiled
        IOException - if error reading the binding
        org.jibx.runtime.JiBXException - if error in processing the binding definition
      • loadFileBinding

        public void loadFileBinding​(String path)
                             throws org.jibx.runtime.JiBXException,
                                    IOException
        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 compiled
        IOException - if error reading the file
        org.jibx.runtime.JiBXException - if error in processing the binding definition
      • loadResourceBinding

        public void loadResourceBinding​(String path)
                                 throws org.jibx.runtime.JiBXException,
                                        IOException
        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 compiled
        IOException - if error reading the file
        org.jibx.runtime.JiBXException - if error in processing the binding definition
      • processBindings

        public void processBindings()
                             throws org.jibx.runtime.JiBXException
        Process the binding definitions. This compiles the bindings into the classes, saving the modified classes for loading when needed.
        Throws:
        org.jibx.runtime.JiBXException - if error in processing the binding definition
      • isBoundClass

        protected boolean isBoundClass​(String name)
        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

        protected Class findClass​(String name)
                           throws ClassNotFoundException
        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 class URLClassLoader
        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:
        ClassLoader.findClass(java.lang.String)