[jboss-cvs] JBossAS SVN: r104821 - in projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency: policy and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat May 15 05:06:28 EDT 2010
Author: alesj
Date: 2010-05-15 05:06:28 -0400 (Sat, 15 May 2010)
New Revision: 104821
Modified:
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java
Log:
Fix addition of existing modules.
Revert module name hack.
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java 2010-05-15 06:10:02 UTC (rev 104820)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java 2010-05-15 09:06:28 UTC (rev 104821)
@@ -38,7 +38,7 @@
/**
* Domain.
- *
+ *
* @author <a href="adrian at jboss.org">Adrian Brock</a>
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @author Thomas.Diesler at jboss.com
@@ -48,7 +48,7 @@
{
/** The log */
private static final Logger log = Logger.getLogger(Domain.class);
-
+
/** The domain name */
private String name;
@@ -57,20 +57,20 @@
/** The parent domain name */
private String parentDomainName;
-
+
/** Whether we are parent first */
private boolean parentFirst;
-
+
/** The registered modules in registration order */
private List<Module> modules = new CopyOnWriteArrayList<Module>();
-
+
/** The registered modules by name */
private Map<String, Module> modulesByName = new ConcurrentHashMap<String, Module>();
-
+
/**
* Create a new Domain.
- *
- * @param classLoading the classloading
+ *
+ * @param classLoading the classloading
* @param name the name
* @param parentDomainName the parent domain name
* @param parentFirst whether to check the parent first
@@ -90,7 +90,7 @@
/**
* Get the name.
- *
+ *
* @return the name.
*/
public String getName()
@@ -110,7 +110,7 @@
/**
* Get the parentDomainName.
- *
+ *
* @return the parentDomainName.
*/
public String getParentDomainName()
@@ -124,10 +124,10 @@
return classLoading.getDomain(parentDomainName);
return null;
}
-
+
/**
* Get the parentFirst.
- *
+ *
* @return the parentFirst.
*/
public boolean isParentFirst()
@@ -137,7 +137,7 @@
/**
* Add a module
- *
+ *
* @param module the module
* @throws IllegalStateException if the module is already registered
* @throws IllegalArgumentException for a null parameter
@@ -154,7 +154,7 @@
throw new IllegalArgumentException("The context " + contextName + " is already registered in domain " + getName());
log.debug(this + " add module " + module);
-
+
module.setDomain(this);
modulesByName.put(contextName, module);
modules.add(module);
@@ -180,10 +180,10 @@
throw new RuntimeException("Error adding module " + module, t);
}
}
-
+
/**
* Remove a deployment
- *
+ *
* @param module the module
* @throws IllegalArgumentException for a null parameter
*/
@@ -206,7 +206,7 @@
/**
* Get a module for a context name
- *
+ *
* @param name the context name
* @return the module
*/
@@ -223,7 +223,7 @@
return parent.getModule(name);
return null;
}
-
+
/**
* Merges the capabilities provided by our global capabilities provider with the passed in capabilities.
*
@@ -237,7 +237,7 @@
/**
* Resolve a requirement to a module
- *
+ *
* @param module the module
* @param requirement the requirement
* @return the resolved name or null if not resolved
@@ -252,7 +252,7 @@
if (classLoading.resolve(new ResolutionContext(this, module, requirement)))
result = doResolveModule(module, requirement);
}
-
+
// If there is a result, check to see whether we need to resolve it
if (result != null)
{
@@ -269,13 +269,13 @@
}
}
}
-
+
return result;
- }
-
+ }
+
/**
* Resolve a requirement to a module
- *
+ *
* @param module the module
* @param requirement the requirement
* @return the resolved name or null if not resolved
@@ -298,7 +298,7 @@
if (result != null)
return result;
}
-
+
Module firstMatch = null;
for (Module other : modules)
{
@@ -311,8 +311,8 @@
{
if (firstMatch != null)
{
- String otherName = other.getName() + ":" + other.getVersion();
- String firstName = firstMatch.getName() + ":" + firstMatch.getVersion();
+ String otherName = other.getName() + ":" + other.getVersion();
+ String firstName = firstMatch.getName() + ":" + firstMatch.getVersion();
log.debug("Requirement " + requirement + " resolves agaist " + firstName + " and " + otherName + " - using first.");
}
if (firstMatch == null)
@@ -321,48 +321,48 @@
}
}
}
-
+
if (firstMatch != null)
return firstMatch;
// Check the parent afterwards when required
if (parentDomain != null && parentFirst == false)
return parentDomain.resolveModule(module, requirement);
-
+
return null;
}
-
+
public Module getModuleForClass(Class<?> clazz)
{
return Module.getModuleForClass(clazz);
}
-
+
public Collection<Module> getModules(String name, VersionRange range)
{
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+
Collection<Module> result = new HashSet<Module>();
getModulesInternal(name, range, result);
return result;
}
-
+
/**
* Get the modules matching the name and range
- *
- * If the given name is null, it matches all names.
- * If the given range is null, it matches all versions.
- *
- * @param name the name or null
- * @param range the range or null
+ *
+ * @param name the name
+ * @param range the range
* @param result the matching modules
*/
void getModulesInternal(String name, VersionRange range, Collection<Module> result)
{
if (range == null)
range = VersionRange.ALL_VERSIONS;
-
+
for (Module module : modules)
{
List<Capability> capabilities = module.getCapabilitiesRaw();
- if (name != null && capabilities != null && capabilities.isEmpty() == false)
+ if (capabilities != null && capabilities.isEmpty() == false)
{
ModuleRequirement requirement = new ModuleRequirement(name, range);
for (Capability capability : capabilities)
@@ -376,26 +376,25 @@
}
else
{
- boolean nameMatch = (name == null || name.equals(module.getName()));
- boolean versionMatch = range.isInRange(module.getVersion());
- if (nameMatch && versionMatch)
+ if (name.equals(module.getName()) && range.isInRange(module.getVersion()))
{
result.add(module);
+ return;
}
}
}
}
-
+
public Collection<ImportModule> getImportedModules(String name, VersionRange range)
{
Collection<ImportModule> result = new HashSet<ImportModule>();
getImportingModulesInternal(name, range, result);
return result;
}
-
+
/**
* Get the importing modules matching the name and range
- *
+ *
* @param name the name
* @param range the range
* @param result the matching modules
@@ -404,7 +403,7 @@
{
if (range == null)
range = VersionRange.ALL_VERSIONS;
-
+
for (Module module : modules)
{
List<RequirementDependencyItem> requirementDependencyItems = module.getDependencies();
@@ -430,27 +429,27 @@
}
}
}
-
+
public Collection<ExportPackage> getExportedPackages(Module module)
{
if (module == null)
throw new IllegalArgumentException("Null module");
return module.getExportedPackages();
}
-
+
public Collection<ExportPackage> getExportedPackages(String name, VersionRange range)
{
if (name == null)
throw new IllegalArgumentException("Null name");
-
+
Collection<ExportPackage> result = new HashSet<ExportPackage>();
getExportedPackagesInternal(name, range, result);
return result;
}
-
+
/**
* Get the exported packages matching the name and range
- *
+ *
* @param name the name
* @param range the range
* @param result the matching modules
@@ -459,7 +458,7 @@
{
if (range == null)
range = VersionRange.ALL_VERSIONS;
-
+
for (Module module : modules)
{
List<Capability> capabilities = module.getCapabilitiesRaw();
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java 2010-05-15 06:10:02 UTC (rev 104820)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java 2010-05-15 09:06:28 UTC (rev 104821)
@@ -23,10 +23,7 @@
import java.io.IOException;
import java.net.URL;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -42,6 +39,8 @@
/**
* WildcardClassLoaderPolicy.
*
+ * TODO -- module order rules actually need more work; parent of a parent, ...
+ *
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
*/
public class WildcardClassLoaderPolicy extends ClassLoaderPolicy implements ModuleRegistry
@@ -76,21 +75,11 @@
if (module == null)
throw new IllegalArgumentException("Null module");
- // Add the modules that can resolve the requirement
- for (Module aux : domain.getModules(null, null))
- {
- // The wildcard policy should not load from this module
- if (aux == module)
- continue;
-
- // Add the module if it can resolve the requirement
- if (aux.canResolve(requirement))
- modules.add(aux);
- }
-
this.domain = domain;
this.requirement = requirement;
this.module = module;
+
+ fillModules(domain);
}
/**
@@ -205,24 +194,37 @@
boolean isAncestor = (domain != md); // not the same domain, so it must be ancestor
synchronized (this)
{
- if (isAncestor)
- {
- if (domain.isParentFirst())
- {
- modules.add(0, current);
- parentsBefore++;
- }
- else
- modules.add(current);
- }
- else
- modules.add(parentsBefore, current);
+ boolean isParentFirst = domain.isParentFirst();
+ addModule(current, isAncestor, isParentFirst);
}
reset();
}
}
+ /**
+ * Add module, following order rules.
+ *
+ * @param current the current module
+ * @param isAncestor is ancestor
+ * @param isParentFirst is parent first
+ */
+ private void addModule(Module current, boolean isAncestor, boolean isParentFirst)
+ {
+ if (isAncestor)
+ {
+ if (isParentFirst)
+ {
+ modules.add(0, current);
+ parentsBefore++;
+ }
+ else
+ modules.add(current);
+ }
+ else
+ modules.add(parentsBefore, current);
+ }
+
public void removeModule(Module current)
{
boolean sameModule = module == current;
@@ -279,6 +281,35 @@
}
/**
+ * Fill modules according to domain rules.
+ *
+ * @param current the current domain
+ */
+ protected void fillModules(Domain current)
+ {
+ Domain parent = current.getParentDomain();
+ boolean parentFirst = current.isParentFirst();
+
+ if (parent != null && parentFirst)
+ fillModules(parent);
+
+ Collection<ExportPackage> eps = current.getExportedPackages(requirement.getName(), requirement.getVersionRange());
+ if (eps != null && eps.isEmpty() == false)
+ {
+ boolean isAncestor = (current != domain);
+ boolean isParentFirst = domain.isParentFirst();
+ for (ExportPackage ep : eps)
+ {
+ Module m = ep.getModule();
+ addModule(m, isAncestor, isParentFirst);
+ }
+ }
+
+ if (parent != null && parentFirst == false)
+ fillModules(parent);
+ }
+
+ /**
* Get BaseClassLoader from module.
*
* @param context the context
More information about the jboss-cvs-commits
mailing list