net.sf.fikin.classmarshaling.util
Class HidingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by net.sf.fikin.classmarshaling.util.HidingClassLoader

public class HidingClassLoader
extends java.lang.ClassLoader

Class loader "hiding" any class part of given list of hierarchies.

This is useful in cases when it is required an "artificial" environment where given classes are assumed not to be present.

I use it in testing and initial implementation stages of my applications. created on Aug 5, 2005

Since:
Version:
$Revision: 1.1 $
Author:
fiykov

Constructor Summary
HidingClassLoader(java.lang.ClassLoader parent)
          construct hiding classloader with given parent
HidingClassLoader(java.lang.ClassLoader parent, java.util.Collection prefixes)
          construct hiding classloader with given parent and list of prefixes
HidingClassLoader(java.lang.ClassLoader parent, java.lang.String[] prefixes)
          construct hiding classloader with given parent and list of prefixes
 
Method Summary
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          class lookup call.
 void setPrefixes(java.util.Collection prefixes)
          assign list of class hierarchies which are to be hided by this classloader
 void setPrefixes(java.lang.String[] prefixes)
          assign list of class hierarchies which are to be hided by this classloader
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HidingClassLoader

public HidingClassLoader(java.lang.ClassLoader parent)
construct hiding classloader with given parent

Parameters:
parent - classloader

HidingClassLoader

public HidingClassLoader(java.lang.ClassLoader parent,
                         java.util.Collection prefixes)
construct hiding classloader with given parent and list of prefixes

Parameters:
parent - classloader
prefixes - of classes to hide

HidingClassLoader

public HidingClassLoader(java.lang.ClassLoader parent,
                         java.lang.String[] prefixes)
construct hiding classloader with given parent and list of prefixes

Parameters:
parent - classloader
prefixes - of classes to hide
Method Detail

setPrefixes

public void setPrefixes(java.util.Collection prefixes)
assign list of class hierarchies which are to be hided by this classloader

Parameters:
prefixes -

setPrefixes

public void setPrefixes(java.lang.String[] prefixes)
assign list of class hierarchies which are to be hided by this classloader

Parameters:
prefixes -

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
class lookup call.

if asked class is part of one the specified prefix hierarchies it will throw ClassNotFoundException exception.

All other classes are propagated to its parent classloader.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - of the class to check
resolve - the class
Returns:
the actual Class object
Throws:
java.lang.ClassNotFoundException


Copyright © 2007 Nikolay Fiykov. All Rights Reserved.