[jboss-cvs] JBossAS SVN: r104736 - in projects/jboss-cl/trunk: classloading/src/main/java/org/jboss/classloading/plugins/metadata and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 12 15:12:21 EDT 2010
Author: thomas.diesler at jboss.com
Date: 2010-05-12 15:12:21 -0400 (Wed, 12 May 2010)
New Revision: 104736
Modified:
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/PackageClassFilter.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/RecursivePackageClassFilter.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
Log:
[JBOSGI-323] Add support for wildcard package names
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/PackageClassFilter.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/PackageClassFilter.java 2010-05-12 18:53:41 UTC (rev 104735)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/PackageClassFilter.java 2010-05-12 19:12:21 UTC (rev 104736)
@@ -59,6 +59,10 @@
if (packageNames[i] == null)
throw new IllegalArgumentException("Null package name in " + Arrays.asList(packageNames));
+ // Wildcards should be handled external to this
+ if (packageNames[i].indexOf('*') >= 0)
+ throw new IllegalArgumentException("Invalid package name: " + packageNames[i]);
+
if (packageNames[i].length() == 0)
// Base package - it is a match if there is no . in the class name
patterns[i] = "[^.]*";
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/RecursivePackageClassFilter.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/RecursivePackageClassFilter.java 2010-05-12 18:53:41 UTC (rev 104735)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/RecursivePackageClassFilter.java 2010-05-12 19:12:21 UTC (rev 104736)
@@ -61,6 +61,10 @@
if (packageNames[i] == null)
throw new IllegalArgumentException("Null package name in " + Arrays.asList(packageNames));
+ // Wildcards should be handled external to this
+ if (packageNames[i].indexOf('*') >= 0)
+ throw new IllegalArgumentException("Invalid package name: " + packageNames[i]);
+
if (packageNames[i].length() == 0)
// Base package - match everything
return EVERYTHING_PATTERN;
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java 2010-05-12 18:53:41 UTC (rev 104735)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java 2010-05-12 19:12:21 UTC (rev 104736)
@@ -24,6 +24,10 @@
import java.util.Collections;
import java.util.Set;
+import org.jboss.classloader.plugins.filter.EverythingClassFilter;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.PackageClassFilter;
+import org.jboss.classloader.spi.filter.RecursivePackageClassFilter;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.metadata.OptionalPackages;
import org.jboss.classloading.spi.metadata.Requirement;
@@ -78,6 +82,35 @@
return Collections.singleton(getName());
}
+ /**
+ * Gets the {@link ClassFilter} that corrsponds to this PackageRequiment.
+ *
+ * This methods supports explicit packages, wildcard sub packages (e.g. org.foo.*)
+ * and the everything wildcard (i.e. '*')
+ *
+ * @return
+ */
+ public ClassFilter toClassFilter()
+ {
+ ClassFilter filter;
+ String packageName = getName();
+ if ("*".equals(packageName))
+ {
+ filter = EverythingClassFilter.INSTANCE;
+
+ }
+ else if (packageName.endsWith(".*"))
+ {
+ packageName = packageName.substring(0, packageName.length() - 2);
+ filter = RecursivePackageClassFilter.createRecursivePackageClassFilter(packageName);
+ }
+ else
+ {
+ filter = PackageClassFilter.createPackageClassFilter(packageName);
+ }
+ return filter;
+ }
+
@Override
public boolean isConsistent(Requirement other)
{
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-12 18:53:41 UTC (rev 104735)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-12 19:12:21 UTC (rev 104736)
@@ -27,8 +27,14 @@
import java.util.List;
import org.jboss.classloader.plugins.loader.ClassLoaderToLoaderAdapter;
-import org.jboss.classloader.spi.*;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.DelegateLoader;
+import org.jboss.classloader.spi.Loader;
+import org.jboss.classloader.spi.ParentPolicy;
import org.jboss.classloader.spi.base.BaseClassLoader;
+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.spi.filter.PackageClassFilter;
@@ -53,16 +59,16 @@
{
/** The serialVersionUID */
private static final long serialVersionUID = -3357427104777457717L;
-
+
/** Our cached policy */
private ClassLoaderPolicy policy;
-
+
/** The classloader system we are registered with */
private ClassLoaderSystem system;
-
+
/** The classloader */
private ClassLoader classLoader;
-
+
/** An optional classloader policy factory */
private ClassLoaderPolicyFactory policyFactory;
@@ -91,11 +97,11 @@
{
if (classLoader == null)
throw new IllegalStateException("No classloader for module " + this);
-
+
if (classLoader instanceof BaseClassLoader == false)
return super.getClassLoaderForClass(className);
-
- final BaseClassLoader bcl = (BaseClassLoader) classLoader;
+
+ final BaseClassLoader bcl = (BaseClassLoader)classLoader;
SecurityManager sm = System.getSecurityManager();
if (sm != null)
{
@@ -105,7 +111,7 @@
{
public ClassLoader run() throws Exception
{
- return bcl.findClassLoader(className);
+ return bcl.findClassLoader(className);
}
});
}
@@ -113,15 +119,15 @@
{
Throwable t = e.getCause();
if (t instanceof ClassNotFoundException)
- throw (ClassNotFoundException) t;
+ throw (ClassNotFoundException)t;
if (t instanceof Error)
- throw (Error) t;
+ throw (Error)t;
if (t instanceof RuntimeException)
- throw (RuntimeException) t;
+ throw (RuntimeException)t;
throw new RuntimeException("Error during findClassLoader for " + className, e);
}
}
- return bcl.findClassLoader(className);
+ return bcl.findClassLoader(className);
}
/**
@@ -137,7 +143,7 @@
if (isValid() == false)
throw new IllegalStateException("Module " + this + " is not registered, see previous error messages");
-
+
String domainName = getDeterminedDomainName();
ParentPolicy parentPolicy = getDeterminedParentPolicy();
String parentName = getDeterminedParentDomainName();
@@ -147,7 +153,7 @@
registerModuleClassLoader(this, result);
return result;
}
-
+
/**
* Register the classloader policy with a classloader system
*
@@ -166,12 +172,12 @@
throw new IllegalStateException("Module " + this + " is not registered, see previous error messages");
Loader loader = new ClassLoaderToLoaderAdapter(parent);
- ClassLoader result = registerClassLoaderPolicy(system, loader);
+ ClassLoader result = registerClassLoaderPolicy(system, loader);
this.classLoader = result;
registerModuleClassLoader(this, result);
return result;
}
-
+
/**
* Register the classloader policy with a classloader system
*
@@ -186,7 +192,7 @@
if (isValid() == false)
throw new IllegalStateException("Module " + this + " is not registered, see previous error messages");
-
+
String domainName = getDeterminedDomainName();
ParentPolicy parentPolicy = getDeterminedParentPolicy();
ClassLoader result = system.registerClassLoaderPolicy(domainName, parentPolicy, loader, getPolicy());
@@ -205,10 +211,10 @@
{
if (policy != null)
return policy;
-
+
if (policyFactory == null)
policyFactory = this;
-
+
policy = policyFactory.createClassLoaderPolicy();
return policy;
}
@@ -229,7 +235,7 @@
system = null;
policy = null;
}
-
+
/**
* Default implementation of class loader policy factory
*/
@@ -250,7 +256,7 @@
{
return classLoader;
}
-
+
@Override
public DelegateLoader createLazyDelegateLoader(Domain domain, RequirementDependencyItem item)
{
@@ -258,15 +264,14 @@
if (context == null)
throw new IllegalStateException("No controller context");
Controller controller = context.getController();
-
+
DynamicClassLoaderPolicyFactory factory = new DynamicClassLoaderPolicyFactory(controller, domain, item);
Requirement requirement = item.getRequirement();
if (requirement instanceof PackageRequirement)
{
- PackageRequirement pr = (PackageRequirement) requirement;
- PackageClassFilter filter = PackageClassFilter.createPackageClassFilter(pr.getName());
- return new FilteredDelegateLoader(factory, filter);
+ PackageRequirement pr = (PackageRequirement)requirement;
+ return new FilteredDelegateLoader(factory, pr.toClassFilter());
}
else
{
@@ -286,11 +291,11 @@
return policy;
}
};
- PackageClassFilter filter;
+ ClassFilter filter;
if (requirement instanceof PackageRequirement)
{
- PackageRequirement pr = (PackageRequirement) requirement;
- filter = PackageClassFilter.createPackageClassFilter(pr.getName());
+ PackageRequirement pr = (PackageRequirement)requirement;
+ filter = pr.toClassFilter();
}
else
{
More information about the jboss-cvs-commits
mailing list