Class DefaultClassRealm

  • All Implemented Interfaces:
    ClassRealm

    public class DefaultClassRealm
    extends java.lang.Object
    implements ClassRealm
    Implementation of ClassRealm. The realm is the class loading gateway. The search is proceded as follows:
    1. Search the parent class loader (passed via the constructor) if there is one.
    2. Search the imports.
    3. Search this realm's constituents.
    4. Search the parent realm.
    Version:
    $Id: DefaultClassRealm.java 126 2006-01-12 04:17:51Z $
    Author:
    bob mcwhirter, Jason van Zyl
    • Field Detail

      • id

        private java.lang.String id
      • imports

        private java.util.TreeSet imports
      • foreignClassLoader

        private java.lang.ClassLoader foreignClassLoader
    • Constructor Detail

      • DefaultClassRealm

        public DefaultClassRealm​(ClassWorld world,
                                 java.lang.String id)
      • DefaultClassRealm

        public DefaultClassRealm​(ClassWorld world,
                                 java.lang.String id,
                                 java.lang.ClassLoader foreignClassLoader)
    • Method Detail

      • getId

        public java.lang.String getId()
        Specified by:
        getId in interface ClassRealm
      • addConstituent

        public void addConstituent​(java.net.URL constituent)
        Specified by:
        addConstituent in interface ClassRealm
      • addConstituent

        public void addConstituent​(java.lang.String constituent,
                                   byte[] b)
                            throws java.lang.ClassNotFoundException
        Adds a byte[] class definition as a constituent for locating classes. Currently uses BytesURLStreamHandler to hold a reference of the byte[] in memory. This ensures we have a unifed URL resource model for all constituents. The code to cache to disk is commented out - maybe a property to choose which method?
        Parameters:
        constituent - class name
        b - the class definition as a byte[]
        Throws:
        java.lang.ClassNotFoundException
      • loadClass

        public java.lang.Class loadClass​(java.lang.String name)
                                  throws java.lang.ClassNotFoundException
        Specified by:
        loadClass in interface ClassRealm
        Throws:
        java.lang.ClassNotFoundException
      • getResource

        public java.net.URL getResource​(java.lang.String name)
        Specified by:
        getResource in interface ClassRealm
      • getResourceAsStream

        public java.io.InputStream getResourceAsStream​(java.lang.String name)
        Specified by:
        getResourceAsStream in interface ClassRealm
      • findResources

        public java.util.Enumeration findResources​(java.lang.String name)
                                            throws java.io.IOException
        Specified by:
        findResources in interface ClassRealm
        Throws:
        java.io.IOException
      • showUrls

        private void showUrls​(ClassRealm classRealm)