public void addLoaderPackagesRoot(String[] packagesroot) { for (String packageroot : packagesroot) addLoaderPackageRoot(packageroot); }
/** * Adds a package root to the list of packages which must be loaded on the * parent loader. * * All subpackages are also included. * * @param packageRoot The root of all packages to be included. * Should not be <code>null</code>. */ public synchronized void addSystemPackageRoot(String packageRoot) { systemPackages.add(appendDot(packageRoot)); }
/** * Loads a class through this class loader even if that class is available * on the parent classpath. * * This ensures that any classes which are loaded by the returned class * will use this classloader. * * @param classname The name of the class to be loaded. * Must not be <code>null</code>. * * @return the required Class object * * @exception ClassNotFoundException if the requested class does not exist * on this loader's classpath. */ public Class forceLoadClass(String classname) throws ClassNotFoundException { LOGGER.finest("force loading " + classname); Class theClass= findLoadedClass(classname); if (theClass == null) { theClass= findClass(classname); } return theClass; }
Class theClass= findLoadedClass(classname); byte[] bs= bytecodes.get(classname); if (bs != null) theClass= defineClassFromData(bs, classname); if (classNeedsLoadingFromParent(classname)) theClass= getParent().loadClass(classname); LOGGER.finest("Class " + classname + " loaded from parent loader " + "(parentFirst)"); theClass= findClass(classname); LOGGER.finest("Class " + classname + " loaded from ant loader " + "(parentFirst)"); theClass= findClass(classname); LOGGER.finest("Class " + classname + " loaded from ant loader"); theClass= getParent().loadClass(classname); LOGGER.finest("Class " + classname + " loaded from parent loader"); resolveClass(theClass);
/** * Finds the resource with the given name. A resource is * some data (images, audio, text, etc) that can be accessed by class * code in a way that is independent of the location of the code. * * @param name The name of the resource for which a stream is required. * Must not be <code>null</code>. * @return a URL for reading the resource, or <code>null</code> if the * resource could not be found or the caller doesn't have * adequate privileges to get the resource. */ public synchronized URL getResource(String name) { // we need to search the components of the path to see if // we can find the class we want. if (isParentFirst(name)) { return super.getResource(name); } // try this class loader first, then parent URL url= findResource(name); if (url == null) { url= getParent().getResource(name); } return url; }
public ClassLoader getNewClassloaderInstance(ClassLoader parent, ClassLoader current) { instrumentationClassLoader= new DragomeInstrumentationClassLoader(new URL[0], parent, current, getBytecodeTransformer(), getLoadedFromParent()); instrumentationClassLoader.setBytecodes(bytecodes); return instrumentationClassLoader; }
InputStream stream= getResourceAsStream(classFileName); if (stream == null) throw new ClassNotFoundException(name); return getClassFromStream(stream, name);
/** * Creates a classloader by using the classpath given. * * @param urls * The URLs from which to load classes and resources * @param parent * The parent classloader to which unsatisfied loading * attempts are delegated. May be <code>null</code>, * in which case the {@link ClassLoader#getSystemClassLoader() system classloader} * is used as the parent. */ public DragomeInstrumentationClassLoader(URL[] urls, ClassLoader parent) { super(urls, fixNullParent(parent)); acc= AccessController.getContext(); }
/** * Reads a class definition from a stream. * * @param stream The stream from which the class is to be read. * Must not be <code>null</code>. * @param classname The name of the class in the stream. * Must not be <code>null</code>. * * @return the Class object read from the stream. * * @exception IOException if there is a problem reading the class from the * stream. * @exception SecurityException if there is a security problem while * reading the class from the stream. */ private Class getClassFromStream(InputStream stream, String classname) throws IOException, SecurityException { ByteArrayOutputStream baos= new ByteArrayOutputStream(); int bytesRead; byte[] buffer= new byte[BUFFER_SIZE]; while ((bytesRead= stream.read(buffer, 0, BUFFER_SIZE)) != -1) { baos.write(buffer, 0, bytesRead); } byte[] classData= baos.toByteArray(); return defineClassFromData(classData, classname); }