Custom ClassLoader Test Example
Example 7.19, “Custom ClassLoader Test� shows a test to verify that the CB2 bean uses a custom ClassLoader, which limits the loadable package scope. Example 7.19. Custom ClassLoader Test public class CustomClassLoader extends ClassLoader { private Pattern pattern; public CustomClassLoader(ClassLoader parent) { super(parent); } public Class loadClass(String name) throws ClassNotFoundException { if (pattern == null || pattern.matcher(name).matches()) return super.loadClass(name); else throw new ClassNotFoundException("Name '" + name + "' doesn't match pattern: " + pattern); } public void setPattern(String regexp) { pattern = Pattern.compile(regexp); } }