[jboss-cvs] JBossAS SVN: r70185 - in projects/microcontainer/trunk/classloader/src: tests/org/jboss/test/classloader/delegate/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 27 10:34:06 EST 2008
Author: adrian at jboss.org
Date: 2008-02-27 10:34:06 -0500 (Wed, 27 Feb 2008)
New Revision: 70185
Added:
projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/filter/LazyFilteredDelegateLoader.java
Modified:
projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateLoaderUnitTestCase.java
Log:
Extend the FilteredDelegateLoader with a version that can lazily initialise itself
Added: projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/filter/LazyFilteredDelegateLoader.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/filter/LazyFilteredDelegateLoader.java (rev 0)
+++ projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/filter/LazyFilteredDelegateLoader.java 2008-02-27 15:34:06 UTC (rev 70185)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.classloader.spi.filter;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
+
+/**
+ * LazyFilteredDelegateLoader.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class LazyFilteredDelegateLoader extends FilteredDelegateLoader
+{
+ /**
+ * Create a new FilteredDelegateLoader that does not filter
+ *
+ * @param factory the factory
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public LazyFilteredDelegateLoader(ClassLoaderPolicyFactory factory)
+ {
+ super(factory, ClassFilter.EVERYTHING);
+ }
+
+ @Override
+ protected void initialise(ClassLoaderPolicy policy)
+ {
+ String[] packageNames = policy.getPackageNames();
+ if (packageNames != null)
+ {
+ ClassFilter filter = PackageClassFilter.createPackageClassFilter(packageNames);
+ setFilter(filter);
+ }
+ }
+}
Modified: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateLoaderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateLoaderUnitTestCase.java 2008-02-27 15:18:05 UTC (rev 70184)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateLoaderUnitTestCase.java 2008-02-27 15:34:06 UTC (rev 70185)
@@ -28,9 +28,12 @@
import org.jboss.classloader.spi.DelegateLoader;
import org.jboss.classloader.spi.filter.ClassFilter;
import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
+import org.jboss.classloader.spi.filter.LazyFilteredDelegateLoader;
import org.jboss.classloader.test.support.MockClassLoaderPolicy;
import org.jboss.test.classloader.AbstractClassLoaderTestWithSecurity;
import org.jboss.test.classloader.delegate.support.a.TestA1;
+import org.jboss.test.classloader.delegate.support.b.TestB1;
+import org.jboss.test.classloader.policy.support.TestClassLoaderPolicyFactory;
/**
* DelegateUnitTestCase
@@ -83,10 +86,31 @@
assertLoadClassFail(TestA1.class, delegate);
}
+ public void testLazyLoadClass() throws Exception
+ {
+ ClassLoaderSystem system = createClassLoaderSystemWithModifiedBootstrap();
+
+ MockClassLoaderPolicy policy = createMockClassLoaderPolicy("a");
+ policy.setPaths(TestA1.class, TestB1.class);
+ policy.setPackageNames(TestA1.class);
+ ClassLoader cl = system.registerClassLoaderPolicy(policy);
+ assertLoadClass(TestA1.class, cl);
+ assertLoadClass(TestB1.class, cl);
+
+ TestClassLoaderPolicyFactory factory = new TestClassLoaderPolicyFactory(policy, false);
+ LazyFilteredDelegateLoader delegate = new LazyFilteredDelegateLoader(factory);
+ assertLoadClassFail(TestA1.class, delegate);
+ assertLoadClassFail(TestB1.class, delegate);
+
+ factory.setCanCreate(true);
+ assertLoadClass(TestA1.class, delegate);
+ assertLoadClassFail(TestB1.class, delegate);
+ }
+
protected Class<?> assertLoadClass(Class<?> reference, DelegateLoader delegate) throws Exception
{
Class<?> result = delegate.loadClass(reference.getName());
- assertNotNull("Should have loaded " + reference.getName() + " from " + delegate);
+ assertNotNull("Should have loaded " + reference.getName() + " from " + delegate, result);
getLog().debug("Loaded " + ClassLoaderUtils.classToString(result) + " from " + delegate);
return result;
}
@@ -95,7 +119,6 @@
{
Class<?> result = delegate.loadClass(reference.getName());
String message = "Should not have loaded " + ClassLoaderUtils.classToString(result) + " from " + delegate;
- getLog().error(message);
assertNull(message, result);
}
}
More information about the jboss-cvs-commits
mailing list