private Class<?> loadWithDelegate( final boolean delegate, final boolean resolve, final String name) throws ClassNotFoundException { setDelegate(delegate); try { return super.loadClass(name, resolve); } finally { filterTempCache.remove(name); // no more needed since class is loaded, avoid to waste mem setDelegate(originalDelegate); } }
@Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if ("org.apache.openejb.hibernate.OpenEJBJtaPlatform".equals(name) || "org.apache.openejb.jpa.integration.hibernate.PrefixNamingStrategy".equals(name) || "org.apache.openejb.jpa.integration.eclipselink.PrefixSessionCustomizer".equals(name) || "org.apache.openejb.jpa.integration.eclipselink.OpenEJBServerPlatform".equals(name) || "org.apache.openejb.jpa.integration.eclipselink.OpenEJBServerPlatform$OpenEJBJTATransactionController" .equals(name) || "org.apache.openejb.eclipselink.JTATransactionController".equals(name) || "org.apache.tomee.mojarra.TomEEInjectionProvider".equals(name)) { // don't load them from system classloader (breaks all in embedded mode and no sense in other // cases) synchronized (this) { final ClassLoader old = getJavaseClassLoader(); setJavaseClassLoader(NoClassClassLoader.INSTANCE); delegate = false; try { return super.loadClass(name, resolve); } finally { setJavaseClassLoader(old); setDelegate(originalDelegate); } } } // avoid to redefine classes from server in this classloader is it not already loaded if (URLClassLoaderFirst.shouldDelegateToTheContainer( this, name)) { // dynamic validation handling overriding try { return OpenEJB.class .getClassLoader() .loadClass( name); // we could use containerClassLoader but this is server loader so cut it even // more } catch (final ClassNotFoundException e) { synchronized (this) { return super.loadClass(name, resolve); } } catch (final NoClassDefFoundError ncdfe) { synchronized (this) { return super.loadClass(name, resolve); } } } else if (name.startsWith("javax.faces.") || name.startsWith("org.apache.webbeans.jsf")) { synchronized (this) { delegate = false; try { return super.loadClass(name, resolve); } finally { setDelegate(originalDelegate); } } } synchronized ( this) { // TODO: rework it to avoid it and get aligned on Java 7 classloaders (but not a big // issue) if (isEar) { final boolean filter = filter(name, true); filterTempCache.put(name, filter); // will be called again by super.loadClass() so cache it if (!filter) { if (URLClassLoaderFirst.class.isInstance(getParent())) { // true final URLClassLoaderFirst urlClassLoaderFirst = URLClassLoaderFirst.class.cast(getParent()); Class<?> c = urlClassLoaderFirst.findAlreadyLoadedClass(name); if (c != null) { return c; } c = urlClassLoaderFirst.loadInternal(name, resolve); if (c != null) { return c; } } return loadWithDelegate( getResource(name.replace('.', '/') + CLASS_EXTENSION) == null, resolve, name); } } return super.loadClass(name, resolve); } }
private int construct() { setDelegate(isDelegate()); configurer = INIT_CONFIGURER.get(); return super.hashCode(); }