[jboss-cvs] JBossAS SVN: r69878 - in projects/microcontainer/trunk: classloading and 46 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 18 08:30:10 EST 2008


Author: adrian at jboss.org
Date: 2008-02-18 08:30:09 -0500 (Mon, 18 Feb 2008)
New Revision: 69878

Added:
   projects/microcontainer/trunk/classloading/
   projects/microcontainer/trunk/classloading/.classpath
   projects/microcontainer/trunk/classloading/.project
   projects/microcontainer/trunk/classloading/.settings/
   projects/microcontainer/trunk/classloading/.settings/org.eclipse.jdt.core.prefs
   projects/microcontainer/trunk/classloading/pom.xml
   projects/microcontainer/trunk/classloading/src/
   projects/microcontainer/trunk/classloading/src/etc/
   projects/microcontainer/trunk/classloading/src/etc/default.mf
   projects/microcontainer/trunk/classloading/src/main/
   projects/microcontainer/trunk/classloading/src/main/org/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/DefaultClassLoadingMetaDataFactory.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleCapability.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleRequirement.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageCapability.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageRequirement.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/UsesPackageRequirement.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/VersionValueAdapter.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/ClassLoading.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Domain.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/helpers/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/helpers/ClassLoadingMetaDataModule.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoadingMetaData.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionRangeSupport.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionSupport.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/CapabilitiesMetaData.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Capability.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData10.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactory.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactoryBuilder.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportAll.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportPackages.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Requirement.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/RequirementsMetaData.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractCapability.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractRequirement.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/package-info.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/Version.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparator.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparatorRegistry.java
   projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionRange.java
   projects/microcontainer/trunk/classloading/src/resources/
   projects/microcontainer/trunk/classloading/src/resources/tests/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportImportMixed.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleNoVersion.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleVersioned.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageNoVersion.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageVersioned.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreeModules.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreePackages.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleNoVersion.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleVersioned.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageNoVersion.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageVersioned.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreeModules.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreePackages.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportVersionRange.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleBlackList.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleCache.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleDomain.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcluded.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcludedExport.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExportAll.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleImportAll.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleIncluded.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleJ2seClassLoadingCompliance.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleName.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleParentDomain.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleVersion.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/OptionalRequirement.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ReExportRequirement.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/UsesRequirement.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardCapability.xml
   projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardRequirement.xml
   projects/microcontainer/trunk/classloading/src/tests/
   projects/microcontainer/trunk/classloading/src/tests/org/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTest.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTestWithSecurity.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/ClassLoadingAllTestSuite.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/DependencyTestSuite.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/a/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/a/A.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/b/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/b/B.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/c/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/c/C.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/AbstractMockClassLoaderUnitTest.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DependencyUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DomainUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ImportAllUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/MockClassLoadingMetaDataUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ModuleDependencyUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportModuleUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportPackageUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/UsesPackageUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/MetaDataTestSuite.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/CapabilitiesMetaDataUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataFactoryUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleCapabilityUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleRequirementUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionRangeUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageCapabilityUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageRequirementUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/RequirementsMetaDataUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/AbstractJBossXBTest.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/JBossXBTestDelegate.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/SchemaPrinter.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/TestSchemaResolver.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestCapability.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestRequirement.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/package-info.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/test/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/test/ClassLoadingMetaDataXmlUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/VersionTestSuite.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersion.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersionToMyVersionComparator.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToMyVersionComparator.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToStringComparator.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToVersionComparator.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToStringComparator.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToVersionComparator.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionComparatorRegistryUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionRangeUnitTestCase.java
   projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionUnitTestCase.java
Log:
Initial Import

Added: projects/microcontainer/trunk/classloading/.classpath
===================================================================
--- projects/microcontainer/trunk/classloading/.classpath	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/.classpath	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main"/>
+	<classpathentry excluding="**/*.java" kind="src" output="target/tests-classes" path="src/resources/tests"/>
+	<classpathentry kind="src" output="target/tests-classes" path="src/tests"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-classloading-spi/5.0.0.Beta3/jboss-classloading-spi-5.0.0.Beta3.jar" sourcepath="M2_REPO/org/jboss/jboss-classloading-spi/5.0.0.Beta3/jboss-classloading-spi-5.0.0.Beta3-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.3.GA/jboss-common-core-2.2.3.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.3.GA/jboss-common-core-2.2.3.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar" sourcepath="M2_REPO/ant/ant/1.6.5/ant-1.6.5-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
+   <classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
+   <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.0/jaxb-api-2.0.jar"/>
+   <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jsr173_api/1.0/jsr173_api-1.0.jar"/>
+   <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1/activation-1.1.jar" sourcepath="M2_REPO/javax/activation/activation/1.1/activation-1.1-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.3.GA/jboss-logging-spi-2.0.3.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.3.GA/jboss-logging-spi-2.0.3.GA-sources.jar"/>
+   <classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.0.CR5/jbossxb-2.0.0.CR5.jar"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/jboss-classloader"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/jboss-container"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/jboss-dependency"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/jboss-kernel"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: projects/microcontainer/trunk/classloading/.project
===================================================================
--- projects/microcontainer/trunk/classloading/.project	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/.project	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>jboss-classloading</name>
+  <comment>JBoss ClassLoading</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>

Added: projects/microcontainer/trunk/classloading/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/microcontainer/trunk/classloading/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/.settings/org.eclipse.jdt.core.prefs	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,5 @@
+#Fri Sep 21 17:50:00 BST 2007
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5

Added: projects/microcontainer/trunk/classloading/pom.xml
===================================================================
--- projects/microcontainer/trunk/classloading/pom.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/pom.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,73 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.microcontainer</groupId>
+    <artifactId>jboss-microcontainer</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-classloading</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss Microcontainer ClassLoading</name>
+  <url>http://www.jboss.com/products/jbossmc</url>
+  <description>JBoss ClassLoading</description>
+  <build>
+    <testResources>
+      <testResource>
+        <directory>src/resources/tests</directory>
+      </testResource>
+    </testResources>
+  </build>
+  <!-- Do not add version information here, use ../build/pom.xml instead -->
+  <dependencies>
+    <!-- Global dependencies -->
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-container</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-dependency</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-classloader</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>jboss</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+	  <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-test</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+	    <groupId>junit</groupId>
+	    <artifactId>junit</artifactId>
+    </dependency>
+  </dependencies>  
+</project>

Added: projects/microcontainer/trunk/classloading/src/etc/default.mf
===================================================================
--- projects/microcontainer/trunk/classloading/src/etc/default.mf	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/etc/default.mf	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Created-By: @java.vm.version@ (@java.vm.vendor@)
+Specification-Title: @specification.title@
+Specification-Version: @specification.version@
+Specification-Vendor: @specification.vendor@
+Implementation-Title: @implementation.title@
+Implementation-URL: @implementation.url@
+Implementation-Version: @implementation.version@
+Implementation-Vendor: @implementation.vendor@
+Implementation-Vendor-Id: @implementation.vendor.id@

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/DefaultClassLoadingMetaDataFactory.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/DefaultClassLoadingMetaDataFactory.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/DefaultClassLoadingMetaDataFactory.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.plugins.metadata;
+
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * DefaultClassLoadingMetaDataFactory.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultClassLoadingMetaDataFactory extends ClassLoadingMetaDataFactory
+{
+   public Capability createModule(String name, Object version)
+   {
+      return new ModuleCapability(name, version);
+   }
+
+   public Requirement createRequireModule(String name, VersionRange versionRange, boolean optional, boolean reExport)
+   {
+      ModuleRequirement result = new ModuleRequirement(name, versionRange);
+      result.setOptional(optional);
+      result.setReExport(reExport);
+      return result;
+   }
+
+   public Capability createPackage(String name, Object version)
+   {
+      return new PackageCapability(name, version);
+   }
+
+   public Requirement createRequirePackage(String name, VersionRange versionRange, boolean optional, boolean reExport)
+   {
+      PackageRequirement result = new PackageRequirement(name, versionRange);
+      result.setOptional(optional);
+      result.setReExport(reExport);
+      return result;
+   }
+
+   public Requirement createUsesPackage(String name, VersionRange versionRange, boolean reExport)
+   {
+      UsesPackageRequirement result = new UsesPackageRequirement(name, versionRange);
+      result.setReExport(reExport);
+      return result;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleCapability.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleCapability.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleCapability.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,89 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.plugins.metadata;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.helpers.AbstractCapability;
+
+/**
+ * ModuleCapability.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModuleCapability extends AbstractCapability implements Capability
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -5444212755644141118L;
+
+   /**
+    * Create a new ModuleCapability.
+    */
+   public ModuleCapability()
+   {
+   }
+   
+   /**
+    * Create a new ModuleCapability with the default version
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public ModuleCapability(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Create a new ModuleCapability.
+    * 
+    * @param name the name
+    * @param version the version - pass null for default version
+    * @throws IllegalArgumentException for a null name
+    */
+   public ModuleCapability(String name, Object version)
+   {
+      super(name, version);
+   }
+
+   public boolean resolves(Module module, Requirement requirement)
+   {
+      if (requirement instanceof ModuleRequirement == false)
+         return false;
+      ModuleRequirement moduleRequirement = (ModuleRequirement) requirement;
+      if (getName().equals(moduleRequirement.getName()) == false)
+         return false;
+      return moduleRequirement.getVersionRange().isInRange(getVersion());
+   }
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof ModuleCapability == false)
+         return false;
+      return super.equals(obj);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleRequirement.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleRequirement.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/ModuleRequirement.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,86 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.plugins.metadata;
+
+import org.jboss.classloading.spi.metadata.helpers.AbstractRequirement;
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * ModuleRequirement.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModuleRequirement extends AbstractRequirement
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -7108063877472769918L;
+
+   /**
+    * Create a new ModuleRequirement.
+    */
+   public ModuleRequirement()
+   {
+   }
+   
+   /**
+    * Create a new ModuleRequirement with no version constraint
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public ModuleRequirement(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Create a new ModuleRequirement.
+    * 
+    * @param name the name
+    * @param versionRange the version range - pass null for all versions
+    * @throws IllegalArgumentException for a null name
+    */
+   public ModuleRequirement(String name, VersionRange versionRange)
+   {
+      super(name, versionRange);
+   }
+
+   /**
+    * For module requirements we want re-exports
+    */
+   @Override
+   public boolean wantReExports()
+   {
+      return true;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof ModuleRequirement == false)
+         return false;
+      return super.equals(obj);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageCapability.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageCapability.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageCapability.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,97 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.plugins.metadata;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.metadata.ExportPackages;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.helpers.AbstractCapability;
+
+/**
+ * PackageCapability.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PackageCapability extends AbstractCapability implements ExportPackages
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -1586959469453286396L;
+
+   /**
+    * Create a new PackageCapability.
+    */
+   public PackageCapability()
+   {
+   }
+   
+   /**
+    * Create a new PackageCapability with the default version
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public PackageCapability(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Create a new PackageCapability.
+    * 
+    * @param name the name
+    * @param version the version - pass null for default version
+    * @throws IllegalArgumentException for a null name
+    */
+   public PackageCapability(String name, Object version)
+   {
+      super(name, version);
+   }
+
+   public boolean resolves(Module module, Requirement requirement)
+   {
+      if (requirement instanceof PackageRequirement == false)
+         return false;
+      PackageRequirement requirePackage = (PackageRequirement) requirement;
+      if (getName().equals(requirePackage.getName()) == false)
+         return false;
+      return requirePackage.getVersionRange().isInRange(getVersion());
+   }
+   
+   public Set<String> getPackageNames(Module module)
+   {
+      return Collections.singleton(getName());
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof PackageCapability == false)
+         return false;
+      return super.equals(obj);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageRequirement.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageRequirement.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/PackageRequirement.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.plugins.metadata;
+
+import org.jboss.classloading.spi.metadata.helpers.AbstractRequirement;
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * PackageRequirement.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PackageRequirement extends AbstractRequirement
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -7552921085464308835L;
+
+   /**
+    * Create a new PackageRequirement.
+    */
+   public PackageRequirement()
+   {
+   }
+   
+   /**
+    * Create a new PackageRequirement with no version constraint
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public PackageRequirement(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Create a new PackageRequirement.
+    * 
+    * @param name the name
+    * @param versionRange the version range - pass null for all versions
+    * @throws IllegalArgumentException for a null name
+    */
+   public PackageRequirement(String name, VersionRange versionRange)
+   {
+      super(name, versionRange);
+   }
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof PackageRequirement == false)
+         return false;
+      return super.equals(obj);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/UsesPackageRequirement.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/UsesPackageRequirement.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/UsesPackageRequirement.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.plugins.metadata;
+
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * UsesPackageRequirement.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class UsesPackageRequirement extends PackageRequirement
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -7552921085464308835L;
+
+   /**
+    * Create a new UsesPackageRequirement.
+    */
+   public UsesPackageRequirement()
+   {
+      init();
+   }
+   
+   /**
+    * Create a new UsesPackageRequirement with no version constraint
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public UsesPackageRequirement(String name)
+   {
+      super(name);
+      init();
+   }
+   
+   /**
+    * Create a new UsesPackageRequirement.
+    * 
+    * @param name the name
+    * @param versionRange the version range - pass null for all versions
+    * @throws IllegalArgumentException for a null name
+    */
+   public UsesPackageRequirement(String name, VersionRange versionRange)
+   {
+      super(name, versionRange);
+      init();
+   }
+   
+   /**
+    * Initialise the requirement
+    */
+   protected void init()
+   {
+      setOptional(true);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/VersionValueAdapter.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/VersionValueAdapter.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/plugins/metadata/VersionValueAdapter.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.plugins.metadata;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.xb.binding.sunday.unmarshalling.ValueAdapter;
+
+/**
+ * VersionXmlJavaTypeAdapter.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VersionValueAdapter implements ValueAdapter
+{
+   @SuppressWarnings("unchecked")
+   public Object cast(Object o, Class c)
+   {
+      return Version.parseVersion((String) o);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/ClassLoading.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/ClassLoading.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/ClassLoading.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,81 @@
+/*
+ * 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.classloading.spi.dependency;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+
+/**
+ * ClassLoading.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoading
+{
+   /** The classloading domains by name */
+   private Map<String, Domain> domains = new ConcurrentHashMap<String, Domain>();
+   
+   /**
+    * Add a module
+    * 
+    * @param module the module
+    * @throws IllegalArgumentException for a null module
+    */
+   public void addModule(Module module)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      
+      String domainName = module.getDeterminedDomainName();
+      if (domainName == null)
+         domainName = ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
+      
+      Domain domain;
+      synchronized (domains)
+      {
+         domain = domains.get(domainName);
+         if (domain == null)
+         {
+            domain = new Domain(domainName);
+            domains.put(domainName, domain);
+         }
+      }
+      
+      domain.addModule(module);
+   }
+   
+   /**
+    * Remove a module
+    * 
+    * @param module the module
+    * @throws IllegalArgumentException for a null module
+    */
+   public void removeModule(Module module)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      module.release();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Domain.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Domain.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Domain.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,164 @@
+/*
+ * 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.classloading.spi.dependency;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.dependency.spi.Controller;
+
+/**
+ * Domain.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Domain
+{
+   /** The domain name */
+   private String name;
+   
+   /** 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 name the name
+    * @throws IllegalArgumentException for a null domain
+    */
+   public Domain(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      this.name = name;
+   }
+
+   /**
+    * Get the name.
+    * 
+    * @return the name.
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Add a module
+    * 
+    * @param module the module
+    * @throws IllegalStateException if the module is already registered
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public synchronized void addModule(Module module)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      Domain domain = module.getDomain();
+      if (domain != null)
+         throw new IllegalArgumentException("The module is already registered with the domain " + domain.getName());
+      String contextName = module.getContextName();
+      if (modulesByName.containsKey(contextName))
+         throw new IllegalArgumentException("The context " + contextName + " is already registered in domain " + getName());
+      module.setDomain(this);
+      modulesByName.put(contextName, module);
+      modules.add(module);
+      try
+      {
+         module.createDependencies();
+      }
+      catch (Throwable t)
+      {
+         removeModule(module);
+         if (t instanceof RuntimeException)
+            throw (RuntimeException) t;
+         else if (t instanceof Error)
+            throw (Error) t;
+         else
+            throw new RuntimeException("Error adding module " + module, t);
+      }
+   }
+
+   /**
+    * Get a module for a context name
+    * 
+    * @param name the context name
+    * @return the module
+    */
+   protected Module getModule(String name)
+   {
+      return modulesByName.get(name);
+   }
+   
+   /**
+    * Resolve the requirement
+    * 
+    * @param controller the controller
+    * @param module the module
+    * @param requirement the requirement
+    * @return the resolved name or null if not resolved
+    */
+   protected Object resolve(Controller controller, Module module, Requirement requirement)
+   {
+      // TODO JBMICROCONT-182 include parent domains in requirements
+      // TODO JBMICROCONT-182 check consistency of re-exports
+      // TODO JBMICROCONT-182 check for self-dependency
+      // TODO JBMICROCONT-182 test circularity
+      for (Module other : modules)
+      {
+         List<Capability> capabilities = other.getCapabilities();
+         if (capabilities != null)
+         {
+            for (Capability capability : capabilities)
+            {
+               if (capability.resolves(module, requirement))
+                  return other.getContextName();
+            }
+         }
+      }
+      return null;
+   }
+   
+   /**
+    * Remove a deployment
+    * 
+    * @param module the module
+    * @throws IllegalArgumentException for a null parameter
+    */
+   protected synchronized void removeModule(Module module)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      modulesByName.remove(module.getContextName());
+      modules.remove(module);
+      module.setDomain(null);
+      module.removeDependencies();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,578 @@
+/*
+ * 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.classloading.spi.dependency;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.DelegateLoader;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.spi.helpers.NameAndVersionSupport;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.metadata.ExportPackages;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Module.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class Module extends NameAndVersionSupport
+{
+   /** The context name */
+   private String contextName;
+   
+   /** Our cached capabilities */
+   private List<Capability> capabilities;
+
+   /** The controller context */
+   private ControllerContext context;
+
+   /** The domain */
+   private Domain domain;
+
+   /** The requirements */
+   private List<RequirementDependencyItem> requirementDependencies;
+   
+   /**
+    * Create a new Module with the default version
+    *
+    * @param name the name
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public Module(String name)
+   {
+      this(name, name, null);
+   }
+   
+   /**
+    * Create a new Module with the given version
+    *
+    * @param name the name
+    * @param version pass null for the default version
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public Module(String name, Object version)
+   {
+      this(name, name, version);
+   }
+   
+   /**
+    * Create a new Module with the given version
+    *
+    * @param name the name
+    * @param contextName the real name of the module in the controller
+    * @param version pass null for the default version
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public Module(String name, String contextName, Object version)
+   {
+      super(name, version);
+      if (contextName == null)
+         contextName = name + version.toString();
+      this.contextName = contextName;
+   }
+
+   /**
+    * Get the context name
+    * 
+    * @return the context name
+    */
+   public String getContextName()
+   {
+      return contextName;
+   }
+   
+   /**
+    * Get the domain.
+    * 
+    * @return the domain.
+    */
+   Domain getDomain()
+   {
+      return domain;
+   }
+
+   void setDomain(Domain domain)
+   {
+      this.domain = domain;
+   }
+
+   Domain checkDomain()
+   {
+      Domain result = domain;
+      if (result == null)
+         throw new IllegalStateException("Domain is not set for " + this);
+      return result;
+   }
+   
+   /**
+    * Get the domain name.
+    * 
+    * @return the domain name.
+    */
+   public String getDomainName()
+   {
+      return null;
+   }
+
+   /**
+    * Get the determined domain name.
+    * 
+    * @return the determined domain.
+    */
+   public String getDeterminedDomainName()
+   {
+      String domainName = getDomainName();
+      if (domainName == null)
+         domainName = ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
+      return domainName;
+   }
+
+   /**
+    * Get the parent domain name.
+    * 
+    * @return the parent domain name.
+    */
+   public String getParentDomainName()
+   {
+      return null;
+   }
+
+   /**
+    * Get the determined parentDomain name.
+    * 
+    * @return the parentDomain.
+    */
+   public String getDeterminedParentDomainName()
+   {
+      String parentDomain = getParentDomainName();
+      if (parentDomain == null)
+      {
+         if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(getDeterminedDomainName()) == false)
+            return ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
+      }
+      return parentDomain;
+   }
+
+   /**
+    * Get the export all for the module
+    * 
+    * @return the export all
+    */
+   public ExportAll getExportAll()
+   {
+      return null;
+   }
+
+   /**
+    * Get a filter for the included packages
+    * 
+    * @return the excluded packages
+    */
+   public ClassFilter getIncluded()
+   {
+      return null;
+   }
+
+   /**
+    * Get a filter for the excluded packages
+    * 
+    * @return the excluded packages
+    */
+   public ClassFilter getExcluded()
+   {
+      return null;
+   }
+
+   /**
+    * Get a filter for the excluded export packages
+    * 
+    * @return the excluded packages
+    */
+   public ClassFilter getExcludedExport()
+   {
+      return null;
+   }
+
+   /**
+    * Get the import all for the module
+    * 
+    * @return the import all
+    */
+   public boolean isImportAll()
+   {
+      return false;
+   }
+
+   /**
+    * Get delegate policy
+    * 
+    * @return the delegation policy
+    */
+   public boolean isJ2seClassLoadingCompliance()
+   {
+      return true;
+   }
+
+   public ParentPolicy getDeterminedParentPolicy()
+   {
+      if (isJ2seClassLoadingCompliance())
+         return ParentPolicy.BEFORE;
+      else
+         return ParentPolicy.AFTER_BUT_JAVA_BEFORE;
+   }
+   
+   /**
+    * Whether to cache<p>
+    * 
+    * @return true to cache
+    */
+   protected boolean isCacheable()
+   {
+      return true;
+   }
+
+   /**
+    * Whether to cache misses<p>
+    * 
+    * @return true to cache misses
+    */
+   protected boolean isBlackListable()
+   {
+      return true;
+   }
+
+   /**
+    * Get the delegate loaders for this module
+    * 
+    * @return the delegates
+    */
+   public List<? extends DelegateLoader> getDelegates()
+   {
+      if (requirementDependencies == null || requirementDependencies.isEmpty())
+         return null;
+
+      List<DelegateLoader> result = new CopyOnWriteArrayList<DelegateLoader>();
+      Set<Module> visited = new HashSet<Module>();
+      addDelegates(this, result, visited, false);
+      return result;
+   }
+   
+   /**
+    * Get the dependency items
+    * 
+    * @return the depenency items
+    */
+   protected List<RequirementDependencyItem> getRequirementDependencyItems()
+   {
+      return requirementDependencies;
+   }
+   
+   protected void addDelegates(Module module, List<DelegateLoader> delegates, Set<Module> visited, boolean reExport)
+   {
+      // Check whether we already did this module
+      if (visited.contains(module))
+         return;
+      visited.add(module);
+      
+      List<RequirementDependencyItem> dependencies = module.getRequirementDependencyItems();
+      if (dependencies == null || dependencies.isEmpty())
+         return;
+      
+      for (RequirementDependencyItem item : dependencies)
+      {
+         Requirement requirement = item.getRequirement();
+         
+         // If we are looking at everything or this is a re-export
+         if (reExport == false || requirement.isReExport());
+         {
+            // Sanity checks
+            if (item.isResolved() == false)
+               throw new IllegalStateException("Item not resolved: " + item);
+            String name = (String) item.getIDependOn();
+            if (name == null)
+            {
+               // Optional requirement, just ignore
+               if (requirement.isOptional())
+                  continue;
+               // Something has gone wrong
+               throw new IllegalStateException("No iDependOn for item: " + item);
+            }
+            Module iDependOnModule = checkDomain().getModule(name);
+            if (module == null)
+               throw new IllegalStateException("Module not found with name: " + name);
+
+            // Determine the delegate loader for the module
+            Module other = item.getModule();
+            DelegateLoader delegate = iDependOnModule.getDelegateLoader(other, requirement);
+
+            // Check for re-export by the module
+            if (requirement.wantReExports())
+               addDelegates(iDependOnModule, delegates, visited, true);
+            
+            // We want a module's re-exports (i.e. part of its imports) before the module itself
+            if (delegate != null)
+               delegates.add(delegate);
+         }
+      }
+   }
+   
+   /**
+    * Get the delegate loader
+    * 
+    * @param requiringModule the requiring module
+    * @param requirement the requirement
+    * @return the delegate loader
+    */
+   public abstract DelegateLoader getDelegateLoader(Module requiringModule, Requirement requirement);
+
+   /**
+    * Get the capabilities.
+    * 
+    * @return the capabilities.
+    */
+   public List<Capability> getCapabilities()
+   {
+      // Have we already worked this out?
+      if (capabilities != null)
+         return capabilities;
+      
+      // Are there any configured ones?
+      List<Capability> capabilities = determineCapabilities();
+      
+      // Use the defaults
+      if (capabilities == null)
+         capabilities = defaultCapabilities();
+      
+      // Cache it
+      this.capabilities = capabilities;
+      return capabilities;
+   }
+
+   /**
+    * Determine the capabilities
+    * 
+    * @return the capabilities
+    */
+   protected List<Capability> determineCapabilities()
+   {
+      return null;
+   }
+
+   /**
+    * Determine the default capabilities.<p>
+    * 
+    * By default it is just the module capability
+    * 
+    * @return the capabilities
+    */
+   protected List<Capability> defaultCapabilities()
+   {
+      List<Capability> capabilities = new CopyOnWriteArrayList<Capability>();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Capability capability = factory.createModule(getName(), getVersion());
+      capabilities.add(capability);
+      return capabilities;
+   }
+
+   /**
+    * Get the package names
+    * 
+    * @return the package names
+    */
+   public String[] getPackageNames()
+   {
+      List<String> packageNames = new ArrayList<String>();
+
+      List<Capability> capabilities = getCapabilities();
+      if (capabilities != null && capabilities.isEmpty() == false)
+      {
+         for (Capability capability : capabilities)
+         {
+            if (capability instanceof ExportPackages)
+            {
+               ExportPackages exported = (ExportPackages) capability;
+               Set<String> exportPackages = exported.getPackageNames(this);
+               if (exportPackages != null)
+                  packageNames.addAll(exportPackages);
+            }
+         }
+      }
+
+      List<Requirement> requirements = getRequirements();
+      if (requirements != null && requirements.isEmpty() == false)
+      {
+         for (Requirement requirement : getRequirements())
+         {
+            if (requirement instanceof ExportPackages)
+            {
+               ExportPackages exported = (ExportPackages) requirement;
+               Set<String> exportPackages = exported.getPackageNames(this);
+               if (exportPackages != null)
+                  packageNames.addAll(exportPackages);
+            }
+         }
+      }
+
+      return packageNames.toArray(new String[packageNames.size()]);
+   }
+   
+   /**
+    * Get the state for the classloader
+    * 
+    * @return the state
+    */
+   public ControllerState getClassLoaderState()
+   {
+      return ControllerState.INSTALLED;
+   }
+
+   /**
+    * Get the requirements.
+    * 
+    * @return the requirements.
+    */
+   public List<Requirement> getRequirements()
+   {
+      return Collections.emptyList();
+   }
+
+   /**
+    * Create the dependencies for the module
+    */
+   protected void createDependencies()
+   {
+      ControllerState classLoaderState = getClassLoaderState();
+      
+      List<Requirement> requirements = getRequirements();
+      if (requirements != null)
+      {
+         requirementDependencies = new ArrayList<RequirementDependencyItem>();
+         for (Requirement requirement : requirements)
+         {
+            RequirementDependencyItem item = new RequirementDependencyItem(this, requirement, classLoaderState);
+            addIDependOn(item);
+            requirementDependencies.add(item);
+         }
+      }
+   }
+
+   /**
+    * Remove dependencies
+    */
+   protected void removeDependencies()
+   {
+      if (requirementDependencies != null && requirementDependencies.isEmpty() == false)
+      {
+         for (RequirementDependencyItem item : requirementDependencies)
+            removeIDependOn(item);
+      }
+      requirementDependencies = null;
+   }
+
+   /**
+    * Set the controller context
+    * 
+    * @param context the context
+    */
+   protected void setControllerContext(ControllerContext context)
+   {
+      this.context = context;
+   }
+   
+   /**
+    * Add a dependency
+    * 
+    * @param item the dependency item
+    */
+   protected void addIDependOn(RequirementDependencyItem item)
+   {
+      if (context == null)
+         throw new IllegalStateException("No controller context");
+      context.getDependencyInfo().addIDependOn(item);
+   }
+   
+   /**
+    * Remove a dependency
+    * 
+    * @param item the dependency item
+    */
+   protected void removeIDependOn(RequirementDependencyItem item)
+   {
+      if (context == null)
+         throw new IllegalStateException("No controller context");
+      context.getDependencyInfo().removeIDependOn(item);
+   }
+   
+   /**
+    * Resolve the requirement
+    * 
+    * @param controller the controller
+    * @param requirement the requirement
+    * @return the resolved name or null if not resolved
+    */
+   protected Object resolve(Controller controller, Requirement requirement)
+   {
+      return checkDomain().resolve(controller, this, requirement);
+   }
+   
+   /**
+    * Release the module
+    */
+   public void release()
+   {
+      checkDomain().removeModule(this);
+      reset();
+   }
+   
+   /**
+    * Reset the module
+    */
+   protected void reset()
+   {
+      this.context = null;
+      this.capabilities = null;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof Module == false)
+         return false;
+      return super.equals(obj);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,146 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.dependency;
+
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * RequirementDependencyItem.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RequirementDependencyItem extends AbstractDependencyItem
+{
+   /** The module */
+   private Module module;
+   
+   /** The requirement */
+   private Requirement requirement;
+
+   /**
+    * Create a new RequirementDependencyItem.
+    * 
+    * @param module the module
+    * @param requirement the requirement
+    * @param state when the dependency is required and the state of the required dependency
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public RequirementDependencyItem(Module module, Requirement requirement, ControllerState state)
+   {
+      this(module, requirement, state, state);
+   }
+   
+   /**
+    * Create a new RequirementDependencyItem.
+    * 
+    * @param module the module
+    * @param requirement the requirement
+    * @param whenRequired when the dependency is required
+    * @param dependentState the state required of the dependency
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public RequirementDependencyItem(Module module, Requirement requirement, ControllerState whenRequired, ControllerState dependentState)
+   {
+      super(module != null ? module.getContextName() : null, null, whenRequired, dependentState);
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      if (requirement == null)
+         throw new IllegalArgumentException("Null requirement");
+      this.module = module;
+      this.requirement = requirement;
+   }
+   
+   /**
+    * Get the module.
+    * 
+    * @return the module.
+    */
+   public Module getModule()
+   {
+      return module;
+   }
+
+   /**
+    * Get the requirement.
+    * 
+    * @return the requirement.
+    */
+   public Requirement getRequirement()
+   {
+      return requirement;
+   }
+
+   public boolean resolve(Controller controller)
+   {
+      Requirement requirement = getRequirement();
+      Object iDependOn = getModule().resolve(controller, requirement);
+      if (iDependOn != null)
+      {
+         ControllerContext context = controller.getContext(iDependOn, getDependentState());
+         if (context != null)
+         {
+            setIDependOn(context.getName());
+            addDependsOnMe(controller, context);
+            setResolved(true);
+         }
+         else
+         {
+            setResolved(false);
+         }
+      }
+      else
+      {
+         // Optional requirement
+         if (requirement.isOptional())
+            setResolved(true);
+      }
+      return isResolved();
+   }
+
+   public void unresolved()
+   {
+      setIDependOn(null);
+      setResolved(false);
+   }
+   
+   public void toString(JBossStringBuilder buffer)
+   {
+      super.toString(buffer);
+      buffer.append(" requirement=").append(getRequirement());
+   }
+   
+   public void toShortString(JBossStringBuilder buffer)
+   {
+      buffer.append(getName()).append(" ").append(getRequirement());
+   }
+
+   public String toHumanReadableString()
+   {
+      return getRequirement().toString();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/helpers/ClassLoadingMetaDataModule.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/helpers/ClassLoadingMetaDataModule.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/helpers/ClassLoadingMetaDataModule.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,167 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.dependency.helpers;
+
+import java.util.List;
+
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.metadata.Requirement;
+
+/**
+ * ClassLoadingMetaDataModule.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ClassLoadingMetaDataModule extends Module
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -1834649865956381804L;
+   
+   /** The classloading metadata */
+   private ClassLoadingMetaData classLoadingMetaData;
+
+   /**
+    * Determine the name from the classloading metadta
+    * 
+    * @param classLoadingMetaData the classloading metadata
+    * @return the name
+    */
+   private static String determineName(ClassLoadingMetaData classLoadingMetaData)
+   {
+      if (classLoadingMetaData == null)
+         throw new IllegalArgumentException("Null classLoading metadata");
+      return classLoadingMetaData.getName();
+   }
+
+   /**
+    * Determine the version from the classloading metadta
+    * 
+    * @param classLoadingMetaData the classloading metadata
+    * @return the version
+    */
+   private static Object determineVersion(ClassLoadingMetaData classLoadingMetaData)
+   {
+      if (classLoadingMetaData == null)
+         throw new IllegalArgumentException("Null classLoading metadata");
+      return classLoadingMetaData.getVersion();
+   }
+   
+   /**
+    * Create a new ClassLoadingMetaDataModule.
+    * 
+    * @param classLoadingMetaData the classLoading metadata
+    * @param contextName the context name 
+    * @throws IllegalArgumentException for null classloading metadata
+    */
+   public ClassLoadingMetaDataModule(ClassLoadingMetaData classLoadingMetaData, String contextName)
+   {
+      super(determineName(classLoadingMetaData), contextName, determineVersion(classLoadingMetaData));
+      this.classLoadingMetaData = classLoadingMetaData;
+   }
+
+   /**
+    * Get the classloading metadata
+    *  
+    * @return the metadata
+    */
+   protected ClassLoadingMetaData getClassLoadingMetaData()
+   {
+      return classLoadingMetaData;
+   }
+   
+   @Override
+   public String getDomainName()
+   {
+      return classLoadingMetaData.getDomain();
+   }
+
+   @Override
+   public String getParentDomainName()
+   {
+      return classLoadingMetaData.getParentDomain();
+   }
+
+   @Override
+   public ExportAll getExportAll()
+   {
+      return classLoadingMetaData.getExportAll();
+   }
+
+   @Override
+   public ClassFilter getIncluded()
+   {
+      return classLoadingMetaData.getIncluded();
+   }
+
+   @Override
+   public ClassFilter getExcluded()
+   {
+      return classLoadingMetaData.getExcluded();
+   }
+
+   @Override
+   public ClassFilter getExcludedExport()
+   {
+      return classLoadingMetaData.getExcludedExport();
+   }
+
+   @Override
+   public boolean isImportAll()
+   {
+      return classLoadingMetaData.isImportAll();
+   }
+
+   @Override
+   public boolean isJ2seClassLoadingCompliance()
+   {
+      return classLoadingMetaData.isJ2seClassLoadingCompliance();
+   }
+
+   @Override
+   public boolean isCacheable()
+   {
+      return classLoadingMetaData.isCacheable();
+   }
+
+   @Override
+   public boolean isBlackListable()
+   {
+      return classLoadingMetaData.isBlackListable();
+   }
+
+   @Override
+   protected List<Capability> determineCapabilities()
+   {
+      return classLoadingMetaData.getCapabilities().getCapabilities();
+   }
+
+   @Override
+   public List<Requirement> getRequirements()
+   {
+      return classLoadingMetaData.getRequirements().getRequirements();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,121 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.dependency.policy;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.DelegateLoader;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.dependency.helpers.ClassLoadingMetaDataModule;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.Requirement;
+
+/**
+ * ClassLoaderPolicyModule.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ClassLoaderPolicyModule extends ClassLoadingMetaDataModule
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -3357427104777457717L;
+   
+   /** Our cached policy */
+   private ClassLoaderPolicy policy;
+   
+   /** The classloader system we are registered with */
+   private ClassLoaderSystem system;
+
+   /**
+    * Create a new ClassLoaderPolicyModule.
+    * 
+    * @param classLoadingMetaData the classloading metadata
+    * @param contextName the context name
+    */
+   public ClassLoaderPolicyModule(ClassLoadingMetaData classLoadingMetaData, String contextName)
+   {
+      super(classLoadingMetaData, contextName);
+   }
+   
+   /**
+    * Register the classloader policy with a classloader system
+    *
+    * @param system the classloader system
+    * @return the classloader
+    */
+   public ClassLoader registerClassLoaderPolicy(ClassLoaderSystem system)
+   {
+      if (system == null)
+         throw new IllegalArgumentException("Null classloader system");
+      
+      String domainName = getDeterminedDomainName();
+      ParentPolicy parentPolicy = getDeterminedParentPolicy();
+      String parentName = getDeterminedParentDomainName();
+      ClassLoader result = system.registerClassLoaderPolicy(domainName, parentPolicy, parentName, getPolicy());
+      this.system = system;
+      return result;
+   }
+
+   /**
+    * Get the policy
+    * 
+    * @return the policy
+    */
+   public ClassLoaderPolicy getPolicy()
+   {
+      if (policy != null)
+         return policy;
+      policy = determinePolicy();
+      return policy;
+   }
+
+   public void removeClassLoader()
+   {
+      if (system != null && policy != null)
+         system.unregisterClassLoaderPolicy(policy);
+      system = null;
+      policy = null;
+   }
+   
+   /**
+    * Determine the classloader policy
+    * 
+    * @return the policy
+    */
+   protected abstract ClassLoaderPolicy determinePolicy();
+   
+   @Override
+   public DelegateLoader getDelegateLoader(Module requiringModule, Requirement requirement)
+   {
+      return getPolicy().getExported();
+   }
+
+   @Override
+   protected void reset()
+   {
+      super.reset();
+      system = null;
+      policy = null;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.dependency.policy.mock;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.test.support.MockClassLoaderHelper;
+import org.jboss.classloader.test.support.MockClassLoaderPolicy;
+import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
+
+/**
+ * VFSClassLoaderPolicyModule.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockClassLoaderPolicyModule extends ClassLoaderPolicyModule implements KernelControllerContextAware
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * Create a new VFSClassLoaderPolicyModule.
+    * 
+    * @param classLoadingMetaData the classloading metadata
+    * @param contextName the context name
+    */
+   public MockClassLoaderPolicyModule(MockClassLoadingMetaData classLoadingMetaData, String contextName)
+   {
+      super(classLoadingMetaData, contextName);
+   }
+
+   @Override
+   protected List<Capability> determineCapabilities()
+   {
+      List<Capability> capabilities = super.determineCapabilities();
+      if (capabilities != null)
+         return capabilities;
+      
+      // We need to work it out
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      capabilities = new CopyOnWriteArrayList<Capability>();
+
+      // We have a module capability
+      Object version = getVersion();
+      Capability capability = factory.createModule(getName(), version);
+      capabilities.add(capability);
+
+      MockClassLoadingMetaData metadata = getClassLoadingMetaData();
+      String[] exported = metadata.getExportedPackages();
+      // Do we determine package capabilities?
+      if (exported != null)
+      {
+         for (String packageName : exported)
+         {
+            capability = factory.createPackage(packageName, version);
+            capabilities.add(capability);
+         }
+      }
+      return capabilities;
+   }
+
+   public void setKernelControllerContext(KernelControllerContext context) throws Exception
+   {
+      setControllerContext(context);
+   }
+
+   public void unsetKernelControllerContext(KernelControllerContext context) throws Exception
+   {
+      setControllerContext(null);
+   }
+
+   @Override
+   protected MockClassLoadingMetaData getClassLoadingMetaData()
+   {
+      return (MockClassLoadingMetaData) super.getClassLoadingMetaData();
+   }
+
+   @Override
+   public MockClassLoaderPolicy getPolicy()
+   {
+      return (MockClassLoaderPolicy) super.getPolicy();
+   }
+   
+   @Override
+   protected MockClassLoaderPolicy determinePolicy()
+   {
+      MockClassLoadingMetaData metaData = getClassLoadingMetaData();
+      MockClassLoaderPolicy policy = MockClassLoaderHelper.createMockClassLoaderPolicy(getContextName());
+      policy.setPrefix(metaData.getPrefix());
+      policy.setPackageNames(getPackageNames());
+      policy.setPaths(metaData.getPaths());
+      policy.setIncluded(metaData.getIncludedClasses());
+      policy.setExcluded(metaData.getExcludedClasses());
+      policy.setImportAll(isImportAll());
+      policy.setDelegates(getDelegates());
+      return policy;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoadingMetaData.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoadingMetaData.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoadingMetaData.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,311 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.dependency.policy.mock;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.version.Version;
+
+/**
+ * MockClassLoadingMetaData.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockClassLoadingMetaData extends ClassLoadingMetaData
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   
+   /** The prefix */
+   private String prefix = "";
+   
+   /** The paths */
+   private String[] paths;
+   
+   /** The included resources */
+   private String[] included;
+   
+   /** The excluded resources */
+   private String[] excluded;
+
+   /** The exported package names */
+   private String[] exported;
+
+   /**
+    * Create a new MockClassLoadingMetaData.
+    * 
+    * @param name the name
+    */
+   public MockClassLoadingMetaData(String name)
+   {
+      this(name, Version.DEFAULT_VERSION);
+   }
+   
+   /**
+    * Create a new MockClassLoadingMetaData.
+    * 
+    * @param name the name
+    * @param version the version
+    */
+   public MockClassLoadingMetaData(String name, String version)
+   {
+      setName(name);
+      setVersion(Version.parseVersion(version));
+   }
+   
+   /**
+    * Create a new MockClassLoadingMetaData.
+    * 
+    * @param name the name
+    * @param version the version
+    */
+   public MockClassLoadingMetaData(String name, Version version)
+   {
+      setName(name);
+      setVersion(version);
+   }
+   
+   /**
+    * Get the prefix.
+    * 
+    * @return the prefix.
+    */
+   public String getPrefix()
+   {
+      return prefix;
+   }
+
+   /**
+    * Set the prefix.
+    * 
+    * @param prefix the prefix.
+    */
+   public void setPrefix(String prefix)
+   {
+      this.prefix = prefix;
+   }
+
+   /**
+    * Get the paths to expose
+    * 
+    * @return the paths
+    */
+   public String[] getPaths()
+   {
+      return paths;
+   }
+   
+   /**
+    * Set the path to expose
+    * 
+    * @param path the path
+    */
+   public void setPath(String path)
+   {
+      setPaths(path);
+   }
+   
+   /**
+    * Set the paths to expose
+    * 
+    * @param paths the paths to expose
+    */
+   public void setPaths(String... paths)
+   {
+      this.paths = paths;
+   }
+   
+   /**
+    * Set the paths to expose
+    * 
+    * @param classes the classes to reference to determine the package paths
+    */
+   public void setPaths(Class<?>... classes)
+   {
+      if (classes == null)
+      {
+         paths = null;
+         return;
+      }
+      paths = new String[classes.length];
+      for (int i = 0; i < classes.length; ++i)
+         paths[i] = ClassLoaderUtils.packageNameToPath(classes[i].getName());
+   }
+
+   public String[] getExportedPackages()
+   {
+      return exported;
+   }
+   
+   /**
+    * Set the exported package names
+    * 
+    * @param packageNames the exported packages
+    */
+   public void setExportedPackages(String... packageNames)
+   {
+      this.exported = packageNames;
+   }
+   
+   /**
+    * Set the exported package names
+    * 
+    * @param classes the classes to reference to determine the package names
+    */
+   public void setExportedPackages(Class<?>... classes)
+   {
+      if (classes == null)
+      {
+         exported = null;
+         return;
+      }
+      exported = new String[classes.length];
+      for (int i = 0; i < classes.length; ++i)
+         exported[i] = ClassLoaderUtils.getClassPackageName(classes[i].getName());
+   }
+   
+   /**
+    * Get the included.
+    * 
+    * @return the included.
+    */
+   public String[] getIncludedClasses()
+   {
+      return included;
+   }
+
+   /**
+    * Set the included.
+    * 
+    * @param included the included.
+    */
+   public void setIncluded(String[] included)
+   {
+      this.included = included;
+   }
+
+   /**
+    * Get the excluded.
+    * 
+    * @return the excluded.
+    */
+   public String[] getExcludedClasses()
+   {
+      return excluded;
+   }
+
+   /**
+    * Set the excluded.
+    * 
+    * @param excluded the excluded.
+    */
+   public void setExcluded(String[] excluded)
+   {
+      this.excluded = excluded;
+   }
+
+   /**
+    * Set the included classes
+    * 
+    * @param classes the classes to include from the paths
+    */
+   public void setIncludedClasses(Class<?>... classes)
+   {
+      if (classes == null)
+      {
+         included = null;
+         return;
+      }
+      included = new String[classes.length];
+      for (int i = 0; i < classes.length; ++i)
+         included[i] = ClassLoaderUtils.classNameToPath(classes[i].getName());
+   }
+   
+   /**
+    * Set the included classes
+    * 
+    * @param included the classes to include from the paths
+    */
+   public void setIncludedClasses(String... included)
+   {
+      this.included = included;
+   }
+   
+   /**
+    * Set the excluded classes
+    * 
+    * @param classes the classes to exclude from the paths
+    */
+   public void setExcludedClasses(Class<?>... classes)
+   {
+      if (classes == null)
+      {
+         excluded = null;
+         return;
+      }
+      excluded = new String[classes.length];
+      for (int i = 0; i < classes.length; ++i)
+         excluded[i] = ClassLoaderUtils.classNameToPath(classes[i].getName());
+   }
+   
+   /**
+    * Set the excluded classes
+    * 
+    * @param excluded the classes to include from the paths
+    */
+   public void setExcludedClasses(String... excluded)
+   {
+      this.excluded = excluded;
+   }
+
+   /**
+    * Set the paths and the exported package names
+    * 
+    * @param classes the classes to reference
+    */
+   public void setPathsAndPackageNames(Class<?>... classes)
+   {
+      setPaths(classes);
+      setExportedPackages(classes);
+   }
+
+   /**
+    * Set the paths and the exported package names
+    * 
+    * @param packages the packages
+    */
+   public void setPathsAndPackageNames(String... packages)
+   {
+      if (packages == null)
+      {
+         paths = null;
+         exported = null;
+         return;
+      }
+      paths = new String[packages.length];
+      for (int i = 0; i < packages.length; ++i)
+         paths[i] = packages[i].replace('.', '/');
+      
+      setExportedPackages(packages);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionRangeSupport.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionRangeSupport.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionRangeSupport.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,306 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.helpers;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * NameAndVersionRangeSupport.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NameAndVersionRangeSupport implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 3318997559330427708L;
+
+   /** The name  */
+   private String name = "<unknown>";
+   
+   /** The version range */
+   private VersionRange versionRange = VersionRange.ALL_VERSIONS;
+   
+   /**
+    * Create a new NameAndVersionRangeSupport
+    */
+   public NameAndVersionRangeSupport()
+   {
+   }
+
+   /**
+    * Create a new NameAndVersionRangeSupport with no version constraint
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public NameAndVersionRangeSupport(String name)
+   {
+      this(name, null);
+   }
+   
+   /**
+    * Create a new NameAndVersionRangeSupport.
+    * 
+    * @param name the name
+    * @param versionRange the version range - pass null for all versions
+    * @throws IllegalArgumentException for a null name
+    */
+   public NameAndVersionRangeSupport(String name, VersionRange versionRange)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      if (versionRange == null)
+         versionRange = VersionRange.ALL_VERSIONS;
+      
+      this.name = name;
+      this.versionRange = versionRange;
+   }
+   
+   /**
+    * Get the name.
+    * 
+    * @return the name.
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Set the name.
+    * 
+    * @param name the name.
+    */
+   @XmlAttribute
+   public void setName(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      this.name = name;
+   }
+
+   /**
+    * Get the versionRange.
+    * 
+    * @return the versionRange.
+    */
+   public VersionRange getVersionRange()
+   {
+      return versionRange;
+   }
+
+   /**
+    * Set the versionRange.
+    * 
+    * @param versionRange the versionRange.
+    */
+   @XmlTransient
+   public void setVersionRange(VersionRange versionRange)
+   {
+      if (versionRange == null)
+         versionRange = VersionRange.ALL_VERSIONS;
+      this.versionRange = versionRange;
+   }
+   
+   /**
+    * Get the fromVersion.
+    * 
+    * @return the fromVersion.
+    */
+   public Object getFrom()
+   {
+      return versionRange.getLow();
+   }
+
+   /**
+    * Set the fromVersion.
+    * 
+    * @param fromVersion the fromVersion.
+    */
+   @XmlTransient
+   public void setFrom(Object fromVersion)
+   {
+      versionRange = new VersionRange(fromVersion, versionRange.isLowInclusive(), versionRange.getHigh(), versionRange.isHighInclusive());
+   }
+   
+   /**
+    * Get the fromVersion.
+    * 
+    * @return the fromVersion.
+    */
+   public Version getFromVersion()
+   {
+      Object from = getFrom();
+      if (from == null)
+         return null;
+      if (from instanceof Version)
+         return (Version) from;
+      if (from instanceof String)
+         return Version.parseVersion((String) from);
+      throw new IllegalStateException(from + " is not an instance of version");
+   }
+
+   /**
+    * Set the fromVersion.
+    * 
+    * @param fromVersion the fromVersion.
+    */
+   @XmlAttribute(name="from")
+   public void setFromVersion(Version fromVersion)
+   {
+      setFrom(fromVersion);
+   }
+
+   /**
+    * Get the fromVersionInclusive.
+    * 
+    * @return the fromVersionInclusive.
+    */
+   public boolean isFromVersionInclusive()
+   {
+      return versionRange.isLowInclusive();
+   }
+
+   /**
+    * Set the fromVersionInclusive.
+    * 
+    * @param fromVersionInclusive the fromVersionInclusive.
+    */
+   @XmlAttribute(name="from-inclusive")
+   public void setFromVersionInclusive(boolean fromVersionInclusive)
+   {
+      versionRange = new VersionRange(versionRange.getLow(), fromVersionInclusive, versionRange.getHigh(), versionRange.isHighInclusive());
+   }
+
+   /**
+    * Get the toVersion.
+    * 
+    * @return the toVersion.
+    */
+   public Object getTo()
+   {
+      return versionRange.getHigh();
+   }
+
+   /**
+    * Set the toVersion.
+    * 
+    * @param toVersion the toVersion.
+    */
+   @XmlTransient
+   public void setTo(Object toVersion)
+   {
+      versionRange = new VersionRange(versionRange.getLow(), versionRange.isLowInclusive(), toVersion, versionRange.isHighInclusive());
+   }
+
+   /**
+    * Get the toVersion.
+    * 
+    * @return the toVersion.
+    */
+   @XmlAttribute(name="to")
+   public Version getToVersion()
+   {
+      Object to = getTo();
+      if (to == null)
+         return null;
+      if (to instanceof Version)
+         return (Version) to;
+      if (to instanceof String)
+         return Version.parseVersion((String) to);
+      throw new IllegalStateException(to + " is not an instance of version");
+   }
+
+   /**
+    * Set the toVersion.
+    * 
+    * @param toVersion the toVersion.
+    */
+   public void setToVersion(Version toVersion)
+   {
+      setTo(toVersion);
+   }
+
+   /**
+    * Get the toVersionInclusive.
+    * 
+    * @return the toVersionInclusive.
+    */
+   public boolean isToVersionInclusive()
+   {
+      return versionRange.isHighInclusive();
+   }
+
+   /**
+    * Set the toVersionInclusive.
+    * 
+    * @param toVersionInclusive the toVersionInclusive.
+    */
+   @XmlAttribute(name="to-inclusive")
+   public void setToVersionInclusive(boolean toVersionInclusive)
+   {
+      versionRange = new VersionRange(versionRange.getLow(), versionRange.isLowInclusive(), versionRange.getHigh(), toVersionInclusive);
+   }
+   
+   /**
+    * Set a single version as the version range
+    * 
+    * @param version the version
+    */
+   @XmlAttribute(name="version")
+   public void setVersion(Version version)
+   {
+      versionRange = new VersionRange(version, true, version, true);
+   }
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof NameAndVersionRangeSupport == false)
+         return false;
+      NameAndVersionRangeSupport other = (NameAndVersionRangeSupport) obj;
+      if (getName().equals(other.getName()) == false)
+         return false;
+      return getVersionRange().equals(other.getVersionRange());
+   }
+   
+   @Override
+   public int hashCode()
+   {
+      return getName().hashCode();
+   }
+   
+   @Override
+   public String toString()
+   {
+      return getClass().getSimpleName() + " " + getName() + ":" + getVersionRange();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionSupport.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionSupport.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/helpers/NameAndVersionSupport.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,180 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.helpers;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparatorRegistry;
+
+/**
+ * NameAndVersionSupport.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NameAndVersionSupport implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 6943685422194480909L;
+
+   /** The name  */
+   private String name = "<unknwown>";
+   
+   /** The version */
+   private Object version = Version.DEFAULT_VERSION;
+
+   /**
+    * Create a new NameAndVersionSupport with the default version
+    */
+   public NameAndVersionSupport()
+   {
+   }
+
+   /**
+    * Create a new NameAndVersionSupport with the default version
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public NameAndVersionSupport(String name)
+   {
+      this(name, null);
+   }
+   
+   /**
+    * Create a new NameAndVersionSupport.
+    * 
+    * @param name the name
+    * @param version the version - pass null for default version
+    * @throws IllegalArgumentException for a null name
+    */
+   public NameAndVersionSupport(String name, Object version)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      if (version == null)
+         version = Version.DEFAULT_VERSION;
+      this.name = name;
+      this.version = version;
+   }
+   
+   /**
+    * Get the name.
+    * 
+    * @return the name.
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Set the name.
+    * 
+    * @param name the name.
+    */
+   @XmlAttribute
+   public void setName(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      this.name = name;
+   }
+
+   /**
+    * Get the version.
+    * 
+    * @return the version.
+    */
+   public Object getVersion()
+   {
+      return version;
+   }
+
+   /**
+    * Set the version.
+    * 
+    * @param version the version.
+    */
+   @XmlTransient
+   public void setVersion(Object version)
+   {
+      if (version == null)
+         version = Version.DEFAULT_VERSION;
+      this.version = version;
+   }
+
+   /**
+    * Get the version.
+    * 
+    * @return the version.
+    */
+   public Version getTheVersion()
+   {
+      Object version = getVersion();
+      if (version instanceof Version)
+         return (Version) version;
+      if (version instanceof String)
+         return Version.parseVersion((String) version);
+      throw new IllegalStateException(version + " is not an instanceof version");
+   }
+
+   /**
+    * Set the version.
+    * 
+    * @param version the version.
+    */
+   @XmlAttribute(name="version")
+   public void setTheVersion(Version version)
+   {
+      setVersion(version);
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof NameAndVersionSupport == false)
+         return false;
+      NameAndVersionSupport other = (NameAndVersionSupport) obj;
+      if (getName().equals(other.getName()) == false)
+         return false;
+      return VersionComparatorRegistry.getInstance().same(getVersion(), other.getVersion());
+   }
+   
+   @Override
+   public int hashCode()
+   {
+      return getName().hashCode();
+   }
+   
+   @Override
+   public String toString()
+   {
+      return getClass().getSimpleName() + " " + getName() + ":" + getVersion();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/CapabilitiesMetaData.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/CapabilitiesMetaData.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/CapabilitiesMetaData.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,106 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.metadata;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.classloading.plugins.metadata.ModuleCapability;
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+
+/**
+ * CapabilitiesMetaData.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlType(propOrder= {"capabilities"})
+public class CapabilitiesMetaData implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -7910704924025591308L;
+   
+   /** The capabilities */
+   private List<Capability> capabilities;
+
+   /**
+    * Get the capabilities.
+    * 
+    * @return the capabilities.
+    */
+   public List<Capability> getCapabilities()
+   {
+      return capabilities;
+   }
+
+   /**
+    * Set the capabilities.
+    * 
+    * @param capabilities the capabilities.
+    */
+   @XmlElements
+   ({
+      @XmlElement(name="module", type=ModuleCapability.class),
+      @XmlElement(name="package", type=PackageCapability.class)
+   })
+   @XmlAnyElement
+   public void setCapabilities(List<Capability> capabilities)
+   {
+      this.capabilities = capabilities;
+   }
+
+   /**
+    * Add a capability
+    * 
+    * @param capability the capability
+    * @throws IllegalArgumentException for a null capability
+    */
+   public void addCapability(Capability capability)
+   {
+      if (capability == null)
+         throw new IllegalArgumentException("Null capability");
+      if (capabilities == null)
+         capabilities = new CopyOnWriteArrayList<Capability>();
+      capabilities.add(capability);
+   }
+
+   /**
+    * Remove a capability
+    * 
+    * @param capability the capability
+    * @throws IllegalArgumentException for a null capability
+    */
+   public void removeCapability(Capability capability)
+   {
+      if (capability == null)
+         throw new IllegalArgumentException("Null capability");
+      if (capabilities == null)
+         return;
+      capabilities.remove(capability);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Capability.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Capability.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Capability.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,45 @@
+/*
+ * 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.classloading.spi.metadata;
+
+import java.io.Serializable;
+
+import org.jboss.classloading.spi.dependency.Module;
+
+/**
+ * Capability.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface Capability extends Serializable
+{
+   /**
+    * Whether this capability resolves the requirement
+    * 
+    * @param module the module
+    * @param requirement the requirement
+    * @throws IllegalArgumentException for a null requirement
+    * @return true when it is resolves the requirement
+    */
+   boolean resolves(Module module, Requirement requirement);
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,542 @@
+/*
+ * 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.classloading.spi.metadata;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.jboss.classloader.plugins.filter.CombiningClassFilter;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.PackageClassFilter;
+import org.jboss.classloading.spi.helpers.NameAndVersionSupport;
+
+/**
+ * ClassLoadingMetaData.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoadingMetaData extends NameAndVersionSupport
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -2782951093046585620L;
+   
+   /** The classloading domain */
+   private String domain;
+
+   /** The parent domain */
+   private String parentDomain;
+   
+   /** Whether to enforce j2se classloading compliance */
+   private boolean j2seClassLoadingCompliance = true;
+   
+   /** Whether we are cacheable */
+   private boolean cacheable = true;
+   
+   /** Whether we are blacklistable */
+   private boolean blackListable = true;
+   
+   /** Whether to export all */
+   private ExportAll exportAll;
+   
+   /** Whether to import all */
+   private boolean importAll;
+
+   /** The included packages */
+   private String includedPackages;
+
+   /** The excluded packages */
+   private String excludedPackages;
+
+   /** The excluded for export */
+   private String excludedExportPackages;
+
+   /** The included packages */
+   private ClassFilter included;
+
+   /** The excluded packages */
+   private ClassFilter excluded;
+
+   /** The excluded for export */
+   private ClassFilter excludedExport;
+   
+   /** The requirements */
+   private RequirementsMetaData requirements = new RequirementsMetaData();
+   
+   /** The capabilities */
+   private CapabilitiesMetaData capabilities = new CapabilitiesMetaData();
+   
+   /**
+    * Get the domain.
+    * 
+    * @return the domain.
+    */
+   public String getDomain()
+   {
+      return domain;
+   }
+
+   /**
+    * Set the domain.
+    * 
+    * @param domain the domain.
+    */
+   @XmlAttribute
+   public void setDomain(String domain)
+   {
+      this.domain = domain;
+   }
+
+   /**
+    * Get the parentDomain.
+    * 
+    * @return the parentDomain.
+    */
+   public String getParentDomain()
+   {
+      return parentDomain;
+   }
+
+   /**
+    * Set the parentDomain.
+    * 
+    * @param parentDomain the parentDomain.
+    */
+   @XmlAttribute
+   public void setParentDomain(String parentDomain)
+   {
+      this.parentDomain = parentDomain;
+   }
+
+   /**
+    * Get the exportAll.
+    * 
+    * @return the exportAll.
+    */
+   public ExportAll getExportAll()
+   {
+      return exportAll;
+   }
+
+   /**
+    * Set the exportAll.
+    * 
+    * @param exportAll the exportAll.
+    */
+   @XmlAttribute(name="export-all")
+   public void setExportAll(ExportAll exportAll)
+   {
+      this.exportAll = exportAll;
+   }
+
+   /**
+    * Get the includedPackages.
+    * 
+    * @return the includedPackages.
+    */
+   public String getIncludedPackages()
+   {
+      return includedPackages;
+   }
+
+   /**
+    * Set the includedPackages.
+    * 
+    * @param includedPackages the includedPackages.
+    */
+   @XmlAttribute(name="included")
+   public void setIncludedPackages(String includedPackages)
+   {
+      this.includedPackages = includedPackages;
+   }
+
+   /**
+    * Get a filter for the included packages
+    * 
+    * @return the included packages
+    */
+   public ClassFilter getIncluded()
+   {
+      ClassFilter packageFilter = null;
+      if (includedPackages != null)
+         packageFilter = PackageClassFilter.createPackageClassFilterFromString(includedPackages);
+      
+      if (packageFilter == null)
+         return included;
+      if (included == null)
+         return packageFilter;
+      return CombiningClassFilter.create(true, packageFilter, included);
+   }
+
+   /**
+    * Set the included.
+    * 
+    * @param included the included.
+    */
+   @XmlTransient
+   public void setIncluded(ClassFilter included)
+   {
+      this.included = included;
+   }
+
+   /**
+    * Get the excludedPackages.
+    * 
+    * @return the excludedPackages.
+    */
+   public String getExcludedPackages()
+   {
+      return excludedPackages;
+   }
+
+   /**
+    * Set the excludedPackages.
+    * 
+    * @param excludedPackages the excludedPackages.
+    */
+   @XmlAttribute(name="excluded")
+   public void setExcludedPackages(String excludedPackages)
+   {
+      this.excludedPackages = excludedPackages;
+   }
+
+   /**
+    * Get a filter for the excluded packages
+    * 
+    * @return the excluded packages
+    */
+   public ClassFilter getExcluded()
+   {
+      ClassFilter packageFilter = null;
+      if (excludedPackages != null)
+         packageFilter = PackageClassFilter.createPackageClassFilterFromString(excludedPackages);
+      
+      if (packageFilter == null)
+         return excluded;
+      if (excluded == null)
+         return packageFilter;
+      return CombiningClassFilter.create(true, packageFilter, excluded);
+   }
+
+   /**
+    * Set the excluded.
+    * 
+    * @param excluded the excluded.
+    */
+   @XmlTransient
+   public void setExcluded(ClassFilter excluded)
+   {
+      this.excluded = excluded;
+   }
+   
+   /**
+    * Get the excludedExportPackages.
+    * 
+    * @return the excludedExportPackages.
+    */
+   public String getExcludedExportPackages()
+   {
+      return excludedExportPackages;
+   }
+
+   /**
+    * Set the excludedExportPackages.
+    * 
+    * @param excludedExportPackages the excludedExportPackages.
+    */
+   @XmlAttribute(name="excludedExport")
+   public void setExcludedExportPackages(String excludedExportPackages)
+   {
+      this.excludedExportPackages = excludedExportPackages;
+   }
+
+   /**
+    * Get a filter for the excluded export packages
+    * 
+    * @return the excluded export packages
+    */
+   public ClassFilter getExcludedExport()
+   {
+      ClassFilter packageFilter = null;
+      if (excludedExportPackages != null)
+         packageFilter = PackageClassFilter.createPackageClassFilterFromString(excludedExportPackages);
+      
+      if (packageFilter == null)
+         return excludedExport;
+      if (excludedExport == null)
+         return packageFilter;
+      return CombiningClassFilter.create(true, packageFilter, excludedExport);
+   }
+
+   /**
+    * Set the excludedExport.
+    * 
+    * @param excludedExport the excludedExport.
+    */
+   @XmlTransient
+   public void setExcludedExport(ClassFilter excludedExport)
+   {
+      this.excludedExport = excludedExport;
+   }
+
+   /**
+    * Whether to import all
+    * 
+    * @return true when there are no requirements
+    */
+   public boolean isImportAll()
+   {
+      return importAll;
+   }
+   
+   /**
+    * Set the importAll.
+    * 
+    * @param importAll the importAll.
+    */
+   @XmlAttribute(name="import-all")
+   public void setImportAll(boolean importAll)
+   {
+      this.importAll = importAll;
+   }
+
+   /**
+    * Get the j2seClassLoadingCompliance.
+    * 
+    * @return the j2seClassLoadingCompliance.
+    */
+   public boolean isJ2seClassLoadingCompliance()
+   {
+      return j2seClassLoadingCompliance;
+   }
+
+   /**
+    * Set the j2seClassLoadingCompliance.
+    * 
+    * @param classLoadingCompliance the j2seClassLoadingCompliance.
+    */
+   @XmlAttribute(name="parent-first")
+   public void setJ2seClassLoadingCompliance(boolean classLoadingCompliance)
+   {
+      j2seClassLoadingCompliance = classLoadingCompliance;
+   }
+
+   /**
+    * Get the cacheable.
+    * 
+    * @return the cacheable.
+    */
+   public boolean isCacheable()
+   {
+      return cacheable;
+   }
+
+   /**
+    * Set the cacheable.
+    * 
+    * @param cacheable the cacheable.
+    */
+   @XmlAttribute(name="cache")
+   public void setCacheable(boolean cacheable)
+   {
+      this.cacheable = cacheable;
+   }
+
+   /**
+    * Get the blackListable.
+    * 
+    * @return the blackListable.
+    */
+   public boolean isBlackListable()
+   {
+      return blackListable;
+   }
+
+   /**
+    * Set the blackListable.
+    * 
+    * @param blackListable the blackListable.
+    */
+   @XmlAttribute(name="blackList")
+   public void setBlackListable(boolean blackListable)
+   {
+      this.blackListable = blackListable;
+   }
+
+   /**
+    * Get the capabilities.
+    * 
+    * @return the capabilities.
+    */
+   public CapabilitiesMetaData getCapabilities()
+   {
+      return capabilities;
+   }
+
+   /**
+    * Set the capabilities.
+    * 
+    * @param capabilities the capabilities.
+    * @throws IllegalArgumentException for null capabilities
+    */
+   public void setCapabilities(CapabilitiesMetaData capabilities)
+   {
+      if (capabilities == null)
+         throw new IllegalArgumentException("Null capabilities");
+      this.capabilities = capabilities;
+   }
+
+   /**
+    * Set the capabilities.
+    * 
+    * @param capabilities the capabilities.
+    */
+   public void setCapabilities(List<Capability> capabilities)
+   {
+      if (this.capabilities == null)
+         this.capabilities = new CapabilitiesMetaData();
+      this.capabilities.setCapabilities(capabilities);
+   }
+
+   /**
+    * Get the requirements.
+    * 
+    * @return the requirements.
+    */
+   public RequirementsMetaData getRequirements()
+   {
+      return requirements;
+   }
+
+   /**
+    * Set the requirements.
+    * 
+    * @param requirements the requirements.
+    * @throws IllegalArgumentException for null requirements
+    */
+   public void setRequirements(RequirementsMetaData requirements)
+   {
+      if (requirements == null)
+         throw new IllegalArgumentException("Null requirements");
+      this.requirements = requirements;
+   }
+
+   /**
+    * Set the requirements.
+    * 
+    * @param requirements the requirements.
+    */
+   public void setRequirements(List<Requirement> requirements)
+   {
+      if (this.requirements == null)
+         this.requirements = new RequirementsMetaData();
+      this.requirements.setRequirements(requirements);
+   }
+
+   @Override 
+   public String toString()
+   {
+      StringBuilder builder = new StringBuilder();
+      builder.append(getClass().getSimpleName());
+      builder.append("@");
+      builder.append(Integer.toHexString(System.identityHashCode(this)));
+      builder.append("{");
+      toString(builder);
+      builder.append("}");
+      return builder.toString();
+   }
+   
+   /**
+    * For subclasses to override the toString contents
+    * 
+    * @param builder the builder
+    */
+   protected void toString(StringBuilder builder)
+   {
+      builder.append("name=").append(getName());
+      builder.append(" version=").append(getVersion());
+      String domain = getDomain();
+      if (domain != null)
+         builder.append(" domain=").append(domain);
+      String parentDomain = getParentDomain();
+      if (parentDomain != null)
+         builder.append(" parentDomain=").append(parentDomain);
+      ExportAll exportAll = getExportAll();
+      if (exportAll != null)
+         builder.append(" ").append(exportAll);
+      if (isImportAll())
+         builder.append(" IMPORT-ALL");
+      builder.append(" parent-first=").append(isJ2seClassLoadingCompliance());
+      if (isCacheable() == false)
+         builder.append(" NO-CACHE");
+      if (isBlackListable() == false)
+         builder.append(" NO-BLACK-LIST");
+      List<Capability> capabilities = getCapabilities().getCapabilities();
+      if (capabilities != null)
+         builder.append(" capabilities=" + capabilities);
+      List<Requirement> requirements = getRequirements().getRequirements();
+      if (requirements != null)
+         builder.append(" requirements=" + requirements);
+   }
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof ClassLoadingMetaData == false)
+         return false;
+      if (super.equals(obj) == false)
+         return false;
+      ClassLoadingMetaData other = (ClassLoadingMetaData) obj;
+      if (equals(this.getDomain(), other.getDomain()) == false)
+         return false;
+      if (equals(this.getParentDomain(), other.getParentDomain()) == false)
+         return false;
+      if (equals(this.getExportAll(), other.getExportAll()) == false)
+         return false;
+      if (this.isImportAll() != other.isImportAll())
+         return false;
+      if (this.isJ2seClassLoadingCompliance() != other.isJ2seClassLoadingCompliance())
+         return false;
+      if (this.isCacheable() != other.isCacheable())
+         return false;
+      if (this.isBlackListable() != other.isBlackListable())
+         return false;
+      if (equals(this.getCapabilities().getCapabilities(), other.getCapabilities().getCapabilities()) == false)
+         return false;
+      if (equals(this.getRequirements().getRequirements(), other.getRequirements().getRequirements()) == false)
+         return false;
+      return true;
+   }
+   
+   private static boolean equals(Object one, Object two)
+   {
+      if (one == null && two == null)
+         return true;
+      if (one == null && two != null)
+         return false;
+      return one.equals(two);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData10.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData10.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaData10.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,41 @@
+/*
+ * 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.classloading.spi.metadata;
+
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * ClassLoadingMetaData version 1.0.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlSchema(namespace="urn:jboss:classloading:1.0", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="classloading")
+public class ClassLoadingMetaData10 extends ClassLoadingMetaData
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -2782951093046585620L;
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactory.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactory.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactory.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,275 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.metadata;
+
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * ClassLoadingMetaDataFactory.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ClassLoadingMetaDataFactory
+{
+   /**
+    * Get an instance of the factory
+    * 
+    * @return the factory
+    */
+   public static ClassLoadingMetaDataFactory getInstance()
+   {
+      return ClassLoadingMetaDataFactoryBuilder.getInstance();
+   }
+
+   /**
+    * Create a new module with the default version
+    * 
+    * @param name the name
+    * @return the module capability
+    * @throws IllegalArgumentException for a null name
+    */
+   public Capability createModule(String name)
+   {
+      return createModule(name, null);
+   }
+
+   /**
+    * Create a new module
+    * 
+    * @param name the name
+    * @param version the version
+    * @return the module capability
+    * @throws IllegalArgumentException for a null name
+    */
+   public abstract Capability createModule(String name, Object version);
+
+   /**
+    * Create a new module requirement with no version constraint
+    * 
+    * @param name the name
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createRequireModule(String name)
+   {
+      return createRequireModule(name, null);
+   }
+
+   /**
+    * Create a new module requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createRequireModule(String name, VersionRange versionRange)
+   {
+      return createRequireModule(name, versionRange, false, false);
+   }
+
+   /**
+    * Create a new module requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @param optional whether the requirement is optional
+    * @param reExport whether the requirement is a re-export
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public abstract Requirement createRequireModule(String name, VersionRange versionRange, boolean optional, boolean reExport);
+
+   /**
+    * Create a new re-export module requirement with no version constraint
+    * 
+    * @param name the name
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createReExportModule(String name)
+   {
+      return createReExportModule(name, null);
+   }
+
+   /**
+    * Create a new re-export module requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createReExportModule(String name, VersionRange versionRange)
+   {
+      return createReExportModule(name, versionRange, false);
+   }
+
+   /**
+    * Create a new re-export module requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @param optional whether the requirement is optional
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createReExportModule(String name, VersionRange versionRange, boolean optional)
+   {
+      return createRequireModule(name, versionRange, optional, true);
+   }
+
+   /**
+    * Create a new package with the default version
+    * 
+    * @param name the name
+    * @return the package capability
+    * @throws IllegalArgumentException for a null name
+    */
+   public Capability createPackage(String name)
+   {
+      return createPackage(name, null);
+   }
+
+   /**
+    * Create a new package
+    * 
+    * @param name the name
+    * @param version the version
+    * @return the package capability
+    * @throws IllegalArgumentException for a null name
+    */
+   public abstract Capability createPackage(String name, Object version);
+
+   /**
+    * Create a new packagerequirement with no version constraint
+    * 
+    * @param name the name
+    * @return the package requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createRequirePackage(String name)
+   {
+      return createRequirePackage(name, null);
+   }
+
+   /**
+    * Create a new package requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @return the package requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createRequirePackage(String name, VersionRange versionRange)
+   {
+      return createRequirePackage(name, versionRange, false, false);
+   }
+
+   /**
+    * Create a new package requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @param optional whether the requirement is optional
+    * @param reExport whether the requirement is a re-export
+    * @return the package requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public abstract Requirement createRequirePackage(String name, VersionRange versionRange, boolean optional, boolean reExport);
+
+   /**
+    * Create a new re-export package requirement with no version constraint
+    * 
+    * @param name the name
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createReExportPackage(String name)
+   {
+      return createReExportPackage(name, null, false);
+   }
+
+   /**
+    * Create a new re-export package requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createReExportPackage(String name, VersionRange versionRange)
+   {
+      return createReExportPackage(name, versionRange, false);
+   }
+
+   /**
+    * Create a new re-export module requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @param optional whether the requirement is optional
+    * @return the module requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createReExportPackage(String name, VersionRange versionRange, boolean optional)
+   {
+      return createRequirePackage(name, versionRange, optional, true);
+   }
+
+   /**
+    * Create a new usespackagerequirement with no version constraint
+    * 
+    * @param name the name
+    * @return the package requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createUsesPackage(String name)
+   {
+      return createUsesPackage(name, null);
+   }
+
+   /**
+    * Create a new uses package requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @return the package requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public Requirement createUsesPackage(String name, VersionRange versionRange)
+   {
+      return createUsesPackage(name, versionRange, false);
+   }
+
+   /**
+    * Create a new uses package requirement
+    * 
+    * @param name the name
+    * @param versionRange the version range
+    * @param reExport whether the requirement is a re-export
+    * @return the package requirement
+    * @throws IllegalArgumentException for a null name
+    */
+   public abstract Requirement createUsesPackage(String name, VersionRange versionRange, boolean reExport);
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactoryBuilder.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactoryBuilder.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ClassLoadingMetaDataFactoryBuilder.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.metadata;
+
+import java.security.AccessController;
+
+import org.jboss.classloading.plugins.metadata.DefaultClassLoadingMetaDataFactory;
+import org.jboss.util.builder.AbstractBuilder;
+
+/**
+ * ClassLoadingMetaDataFactoryBuilder.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class ClassLoadingMetaDataFactoryBuilder
+{
+   /** The default factory */
+   private static String DEFAULT_FACTORY = DefaultClassLoadingMetaDataFactory.class.getName(); 
+   
+   /** The singleton */
+   private static ClassLoadingMetaDataFactory singleton;
+
+   /**
+    * Get the instance
+    * 
+    * @return the instance
+    */
+   static synchronized ClassLoadingMetaDataFactory getInstance()
+   {
+      if (singleton == null)
+      {
+         AbstractBuilder<ClassLoadingMetaDataFactory> builder = new AbstractBuilder<ClassLoadingMetaDataFactory>(ClassLoadingMetaDataFactory.class, DEFAULT_FACTORY);
+         singleton = AccessController.doPrivileged(builder);
+      }
+      return singleton;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportAll.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportAll.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportAll.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,37 @@
+/*
+ * 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.classloading.spi.metadata;
+
+/**
+ * ExportAll.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public enum ExportAll
+{
+   /** All packages */
+   ALL,
+   
+   /** All non empty packages */
+   NON_EMPTY
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportPackages.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportPackages.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/ExportPackages.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,43 @@
+/*
+ * 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.classloading.spi.metadata;
+
+import java.util.Set;
+
+import org.jboss.classloading.spi.dependency.Module;
+
+/**
+ * ExportPackages.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ExportPackages
+{
+   /**
+    * Get the package names
+    *
+    * @param module the module
+    * @return the package names
+    */
+   Set<String> getPackageNames(Module module);
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Requirement.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Requirement.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/Requirement.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,54 @@
+/*
+ * 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.classloading.spi.metadata;
+
+import java.io.Serializable;
+
+/**
+ * Requirement.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface Requirement extends Serializable
+{
+   /**
+    * Whether to re-export the requirement
+    * 
+    * @return true to re-export
+    */
+   boolean isReExport();
+   
+   /**
+    * Whether we want re-exports
+    * 
+    * @return true to process re-exports
+    */
+   boolean wantReExports();
+   
+   /**
+    * Whether the requirement is optional
+    * 
+    * @return true if the requirement is optional
+    */
+   boolean isOptional();
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/RequirementsMetaData.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/RequirementsMetaData.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/RequirementsMetaData.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,108 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.metadata;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.classloading.plugins.metadata.ModuleRequirement;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.plugins.metadata.UsesPackageRequirement;
+
+/**
+ * RequirementsMetaData.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlType(propOrder={"requirements"})
+public class RequirementsMetaData implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 3282035888494128833L;
+   
+   /** The requirements */
+   private List<Requirement> requirements;
+
+   /**
+    * Get the requirements.
+    * 
+    * @return the requirements.
+    */
+   public List<Requirement> getRequirements()
+   {
+      return requirements;
+   }
+
+   /**
+    * Set the requirements.
+    * 
+    * @param requirements the requirements.
+    */
+   @XmlElements
+   ({
+      @XmlElement(name="module", type=ModuleRequirement.class),
+      @XmlElement(name="package", type=PackageRequirement.class),
+      @XmlElement(name="uses", type=UsesPackageRequirement.class)
+   })
+   @XmlAnyElement
+   public void setRequirements(List<Requirement> requirements)
+   {
+      this.requirements = requirements;
+   }
+
+   /**
+    * Add a requirement
+    * 
+    * @param requirement the requirement
+    * @throws IllegalArgumentException for a null requirement
+    */
+   public void addRequirement(Requirement requirement)
+   {
+      if (requirement == null)
+         throw new IllegalArgumentException("Null requirement");
+      if (requirements == null)
+         requirements = new CopyOnWriteArrayList<Requirement>();
+      requirements.add(requirement);
+   }
+
+   /**
+    * Remove a requirement
+    * 
+    * @param requirement the requirement
+    * @throws IllegalArgumentException for a null requirement
+    */
+   public void removeRequirement(Requirement requirement)
+   {
+      if (requirement == null)
+         throw new IllegalArgumentException("Null requirement");
+      if (requirements == null)
+         return;
+      requirements.remove(requirement);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractCapability.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractCapability.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractCapability.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,99 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.metadata.helpers;
+
+import org.jboss.classloading.spi.helpers.NameAndVersionSupport;
+import org.jboss.classloading.spi.metadata.Capability;
+
+/**
+ * AbstractCapability.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractCapability extends NameAndVersionSupport implements Capability
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1099174558119868306L;
+   
+   /**
+    * Create a new AbstractCapability
+    */
+   public AbstractCapability()
+   {
+   }
+   
+   /**
+    * Create a new AbstractCapability
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public AbstractCapability(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Create a new AbstractCapability.
+    * 
+    * @param name the name
+    * @param version the version - pass null for the default version
+    * @throws IllegalArgumentException for a null name
+    */
+   public AbstractCapability(String name, Object version)
+   {
+      super(name, version);
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof AbstractCapability == false)
+         return false;
+      return super.equals(obj);
+   }
+
+   @Override
+   public String toString()
+   {
+      StringBuffer buffer = new StringBuffer();
+      buffer.append(getClass().getSimpleName());
+      buffer.append("{");
+      toString(buffer);
+      buffer.append("}");
+      return buffer.toString();
+   }
+   
+   /**
+    * For subclasses to override toString()
+    * 
+    * @param buffer the buffer
+    */
+   protected void toString(StringBuffer buffer)
+   {
+      buffer.append(getName());
+      buffer.append(" ").append(getVersion());
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractRequirement.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractRequirement.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/helpers/AbstractRequirement.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,156 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.metadata.helpers;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+import org.jboss.classloading.spi.helpers.NameAndVersionRangeSupport;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * AbstractRequirement.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class AbstractRequirement extends NameAndVersionRangeSupport implements Requirement
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -7898148730704557596L;
+
+   /** Whether the requirement is optional */
+   private boolean optional = false;
+
+   /** Whether to re-export */
+   private boolean reExport = false;
+   
+   /**
+    * Create a new AbstractRequirement
+    */
+   public AbstractRequirement()
+   {
+   }
+   
+   /**
+    * Create a new AbstractRequirement
+    * 
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   public AbstractRequirement(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Create a new AbstractRequirement.
+    * 
+    * @param name the name
+    * @param versionRange the version range - pass null for all versions
+    * @throws IllegalArgumentException for a null name
+    */
+   public AbstractRequirement(String name, VersionRange versionRange)
+   {
+      super(name, versionRange);
+   }
+
+   public boolean isOptional()
+   {
+      return optional;
+   }
+   
+   /**
+    * Set the optional.
+    * 
+    * @param optional the optional.
+    */
+   @XmlAttribute(name="optional")
+   public void setOptional(boolean optional)
+   {
+      this.optional = optional;
+   }
+
+   public boolean wantReExports()
+   {
+      return false;
+   }
+
+   public boolean isReExport()
+   {
+      return reExport;
+   }
+
+   /**
+    * Set the reExport.
+    * 
+    * @param reExport the reExport.
+    */
+   @XmlAttribute(name="reExport")
+   public void setReExport(boolean reExport)
+   {
+      this.reExport = reExport;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof AbstractRequirement == false)
+         return false;
+      if (super.equals(obj) == false)
+         return false;
+      AbstractRequirement other = (AbstractRequirement) obj;
+      if (this.isOptional() != other.isOptional())
+         return false;
+      if (this.isReExport() != other.isReExport())
+         return false;
+      return true;
+   }
+
+   @Override
+   public String toString()
+   {
+      StringBuffer buffer = new StringBuffer();
+      buffer.append(getClass().getSimpleName());
+      buffer.append("{");
+      toString(buffer);
+      buffer.append("}");
+      return buffer.toString();
+   }
+   
+   /**
+    * For subclasses to override toString()
+    * 
+    * @param buffer the buffer
+    */
+   protected void toString(StringBuffer buffer)
+   {
+      buffer.append(getName());
+      buffer.append(" ").append(getVersionRange());
+      if (isOptional())
+         buffer.append(" OPTIONAL");
+      if (isReExport())
+         buffer.append(" RE-EXPORT");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/package-info.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/package-info.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/metadata/package-info.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,31 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+ at JBossXmlAdaptedTypes
+({
+   @JBossXmlAdaptedType(type=Version.class, valueAdapter=VersionValueAdapter.class)
+})
+package org.jboss.classloading.spi.metadata;
+
+import org.jboss.classloading.plugins.metadata.VersionValueAdapter;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.xb.annotations.JBossXmlAdaptedType;
+import org.jboss.xb.annotations.JBossXmlAdaptedTypes;

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/Version.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/Version.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/Version.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,291 @@
+/*
+ * 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.classloading.spi.version;
+
+import java.io.Serializable;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+
+/**
+ * Version.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Version implements Serializable, Comparable<Version>  
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   
+   /** The sperator */
+   private static final String SEPARATOR = ".";
+   
+   /** The raw pattern */
+   private static final String PATTERN = "[a-zA-Z0-9_-]*";
+   
+   /** The qualifier pattern */
+   private static final Pattern QUALIFIER_PATTERN = Pattern.compile(PATTERN);
+
+   /** The default version */
+   public static final Version DEFAULT_VERSION = new Version(0, 0, 0);
+
+   /** The major part of the version */
+   private int major;
+
+   /** The minor part of the version */
+   private int minor;
+
+   /** The micro part of the version */
+   private int micro;
+
+   /** The qualifier part of the version */
+   private String qualifier;
+
+   /**
+    * Create a new Version.
+    * 
+    * @param major the major part
+    * @param minor the minor part
+    * @param micro the micro part
+    */
+   public Version(int major, int minor, int micro)
+   {
+      this(major, minor, micro, null);
+   }
+
+   /**
+    * Create a new VersionImpl.
+    * 
+    * @param major the major part
+    * @param minor the minor part
+    * @param micro the micro part
+    * @param qualifier the qualifier
+    */
+   public Version(int major, int minor, int micro, String qualifier)
+   {
+      this.major = major;
+      this.minor = minor;
+      this.micro = micro;
+      if (qualifier == null)
+         qualifier = "";
+      this.qualifier = qualifier;
+      validate();
+   }
+
+   /**
+    * Create a new VersionImpl.
+    * 
+    * @param version the version as a string
+    * @throws IllegalArgumentException for a null version or invalid format
+    */
+   private Version(String version)
+   {
+      if (version == null)
+         throw new IllegalArgumentException("Null version");
+      
+      int major = 0;
+      int minor = 0;
+      int micro = 0;
+      String qualifier = "";
+
+      try
+      {
+         StringTokenizer st = new StringTokenizer(version, SEPARATOR, true);
+         major = Integer.parseInt(st.nextToken().trim());
+
+         if (st.hasMoreTokens())
+         {
+            st.nextToken();
+            minor = Integer.parseInt(st.nextToken().trim());
+
+            if (st.hasMoreTokens())
+            {
+               st.nextToken();
+               micro = Integer.parseInt(st.nextToken().trim());
+
+               if (st.hasMoreTokens())
+               {
+                  st.nextToken();
+                  qualifier = st.nextToken().trim();
+
+                  if (st.hasMoreTokens())
+                  {
+                     throw new IllegalArgumentException("Invalid version format, too many seperators: " + version);
+                  }
+               }
+            }
+         }
+      }
+      catch (NoSuchElementException e)
+      {
+         throw new IllegalArgumentException("Invalid version format: " + version);
+      }
+      catch (NumberFormatException e)
+      {
+         throw new IllegalArgumentException("Invalid version format: " + version);
+      }
+
+      this.major = major;
+      this.minor = minor;
+      this.micro = micro;
+      this.qualifier = qualifier;
+      validate();
+   }
+
+   /**
+    * Validate arguments.
+    */
+   protected void validate()
+   {
+      if (major < 0)
+         throw new IllegalArgumentException("negative major: " + major);
+      if (minor < 0)
+         throw new IllegalArgumentException("negative minor: " + minor);
+      if (micro < 0)
+         throw new IllegalArgumentException("negative micro: " + micro);
+
+      if (QUALIFIER_PATTERN.matcher(qualifier).matches() == false)
+         throw new IllegalArgumentException("Invalid qualifier, it must be " + PATTERN + ": " + qualifier);
+   }
+
+   /**
+    * Parses a version identifier from the specified string.
+    * See <code>Version(String)</code> for the format of the version string.
+    *
+    * @param version String representation of the version identifier. Leading
+    *                and trailing whitespace will be ignored.
+    * @return A <code>Version</code> object representing the version
+    *         identifier. If <code>version</code> is <code>null</code> or
+    *         the empty string then <code>emptyVersion</code> will be
+    *         returned.
+    * @throws IllegalArgumentException If <code>version</code> is improperly
+    *                                  formatted.
+    */
+   public static Version parseVersion(String version)
+   {
+      if (version == null)
+         return DEFAULT_VERSION;
+
+      version = version.trim();
+      if (version.length() == 0)
+         return DEFAULT_VERSION;
+
+      return new Version(version);
+   }
+
+   /**
+    * Returns the major component of this version identifier.
+    *
+    * @return The major component.
+    */
+   public int getMajor()
+   {
+      return major;
+   }
+
+   /**
+    * Returns the minor component of this version identifier.
+    *
+    * @return The minor component.
+    */
+   public int getMinor()
+   {
+      return minor;
+   }
+
+   /**
+    * Returns the micro component of this version identifier.
+    *
+    * @return The micro component.
+    */
+   public int getMicro()
+   {
+      return micro;
+   }
+
+   /**
+    * Returns the qualifier component of this version identifier.
+    *
+    * @return The qualifier component.
+    */
+   public String getQualifier()
+   {
+      return qualifier;
+   }
+
+   @Override
+   public String toString()
+   {
+      StringBuilder builder = new StringBuilder();
+      builder.append(major).append(SEPARATOR).append(minor).append(SEPARATOR).append(micro);
+      if (qualifier.length() > 0)
+         builder.append(SEPARATOR).append(qualifier);
+      return builder.toString();
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return (major << 24) + (minor << 16) + (micro << 8) + qualifier.hashCode();
+   }
+
+   @Override
+   @SuppressWarnings("unchecked")
+   public boolean equals(Object object)
+   {
+      if (object == this)
+         return true;
+
+      if (object == null)
+         return false;
+      
+      return VersionComparatorRegistry.getInstance().same(this, object);
+   }
+
+   /**
+    * Compare two Versions.
+    *
+    * @param version the other version
+    * @return compare result
+    */
+   public int compareTo(Version version)
+   {
+      if (version == this)
+         return 0;
+
+      int result = major - version.major;
+      if (result != 0)
+         return result;
+
+      result = minor - version.minor;
+      if (result != 0)
+         return result;
+
+      result = micro - version.micro;
+      if (result != 0)
+         return result;
+
+      return qualifier.compareTo(version.qualifier);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparator.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparator.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparator.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.version;
+
+/**
+ * The Version impl comparator.
+ *
+ * @param <T> the first version type
+ * @param <U> the second version type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ */
+public interface VersionComparator<T, U>
+{
+   /**
+    * Compare the two version impls.
+    *
+    * @param one the first version
+    * @param two the second versionl
+    * @return compare the two versions
+    */
+   int compare(T one, U two);
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparatorRegistry.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparatorRegistry.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionComparatorRegistry.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,327 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classloading.spi.version;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Version comparator registry.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ */
+public class VersionComparatorRegistry
+{
+   /** The singleton */
+   private static VersionComparatorRegistry registry = new VersionComparatorRegistry();
+
+   /** The comparators */
+   private Map<Class<?>, Map<Class<?>, VersionComparator<?, ?>>> comparatorMap = new ConcurrentHashMap<Class<?>, Map<Class<?>, VersionComparator<?, ?>>>();
+
+   /**
+    * Create a new VersionComparatorRegistry.
+    */
+   public VersionComparatorRegistry()
+   {
+      // register all our known impls
+      internalRegisterVersionComparator(Version.class, Version.class, new VersionToVersionComparator(), true);
+      internalRegisterVersionComparator(Version.class, String.class, new VersionToStringComparator(), true);
+      internalRegisterVersionComparator(String.class, String.class, new StringToStringComparator(), true);
+   }
+
+   /**
+    * Get the singleton
+    *  
+    * @return the singleton
+    */
+   public static VersionComparatorRegistry getInstance()
+   {
+      return registry;
+   }
+
+   /**
+    * Remove the version comparator.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param t first version impl
+    * @param u second version impl
+    */
+   public <T, U> void removeVersionComparator(Class<T> t, Class<U> u)
+   {
+      registerVersionComparator(t, u, null);
+   }
+
+   /**
+    * Remove the version comparator.
+    *
+    * @param <T> the version type
+    * @param t version impl
+    */
+   public <T> void removeVersionComparator(Class<T> t)
+   {
+      registerVersionComparator(t, null);
+   }
+
+   /**
+    * Register version comparator.
+    * If comparator parameter is null, it's actually a removal.
+    *
+    * @param <T> the version type
+    * @param t version impl
+    * @param comparator the version comparator
+    */
+   public <T> void registerVersionComparator(Class<T> t, VersionComparator<T, T> comparator)
+   {
+      registerVersionComparator(t, t, comparator);
+   }
+
+   /**
+    * Register version comparator.
+    * If comparator parameter is null, it's actually a removal.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param t first version impl
+    * @param u second version impl
+    * @param comparator the version comparator
+    */
+   public <T, U> void registerVersionComparator(Class<T> t, Class<U> u, VersionComparator<T, U> comparator)
+   {
+      internalRegisterVersionComparator(t, u, comparator, false);
+   }
+
+   /**
+    * Register version comparator.
+    * If comparator parameter is null, it's actually a removal.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param t first version impl
+    * @param u second version impl
+    * @param comparator the version comparator
+    * @param setup whether this is during setup
+    */
+   private <T, U> void internalRegisterVersionComparator(Class<T> t, Class<U> u, VersionComparator<T, U> comparator, boolean setup)
+   {
+      if (t == null || u == null)
+         throw new IllegalArgumentException("Null version class");
+
+      // Don't allow removal of the standard comparators
+      if (setup == false)
+      {
+         if (t == Version.class && u == Version.class)
+            throw new IllegalArgumentException("You can't remove or replace the built in Version->Version comparator");
+         if (t == Version.class && u == String.class)
+            throw new IllegalArgumentException("You can't remove or replace the built in Version->String comparator");
+         if (t == String.class && u == Version.class)
+            throw new IllegalArgumentException("You can't remove or replace the built in Version->String comparator");
+         if (t == String.class && u == String.class)
+            throw new IllegalArgumentException("You can't remove or replace the built in Version->String comparator");
+      }
+      
+      if (comparator == null)
+      {
+         
+         Map<Class<?>, VersionComparator<?, ?>> tKeyMap = comparatorMap.get(t);
+         if (tKeyMap != null)
+            tKeyMap.remove(u);
+
+         // different impls
+         if (t.equals(u) == false)
+         {
+            Map<Class<?>, VersionComparator<?, ?>> uKeyMap = comparatorMap.get(u);
+            if (uKeyMap != null)
+               uKeyMap.remove(t);
+         }
+      }
+      else
+      {
+         Map<Class<?>, VersionComparator<?, ?>> tKeyMap = comparatorMap.get(t);
+         if (tKeyMap == null)
+         {
+            tKeyMap = new ConcurrentHashMap<Class<?>, VersionComparator<?, ?>>();
+            comparatorMap.put(t, tKeyMap);
+         }
+         tKeyMap.put(u, comparator);
+
+         // different impls
+         if (t.equals(u) == false)
+         {
+            Map<Class<?>, VersionComparator<?, ?>> uKeyMap = comparatorMap.get(u);
+            if (uKeyMap == null)
+            {
+               uKeyMap = new ConcurrentHashMap<Class<?>, VersionComparator<?, ?>>();
+               comparatorMap.put(u, uKeyMap);
+            }
+            uKeyMap.put(t, new SwitchVersionComparator<U, T>(comparator));
+         }
+      }
+   }
+
+   /**
+    * Get the comparator.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param t first version impl
+    * @param u second version impl 
+    * @return the matching comparator
+    */
+   @SuppressWarnings("unchecked")
+   protected <T, U> VersionComparator<T, U> getComparator(T t, U u)
+   {
+      if (t == null || u == null)
+         return null;
+      Class<T> classT = (Class) t.getClass();
+      Class<U> classU = (Class) u.getClass();
+      return getComparator(classT, classU);
+   }
+
+   /**
+    * Get the comparator.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param t first version impl class
+    * @param u second version impl class
+    * @return the matching comparator
+    */
+   @SuppressWarnings("unchecked")
+   public <T, U> VersionComparator<T, U> getComparator(Class<T> t, Class<U> u)
+   {
+      Map<Class<?>, VersionComparator<?, ?>> map = comparatorMap.get(t);
+      if (map == null)
+         return null;
+      else
+         return (VersionComparator) map.get(u);
+   }
+
+   /**
+    * Compare two version impls.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param t the first version
+    * @param u the second version
+    * @return the compare result
+    */
+   public <T, U> int compare(T t, U u)
+   {
+      VersionComparator<T, U> comparator = getComparator(t, u);
+      if (comparator == null)
+      {
+         String classT = null;
+         if (t != null)
+            classT = t.getClass().getName();
+         String classU = null;
+         if (u != null)
+            classU = u.getClass().getName();
+         throw new IllegalArgumentException("Missing version comparator for Version pair: (" + classT + "," + classU + ")");
+      }
+
+      return comparator.compare(t, u);
+   }
+
+   /**
+    * Test whether two version impls are request.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param t T version impl
+    * @param u U version impl
+    * @return the compare result
+    */
+   public <T, U> boolean same(T t, U u)
+   {
+      VersionComparator<T, U> comparator = getComparator(t, u);
+      if (comparator == null)
+         return false;
+
+      return comparator.compare(t, u) == 0;
+   }
+
+   /**
+    * Switch the compare value.
+    *
+    * @param <T> the first version type
+    * @param <U> the second version type
+    * @param <T> exact version type
+    * @param <U> exact version type
+    */
+   private class SwitchVersionComparator<T, U> implements VersionComparator<T, U>
+   {
+      /** The delegate */
+      private VersionComparator<U, T> delegate;
+
+      /**
+       * Create a new SwitchVersionComparator.
+       * 
+       * @param delegate the delegate comparator
+       */
+      public SwitchVersionComparator(VersionComparator<U, T> delegate)
+      {
+         if (delegate == null)
+            throw new IllegalArgumentException("Null delegate");
+         this.delegate = delegate;
+      }
+
+      public int compare(T t, U u)
+      {
+         return (-1) * delegate.compare(u, t); 
+      }
+   }
+
+   /**
+    * VersionToVersionComparator.
+    */
+   private class VersionToVersionComparator implements VersionComparator<Version, Version>
+   {
+      public int compare(Version t, Version u)
+      {
+         return t.compareTo(u);
+      }
+   }
+
+   /**
+    * VersionToStringComparator.
+    */
+   private class VersionToStringComparator implements VersionComparator<Version, String>
+   {
+      public int compare(Version t, String u)
+      {
+         return t.compareTo(Version.parseVersion(u));
+      }
+   }
+
+   /**
+    * StringToStringComparator.
+    */
+   private class StringToStringComparator implements VersionComparator<String, String>
+   {
+      public int compare(String t, String u)
+      {
+         return Version.parseVersion(t).compareTo(Version.parseVersion(u));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionRange.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionRange.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/main/org/jboss/classloading/spi/version/VersionRange.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,257 @@
+/*
+ * 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.classloading.spi.version;
+
+import java.io.Serializable;
+
+/**
+ * VersionRange.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VersionRange implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 8494384641173842116L;
+
+   /** The low range */
+   private Object low;
+   
+   /** Whether low is inclusive */
+   private boolean lowInclusive;
+   
+   /** The high range */
+   private Object high;
+   
+   /** Whether high is inclusive */
+   private boolean highInclusive;
+   
+   /** All versions */
+   public static final VersionRange ALL_VERSIONS = new VersionRange(Version.DEFAULT_VERSION);
+   
+   /**
+    * Create a new VersionRange with just a low inclusive check
+    * 
+    * @param low the low range (null for no lower bound)
+    */
+   public VersionRange(Object low)
+   {
+      this(low, null);
+   }
+   
+   /**
+    * Create a new VersionRange with low inclusive and high non-inclusive
+    * 
+    * @param low the low range (null for no lower bound)
+    * @param high the high range (null for no higher bound)
+    */
+   public VersionRange(Object low, Object high)
+   {
+      this(low, true, high, false);
+   }
+   
+   /**
+    * Create a new VersionRange.
+    * 
+    * @param low the low range (null for no lower bound)
+    * @param lowInclusive whether the low bound is inclusive
+    * @param high the high range (null for no higher bound)
+    * @param highInclusive whether the high bound is inclusive
+    * @throws IllegalArgumentException if the low or is inclusive but not in the range or the high is less than the low 
+    */
+   public VersionRange(Object low, boolean lowInclusive, Object high, boolean highInclusive)
+   {
+      if (low == null)
+         low = Version.DEFAULT_VERSION;
+      this.low = low;
+      this.lowInclusive = lowInclusive;
+      this.high = high;
+      this.highInclusive = highInclusive;
+      validate();
+   }
+
+   /**
+    * Validate the range
+    * 
+    * @throws IllegalArgumentException for any error
+    */
+   protected void validate()
+   {
+      if (lowInclusive && isInRange(low) == false)
+         throw new IllegalArgumentException("Inclusive low is not in the range: " + toString());
+      if (high != null && highInclusive && isInRange(high) == false)
+         throw new IllegalArgumentException("Inclusive high is not in the range: " + toString());
+      if (high != null)
+      {
+         VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
+         int comparison = registry.compare(low, high);
+         if (comparison > 0)
+            throw new IllegalArgumentException("High is less than the low: " + toString());
+         if (comparison == 0)
+         {
+            if (lowInclusive == false || highInclusive == false)
+               throw new IllegalArgumentException("High and low don't include each other: " + toString());
+         }
+      }
+   }
+   
+   /**
+    * Get the low.
+    * 
+    * @return the low.
+    */
+   public Object getLow()
+   {
+      return low;
+   }
+
+   /**
+    * Get the lowInclusive.
+    * 
+    * @return the lowInclusive.
+    */
+   public boolean isLowInclusive()
+   {
+      return lowInclusive;
+   }
+
+   /**
+    * Get the high.
+    * 
+    * @return the high.
+    */
+   public Object getHigh()
+   {
+      return high;
+   }
+
+   /**
+    * Get the highInclusive.
+    * 
+    * @return the highInclusive.
+    */
+   public boolean isHighInclusive()
+   {
+      return highInclusive;
+   }
+
+   /**
+    * Test whether a version is in range
+    * 
+    * @param version the version to test
+    * @return true when the version is in range
+    * @throws IllegalArgumentException for a null version
+    */
+   public boolean isInRange(Object version)
+   {
+      if (version == null)
+         throw new IllegalArgumentException("Null version");
+      
+      VersionComparatorRegistry comparator = VersionComparatorRegistry.getInstance();
+      
+      int comparison = comparator.compare(low, version);
+      if (comparison > 0)
+         return false;
+      if (lowInclusive == false && comparison == 0)
+         return false;
+
+      if (high != null)
+      {
+         comparison = comparator.compare(high, version);
+         if (comparison < 0)
+            return false;
+         if (highInclusive == false && comparison == 0)
+            return false;
+      }
+      return true;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof VersionRange == false)
+         return false;
+      
+      VersionRange other = (VersionRange) obj;
+      
+      VersionComparatorRegistry comparator = VersionComparatorRegistry.getInstance();
+      
+      Object thisLow = other.getLow();
+      Object otherLow = other.getLow();
+      if (comparator.same(thisLow, otherLow) == false)
+         return false;
+      
+      if (isLowInclusive() != other.isLowInclusive())
+         return false;
+      
+      Object thisHigh = this.getHigh();
+      Object otherHigh = other.getHigh();
+      if (thisHigh == null)
+      {
+         if (otherHigh != null)
+            return false;
+      }
+      else if (comparator.same(thisHigh, otherHigh) == false)
+         return false;
+      
+      if (thisHigh != null && isHighInclusive() != other.isHighInclusive())
+         return false;
+      
+      return true;
+   }
+   
+   @Override 
+   public int hashCode()
+   {
+      if (high != null)
+         return high.hashCode();
+      return low.hashCode();
+   }
+   
+   @Override
+   public String toString()
+   {
+      StringBuilder builder = new StringBuilder();
+      if (isLowInclusive())
+         builder.append("[");
+      else
+         builder.append("(");
+      builder.append(low);
+      builder.append(",");
+      if (high != null)
+      {
+         builder.append(high);
+         if (isHighInclusive())
+            builder.append("]");
+         else
+            builder.append(")");
+      }
+      else
+      {
+         builder.append("?)");
+      }
+      return builder.toString();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportImportMixed.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportImportMixed.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportImportMixed.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <module name="test2" version="2.0.0"/>
+      <package name="test2" version="2.0.0"/>
+      <module name="test1" version="1.0.0"/>
+      <package name="test1" version="1.0.0"/>
+   </capabilities>
+   <requirements>
+      <module name="test2" from="2.0.0"/>
+      <package name="test2" from="2.0.0"/>
+      <module name="test1" from="1.0.0"/>
+      <package name="test1" from="1.0.0"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleNoVersion.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleNoVersion.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleNoVersion.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <module name="export1"/>
+   </capabilities>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleVersioned.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleVersioned.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOneModuleVersioned.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <module name="export1" version="1.0.0"/>
+   </capabilities>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageNoVersion.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageNoVersion.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageNoVersion.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <package name="export1"/>
+   </capabilities>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageVersioned.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageVersioned.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportOnePackageVersioned.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <package name="export1" version="1.0.0"/>
+   </capabilities>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreeModules.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreeModules.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreeModules.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <module name="export1" version="1.0.0"/>
+      <module name="export2" version="2.0.0"/>
+      <module name="export3" version="3.0.0"/>
+   </capabilities>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreePackages.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreePackages.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ExportThreePackages.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <package name="export1" version="1.0.0"/>
+      <package name="export2" version="2.0.0"/>
+      <package name="export3" version="3.0.0"/>
+   </capabilities>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleNoVersion.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleNoVersion.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleNoVersion.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <module name="export1"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleVersioned.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleVersioned.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOneModuleVersioned.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <module name="export1" from="1.0.0" to="2.0.0"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageNoVersion.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageNoVersion.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageNoVersion.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <package name="export1"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageVersioned.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageVersioned.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportOnePackageVersioned.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <package name="export1" from="1.0.0" to="2.0.0"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreeModules.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreeModules.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreeModules.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <module name="export1" from="1.0.0" to="1.1.0"/>
+      <module name="export2" from="2.0.0" to="2.1.0"/>
+      <module name="export3" from="3.0.0" to="3.1.0"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreePackages.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreePackages.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportThreePackages.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <package name="export1" from="1.0.0" to="1.1.0"/>
+      <package name="export2" from="2.0.0" to="2.1.0"/>
+      <package name="export3" from="3.0.0" to="3.1.0"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportVersionRange.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportVersionRange.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ImportVersionRange.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <module name="export1"/>
+      <module name="export2" from="1.0.0"/>
+      <module name="export3" to="1.0.0"/>
+      <module name="export4" from="1.0.0" to="2.0.0"/>
+      <module name="export5" from="1.0.0" from-inclusive="false" to="2.0.0" to-inclusive="false"/>
+      <module name="export6" from="1.0.0" from-inclusive="false" to="2.0.0" to-inclusive="true"/>
+      <module name="export7" from="1.0.0" from-inclusive="true" to="2.0.0" to-inclusive="false"/>
+      <module name="export8" from="1.0.0" from-inclusive="true" to="2.0.0" to-inclusive="true"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleBlackList.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleBlackList.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleBlackList.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              blackList="false">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleCache.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleCache.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleCache.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              cache="false">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleDomain.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleDomain.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleDomain.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              domain="testDomain">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcluded.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcluded.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcluded.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test" excluded="Excluded">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcludedExport.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcludedExport.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExcludedExport.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test" excludedExport="ExcludedExport">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExportAll.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExportAll.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleExportAll.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              export-all="ALL">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleImportAll.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleImportAll.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleImportAll.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              import-all="true">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleIncluded.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleIncluded.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleIncluded.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test" included="Included">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleJ2seClassLoadingCompliance.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleJ2seClassLoadingCompliance.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleJ2seClassLoadingCompliance.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              parent-first="false">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleName.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleName.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleName.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleParentDomain.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleParentDomain.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleParentDomain.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              parent-domain="testParentDomain">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleVersion.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleVersion.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ModuleVersion.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test"
+              version="1.0.0">
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/OptionalRequirement.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/OptionalRequirement.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/OptionalRequirement.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <module name="test1" from="1.0.0" optional="true"/>
+      <package name="test1" from="1.0.0" optional="true"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ReExportRequirement.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ReExportRequirement.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/ReExportRequirement.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <module name="test1" from="1.0.0" reExport="true"/>
+      <package name="test1" from="1.0.0" reExport="true"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/UsesRequirement.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/UsesRequirement.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/UsesRequirement.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <uses name="test1" from="1.0.0"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardCapability.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardCapability.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardCapability.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <capabilities>
+      <module name="test1" version="1.0.0"/>
+      <package name="test1" version="1.0.0"/>
+      <test xmlns="urn:jboss:test:classloading:capability:1.0" name="test" version="1.0.0"/>
+   </capabilities>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardRequirement.xml
===================================================================
--- projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardRequirement.xml	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/resources/tests/org/jboss/test/classloading/metadata/xml/test/WildcardRequirement.xml	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classloading xmlns="urn:jboss:classloading:1.0"
+              name="test">
+   <requirements>
+      <module name="test1" from="1.0.0"/>
+      <package name="test1" from="1.0.0"/>
+      <test xmlns="urn:jboss:test:classloading:requirement:1.0" name="test" from="1.0.0"/>
+   </requirements>
+</classloading>

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTest.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTest.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTest.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,176 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloader.test.support.MockClassLoaderHelper;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * AbstractClassLoadingTest.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractClassLoadingTest extends AbstractTestCaseWithSetup
+{
+   public static AbstractTestDelegate getDelegate(Class<?> clazz)
+   {
+      return new AbstractTestDelegate(clazz);
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      configureLogging();
+   }
+
+   public AbstractClassLoadingTest(String name)
+   {
+      super(name);
+   }
+
+   protected void assertVersion(Version version, int major, int minor, int micro)
+   {
+      assertVersion(version, major, minor, micro, null);
+   }
+
+   protected void assertVersion(Version version, int major, int minor, int micro, String qualifier)
+   {
+      assertNotNull(version);
+      assertEquals(major, version.getMajor());
+      assertEquals(minor, version.getMinor());
+      assertEquals(micro, version.getMicro());
+      if (qualifier == null)
+         assertEquals("", version.getQualifier());
+      else
+         assertEquals(qualifier, version.getQualifier());
+   }
+
+   protected void assertVersionRange(VersionRange range, Object low, Object high)
+   {
+      assertVersionRange(range, low, true, high, false);
+   }
+
+   protected void assertVersionRange(VersionRange range, Object low, boolean lowInclusive, Object high, boolean highInclusive)
+   {
+      assertNotNull(range);
+      if (low == null)
+         assertEquals(Version.DEFAULT_VERSION, range.getLow());
+      else
+         assertEquals(low, range.getLow());
+      assertEquals(lowInclusive, range.isLowInclusive());
+      assertEquals(high, range.getHigh());
+      assertEquals(highInclusive, range.isHighInclusive());
+   }
+   
+   protected void assertClassLoader(Class<?> clazz, ClassLoader expected)
+   {
+      if (expected == null)
+         return;
+      boolean result = MockClassLoaderHelper.isExpectedClassLoader(clazz, expected);
+      assertTrue(ClassLoaderUtils.classToString(clazz) + " should have expected classloader=" + expected, result);
+   }
+   
+   protected void assertClassEquality(Class<?> expected, Class<?> actual)
+   {
+      assertTrue("Should be the same " + ClassLoaderUtils.classToString(expected) +" and " + ClassLoaderUtils.classToString(actual), expected == actual);
+   }
+   
+   protected void assertNoClassEquality(Class<?> expected, Class<?> actual)
+   {
+      assertTrue("Should NOT be the same " + ClassLoaderUtils.classToString(expected) +" and " + ClassLoaderUtils.classToString(actual), expected != actual);
+   }
+   
+   protected Class<?> assertLoadClass(Class<?> reference, ClassLoader start)
+   {
+      return assertLoadClass(reference, start, start, false);
+   }
+   
+   protected Class<?> assertLoadClass(Class<?> reference, ClassLoader start, boolean isReference)
+   {
+      return assertLoadClass(reference, start, start, isReference);
+   }
+   
+   protected Class<?> assertLoadClass(Class<?> reference, ClassLoader start, ClassLoader expected)
+   {
+      return assertLoadClass(reference, start, expected, false);
+   }
+   
+   protected Class<?> assertLoadClass(Class<?> reference, ClassLoader start, ClassLoader expected, boolean isReference)
+   {
+      Class<?> result = assertLoadClass(reference.getName(), start, expected);
+      if (isReference)
+         assertClassEquality(reference, result);
+      else
+         assertNoClassEquality(reference, result);
+      return result;
+   }
+   
+   protected Class<?> assertLoadClass(String name, ClassLoader start)
+   {
+      return assertLoadClass(name, start, start);
+   }
+   
+   protected Class<?> assertLoadClass(String name, ClassLoader start, ClassLoader expected)
+   {
+      Class<?> result = null;
+      try
+      {
+         result = start.loadClass(name);
+         getLog().debug("Got class: " + ClassLoaderUtils.classToString(result) + " for " + name + " from " + start);
+      }
+      catch (ClassNotFoundException e)
+      {
+         failure("Did not expect CNFE for " + name + " from " + start, e);
+      }
+      assertClassLoader(result, expected);
+      return result;
+   }
+   
+   protected void assertLoadClassFail(Class<?> reference, ClassLoader start)
+   {
+      assertLoadClassFail(reference.getName(), start);
+   }
+      
+   protected void assertLoadClassFail(String name, ClassLoader start)
+   {
+      try
+      {
+         start.loadClass(name);
+         fail("Should not be here!");
+      }
+      catch (Exception expected)
+      {
+         checkThrowable(ClassNotFoundException.class, expected);
+      }
+   }
+
+   protected void configureLogging()
+   {
+      //enableTrace("org.jboss.classloading");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTestWithSecurity.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTestWithSecurity.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/AbstractClassLoadingTestWithSecurity.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading;
+
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.security.NothingPolicyPlugin;
+
+/**
+ * AbstractClassLoaderTest.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractClassLoadingTestWithSecurity extends AbstractClassLoadingTest
+{
+   public static AbstractTestDelegate getDelegate(Class<?> clazz)
+   {
+      AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
+      delegate.enableSecurity = true;
+      delegate.securityPolicyName = NothingPolicyPlugin.class.getName();
+      return delegate;
+   }
+
+   public AbstractClassLoadingTestWithSecurity(String name)
+   {
+      super(name);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/ClassLoadingAllTestSuite.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/ClassLoadingAllTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/ClassLoadingAllTestSuite.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.classloading.dependency.DependencyTestSuite;
+import org.jboss.test.classloading.metadata.MetaDataTestSuite;
+import org.jboss.test.classloading.version.VersionTestSuite;
+
+/**
+ * ClassLoading All Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class ClassLoadingAllTestSuite extends TestSuite
+{
+   /**
+    * For running the testsuite from the command line
+    * 
+    * @param args the command line args
+    */
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   /**
+    * Create the testsuite
+    * 
+    * @return the testsuite
+    */
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("ClassLoading All Tests");
+
+      suite.addTest(VersionTestSuite.suite());
+      suite.addTest(MetaDataTestSuite.suite());
+      suite.addTest(DependencyTestSuite.suite());
+      
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/DependencyTestSuite.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/DependencyTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/DependencyTestSuite.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.classloading.dependency.test.DependencyUnitTestCase;
+import org.jboss.test.classloading.dependency.test.DomainUnitTestCase;
+import org.jboss.test.classloading.dependency.test.ImportAllUnitTestCase;
+import org.jboss.test.classloading.dependency.test.MockClassLoadingMetaDataUnitTestCase;
+import org.jboss.test.classloading.dependency.test.ModuleDependencyUnitTestCase;
+import org.jboss.test.classloading.dependency.test.PackageDependencyUnitTestCase;
+import org.jboss.test.classloading.dependency.test.ReExportModuleUnitTestCase;
+import org.jboss.test.classloading.dependency.test.ReExportPackageUnitTestCase;
+import org.jboss.test.classloading.dependency.test.UsesPackageUnitTestCase;
+
+/**
+ * Version Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class DependencyTestSuite extends TestSuite
+{
+   /**
+    * For running the testsuite from the command line
+    * 
+    * @param args the command line args
+    */
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   /**
+    * Create the testsuite
+    * 
+    * @return the testsuite
+    */
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Dependency Tests");
+
+      suite.addTest(MockClassLoadingMetaDataUnitTestCase.suite());
+      suite.addTest(DomainUnitTestCase.suite());
+      suite.addTest(ImportAllUnitTestCase.suite());
+      suite.addTest(ModuleDependencyUnitTestCase.suite());
+      suite.addTest(PackageDependencyUnitTestCase.suite());
+      suite.addTest(DependencyUnitTestCase.suite());
+      suite.addTest(ReExportModuleUnitTestCase.suite());
+      suite.addTest(ReExportPackageUnitTestCase.suite());
+      suite.addTest(UsesPackageUnitTestCase.suite());
+      
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/a/A.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/a/A.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/a/A.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.dependency.support.a;
+
+/**
+ * A.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/b/B.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/b/B.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/b/B.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.dependency.support.b;
+
+/**
+ * B.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/c/C.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/c/C.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/support/c/C.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.dependency.support.c;
+
+/**
+ * C.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class C
+{
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/AbstractMockClassLoaderUnitTest.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/AbstractMockClassLoaderUnitTest.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/AbstractMockClassLoaderUnitTest.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import java.util.Collections;
+
+import junit.framework.Test;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.InstallCallbackMetaData;
+import org.jboss.beans.metadata.plugins.UninstallCallbackMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.CallbackMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoaderPolicyModule;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.AbstractClassLoadingTest;
+
+/**
+ * AbstractMockClassLoaderUnitTest.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractMockClassLoaderUnitTest extends AbstractClassLoadingTest
+{
+   private Kernel kernel;
+   
+   private KernelController controller;
+
+   protected ClassLoaderSystem system;
+   
+   public static Test suite()
+   {
+      return suite(AbstractMockClassLoaderUnitTest.class);
+   }
+
+   public AbstractMockClassLoaderUnitTest(String name)
+   {
+      super(name);
+   }
+   
+   protected ClassLoader assertClassLoader(KernelControllerContext context) throws Exception
+   {
+      MockClassLoaderPolicyModule module = assertModule(context);
+      return module.registerClassLoaderPolicy(system);
+   }
+   
+   protected MockClassLoaderPolicyModule assertModule(KernelControllerContext context) throws Exception
+   {
+      assertEquals(context.getName() + " should be installed: " + context.getState() + " unresolved=" + context.getDependencyInfo().getUnresolvedDependencies(), ControllerState.INSTALLED, context.getState());
+      Object target = context.getTarget();
+      assertNotNull(target);
+      return assertInstanceOf(target, MockClassLoaderPolicyModule.class);
+   }
+
+   protected void assertNoClassLoader(KernelControllerContext context) throws Exception
+   {
+      assertNoModule(context);
+   }
+
+   protected void assertNoModule(KernelControllerContext context) throws Exception
+   {
+      boolean test = ControllerState.INSTALLED.equals(context.getState());
+      if (test)
+      {
+         MockClassLoaderPolicyModule module = assertModule(context);
+         Object target = context.getTarget();
+         assertNotNull(target);
+         fail("Should not be able to create classloader: " + module.registerClassLoaderPolicy(system));
+      }
+   }
+   
+   protected KernelControllerContext install(MockClassLoadingMetaData metaData) throws Exception
+   {
+      // Determine some properties
+      String contextName = metaData.getName() + ":" + metaData.getVersion().toString(); 
+      
+      // Create the module
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(contextName, MockClassLoaderPolicyModule.class.getName());
+      builder.addConstructorParameter(MockClassLoadingMetaData.class.getName(), metaData);
+      builder.addConstructorParameter(String.class.getName(), contextName);
+      builder.setNoClassLoader();
+      builder.addUninstall("removeClassLoader");
+      BeanMetaData module = builder.getBeanMetaData();
+      return install(module);
+   }
+   
+   protected KernelControllerContext install(BeanMetaData beanMetaData) throws Exception
+   {
+      try
+      {
+         return controller.install(beanMetaData);
+      }
+      catch (Exception e)
+      {
+         throw e;
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error during install: " + beanMetaData, t);
+      }
+   }
+
+   protected void uninstall(KernelControllerContext context)
+   {
+      controller.uninstall(context.getName());
+   }
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      // Bootstrap the kernel
+      AbstractBootstrap bootstrap = new BasicBootstrap();
+      bootstrap.run();
+      kernel = bootstrap.getKernel();
+      controller = kernel.getController();
+
+      system = new DefaultClassLoaderSystem();
+      ClassLoaderDomain defaultDomain = system.getDefaultDomain();
+      defaultDomain.setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
+
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("ClassLoading", ClassLoading.class.getName());
+      BeanMetaData beanMetaData = builder.getBeanMetaData();
+      
+      // TODO Add in/uncallbacks to the builder
+      AbstractBeanMetaData abmd = (AbstractBeanMetaData) beanMetaData;
+      InstallCallbackMetaData install = new InstallCallbackMetaData();
+      install.setMethodName("addModule");
+      install.setDependentState(ControllerState.CONFIGURED);
+      abmd.setInstallCallbacks(Collections.singletonList((CallbackMetaData) install));
+      UninstallCallbackMetaData uninstall = new UninstallCallbackMetaData();
+      uninstall.setMethodName("removeModule");
+      uninstall.setDependentState(ControllerState.CONFIGURED);
+      abmd.setUninstallCallbacks(Collections.singletonList((CallbackMetaData) uninstall));
+      install(beanMetaData);
+   }
+
+   protected void tearDown() throws Exception
+   {
+      controller.shutdown();
+      super.tearDown();
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DependencyUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DependencyUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DependencyUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,261 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import java.util.Collections;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+
+/**
+ * DependencyUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DependencyUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(DependencyUnitTestCase.class);
+   }
+
+   public DependencyUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testSmoke() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testBDependsACorrectWay() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.setPathsAndPackageNames(B.class);
+         ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+         Requirement requirement = factory.createRequirePackage(A.class.getPackage().getName());
+         b.setRequirements(Collections.singletonList(requirement));
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testBDependsAWrongWay() throws Exception
+   {
+      MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+      b.setPathsAndPackageNames(B.class);
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Requirement requirement = factory.createRequirePackage(A.class.getPackage().getName());
+      b.setRequirements(Collections.singletonList(requirement));
+      KernelControllerContext contextB = install(b);
+      try
+      {
+         assertNoClassLoader(contextB);
+
+         MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+         a.setPathsAndPackageNames(A.class);
+         KernelControllerContext contextA = install(a);
+         try
+         {
+            ClassLoader clA = assertClassLoader(contextA);
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextA);
+         }
+         assertNoClassLoader(contextA);
+      }
+      finally
+      {
+         uninstall(contextB);
+      }
+      assertNoClassLoader(contextB);
+   }
+   
+   public void testBDependsARedeployA() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.setPathsAndPackageNames(B.class);
+         ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+         Requirement requirement = factory.createRequirePackage(A.class.getPackage().getName());
+         b.setRequirements(Collections.singletonList(requirement));
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+            
+            uninstall(contextA);
+            try
+            {
+               assertNoClassLoader(contextA);
+               assertNoClassLoader(contextB);
+            }
+            finally
+            {
+               contextA = install(a);
+            }
+            clA = assertClassLoader(contextA);
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testBDependsARedeployB() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.setPathsAndPackageNames(B.class);
+         ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+         Requirement requirement = factory.createRequirePackage(A.class.getPackage().getName());
+         b.setRequirements(Collections.singletonList(requirement));
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+            
+            uninstall(contextB);
+            try
+            {
+               assertLoadClass(A.class, clA);
+               assertLoadClassFail(B.class, clA);
+               assertNoClassLoader(contextB);
+            }
+            finally
+            {
+               contextB = install(b);
+            }
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DomainUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DomainUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/DomainUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,199 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+
+/**
+ * DomainUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DomainUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(DomainUnitTestCase.class);
+   }
+
+   public DomainUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testDefaultDomain() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testSubDomainParentBefore() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.setDomain("SubDomain");
+         b.setPathsAndPackageNames(A.class, B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testSubDomainParentAfter() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.setDomain("SubDomain");
+         b.setJ2seClassLoadingCompliance(false);
+         b.setPathsAndPackageNames(A.class, B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testParentDoesNotExist() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setDomain("SubDomain");
+      a.setParentDomain("DOESNOTEXIST");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         assertNoClassLoader(contextA);
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testParentDoesExists() throws Exception
+   {
+      ClassLoaderDomain domain = system.createAndRegisterDomain("TestDomain", ParentPolicy.BEFORE_BUT_JAVA_ONLY);
+      try
+      {
+         MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+         a.setDomain("SubDomain");
+         a.setParentDomain("TestDomain");
+         a.setPathsAndPackageNames(A.class);
+         KernelControllerContext contextA = install(a);
+         try
+         {
+            ClassLoader clA = assertClassLoader(contextA);
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         finally
+         {
+            uninstall(contextA);
+         }
+         assertNoClassLoader(contextA);
+      }
+      finally
+      {
+         system.unregisterDomain(domain);
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ImportAllUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ImportAllUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ImportAllUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+
+/**
+ * ImportAllUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ImportAllUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(ImportAllUnitTestCase.class);
+   }
+
+   public ImportAllUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testImportAll() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.setImportAll(true);
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/MockClassLoadingMetaDataUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/MockClassLoadingMetaDataUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/MockClassLoadingMetaDataUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,319 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoaderPolicyModule;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+
+/**
+ * MockClassLoadingMetaDataUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockClassLoadingMetaDataUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(MockClassLoadingMetaDataUnitTestCase.class);
+   }
+
+   public MockClassLoadingMetaDataUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testName() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals("a", module.getName());
+         assertEquals(Version.DEFAULT_VERSION, module.getVersion());
+         assertNull(module.getDomainName());
+         assertNull(module.getParentDomainName());
+         assertNull(module.getExportAll());
+         assertNull(module.getIncluded());
+         assertNull(module.getExcluded());
+         assertNull(module.getExcludedExport());
+         assertFalse(module.isImportAll());
+         assertTrue(module.isJ2seClassLoadingCompliance());
+         ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+         Capability capability = factory.createModule("a");
+         assertEquals(Collections.singletonList(capability), module.getCapabilities());
+         assertNull(module.getRequirements());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testVersion() throws Exception
+   {
+      Version version = Version.parseVersion("1.0.0");
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a", version);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals(version, module.getVersion());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testDomainName() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setDomain("DomainName");
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals("DomainName", module.getDomainName());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testParentDomainName() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setDomain("DomainName");
+      a.setParentDomain(ClassLoaderSystem.DEFAULT_DOMAIN_NAME);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals(ClassLoaderSystem.DEFAULT_DOMAIN_NAME, module.getParentDomainName());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testExportAll() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setExportAll(ExportAll.ALL);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals(ExportAll.ALL, module.getExportAll());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testIncluded() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setIncluded(ClassFilter.JAVA_ONLY);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals(ClassFilter.JAVA_ONLY, module.getIncluded());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testExcluded() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setExcluded(ClassFilter.JAVA_ONLY);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals(ClassFilter.JAVA_ONLY, module.getExcluded());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testExcludedExport() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setExcludedExport(ClassFilter.JAVA_ONLY);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals(ClassFilter.JAVA_ONLY, module.getExcludedExport());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testImportAll() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setImportAll(true);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertTrue(module.isImportAll());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testJ2seClassLoading() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setJ2seClassLoadingCompliance(false);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertFalse(module.isJ2seClassLoadingCompliance());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testManualCapabilities() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      List<Capability> capabilities = new ArrayList<Capability>();
+      capabilities.add(factory.createModule("b"));
+      capabilities.add(factory.createPackage("p1"));
+      capabilities.add(factory.createPackage("p2"));
+      a.setCapabilities(capabilities);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         assertEquals(capabilities, module.getCapabilities());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testAutoCapabilities() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class, B.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoaderPolicyModule module = assertModule(contextA);
+         ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+         List<Capability> capabilities = new ArrayList<Capability>();
+         capabilities.add(factory.createModule("a"));
+         capabilities.add(factory.createPackage(A.class.getPackage().getName()));
+         capabilities.add(factory.createPackage(B.class.getPackage().getName()));
+         assertEquals(capabilities, module.getCapabilities());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+   
+   public void testRequirements() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      List<Requirement> requirements = new ArrayList<Requirement>();
+      requirements.add(factory.createRequireModule("b"));
+      requirements.add(factory.createRequirePackage(B.class.getPackage().getName()));
+      a.setRequirements(requirements);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            MockClassLoaderPolicyModule module = assertModule(contextA);
+            assertEquals(requirements, module.getRequirements());
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertNoModule(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoModule(contextA);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ModuleDependencyUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ModuleDependencyUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ModuleDependencyUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+
+/**
+ * ModuleDependencyUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModuleDependencyUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(ModuleDependencyUnitTestCase.class);
+   }
+
+   public ModuleDependencyUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testImportModuleNoVersionCheck() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testImportModuleVersionCheck() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA", "1.0.0"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testImportModuleVersionCheckFailed() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA", "3.0.0"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertNoClassLoader(contextB);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+
+/**
+ * PackageDependencyUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PackageDependencyUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(PackageDependencyUnitTestCase.class);
+   }
+
+   public PackageDependencyUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testImportPackageNoVersionCheck() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequirePackage(A.class.getPackage().getName()));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testImportPackageVersionCheck() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName(), "1.0.0"));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequirePackage(A.class.getPackage().getName(), new VersionRange("1.0.0", "2.0.0")));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testImportPackageVersionCheckFailed() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName(), "3.0.0"));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequirePackage(A.class.getPackage().getName(), new VersionRange("1.0.0", "2.0.0")));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertNoClassLoader(contextB);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertNoClassLoader(contextB);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportModuleUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportModuleUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportModuleUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+import org.jboss.test.classloading.dependency.support.c.C;
+
+/**
+ * ReExportModuleUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ReExportModuleUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(ReExportModuleUnitTestCase.class);
+   }
+
+   public ReExportModuleUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testReExport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createReExportModule("a"));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+
+            MockClassLoadingMetaData c = new MockClassLoadingMetaData("c");
+            c.getRequirements().addRequirement(factory.createRequireModule("b"));
+            c.setPathsAndPackageNames(C.class);
+            KernelControllerContext contextC = install(c);
+            try
+            {
+               assertLoadClass(A.class, clA);
+               assertLoadClassFail(B.class, clA);
+               assertLoadClassFail(C.class, clA);
+               assertLoadClass(A.class, clB, clA);
+               assertLoadClass(B.class, clB);
+               assertLoadClassFail(C.class, clB);
+               ClassLoader clC = assertClassLoader(contextC);
+               assertLoadClass(A.class, clC, clA);
+               assertLoadClass(B.class, clC, clB);
+               assertLoadClass(C.class, clC);
+            }
+            finally
+            {
+               uninstall(contextC);
+            }
+            assertNoClassLoader(contextC);
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertNoClassLoader(contextB);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testNoReExport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createReExportModule("a"));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+
+            MockClassLoadingMetaData c = new MockClassLoadingMetaData("c");
+            c.getRequirements().addRequirement(factory.createRequirePackage(B.class.getPackage().getName()));
+            c.setPathsAndPackageNames(C.class);
+            KernelControllerContext contextC = install(c);
+            try
+            {
+               assertLoadClass(A.class, clA);
+               assertLoadClassFail(B.class, clA);
+               assertLoadClassFail(C.class, clA);
+               assertLoadClass(A.class, clB, clA);
+               assertLoadClass(B.class, clB);
+               assertLoadClassFail(C.class, clB);
+               ClassLoader clC = assertClassLoader(contextC);
+               assertLoadClassFail(A.class, clC);
+               assertLoadClass(B.class, clC, clB);
+               assertLoadClass(C.class, clC);
+            }
+            finally
+            {
+               uninstall(contextC);
+            }
+            assertNoClassLoader(contextC);
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertNoClassLoader(contextB);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportPackageUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportPackageUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/ReExportPackageUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+import org.jboss.test.classloading.dependency.support.c.C;
+
+/**
+ * ReExportPackageUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ReExportPackageUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(ReExportPackageUnitTestCase.class);
+   }
+
+   public ReExportPackageUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testReExport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createReExportPackage(A.class.getPackage().getName()));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+
+            MockClassLoadingMetaData c = new MockClassLoadingMetaData("c");
+            c.getRequirements().addRequirement(factory.createRequireModule("b"));
+            c.setPathsAndPackageNames(C.class);
+            KernelControllerContext contextC = install(c);
+            try
+            {
+               assertLoadClass(A.class, clA);
+               assertLoadClassFail(B.class, clA);
+               assertLoadClassFail(C.class, clA);
+               assertLoadClass(A.class, clB, clA);
+               assertLoadClass(B.class, clB);
+               assertLoadClassFail(C.class, clB);
+               ClassLoader clC = assertClassLoader(contextC);
+               assertLoadClass(A.class, clC, clA);
+               assertLoadClass(B.class, clC, clB);
+               assertLoadClass(C.class, clC);
+            }
+            finally
+            {
+               uninstall(contextC);
+            }
+            assertNoClassLoader(contextC);
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertNoClassLoader(contextB);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testNoReExport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createReExportPackage(A.class.getPackage().getName()));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+
+            MockClassLoadingMetaData c = new MockClassLoadingMetaData("c");
+            c.getRequirements().addRequirement(factory.createRequirePackage(B.class.getPackage().getName()));
+            c.setPathsAndPackageNames(C.class);
+            KernelControllerContext contextC = install(c);
+            try
+            {
+               assertLoadClass(A.class, clA);
+               assertLoadClassFail(B.class, clA);
+               assertLoadClassFail(C.class, clA);
+               assertLoadClass(A.class, clB, clA);
+               assertLoadClass(B.class, clB);
+               assertLoadClassFail(C.class, clB);
+               ClassLoader clC = assertClassLoader(contextC);
+               assertLoadClassFail(A.class, clC);
+               assertLoadClass(B.class, clC, clB);
+               assertLoadClass(C.class, clC);
+            }
+            finally
+            {
+               uninstall(contextC);
+            }
+            assertNoClassLoader(contextC);
+            assertLoadClass(A.class, clA);
+            assertLoadClassFail(B.class, clA);
+            assertLoadClassFail(C.class, clA);
+            assertLoadClass(A.class, clB, clA);
+            assertLoadClass(B.class, clB);
+            assertLoadClassFail(C.class, clB);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+         assertNoClassLoader(contextB);
+         assertLoadClass(A.class, clA);
+         assertLoadClassFail(B.class, clA);
+         assertLoadClassFail(C.class, clA);
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/UsesPackageUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/UsesPackageUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/dependency/test/UsesPackageUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.dependency.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+
+/**
+ * ReExportPackageUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class UsesPackageUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(UsesPackageUnitTestCase.class);
+   }
+
+   public UsesPackageUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testUsesImport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      MockClassLoadingMetaData a1 = new MockClassLoadingMetaData("a1");
+      a1.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA1 = install(a1);
+      try
+      {
+         ClassLoader clA1 = assertClassLoader(contextA1);
+         assertLoadClass(A.class, clA1);
+
+         MockClassLoadingMetaData a2 = new MockClassLoadingMetaData("a2");
+         a2.getRequirements().addRequirement(factory.createUsesPackage(A.class.getPackage().getName()));
+         a2.setPathsAndPackageNames(A.class);
+         KernelControllerContext contextA2 = install(a2);
+         try
+         {
+            assertLoadClass(A.class, clA1);
+            ClassLoader clA2 = assertClassLoader(contextA2);
+            assertLoadClass(A.class, clA2, clA1);
+         }
+         finally
+         {
+            uninstall(contextA2);
+         }
+         assertNoClassLoader(contextA2);
+         assertLoadClass(A.class, clA1);
+      }
+      finally
+      {
+         uninstall(contextA1);
+      }
+      assertNoClassLoader(contextA1);
+   }
+   
+   public void testUsesNoImport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      MockClassLoadingMetaData a1 = new MockClassLoadingMetaData("a1");
+      a1.getRequirements().addRequirement(factory.createUsesPackage(A.class.getPackage().getName()));
+      a1.setPaths(A.class);
+      KernelControllerContext contextA1 = install(a1);
+      try
+      {
+         ClassLoader clA1 = assertClassLoader(contextA1);
+         assertLoadClass(A.class, clA1);
+      }
+      finally
+      {
+         uninstall(contextA1);
+      }
+      assertNoClassLoader(contextA1);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/MetaDataTestSuite.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/MetaDataTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/MetaDataTestSuite.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.classloading.metadata.test.CapabilitiesMetaDataUnitTestCase;
+import org.jboss.test.classloading.metadata.test.ClassLoadingMetaDataFactoryUnitTestCase;
+import org.jboss.test.classloading.metadata.test.ClassLoadingMetaDataUnitTestCase;
+import org.jboss.test.classloading.metadata.test.ModuleCapabilityUnitTestCase;
+import org.jboss.test.classloading.metadata.test.ModuleRequirementUnitTestCase;
+import org.jboss.test.classloading.metadata.test.NameAndVersionRangeUnitTestCase;
+import org.jboss.test.classloading.metadata.test.NameAndVersionUnitTestCase;
+import org.jboss.test.classloading.metadata.test.PackageCapabilityUnitTestCase;
+import org.jboss.test.classloading.metadata.test.PackageRequirementUnitTestCase;
+import org.jboss.test.classloading.metadata.test.RequirementsMetaDataUnitTestCase;
+import org.jboss.test.classloading.metadata.xml.test.ClassLoadingMetaDataXmlUnitTestCase;
+
+/**
+ * Version Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class MetaDataTestSuite extends TestSuite
+{
+   /**
+    * For running the testsuite from the command line
+    * 
+    * @param args the command line args
+    */
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   /**
+    * Create the testsuite
+    * 
+    * @return the testsuite
+    */
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("MetaData Tests");
+
+      suite.addTest(NameAndVersionUnitTestCase.suite());
+      suite.addTest(NameAndVersionRangeUnitTestCase.suite());
+      suite.addTest(ModuleCapabilityUnitTestCase.suite());
+      suite.addTest(PackageRequirementUnitTestCase.suite());
+      suite.addTest(ModuleRequirementUnitTestCase.suite());
+      suite.addTest(PackageCapabilityUnitTestCase.suite());
+      suite.addTest(CapabilitiesMetaDataUnitTestCase.suite());
+      suite.addTest(RequirementsMetaDataUnitTestCase.suite());
+      suite.addTest(ClassLoadingMetaDataFactoryUnitTestCase.suite());
+      suite.addTest(ClassLoadingMetaDataUnitTestCase.suite());
+      suite.addTest(ClassLoadingMetaDataXmlUnitTestCase.suite());
+      
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/CapabilitiesMetaDataUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/CapabilitiesMetaDataUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/CapabilitiesMetaDataUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * CapabilitiesMetaDataUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CapabilitiesMetaDataUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(CapabilitiesMetaDataUnitTestCase.class);
+   }
+
+   public CapabilitiesMetaDataUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructor() throws Exception
+   {
+      CapabilitiesMetaData metadata = new CapabilitiesMetaData();
+      assertNull(metadata.getCapabilities());
+   }
+   
+   public void testSetCapabilities() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      CapabilitiesMetaData metadata = new CapabilitiesMetaData();
+      assertNull(metadata.getCapabilities());
+      
+      List<Capability> list = new ArrayList<Capability>();
+      list.add(factory.createModule("module", "1.0.0"));
+      list.add(factory.createPackage("package", "1.0.0"));
+      metadata.setCapabilities(list);
+      
+      assertEquals(list, metadata.getCapabilities());
+   }
+   
+   public void testAddCapabilities() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      CapabilitiesMetaData metadata = new CapabilitiesMetaData();
+      assertNull(metadata.getCapabilities());
+      
+      List<Capability> list = new ArrayList<Capability>();
+      Capability capability = factory.createModule("module", "1.0.0");
+      metadata.addCapability(capability);
+      list.add(capability);
+      assertEquals(list, metadata.getCapabilities());
+
+      capability = factory.createPackage("module", "1.0.0");
+      metadata.addCapability(capability);
+      list.add(capability);
+      assertEquals(list, metadata.getCapabilities());
+   }
+   
+   public void testRemoveCapabilities() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      CapabilitiesMetaData metadata = new CapabilitiesMetaData();
+      assertNull(metadata.getCapabilities());
+
+      Capability module = factory.createModule("module", "1.0.0");
+      Capability pkge = factory.createPackage("module", "1.0.0");
+
+      List<Capability> list = new ArrayList<Capability>();
+      list.add(module);
+      list.add(pkge);
+      metadata.setCapabilities(list);
+      
+      metadata.removeCapability(module);
+      list.remove(module);
+      assertEquals(list, metadata.getCapabilities());
+      
+      metadata.removeCapability(pkge);
+      list.remove(pkge);
+      assertEquals(list, metadata.getCapabilities());
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      CapabilitiesMetaData test = new CapabilitiesMetaData();
+      test.addCapability(factory.createModule("module", "1.0.0"));
+      test.addCapability(factory.createPackage("package", "1.0.0"));
+      CapabilitiesMetaData other = serializeDeserialize(test, CapabilitiesMetaData.class);
+      assertEquals(test.getCapabilities(), other.getCapabilities());
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataFactoryUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataFactoryUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataFactoryUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,221 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.plugins.metadata.ModuleCapability;
+import org.jboss.classloading.plugins.metadata.ModuleRequirement;
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.plugins.metadata.UsesPackageRequirement;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * ClassLoadingMetaDataFactoryUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoadingMetaDataFactoryUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(ClassLoadingMetaDataFactoryUnitTestCase.class);
+   }
+
+   public ClassLoadingMetaDataFactoryUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testCreateModuleNoVersion() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Capability test = factory.createModule("test");
+      assertEquals(new ModuleCapability("test"), test);
+   }
+   
+   public void testCreateModuleVersioned() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Capability test = factory.createModule("test", "1.0.0");
+      assertEquals(new ModuleCapability("test", "1.0.0"), test);
+   }
+   
+   public void testCreatePackageNoVersion() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Capability test = factory.createPackage("test");
+      assertEquals(new PackageCapability("test"), test);
+   }
+   
+   public void testCreatePackageVersioned() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Capability test = factory.createPackage("test", "1.0.0");
+      assertEquals(new PackageCapability("test", "1.0.0"), test);
+   }
+   
+   public void testCreateRequireModuleNoVersion() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Requirement test = factory.createRequireModule("test");
+      assertEquals(new ModuleRequirement("test"), test);
+   }
+   
+   public void testCreateRequireModuleVersioned() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createRequireModule("test", range);
+      assertEquals(new ModuleRequirement("test", range), test);
+   }
+   
+   public void testCreateRequireModuleVersionedOptionalReExport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createRequireModule("test", range, true, true);
+      ModuleRequirement expected = new ModuleRequirement("test", range);
+      expected.setOptional(true);
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateReExportModuleNoVersion() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Requirement test = factory.createReExportModule("test");
+      ModuleRequirement expected = new ModuleRequirement("test");
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateReExportModuleVersioned() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createReExportModule("test", range);
+      ModuleRequirement expected = new ModuleRequirement("test", range);
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateReExportModuleVersionedOptional() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createReExportModule("test", range, true);
+      ModuleRequirement expected = new ModuleRequirement("test", range);
+      expected.setOptional(true);
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateRequirePackageNoVersion() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Requirement test = factory.createRequirePackage("test");
+      assertEquals(new PackageRequirement("test"), test);
+   }
+   
+   public void testCreateRequirePackageVersioned() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createRequirePackage("test", range);
+      assertEquals(new PackageRequirement("test", range), test);
+   }
+   
+   public void testCreateRequirePackageVersionedOptionalReExport() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createRequirePackage("test", range, true, true);
+      PackageRequirement expected = new PackageRequirement("test", range);
+      expected.setOptional(true);
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateReExportPackageNoVersion() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Requirement test = factory.createReExportPackage("test");
+      PackageRequirement expected = new PackageRequirement("test");
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateReExportPackageVersioned() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createReExportPackage("test", range);
+      PackageRequirement expected = new PackageRequirement("test", range);
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateReExportPackageVersionedOptional() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createReExportPackage("test", range, true);
+      PackageRequirement expected = new PackageRequirement("test", range);
+      expected.setOptional(true);
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateUsesPackageNoVersion() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Requirement test = factory.createUsesPackage("test");
+      UsesPackageRequirement expected = new UsesPackageRequirement("test");
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateUsesPackageVersioned() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createUsesPackage("test", range);
+      UsesPackageRequirement expected = new UsesPackageRequirement("test", range);
+      assertEquals(expected, test);
+   }
+   
+   public void testCreateUsesPackageVersionedOptional() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      Requirement test = factory.createUsesPackage("test", range, true);
+      UsesPackageRequirement expected = new UsesPackageRequirement("test", range);
+      expected.setReExport(true);
+      assertEquals(expected, test);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ClassLoadingMetaDataUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,389 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.RequirementsMetaData;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * ClassLoadingMetaDataUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoadingMetaDataUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(ClassLoadingMetaDataUnitTestCase.class);
+   }
+
+   public ClassLoadingMetaDataUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructor() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      assertNull(test.getDomain());
+      assertNull(test.getParentDomain());
+      assertNull(test.getExportAll());
+      assertNull(test.getIncluded());
+      assertNull(test.getExcluded());
+      assertNull(test.getExcludedExport());
+      assertNull(test.getIncludedPackages());
+      assertNull(test.getExcludedPackages());
+      assertNull(test.getExcludedExportPackages());
+      assertFalse(test.isImportAll());
+      assertTrue(test.isJ2seClassLoadingCompliance());
+      assertNull(test.getCapabilities().getCapabilities());
+      assertNull(test.getRequirements().getRequirements());
+   }
+   
+   public void testSetName() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNotNull(test.getName());
+      test.setName("test");
+      assertEquals("test", test.getName());
+      
+      try
+      {
+         test.setName(null);
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+      
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setName("test");
+      testEquals(test, test2, true);
+   }
+   
+   public void testSetVersion() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      test.setVersion("1.0.0");
+      assertEquals("1.0.0", test.getVersion());
+      test.setVersion(null);
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+
+      test.setVersion("1.0.0");
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setVersion("1.0.0");
+      testEquals(test, test2, true);
+   }
+
+   public void testSetDomain() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getDomain());
+      test.setDomain("test");
+      assertEquals("test", test.getDomain());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setDomain("test");
+      testEquals(test, test2, true);
+   }
+   
+   public void testSetParentDomain() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getParentDomain());
+      test.setParentDomain("test");
+      assertEquals("test", test.getParentDomain());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setParentDomain("test");
+      testEquals(test, test2, true);
+   }
+   
+   public void testSetExportAll() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getExportAll());
+      test.setExportAll(ExportAll.ALL);
+      assertEquals(ExportAll.ALL, test.getExportAll());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setExportAll(ExportAll.ALL);
+      testEquals(test, test2, true);
+   }
+   
+   public void testSetIncludedPackages() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getIncludedPackages());
+      test.setIncludedPackages("Included");
+      assertEquals("Included", test.getIncludedPackages());
+   }
+   
+   public void testSetExcludedPackages() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getExcludedPackages());
+      test.setExcludedPackages("Excluded");
+      assertEquals("Excluded", test.getExcludedPackages());
+   }
+   
+   public void testSetExcludedExportPackages() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getExcludedExportPackages());
+      test.setExcludedExportPackages("ExcludedExport");
+      assertEquals("ExcludedExport", test.getExcludedExportPackages());
+   }
+   
+   public void testSetIncluded() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getIncluded());
+      test.setIncluded(ClassFilter.EVERYTHING);
+      assertEquals(ClassFilter.EVERYTHING, test.getIncluded());
+   }
+   
+   public void testSetExcluded() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getExcluded());
+      test.setExcluded(ClassFilter.EVERYTHING);
+      assertEquals(ClassFilter.EVERYTHING, test.getExcluded());
+   }
+   
+   public void testSetExcludedExport() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getExcludedExport());
+      test.setExcludedExport(ClassFilter.EVERYTHING);
+      assertEquals(ClassFilter.EVERYTHING, test.getExcludedExport());
+   }
+   
+   public void testGetIncluded() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getIncluded());
+      
+      test.setIncludedPackages("java.lang");
+      ClassFilter filter = test.getIncluded();
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertFalse(filter.matchesClassName(Collection.class.getName()));
+      
+      test.setIncluded(ClassFilter.JAVA_ONLY);
+      filter = test.getIncluded();
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertFalse(filter.matchesClassName(Collection.class.getName()));
+      
+      test.setIncludedPackages(null);
+      filter = test.getIncluded();
+      assertEquals(ClassFilter.JAVA_ONLY, filter);
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertTrue(filter.matchesClassName(Collection.class.getName()));
+   }
+   
+   public void testGetExcluded() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getExcluded());
+      
+      test.setExcludedPackages("java.lang");
+      ClassFilter filter = test.getExcluded();
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertFalse(filter.matchesClassName(Collection.class.getName()));
+      
+      test.setExcluded(ClassFilter.JAVA_ONLY);
+      filter = test.getExcluded();
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertFalse(filter.matchesClassName(Collection.class.getName()));
+      
+      test.setExcludedPackages(null);
+      filter = test.getExcluded();
+      assertEquals(ClassFilter.JAVA_ONLY, filter);
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertTrue(filter.matchesClassName(Collection.class.getName()));
+   }
+   
+   public void testGetExcludedExport() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertNull(test.getExcludedExport());
+      
+      test.setExcludedExportPackages("java.lang");
+      ClassFilter filter = test.getExcludedExport();
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertFalse(filter.matchesClassName(Collection.class.getName()));
+      
+      test.setExcludedExport(ClassFilter.JAVA_ONLY);
+      filter = test.getExcludedExport();
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertFalse(filter.matchesClassName(Collection.class.getName()));
+      
+      test.setExcludedExportPackages(null);
+      filter = test.getExcludedExport();
+      assertEquals(ClassFilter.JAVA_ONLY, filter);
+      assertTrue(filter.matchesClassName(Object.class.getName()));
+      assertTrue(filter.matchesClassName(Collection.class.getName()));
+   }
+   
+   public void testSetImportAll() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertFalse(test.isImportAll());
+      test.setImportAll(true);
+      assertTrue(test.isImportAll());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setImportAll(true);
+      testEquals(test, test2, true);
+   }
+   
+   public void testJ2seClassLoadingComplaince() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertTrue(test.isJ2seClassLoadingCompliance());
+      test.setJ2seClassLoadingCompliance(false);
+      assertFalse(test.isJ2seClassLoadingCompliance());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setJ2seClassLoadingCompliance(false);
+      testEquals(test, test2, true);
+   }
+   
+   public void testCacheable() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertTrue(test.isCacheable());
+      test.setCacheable(false);
+      assertFalse(test.isCacheable());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setCacheable(false);
+      testEquals(test, test2, true);
+   }
+   
+   public void testBlackList() throws Exception
+   {
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      assertTrue(test.isBlackListable());
+      test.setBlackListable(false);
+      assertFalse(test.isBlackListable());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.setBlackListable(false);
+      testEquals(test, test2, true);
+   }
+   
+   public void testCapabilities() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      CapabilitiesMetaData capabilitiesMetaData = test.getCapabilities();
+      assertNull(capabilitiesMetaData.getCapabilities());
+      Capability capability = factory.createModule("test");
+      capabilitiesMetaData.addCapability(capability);
+      assertEquals(Collections.singletonList(capability), capabilitiesMetaData.getCapabilities());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.getCapabilities().addCapability(capability);
+      testEquals(test, test2, true);
+   }
+   
+   public void testRequirements() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      RequirementsMetaData requirementsMetaData = test.getRequirements();
+      assertNull(requirementsMetaData.getRequirements());
+      Requirement requirement = factory.createRequireModule("test");
+      requirementsMetaData.addRequirement(requirement);
+      assertEquals(Collections.singletonList(requirement), requirementsMetaData.getRequirements());
+
+      ClassLoadingMetaData test2 = new ClassLoadingMetaData();
+      testEquals(test, test2, false);
+      test2.getRequirements().addRequirement(requirement);
+      testEquals(test, test2, true);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      
+      ClassLoadingMetaData test = new ClassLoadingMetaData();
+      test.setName("test");
+      test.setVersion("1.0.0");
+      test.setDomain("domain");
+      test.setParentDomain("parent-domain");
+      test.setExportAll(ExportAll.ALL);
+      test.setImportAll(true);
+      test.setJ2seClassLoadingCompliance(false);
+      test.getCapabilities().addCapability(factory.createModule("module", "1.0.0"));
+      test.getCapabilities().addCapability(factory.createPackage("package", "1.0.0"));
+      test.getRequirements().addRequirement(factory.createRequireModule("module", new VersionRange("1.0.0", "2.0.0")));
+      test.getRequirements().addRequirement(factory.createRequireModule("package", new VersionRange("1.0.0", "2.0.0")));
+      ClassLoadingMetaData other = serializeDeserialize(test, ClassLoadingMetaData.class);
+      assertEquals(test, other);
+   }
+   
+   protected void testEquals(ClassLoadingMetaData test1, ClassLoadingMetaData test2, boolean result)
+   {
+      if (result)
+      {
+         assertTrue("Expected " + test1 + ".equals(" + test2 + ") to be true", test1.equals(test2));
+         assertTrue("Expected " + test2 + ".equals(" + test1 + ") to be true", test2.equals(test1));
+      }
+      else
+      {
+         assertFalse("Expected " + test1 + ".equals(" + test2 + ") to be false", test1.equals(test2));
+         assertFalse("Expected " + test2 + ".equals(" + test1 + ") to be false", test2.equals(test1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleCapabilityUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleCapabilityUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleCapabilityUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.plugins.metadata.ModuleCapability;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * ModuleCapabilityUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModuleCapabilityUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(ModuleCapabilityUnitTestCase.class);
+   }
+
+   public ModuleCapabilityUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructors() throws Exception
+   {
+      ModuleCapability test = new ModuleCapability();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+
+      test = new ModuleCapability("test");
+      assertEquals("test", test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+
+      test = new ModuleCapability("test", "version");
+      assertEquals("test", test.getName());
+      assertEquals("version", test.getVersion());
+      
+      try
+      {
+         fail("Should not be here for: " + new ModuleCapability(null));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+      
+      try
+      {
+         fail("Should not be here for: " + new ModuleCapability(null, "version"));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetName() throws Exception
+   {
+      ModuleCapability test = new ModuleCapability();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      test.setName("name");
+      assertEquals("name", test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      
+      test = new ModuleCapability();
+      try
+      {
+         test.setName(null);
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetVersion() throws Exception
+   {
+      ModuleCapability test = new ModuleCapability();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      test.setVersion("version");
+      assertNotNull(test.getName());
+      assertEquals("version", test.getVersion());
+      test.setVersion(null);
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+   }
+      
+   public void testEquals() throws Exception
+   {
+      testEquals("a", Version.DEFAULT_VERSION, "a", Version.DEFAULT_VERSION, true);
+      testEquals("a", Version.DEFAULT_VERSION, "a", null, true);
+      testEquals("a", Version.DEFAULT_VERSION, "a", "0.0.0", true);
+      testEquals("b", "1.0.0", "b", "1.0.0", true);
+      
+      testEquals("a", Version.DEFAULT_VERSION, "b", Version.DEFAULT_VERSION, false);
+      testEquals("a", "1.0.0", "a", Version.DEFAULT_VERSION, false);
+      testEquals("a", "1.0.0", "a", "0.0.0", false);
+      testEquals("a", "1.0.0", "a", "2.0.0", false);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      ModuleCapability test = new ModuleCapability("a", Version.DEFAULT_VERSION);
+      ModuleCapability other = serializeDeserialize(test, ModuleCapability.class);
+      assertEquals(test, other);
+   }
+   
+   protected void testEquals(String name1, Object version1, String name2, Object version2, boolean result)
+   {
+      ModuleCapability test1 = new ModuleCapability(name1, version1);
+      ModuleCapability test2 = new ModuleCapability(name2, version2);
+      if (result)
+      {
+         assertTrue("Expected " + test1 + ".equals(" + test2 + ") to be true", test1.equals(test2));
+         assertTrue("Expected " + test2 + ".equals(" + test1 + ") to be true", test2.equals(test1));
+      }
+      else
+      {
+         assertFalse("Expected " + test1 + ".equals(" + test2 + ") to be false", test1.equals(test2));
+         assertFalse("Expected " + test2 + ".equals(" + test1 + ") to be false", test2.equals(test1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleRequirementUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleRequirementUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/ModuleRequirementUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.plugins.metadata.ModuleRequirement;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * ModuleRequirementUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModuleRequirementUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(ModuleRequirementUnitTestCase.class);
+   }
+
+   public ModuleRequirementUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructors() throws Exception
+   {
+      ModuleRequirement test = new ModuleRequirement();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+
+      test = new ModuleRequirement("test");
+      assertEquals("test", test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      test = new ModuleRequirement("test", range);
+      assertEquals("test", test.getName());
+      assertEquals(range, test.getVersionRange());
+      
+      try
+      {
+         fail("Should not be here for: " + new ModuleRequirement(null));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+      
+      try
+      {
+         fail("Should not be here for: " + new ModuleRequirement(null, range));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetName() throws Exception
+   {
+      ModuleRequirement test = new ModuleRequirement();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      test.setName("name");
+      assertEquals("name", test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      
+      test = new ModuleRequirement();
+      try
+      {
+         test.setName(null);
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetVersionRange() throws Exception
+   {
+      ModuleRequirement test = new ModuleRequirement();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      test.setVersionRange(range);
+      assertNotNull(test.getName());
+      assertEquals(range, test.getVersionRange());
+      test.setVersionRange(null);
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+   }
+      
+   public void testEquals() throws Exception
+   {
+      testEquals("a", VersionRange.ALL_VERSIONS, "a", VersionRange.ALL_VERSIONS, true);
+      testEquals("a", VersionRange.ALL_VERSIONS, "a", null, true);
+      VersionRange range1 = new VersionRange("1.0.0", true, "1.0.0", true);
+      testEquals("b", range1, "b", range1, true);
+      
+      testEquals("a", VersionRange.ALL_VERSIONS, "b", VersionRange.ALL_VERSIONS, false);
+      testEquals("a", range1, "a", VersionRange.ALL_VERSIONS, false);
+      VersionRange range2 = new VersionRange("1.0.0", true, "2.0.0", true);
+      testEquals("a", range1, "a", range2, false);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      ModuleRequirement test = new ModuleRequirement("a", VersionRange.ALL_VERSIONS);
+      ModuleRequirement other = serializeDeserialize(test, ModuleRequirement.class);
+      assertEquals(test, other);
+   }
+   
+   protected void testEquals(String name1, VersionRange range1, String name2, VersionRange range2, boolean result)
+   {
+      ModuleRequirement test1 = new ModuleRequirement(name1, range1);
+      ModuleRequirement test2 = new ModuleRequirement(name2, range2);
+      if (result)
+      {
+         assertTrue("Expected " + test1 + ".equals(" + test2 + ") to be true", test1.equals(test2));
+         assertTrue("Expected " + test2 + ".equals(" + test1 + ") to be true", test2.equals(test1));
+      }
+      else
+      {
+         assertFalse("Expected " + test1 + ".equals(" + test2 + ") to be false", test1.equals(test2));
+         assertFalse("Expected " + test2 + ".equals(" + test1 + ") to be false", test2.equals(test1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionRangeUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionRangeUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionRangeUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.helpers.NameAndVersionRangeSupport;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * NameAndVersionRangeUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NameAndVersionRangeUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(NameAndVersionRangeUnitTestCase.class);
+   }
+
+   public NameAndVersionRangeUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructors() throws Exception
+   {
+      NameAndVersionRangeSupport test = new NameAndVersionRangeSupport();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+
+      test = new NameAndVersionRangeSupport("test");
+      assertEquals("test", test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      test = new NameAndVersionRangeSupport("test", range);
+      assertEquals("test", test.getName());
+      assertEquals(range, test.getVersionRange());
+      
+      try
+      {
+         fail("Should not be here for: " + new NameAndVersionRangeSupport(null));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+      
+      try
+      {
+         fail("Should not be here for: " + new NameAndVersionRangeSupport(null, range));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetName() throws Exception
+   {
+      NameAndVersionRangeSupport test = new NameAndVersionRangeSupport();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      test.setName("name");
+      assertEquals("name", test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      
+      test = new NameAndVersionRangeSupport();
+      try
+      {
+         test.setName(null);
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetVersionRange() throws Exception
+   {
+      NameAndVersionRangeSupport test = new NameAndVersionRangeSupport();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      test.setVersionRange(range);
+      assertNotNull(test.getName());
+      assertEquals(range, test.getVersionRange());
+      test.setVersionRange(null);
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+   }
+      
+   public void testEquals() throws Exception
+   {
+      testEquals("a", VersionRange.ALL_VERSIONS, "a", VersionRange.ALL_VERSIONS, true);
+      testEquals("a", VersionRange.ALL_VERSIONS, "a", null, true);
+      VersionRange range1 = new VersionRange("1.0.0", true, "1.0.0", true);
+      testEquals("b", range1, "b", range1, true);
+      
+      testEquals("a", VersionRange.ALL_VERSIONS, "b", VersionRange.ALL_VERSIONS, false);
+      testEquals("a", range1, "a", VersionRange.ALL_VERSIONS, false);
+      VersionRange range2 = new VersionRange("1.0.0", true, "2.0.0", true);
+      testEquals("a", range1, "a", range2, false);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      NameAndVersionRangeSupport test = new NameAndVersionRangeSupport("a", VersionRange.ALL_VERSIONS);
+      NameAndVersionRangeSupport other = serializeDeserialize(test, NameAndVersionRangeSupport.class);
+      assertEquals(test, other);
+   }
+   
+   protected void testEquals(String name1, VersionRange range1, String name2, VersionRange range2, boolean result)
+   {
+      NameAndVersionRangeSupport test1 = new NameAndVersionRangeSupport(name1, range1);
+      NameAndVersionRangeSupport test2 = new NameAndVersionRangeSupport(name2, range2);
+      if (result)
+      {
+         assertTrue("Expected " + test1 + ".equals(" + test2 + ") to be true", test1.equals(test2));
+         assertTrue("Expected " + test2 + ".equals(" + test1 + ") to be true", test2.equals(test1));
+      }
+      else
+      {
+         assertFalse("Expected " + test1 + ".equals(" + test2 + ") to be false", test1.equals(test2));
+         assertFalse("Expected " + test2 + ".equals(" + test1 + ") to be false", test2.equals(test1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/NameAndVersionUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.helpers.NameAndVersionSupport;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * NameAndVersionUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NameAndVersionUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(NameAndVersionUnitTestCase.class);
+   }
+
+   public NameAndVersionUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructors() throws Exception
+   {
+      NameAndVersionSupport test = new NameAndVersionSupport();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+
+      test = new NameAndVersionSupport("test");
+      assertEquals("test", test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+
+      test = new NameAndVersionSupport("test", "version");
+      assertEquals("test", test.getName());
+      assertEquals("version", test.getVersion());
+      
+      try
+      {
+         fail("Should not be here for: " + new NameAndVersionSupport(null));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+      
+      try
+      {
+         fail("Should not be here for: " + new NameAndVersionSupport(null, "version"));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetName() throws Exception
+   {
+      NameAndVersionSupport test = new NameAndVersionSupport();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      test.setName("name");
+      assertEquals("name", test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      
+      test = new NameAndVersionSupport();
+      try
+      {
+         test.setName(null);
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetVersion() throws Exception
+   {
+      NameAndVersionSupport test = new NameAndVersionSupport();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      test.setVersion("version");
+      assertNotNull(test.getName());
+      assertEquals("version", test.getVersion());
+      test.setVersion(null);
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+   }
+      
+   public void testEquals() throws Exception
+   {
+      testEquals("a", Version.DEFAULT_VERSION, "a", Version.DEFAULT_VERSION, true);
+      testEquals("a", Version.DEFAULT_VERSION, "a", null, true);
+      testEquals("a", Version.DEFAULT_VERSION, "a", "0.0.0", true);
+      testEquals("b", "1.0.0", "b", "1.0.0", true);
+      
+      testEquals("a", Version.DEFAULT_VERSION, "b", Version.DEFAULT_VERSION, false);
+      testEquals("a", "1.0.0", "a", Version.DEFAULT_VERSION, false);
+      testEquals("a", "1.0.0", "a", "0.0.0", false);
+      testEquals("a", "1.0.0", "a", "2.0.0", false);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      NameAndVersionSupport test = new NameAndVersionSupport("a", Version.DEFAULT_VERSION);
+      NameAndVersionSupport other = serializeDeserialize(test, NameAndVersionSupport.class);
+      assertEquals(test, other);
+   }
+   
+   protected void testEquals(String name1, Object version1, String name2, Object version2, boolean result)
+   {
+      NameAndVersionSupport test1 = new NameAndVersionSupport(name1, version1);
+      NameAndVersionSupport test2 = new NameAndVersionSupport(name2, version2);
+      if (result)
+      {
+         assertTrue("Expected " + test1 + ".equals(" + test2 + ") to be true", test1.equals(test2));
+         assertTrue("Expected " + test2 + ".equals(" + test1 + ") to be true", test2.equals(test1));
+      }
+      else
+      {
+         assertFalse("Expected " + test1 + ".equals(" + test2 + ") to be false", test1.equals(test2));
+         assertFalse("Expected " + test2 + ".equals(" + test1 + ") to be false", test2.equals(test1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageCapabilityUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageCapabilityUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageCapabilityUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * PackageCapabilityUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PackageCapabilityUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(PackageCapabilityUnitTestCase.class);
+   }
+
+   public PackageCapabilityUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructors() throws Exception
+   {
+      PackageCapability test = new PackageCapability();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+
+      test = new PackageCapability("test");
+      assertEquals("test", test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+
+      test = new PackageCapability("test", "version");
+      assertEquals("test", test.getName());
+      assertEquals("version", test.getVersion());
+      
+      try
+      {
+         fail("Should not be here for: " + new PackageCapability(null));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+      
+      try
+      {
+         fail("Should not be here for: " + new PackageCapability(null, "version"));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetName() throws Exception
+   {
+      PackageCapability test = new PackageCapability();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      test.setName("name");
+      assertEquals("name", test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      
+      test = new PackageCapability();
+      try
+      {
+         test.setName(null);
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetVersion() throws Exception
+   {
+      PackageCapability test = new PackageCapability();
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+      test.setVersion("version");
+      assertNotNull(test.getName());
+      assertEquals("version", test.getVersion());
+      test.setVersion(null);
+      assertNotNull(test.getName());
+      assertEquals(Version.DEFAULT_VERSION, test.getVersion());
+   }
+      
+   public void testEquals() throws Exception
+   {
+      testEquals("a", Version.DEFAULT_VERSION, "a", Version.DEFAULT_VERSION, true);
+      testEquals("a", Version.DEFAULT_VERSION, "a", null, true);
+      testEquals("a", Version.DEFAULT_VERSION, "a", "0.0.0", true);
+      testEquals("b", "1.0.0", "b", "1.0.0", true);
+      
+      testEquals("a", Version.DEFAULT_VERSION, "b", Version.DEFAULT_VERSION, false);
+      testEquals("a", "1.0.0", "a", Version.DEFAULT_VERSION, false);
+      testEquals("a", "1.0.0", "a", "0.0.0", false);
+      testEquals("a", "1.0.0", "a", "2.0.0", false);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      PackageCapability test = new PackageCapability("a", Version.DEFAULT_VERSION);
+      PackageCapability other = serializeDeserialize(test, PackageCapability.class);
+      assertEquals(test, other);
+   }
+   
+   protected void testEquals(String name1, Object version1, String name2, Object version2, boolean result)
+   {
+      PackageCapability test1 = new PackageCapability(name1, version1);
+      PackageCapability test2 = new PackageCapability(name2, version2);
+      if (result)
+      {
+         assertTrue("Expected " + test1 + ".equals(" + test2 + ") to be true", test1.equals(test2));
+         assertTrue("Expected " + test2 + ".equals(" + test1 + ") to be true", test2.equals(test1));
+      }
+      else
+      {
+         assertFalse("Expected " + test1 + ".equals(" + test2 + ") to be false", test1.equals(test2));
+         assertFalse("Expected " + test2 + ".equals(" + test1 + ") to be false", test2.equals(test1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageRequirementUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageRequirementUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/PackageRequirementUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * PackageRequirementUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PackageRequirementUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(PackageRequirementUnitTestCase.class);
+   }
+
+   public PackageRequirementUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructors() throws Exception
+   {
+      PackageRequirement test = new PackageRequirement();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+
+      test = new PackageRequirement("test");
+      assertEquals("test", test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      test = new PackageRequirement("test", range);
+      assertEquals("test", test.getName());
+      assertEquals(range, test.getVersionRange());
+      
+      try
+      {
+         fail("Should not be here for: " + new PackageRequirement(null));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+      
+      try
+      {
+         fail("Should not be here for: " + new PackageRequirement(null, range));
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetName() throws Exception
+   {
+      PackageRequirement test = new PackageRequirement();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      test.setName("name");
+      assertEquals("name", test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      
+      test = new PackageRequirement();
+      try
+      {
+         test.setName(null);
+      }
+      catch (Throwable t)
+      {
+         checkDeepThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testSetVersionRange() throws Exception
+   {
+      PackageRequirement test = new PackageRequirement();
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");
+      test.setVersionRange(range);
+      assertNotNull(test.getName());
+      assertEquals(range, test.getVersionRange());
+      test.setVersionRange(null);
+      assertNotNull(test.getName());
+      assertEquals(VersionRange.ALL_VERSIONS, test.getVersionRange());
+   }
+      
+   public void testEquals() throws Exception
+   {
+      testEquals("a", VersionRange.ALL_VERSIONS, "a", VersionRange.ALL_VERSIONS, true);
+      testEquals("a", VersionRange.ALL_VERSIONS, "a", null, true);
+      VersionRange range1 = new VersionRange("1.0.0", true, "1.0.0", true);
+      testEquals("b", range1, "b", range1, true);
+      
+      testEquals("a", VersionRange.ALL_VERSIONS, "b", VersionRange.ALL_VERSIONS, false);
+      testEquals("a", range1, "a", VersionRange.ALL_VERSIONS, false);
+      VersionRange range2 = new VersionRange("1.0.0", true, "2.0.0", true);
+      testEquals("a", range1, "a", range2, false);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      PackageRequirement test = new PackageRequirement("a", VersionRange.ALL_VERSIONS);
+      PackageRequirement other = serializeDeserialize(test, PackageRequirement.class);
+      assertEquals(test, other);
+   }
+   
+   protected void testEquals(String name1, VersionRange range1, String name2, VersionRange range2, boolean result)
+   {
+      PackageRequirement test1 = new PackageRequirement(name1, range1);
+      PackageRequirement test2 = new PackageRequirement(name2, range2);
+      if (result)
+      {
+         assertTrue("Expected " + test1 + ".equals(" + test2 + ") to be true", test1.equals(test2));
+         assertTrue("Expected " + test2 + ".equals(" + test1 + ") to be true", test2.equals(test1));
+      }
+      else
+      {
+         assertFalse("Expected " + test1 + ".equals(" + test2 + ") to be false", test1.equals(test2));
+         assertFalse("Expected " + test2 + ".equals(" + test1 + ") to be false", test2.equals(test1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/RequirementsMetaDataUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/RequirementsMetaDataUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/test/RequirementsMetaDataUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.metadata.RequirementsMetaData;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * RequirementsMetaDataUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RequirementsMetaDataUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(RequirementsMetaDataUnitTestCase.class);
+   }
+
+   public RequirementsMetaDataUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConstructor() throws Exception
+   {
+      RequirementsMetaData metadata = new RequirementsMetaData();
+      assertNull(metadata.getRequirements());
+   }
+   
+   public void testSetRequirements() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      RequirementsMetaData metadata = new RequirementsMetaData();
+      assertNull(metadata.getRequirements());
+      
+      List<Requirement> list = new ArrayList<Requirement>();
+      list.add(factory.createRequireModule("module", new VersionRange("1.0.0")));
+      list.add(factory.createRequirePackage("package", new VersionRange("1.0.0")));
+      metadata.setRequirements(list);
+      
+      assertEquals(list, metadata.getRequirements());
+   }
+   
+   public void testAddRequirements() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      RequirementsMetaData metadata = new RequirementsMetaData();
+      assertNull(metadata.getRequirements());
+      
+      List<Requirement> list = new ArrayList<Requirement>();
+      Requirement Requirement = factory.createRequireModule("module", new VersionRange("1.0.0"));
+      metadata.addRequirement(Requirement);
+      list.add(Requirement);
+      assertEquals(list, metadata.getRequirements());
+
+      Requirement = factory.createRequirePackage("module", new VersionRange("1.0.0"));
+      metadata.addRequirement(Requirement);
+      list.add(Requirement);
+      assertEquals(list, metadata.getRequirements());
+   }
+   
+   public void testRemoveRequirements() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      RequirementsMetaData metadata = new RequirementsMetaData();
+      assertNull(metadata.getRequirements());
+
+      Requirement module = factory.createRequireModule("module", new VersionRange("1.0.0"));
+      Requirement pkge = factory.createRequirePackage("module", new VersionRange("1.0.0"));
+
+      List<Requirement> list = new ArrayList<Requirement>();
+      list.add(module);
+      list.add(pkge);
+      metadata.setRequirements(list);
+      
+      metadata.removeRequirement(module);
+      list.remove(module);
+      assertEquals(list, metadata.getRequirements());
+      
+      metadata.removeRequirement(pkge);
+      list.remove(pkge);
+      assertEquals(list, metadata.getRequirements());
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      RequirementsMetaData test = new RequirementsMetaData();
+      test.addRequirement(factory.createRequireModule("module", new VersionRange("1.0.0")));
+      test.addRequirement(factory.createRequirePackage("package", new VersionRange("1.0.0")));
+      RequirementsMetaData other = serializeDeserialize(test, RequirementsMetaData.class);
+      assertEquals(test.getRequirements(), other.getRequirements());
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/AbstractJBossXBTest.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/AbstractJBossXBTest.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/AbstractJBossXBTest.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,153 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.metadata.xml;
+
+import java.net.URL;
+
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.util.UnreachableStatementException;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+/**
+ * AbstractBuilderTest.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class AbstractJBossXBTest extends AbstractTestCaseWithSetup
+{
+   public AbstractJBossXBTest(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test delegate
+    *
+    * @param clazz the class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      return new JBossXBTestDelegate(clazz);
+   }
+
+   protected JBossXBTestDelegate getJBossXBDelegate()
+   {
+      return (JBossXBTestDelegate) getDelegate();
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      configureLogging();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+
+   protected <T, U> T unmarshalObject(Class<T> expected, Class<U> reference, Class<?>... others) throws Exception
+   {
+      TestSchemaResolver resolver = new TestSchemaResolver();
+
+      SchemaBinding schemaBinding = JBossXBBuilder.build(reference);
+      resolver.addSchemaBinding(schemaBinding);
+      if (others != null)
+      {
+         for (Class<?> other : others)
+         {
+            SchemaBinding otherBinding = JBossXBBuilder.build(other);
+            resolver.addSchemaBinding(otherBinding);
+         }
+      }
+
+      String testXml = findTestXml();
+      Object o = unmarshal(testXml, schemaBinding);
+      assertNotNull(o);
+      getLog().debug("Unmarshalled " + o + " of type " + o.getClass().getName());
+      try
+      {
+         return expected.cast(o);
+      }
+      catch (ClassCastException e)
+      {
+         fail("Expected " + expected.getName() + " got " + o.getClass().getName());
+         throw new UnreachableStatementException();
+      }
+   }
+
+   /**
+    * Unmarshal some xml
+    *
+    * @param name the name
+    * @param schema the schema
+    * @return the unmarshalled object
+    * @throws Exception for any error
+    */
+   protected Object unmarshal(String name, SchemaBinding schema) throws Exception
+   {
+      String url = findXML(name);
+      return getJBossXBDelegate().unmarshal(url, schema);
+   }
+
+   protected <T, U> T unmarshalObject(Class<T> expected, Class<U> reference) throws Exception
+   {
+      return unmarshalObject(expected, reference, null);
+   }
+
+   protected <T> T unmarshalObject(Class<T> expected) throws Exception
+   {
+      return unmarshalObject(expected, expected, null);
+   }
+
+   protected String findTestXml()
+   {
+      return getName().substring(4) + ".xml";
+   }
+
+   /**
+    * Find the xml
+    *
+    * @param name the name
+    * @return the url of the xml
+    */
+   protected String findXML(String name)
+   {
+      URL url = getResource(name);
+      if (url == null)
+         fail(name + " not found");
+      return url.toString();
+   }
+
+   @Override
+   public void configureLogging()
+   {
+      //enableTrace("org.jboss.xb");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/JBossXBTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/JBossXBTestDelegate.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/JBossXBTestDelegate.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,171 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.metadata.xml;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import org.jboss.net.protocol.URLStreamHandlerFactory;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
+
+/**
+ * JBossXBTestDelegate.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 40492 $
+ */
+public class JBossXBTestDelegate extends AbstractTestDelegate
+{
+   /** Whether initialization has been done */
+   private static boolean done = false;
+
+   /** The unmarshaller factory */
+   protected UnmarshallerFactory unmarshallerFactory;
+
+   /** The resolver */
+   protected SchemaBindingResolver defaultResolver;
+
+   /**
+    * Initialize
+    */
+   public synchronized static void init()
+   {
+      if (done)
+         return;
+      done = true;
+      URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());
+      URLStreamHandlerFactory.preload();
+      String handlerPkgs = System.getProperty("java.protocol.handler.pkgs");
+      if (handlerPkgs != null)
+         handlerPkgs += "|org.jboss.net.protocol";
+      else
+         handlerPkgs = "org.jboss.net.protocol";
+      System.setProperty("java.protocol.handler.pkgs", handlerPkgs);
+   }
+
+   /**
+    * Create a new JBossXBTestDelegate.
+    *
+    * @param clazz the test class
+    */
+   public JBossXBTestDelegate(Class<?> clazz)
+   {
+      super(clazz);
+   }
+
+   @Override
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      init();
+      unmarshallerFactory = UnmarshallerFactory.newInstance();
+      initResolver();
+   }
+
+   protected void initResolver() throws Exception
+   {
+      try
+      {
+         Method method = clazz.getMethod("initResolver", null);
+         defaultResolver = (SchemaBindingResolver) method.invoke(null, null);
+      }
+      catch (NoSuchMethodException ignored)
+      {
+         defaultResolver = new DefaultSchemaResolver();
+      }
+   }
+
+   /**
+    * Unmarshal an object
+    *
+    * @param url the url
+    * @param resolver the resolver
+    * @return the object
+    * @throws Exception for any error
+    */
+   public Object unmarshal(String url, SchemaBindingResolver resolver) throws Exception
+   {
+      if (resolver == null)
+         resolver = defaultResolver;
+
+      long start = System.currentTimeMillis();
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      log.debug("Initialized parsing in " + (System.currentTimeMillis() - start) + "ms");
+      try
+      {
+         Object result = unmarshaller.unmarshal(url, resolver);
+         log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+         return result;
+      }
+      catch (Exception e)
+      {
+         log.debug("Error during parsing: " + url, e);
+         throw e;
+      }
+   }
+
+   /**
+    * Unmarshal an object
+    *
+    * @param url the url
+    * @param schema the schema
+    * @return the object
+    * @throws Exception for any error
+    */
+   public Object unmarshal(String url, SchemaBinding schema) throws Exception
+   {
+      long start = System.currentTimeMillis();
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      log.debug("Initialized parsing in " + (System.currentTimeMillis() - start) + "ms");
+      try
+      {
+         Object result = unmarshaller.unmarshal(url, schema);
+         log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+         return result;
+      }
+      catch (Exception e)
+      {
+         log.debug("Error during parsing: " + url, e);
+         throw e;
+      }
+   }
+
+   /**
+    * Bind a schema
+    *
+    * @param url the url
+    * @param resolver the resolver
+    * @return the object
+    * @throws Exception for any error
+    */
+   public SchemaBinding bind(String url, SchemaBindingResolver resolver) throws Exception
+   {
+      return XsdBinder.bind(url, resolver);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/SchemaPrinter.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/SchemaPrinter.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/SchemaPrinter.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,276 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.metadata.xml;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.XMLConstants;
+
+import org.jboss.xb.binding.sunday.unmarshalling.AllBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.AttributeBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ChoiceBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ModelGroupBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SequenceBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.WildcardBinding;
+
+/**
+ * SchemaPrinter.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SchemaPrinter
+{
+   @SuppressWarnings("unchecked")
+   public static String printSchema(SchemaBinding schemaBinding)
+   {
+      String nsURI = (String) schemaBinding.getNamespaces().iterator().next();
+      StringBuilder builder = new StringBuilder();
+      builder.append("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n");
+      if (XMLConstants.NULL_NS_URI.equals(nsURI) == false)
+      {
+         builder.append("            targetNamespace=\"").append(nsURI).append("\"\n");
+         builder.append("            xmlns=\"").append(nsURI).append("\"\n");
+      }
+      builder.append(">\n");
+      int pad=3;
+      Iterator<ParticleBinding> elements = schemaBinding.getElementParticles();
+      while (elements != null && elements.hasNext())
+         printElement(builder, pad, elements.next());
+      Iterator<TypeBinding> types = schemaBinding.getTypes();
+      while (types != null && types.hasNext())
+         printType(builder, pad, types.next());
+      builder.append("</xsd:schema>");
+      return builder.toString();
+   }
+
+   public static void printElement(StringBuilder builder, int pad, ParticleBinding particle)
+   {
+      ElementBinding element = (ElementBinding) particle.getTerm();
+      pad(builder, pad);
+      builder.append("<element name=\"").append(element.getQName()).append("\"");
+      int minOccurs = particle.getMinOccurs();
+      if (minOccurs != 1)
+         builder.append(" minOccurs=\"").append(minOccurs).append("\"");
+      int maxOccurs = particle.getMaxOccurs();
+      if (maxOccurs != 1)
+      {
+         builder.append(" maxOccurs=\"");
+         if (maxOccurs == -1)
+            builder.append("unbounded");
+         else
+            builder.append(maxOccurs);
+         builder.append("\"");
+      }
+      TypeBinding type = element.getType();
+      if (type != null && type.getQName() != null)
+         builder.append(" type=\"").append(type.getQName()).append("\"");
+      builder.append(">");
+      if (type != null && type.getQName() == null)
+         printAnonymousType(builder, pad + 3, type);
+      pad(builder, pad);
+      builder.append("</element>");
+   }
+
+   public static void printAnonymousType(StringBuilder builder, int pad, TypeBinding type)
+   {
+      pad(builder, pad);
+      builder.append("<complexType>");
+      TypeBinding baseTypeBinding = type.getBaseType();
+      String qName;
+      if (baseTypeBinding != null)
+         qName = baseTypeBinding.getQName().toString();
+      else
+         qName = "xsd:anyType";
+      pad(builder, pad);
+      builder.append("   <restriction base=\"").append(qName).append("\">");
+      printTypeInfo(builder, pad+6, type);
+      pad(builder, pad);
+      builder.append("   </restriction>");
+      pad(builder, pad);
+      builder.append("</complexType>");
+   }
+
+   public static void printType(StringBuilder builder, int pad, TypeBinding type)
+   {
+      if (type.isSimple())
+         printSimpleType(builder, pad, type);
+      else
+         printComplexType(builder, pad, type);
+   }
+
+   public static void printSimpleType(StringBuilder builder, int pad, TypeBinding type)
+   {
+      pad(builder, pad);
+      builder.append("<simpleType name=\"").append(type.getQName()).append("\"");
+      TypeBinding baseTypeBinding = type.getBaseType();
+      String qName = null;
+      if (baseTypeBinding != null)
+         qName = baseTypeBinding.getQName().toString();
+      else
+         qName = "xsd:anySimpleType";
+      builder.append(" base=\"").append(qName).append("\">");
+      printTypeInfo(builder, pad+3, type);
+      pad(builder, pad);
+      builder.append("</simpleType>");
+   }
+
+   public static void printComplexType(StringBuilder builder, int pad, TypeBinding type)
+   {
+      pad(builder, pad);
+      builder.append("<complexType name=\"").append(type.getQName()).append("\"");
+      TypeBinding baseTypeBinding = type.getBaseType();
+      String qName = null;
+      if (baseTypeBinding != null)
+         qName = baseTypeBinding.getQName().toString();
+      else
+         qName = "xsd:anyType";
+      builder.append(" base=\"").append(qName).append("\">");
+      printTypeInfo(builder, pad+3, type);
+      pad(builder, pad);
+      builder.append("</complexType>");
+   }
+
+   @SuppressWarnings("unchecked")
+   public static void printTypeInfo(StringBuilder builder, int pad, TypeBinding type)
+   {
+      ParticleBinding particle = type.getParticle();
+      if (particle != null)
+      {
+         printParticle(builder, pad, particle);
+      }
+
+      Collection<AttributeBinding> attributes = type.getAttributes();
+      if (attributes != null)
+      {
+         for (AttributeBinding attribute : attributes)
+         {
+            printAttribute(builder, pad, attribute);
+         }
+      }
+   }
+
+   public static void printParticle(StringBuilder builder, int pad, ParticleBinding particle)
+   {
+      TermBinding term = particle.getTerm();
+      if (term instanceof ElementBinding)
+         printElement(builder, pad, particle);
+      else if (term instanceof WildcardBinding)
+         printWildcard(builder, pad, particle);
+      else if (term instanceof SequenceBinding)
+         printModel(builder, pad, particle, "sequence");
+      else if (term instanceof AllBinding)
+         printModel(builder, pad, particle, "all");
+      else if (term instanceof ChoiceBinding)
+         printModel(builder, pad, particle, "choice");
+   }
+
+   @SuppressWarnings("unchecked")
+   public static void printModel(StringBuilder builder, int pad, ParticleBinding particle, String prefix)
+   {
+      pad(builder, pad);
+      builder.append("<").append(prefix);
+      int minOccurs = particle.getMinOccurs();
+      if (minOccurs != 1)
+         builder.append(" minOccurs=\"").append(minOccurs).append("\"");
+      int maxOccurs = particle.getMaxOccurs();
+      if (maxOccurs != 1)
+      {
+         builder.append(" maxOccurs=\"");
+         if (maxOccurs == -1)
+            builder.append("unbounded");
+         else
+            builder.append(maxOccurs);
+         builder.append("\"");
+      }
+      builder.append(">");
+      ModelGroupBinding model = (ModelGroupBinding) particle.getTerm();
+      Collection<ParticleBinding> particles = model.getParticles();
+      boolean newLine = true;
+      if (particles != null)
+      {
+         for (ParticleBinding component : particles)
+            printParticle(builder, pad+3, component);
+      }
+      else
+      {
+         newLine = false;
+      }
+      pad(builder, pad, newLine);
+      builder.append("</").append(prefix).append(">");
+   }
+
+   public static void printWildcard(StringBuilder builder, int pad, ParticleBinding particle)
+   {
+      pad(builder, pad);
+      builder.append("<any");
+      int minOccurs = particle.getMinOccurs();
+      if (minOccurs != 1)
+         builder.append(" minOccurs=\"").append(minOccurs).append("\"");
+      int maxOccurs = particle.getMaxOccurs();
+      if (maxOccurs != 1)
+      {
+         builder.append(" maxOccurs=\"");
+         if (maxOccurs == -1)
+            builder.append("unbounded");
+         else
+            builder.append(maxOccurs);
+         builder.append("\"");
+      }
+      builder.append("/>");
+   }
+
+   public static void printAttribute(StringBuilder builder, int pad, AttributeBinding attribute)
+   {
+      pad(builder, pad);
+      TypeBinding typeBinding = attribute.getType();
+      String qName = null;
+      if (typeBinding != null && typeBinding.getQName() != null)
+         qName = typeBinding.getQName().toString();
+      else
+         qName = "CDATA";
+      builder.append("<attribute name=\"").append(attribute.getQName().getLocalPart()).append("\"");
+      builder.append(" type=\"").append(qName).append("\"");
+      if (attribute.getRequired() == false)
+         builder.append(" optional=\"true\"/>");
+   }
+
+   public static void pad(StringBuilder builder, int pad)
+   {
+      pad(builder, pad, true);
+   }
+
+   public static void pad(StringBuilder builder, int pad, boolean newLine)
+   {
+      if (newLine)
+         builder.append("\n");
+      for (int i = 0; i < pad; ++ i)
+         builder.append(' ');
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/TestSchemaResolver.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/TestSchemaResolver.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/TestSchemaResolver.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,78 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.metadata.xml;
+
+import java.util.HashMap;
+
+import org.jboss.logging.Logger;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.w3c.dom.ls.LSInput;
+
+/**
+ * TestSchemaResolver.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestSchemaResolver implements SchemaBindingResolver
+{
+   private static final Logger log = Logger.getLogger(TestSchemaResolver.class);
+
+   private HashMap<String, SchemaBinding> bindings = new HashMap<String, SchemaBinding>();
+
+   public String getBaseURI()
+   {
+      return null;
+   }
+
+   public void addSchemaBinding(SchemaBinding schemaBinding)
+   {
+      schemaBinding.setSchemaResolver(this);
+      String nsURI = (String) schemaBinding.getNamespaces().iterator().next();
+      bindings.put(nsURI, schemaBinding);
+      if (log.isTraceEnabled())
+      {
+         String schema = SchemaPrinter.printSchema(schemaBinding);
+         log.trace("Bound: " + nsURI + "\n" + schema);
+      }
+   }
+
+   public SchemaBinding resolve(String nsUri, String baseURI, String schemaLocation)
+   {
+      SchemaBinding result = bindings.get(nsUri);
+      if (result == null)
+         throw new RuntimeException("Schema not bound: " + nsUri + " available: " + bindings.keySet());
+      return result;
+   }
+
+   public LSInput resolveAsLSInput(String nsUri, String baseUri, String schemaLocation)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void setBaseURI(String baseURI)
+   {
+      throw new org.jboss.util.NotImplementedException("setBaseURI");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestCapability.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestCapability.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestCapability.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.metadata.xml.support;
+
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.helpers.AbstractCapability;
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+ at JBossXmlSchema(namespace="urn:jboss:test:classloading:capability:1.0", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="test")
+public class TestCapability extends AbstractCapability
+{
+   private static final long serialVersionUID = -1L;
+
+   public TestCapability()
+   {
+   }
+   
+   public TestCapability(String name, Object version)
+   {
+      super(name, version);
+   }
+   
+   public boolean resolves(Module module, Requirement requirement)
+   {
+      return false;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestRequirement.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestRequirement.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/TestRequirement.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.metadata.xml.support;
+
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.classloading.spi.metadata.helpers.AbstractRequirement;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+ at JBossXmlSchema(namespace="urn:jboss:test:classloading:requirement:1.0", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="test")
+public class TestRequirement extends AbstractRequirement
+{
+   private static final long serialVersionUID = -1L;
+
+   public TestRequirement()
+   {
+   }
+   
+   public TestRequirement(String name, VersionRange range)
+   {
+      super(name, range);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/package-info.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/package-info.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/support/package-info.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+ at JBossXmlAdaptedTypes
+({
+   @JBossXmlAdaptedType(type=Version.class, valueAdapter=VersionValueAdapter.class)
+})
+package org.jboss.test.classloading.metadata.xml.support;
+
+import org.jboss.classloading.plugins.metadata.VersionValueAdapter;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.xb.annotations.JBossXmlAdaptedType;
+import org.jboss.xb.annotations.JBossXmlAdaptedTypes;
+

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/test/ClassLoadingMetaDataXmlUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/test/ClassLoadingMetaDataXmlUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/metadata/xml/test/ClassLoadingMetaDataXmlUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,325 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.metadata.xml.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData10;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.metadata.xml.AbstractJBossXBTest;
+import org.jboss.test.classloading.metadata.xml.support.TestCapability;
+import org.jboss.test.classloading.metadata.xml.support.TestRequirement;
+
+/**
+ * ClassLoadingMetaDataXmlUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoadingMetaDataXmlUnitTestCase extends AbstractJBossXBTest
+{
+   public static Test suite()
+   {
+      return suite(ClassLoadingMetaDataXmlUnitTestCase.class);
+   }
+
+   public ClassLoadingMetaDataXmlUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testModuleName() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals("test", result.getName());
+      assertEquals(Version.DEFAULT_VERSION, result.getVersion());
+      assertNull(result.getDomain());
+      assertNull(result.getParentDomain());
+      assertNull(result.getExportAll());
+      assertNull(result.getIncludedPackages());
+      assertNull(result.getExcludedPackages());
+      assertNull(result.getExcludedExportPackages());
+      assertFalse(result.isImportAll());
+      assertTrue(result.isJ2seClassLoadingCompliance());
+      assertTrue(result.isCacheable());
+      assertTrue(result.isBlackListable());
+      assertNull(result.getCapabilities().getCapabilities());
+      assertNull(result.getRequirements().getRequirements());
+   }
+
+   public void testModuleVersion() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals(Version.parseVersion("1.0.0"), result.getVersion());
+   }
+
+   public void testModuleDomain() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals("testDomain", result.getDomain());
+   }
+
+   public void testModuleParentDomain() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals("testParentDomain", result.getParentDomain());
+   }
+
+   public void testModuleExportAll() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals(ExportAll.ALL, result.getExportAll());
+   }
+
+   public void testModuleIncluded() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals("Included", result.getIncludedPackages());
+   }
+
+   public void testModuleExcluded() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals("Excluded", result.getExcludedPackages());
+   }
+
+   public void testModuleExcludedExport() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertEquals("ExcludedExport", result.getExcludedExportPackages());
+   }
+
+   public void testModuleImportAll() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertTrue(result.isImportAll());
+   }
+
+   public void testModuleJ2seClassLoadingCompliance() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertFalse(result.isJ2seClassLoadingCompliance());
+   }
+
+   public void testModuleCache() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertFalse(result.isCacheable());
+   }
+
+   public void testModuleBlackList() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      assertFalse(result.isBlackListable());
+   }
+
+   public void testExportOneModuleNoVersion() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createModule("export1"));
+   }
+
+   public void testExportOneModuleVersioned() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createModule("export1", "1.0.0"));
+   }
+
+   public void testExportThreeModules() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createModule("export1", "1.0.0"), 
+                                 factory.createModule("export2", "2.0.0"), 
+                                 factory.createModule("export3", "3.0.0"));
+   }
+
+   public void testExportOnePackageNoVersion() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createPackage("export1"));
+   }
+
+   public void testExportOnePackageVersioned() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createPackage("export1", "1.0.0"));
+   }
+
+   public void testExportThreePackages() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createPackage("export1", "1.0.0"), 
+                                 factory.createPackage("export2", "2.0.0"), 
+                                 factory.createPackage("export3", "3.0.0"));
+   }
+
+   public void testImportOneModuleNoVersion() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequireModule("export1"));
+   }
+
+   public void testImportOneModuleVersioned() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequireModule("export1", new VersionRange("1.0.0", "2.0.0")));
+   }
+
+   public void testImportThreeModules() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequireModule("export1", new VersionRange("1.0.0", "1.1.0")), 
+                                 factory.createRequireModule("export2", new VersionRange("2.0.0", "2.1.0")), 
+                                 factory.createRequireModule("export3", new VersionRange("3.0.0", "3.1.0")));
+   }
+
+   public void testImportOnePackageNoVersion() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequirePackage("export1"));
+   }
+
+   public void testImportOnePackageVersioned() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequirePackage("export1", new VersionRange("1.0.0", "2.0.0")));
+   }
+
+   public void testImportThreePackages() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequirePackage("export1", new VersionRange("1.0.0", "1.1.0")), 
+                                 factory.createRequirePackage("export2", new VersionRange("2.0.0", "2.1.0")), 
+                                 factory.createRequirePackage("export3", new VersionRange("3.0.0", "3.1.0")));
+   }
+
+   public void testImportVersionRange() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequireModule("export1"), 
+                                 factory.createRequireModule("export2", new VersionRange("1.0.0")), 
+                                 factory.createRequireModule("export3", new VersionRange("0.0.0", "1.0.0")),
+                                 factory.createRequireModule("export4", new VersionRange("1.0.0", "2.0.0")),
+                                 factory.createRequireModule("export5", new VersionRange("1.0.0", false, "2.0.0", false)),
+                                 factory.createRequireModule("export6", new VersionRange("1.0.0", false, "2.0.0", true)),
+                                 factory.createRequireModule("export7", new VersionRange("1.0.0", true, "2.0.0", false)),
+                                 factory.createRequireModule("export8", new VersionRange("1.0.0", true, "2.0.0", true)));
+   }
+
+   public void testExportImportMixed() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createModule("test2", "2.0.0"), 
+                                 factory.createPackage("test2", "2.0.0"), 
+                                 factory.createModule("test1", "1.0.0"),
+                                 factory.createPackage("test1", "1.0.0"));
+      assertRequirements(result, factory.createRequireModule("test2", new VersionRange("2.0.0")), 
+                                 factory.createRequirePackage("test2", new VersionRange("2.0.0")), 
+                                 factory.createRequireModule("test1", new VersionRange("1.0.0")),
+                                 factory.createRequirePackage("test1", new VersionRange("1.0.0")));
+   }
+
+   public void testWildcardCapability() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal(TestCapability.class);
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertCapabilities(result, factory.createModule("test1", "1.0.0"), 
+                                 factory.createPackage("test1", "1.0.0"),
+                                 new TestCapability("test", "1.0.0"));
+   }
+
+   public void testWildcardRequirement() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal(TestRequirement.class);
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequireModule("test1", new VersionRange("1.0.0")), 
+                                 factory.createRequirePackage("test1", new VersionRange("1.0.0")),
+                                 new TestRequirement("test", new VersionRange("1.0.0")));
+   }
+
+   public void testOptionalRequirement() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal(TestRequirement.class);
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createRequireModule("test1", new VersionRange("1.0.0"), true, false), 
+                                 factory.createRequirePackage("test1", new VersionRange("1.0.0"), true, false));
+   }
+
+   public void testReExportRequirement() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal(TestRequirement.class);
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createReExportModule("test1", new VersionRange("1.0.0")), 
+                                 factory.createReExportPackage("test1", new VersionRange("1.0.0")));
+   }
+
+   public void testUsesRequirement() throws Exception
+   {
+      ClassLoadingMetaData result = unmarshal(TestRequirement.class);
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      assertRequirements(result, factory.createUsesPackage("test1", new VersionRange("1.0.0"))); 
+   }
+   
+   public void assertCapabilities(ClassLoadingMetaData metadata, Capability... expected)
+   {
+      List<Capability> temp = new ArrayList<Capability>();
+      for (Capability capability : expected)
+         temp.add(capability);
+      assertEquals(temp, metadata.getCapabilities().getCapabilities());
+   }
+
+   public void assertRequirements(ClassLoadingMetaData metadata, Requirement... expected)
+   {
+      List<Requirement> temp = new ArrayList<Requirement>();
+      for (Requirement requirement : expected)
+         temp.add(requirement);
+      assertEquals(temp, metadata.getRequirements().getRequirements());
+   }
+   
+   protected ClassLoadingMetaData unmarshal(Class<?>... extra) throws Exception
+   {
+      return unmarshalObject(ClassLoadingMetaData10.class, ClassLoadingMetaData10.class, extra);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/VersionTestSuite.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/VersionTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/VersionTestSuite.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.version;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.classloading.version.test.VersionComparatorRegistryUnitTestCase;
+import org.jboss.test.classloading.version.test.VersionRangeUnitTestCase;
+import org.jboss.test.classloading.version.test.VersionUnitTestCase;
+
+/**
+ * Version Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class VersionTestSuite extends TestSuite
+{
+   /**
+    * For running the testsuite from the command line
+    * 
+    * @param args the command line args
+    */
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   /**
+    * Create the testsuite
+    * 
+    * @return the testsuite
+    */
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Version Tests");
+
+      suite.addTest(VersionUnitTestCase.suite());
+      suite.addTest(VersionRangeUnitTestCase.suite());
+      suite.addTest(VersionComparatorRegistryUnitTestCase.suite());
+      
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersion.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersion.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersion.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.version.support;
+
+/**
+ * MyVersion.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MyVersion
+{
+   private String version;
+
+   public static MyVersion parseMyVersion(String version)
+   {
+      return new MyVersion(version);
+   }
+   
+   public MyVersion(String version)
+   {
+      this.version = version;
+   }
+   
+   public String getVersion()
+   {
+      return version;
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersionToMyVersionComparator.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersionToMyVersionComparator.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/MyVersionToMyVersionComparator.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.version.support;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparator;
+
+/**
+ * MyVersionToMyVersionComparator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MyVersionToMyVersionComparator implements VersionComparator<MyVersion, MyVersion>
+{
+   public int compare(MyVersion one, MyVersion two)
+   {
+      Version version1 = Version.parseVersion(one.getVersion());
+      Version version2 = Version.parseVersion(two.getVersion());
+      return version1.compareTo(version2);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToMyVersionComparator.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToMyVersionComparator.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToMyVersionComparator.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.version.support;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparator;
+
+/**
+ * TestStringToMyVersionComparator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestStringToMyVersionComparator implements VersionComparator<String, MyVersion>
+{
+   public int compare(String one, MyVersion two)
+   {
+      Version version1 = Version.parseVersion(one);
+      Version version2 = Version.parseVersion(two.getVersion());
+      return version1.compareTo(version2);
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToStringComparator.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToStringComparator.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToStringComparator.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.version.support;
+
+import org.jboss.classloading.spi.version.VersionComparator;
+
+/**
+ * TestStringToStringComparator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestStringToStringComparator implements VersionComparator<String, String>
+{
+   public int compare(String one, String two)
+   {
+      throw new UnsupportedOperationException("Not implemented");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToVersionComparator.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToVersionComparator.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestStringToVersionComparator.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.version.support;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparator;
+
+/**
+ * TestStringToVersionComparator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestStringToVersionComparator implements VersionComparator<String, Version>
+{
+   public int compare(String one, Version two)
+   {
+      throw new UnsupportedOperationException("Not implemented");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToStringComparator.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToStringComparator.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToStringComparator.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.version.support;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparator;
+
+/**
+ * TestVersionToStringComparator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestVersionToStringComparator implements VersionComparator<Version, String>
+{
+   public int compare(Version one, String two)
+   {
+      throw new UnsupportedOperationException("Not implemented");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToVersionComparator.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToVersionComparator.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/support/TestVersionToVersionComparator.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classloading.version.support;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparator;
+
+/**
+ * TestVersionToVersionComparator.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestVersionToVersionComparator implements VersionComparator<Version, Version>
+{
+   public int compare(Version one, Version two)
+   {
+      throw new UnsupportedOperationException("Not implemented");
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionComparatorRegistryUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionComparatorRegistryUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionComparatorRegistryUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,427 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.version.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparator;
+import org.jboss.classloading.spi.version.VersionComparatorRegistry;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+import org.jboss.test.classloading.version.support.TestStringToMyVersionComparator;
+import org.jboss.test.classloading.version.support.TestStringToStringComparator;
+import org.jboss.test.classloading.version.support.TestStringToVersionComparator;
+import org.jboss.test.classloading.version.support.MyVersion;
+import org.jboss.test.classloading.version.support.MyVersionToMyVersionComparator;
+import org.jboss.test.classloading.version.support.TestVersionToStringComparator;
+import org.jboss.test.classloading.version.support.TestVersionToVersionComparator;
+
+/**
+ * VersionComparatorRegistryUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VersionComparatorRegistryUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(VersionComparatorRegistryUnitTestCase.class);
+   }
+
+   public VersionComparatorRegistryUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testComparatorSameClass()
+   {
+      VersionComparatorRegistry registry = new VersionComparatorRegistry();
+      MyVersion version1 = MyVersion.parseMyVersion("1.0");
+      MyVersion version2 = MyVersion.parseMyVersion("2.0");
+      
+      try
+      {
+         registry.compare(version1, version2);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      
+      MyVersionToMyVersionComparator comparator = new MyVersionToMyVersionComparator();
+      registry.registerVersionComparator(MyVersion.class, comparator);
+      assertTrue(registry.compare(version1, version2) < 0);
+      assertTrue(registry.compare(version2, version1) > 0);
+      
+      registry.removeVersionComparator(MyVersion.class);
+      
+      try
+      {
+         registry.compare(version1, version2);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      registry.registerVersionComparator(MyVersion.class, MyVersion.class, comparator);
+      assertTrue(registry.compare(version1, version2) < 0);
+      assertTrue(registry.compare(version2, version1) > 0);
+      
+      registry.removeVersionComparator(MyVersion.class, MyVersion.class);
+      
+      try
+      {
+         registry.compare(version1, version2);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testComparatorDifferentClass()
+   {
+      VersionComparatorRegistry registry = new VersionComparatorRegistry();
+      String version1 = "1.0";
+      MyVersion version2 = MyVersion.parseMyVersion("2.0");
+      
+      try
+      {
+         registry.compare(version1, version2);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      
+      TestStringToMyVersionComparator comparator = new TestStringToMyVersionComparator();
+      registry.registerVersionComparator(String.class, MyVersion.class, comparator);
+      assertTrue(registry.compare(version1, version2) < 0);
+      assertTrue(registry.compare(version2, version1) > 0);
+      
+      registry.removeVersionComparator(MyVersion.class, String.class);
+      
+      try
+      {
+         registry.compare(version1, version2);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      registry.registerVersionComparator(String.class, MyVersion.class, comparator);
+      assertTrue(registry.compare(version1, version2) < 0);
+      assertTrue(registry.compare(version2, version1) > 0);
+      
+      registry.removeVersionComparator(MyVersion.class, String.class);
+      
+      try
+      {
+         registry.compare(version1, version2);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   public void testReplaceBuiltInComparator() throws Exception
+   {
+      testReplaceBuiltInComparator(Version.class, new TestVersionToVersionComparator());
+      testReplaceBuiltInComparator(String.class, new TestStringToStringComparator());
+      testReplaceBuiltInComparator(Version.class, String.class, new TestVersionToStringComparator());
+      testReplaceBuiltInComparator(String.class, Version.class, new TestStringToVersionComparator());
+   }
+   
+   public void testVersionVersionCompare() throws Exception
+   {
+      testVersionVersionCompare(null, Version.DEFAULT_VERSION, 0);
+      testVersionVersionCompare("", Version.DEFAULT_VERSION, 0);
+      testVersionVersionCompare("0", Version.DEFAULT_VERSION, 0);
+
+      testVersionVersionCompare("0", "0", 0);
+      testVersionVersionCompare("0", "0.0", 0);
+      testVersionVersionCompare("0", "0.0.0", 0);
+      testVersionVersionCompare("0.0", "0.0.0", 0);
+
+      testVersionVersionCompare("1", "1", 0);
+      testVersionVersionCompare("1", "1.0", 0);
+      testVersionVersionCompare("1", "1.0.0", 0);
+      testVersionVersionCompare("1.0", "1.0.0", 0);
+
+      testVersionVersionCompare("1", "2", -1);
+      testVersionVersionCompare("1", "2.0", -1);
+      testVersionVersionCompare("1", "2.0.0", -1);
+
+      testVersionVersionCompare("1.0", "1.1", -1);
+      testVersionVersionCompare("1.0", "1.1.0", -1);
+      testVersionVersionCompare("1.0", "1.2", -1);
+      testVersionVersionCompare("1.0", "1.2.0", -1);
+
+      testVersionVersionCompare("1.1", "1.2", -1);
+      testVersionVersionCompare("1.1", "1.2.0", -1);
+      testVersionVersionCompare("1.1", "1.3", -1);
+      testVersionVersionCompare("1.1", "1.3.0", -1);
+
+      testVersionVersionCompare("1.0.0", "1.0.1", -1);
+      testVersionVersionCompare("1.0.0", "1.0.2", -1);
+
+      testVersionVersionCompare("1.1.1", "1.1.2", -1);
+      testVersionVersionCompare("1.1.1", "1.1.3", -1);
+
+      testVersionVersionCompare("1.0.0", "1.0.0.A", -1);
+      testVersionVersionCompare("1.0.0.A", "1.0.0.B", -1);
+      testVersionVersionCompare("1.0.0.AA", "1.0.0.AB", -1);
+      testVersionVersionCompare("1.0.0.Beta1", "1.0.0.Beta2", -1);
+      testVersionVersionCompare("1.0.0.Beta10", "1.0.0.Beta2", -1);
+   }
+   
+   public void testVersionStringCompare() throws Exception
+   {
+      testVersionStringCompare("", Version.DEFAULT_VERSION, 0);
+      testVersionStringCompare("0", Version.DEFAULT_VERSION, 0);
+
+      testVersionStringCompare("0", "0", 0);
+      testVersionStringCompare("0", "0.0", 0);
+      testVersionStringCompare("0", "0.0.0", 0);
+      testVersionStringCompare("0.0", "0.0.0", 0);
+
+      testVersionStringCompare("1", "1", 0);
+      testVersionStringCompare("1", "1.0", 0);
+      testVersionStringCompare("1", "1.0.0", 0);
+      testVersionStringCompare("1.0", "1.0.0", 0);
+
+      testVersionStringCompare("1", "2", -1);
+      testVersionStringCompare("1", "2.0", -1);
+      testVersionStringCompare("1", "2.0.0", -1);
+
+      testVersionStringCompare("1.0", "1.1", -1);
+      testVersionStringCompare("1.0", "1.1.0", -1);
+      testVersionStringCompare("1.0", "1.2", -1);
+      testVersionStringCompare("1.0", "1.2.0", -1);
+
+      testVersionStringCompare("1.1", "1.2", -1);
+      testVersionStringCompare("1.1", "1.2.0", -1);
+      testVersionStringCompare("1.1", "1.3", -1);
+      testVersionStringCompare("1.1", "1.3.0", -1);
+
+      testVersionStringCompare("1.0.0", "1.0.1", -1);
+      testVersionStringCompare("1.0.0", "1.0.2", -1);
+
+      testVersionStringCompare("1.1.1", "1.1.2", -1);
+      testVersionStringCompare("1.1.1", "1.1.3", -1);
+
+      testVersionStringCompare("1.0.0", "1.0.0.A", -1);
+      testVersionStringCompare("1.0.0.A", "1.0.0.B", -1);
+      testVersionStringCompare("1.0.0.AA", "1.0.0.AB", -1);
+      testVersionStringCompare("1.0.0.Beta1", "1.0.0.Beta2", -1);
+      testVersionStringCompare("1.0.0.Beta10", "1.0.0.Beta2", -1);
+   }
+   
+   public void testStringStringCompare() throws Exception
+   {
+      testStringStringCompare("0", "0", 0);
+      testStringStringCompare("0", "0.0", 0);
+      testStringStringCompare("0", "0.0.0", 0);
+      testStringStringCompare("0.0", "0.0.0", 0);
+
+      testStringStringCompare("1", "1", 0);
+      testStringStringCompare("1", "1.0", 0);
+      testStringStringCompare("1", "1.0.0", 0);
+      testStringStringCompare("1.0", "1.0.0", 0);
+
+      testStringStringCompare("1", "2", -1);
+      testStringStringCompare("1", "2.0", -1);
+      testStringStringCompare("1", "2.0.0", -1);
+
+      testStringStringCompare("1.0", "1.1", -1);
+      testStringStringCompare("1.0", "1.1.0", -1);
+      testStringStringCompare("1.0", "1.2", -1);
+      testStringStringCompare("1.0", "1.2.0", -1);
+
+      testStringStringCompare("1.1", "1.2", -1);
+      testStringStringCompare("1.1", "1.2.0", -1);
+      testStringStringCompare("1.1", "1.3", -1);
+      testStringStringCompare("1.1", "1.3.0", -1);
+
+      testStringStringCompare("1.0.0", "1.0.1", -1);
+      testStringStringCompare("1.0.0", "1.0.2", -1);
+
+      testStringStringCompare("1.1.1", "1.1.2", -1);
+      testStringStringCompare("1.1.1", "1.1.3", -1);
+
+      testStringStringCompare("1.0.0", "1.0.0.A", -1);
+      testStringStringCompare("1.0.0.A", "1.0.0.B", -1);
+      testStringStringCompare("1.0.0.AA", "1.0.0.AB", -1);
+      testStringStringCompare("1.0.0.Beta1", "1.0.0.Beta2", -1);
+      testStringStringCompare("1.0.0.Beta10", "1.0.0.Beta2", -1);
+   }
+   
+   protected <T> void testReplaceBuiltInComparator(Class<T> classT, VersionComparator<T, T> comparator)
+   {
+      VersionComparatorRegistry registry = new VersionComparatorRegistry();
+      try
+      {
+         registry.registerVersionComparator(classT, comparator);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      try
+      {
+         registry.registerVersionComparator(classT, classT, comparator);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      try
+      {
+         registry.removeVersionComparator(classT);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      try
+      {
+         registry.removeVersionComparator(classT, classT);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      try
+      {
+         registry.registerVersionComparator(classT, classT, null);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   protected <T, U> void testReplaceBuiltInComparator(Class<T> classT, Class<U> classU, VersionComparator<T, U> comparator)
+   {
+      VersionComparatorRegistry registry = new VersionComparatorRegistry();
+      try
+      {
+         registry.registerVersionComparator(classT, classU, comparator);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      try
+      {
+         registry.removeVersionComparator(classT, classU);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      try
+      {
+         registry.registerVersionComparator(classT, classU, null);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   protected void testVersionVersionCompare(String test1, String test2, int result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      Version version2 = Version.parseVersion(test2);
+      testVersionVersionCompareViaRegistry(version1, version2, result);
+   }
+   
+   protected void testVersionVersionCompare(String test1, Version version2, int result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      testVersionVersionCompareViaRegistry(version1, version2, result);
+   }
+   
+   protected void testVersionStringCompare(String version1, String test2, int result)
+   {
+      Version version2 = Version.parseVersion(test2);
+      testVersionVersionCompareViaRegistry(version1, version2, result);
+   }
+   
+   protected void testVersionStringCompare(String version1, Version version2, int result)
+   {
+      testVersionVersionCompareViaRegistry(version1, version2, result);
+   }
+   
+   protected void testStringStringCompare(String version1, String version2, int result)
+   {
+      testVersionVersionCompareViaRegistry(version1, version2, result);
+   }
+   
+   protected void testVersionVersionCompareViaRegistry(Object version1, Object version2, int result)
+   {
+      VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
+      if (result < 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be negative " + registry.compare(version1, version2), registry.compare(version1, version2) < 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be positive " + registry.compare(version2, version1), registry.compare(version2, version1) > 0);
+      }
+      else if (result > 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be positive " + registry.compare(version1, version2), registry.compare(version1, version2) > 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be negative" + registry.compare(version2, version1), registry.compare(version2, version1) < 0);
+      }
+      else
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be zero " + registry.compare(version1, version2), registry.compare(version1, version2) == 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be zero" + registry.compare(version2, version1), registry.compare(version2, version1) == 0);
+      }
+
+      if (result == 0)
+      {
+         assertTrue("Expected " + version1 + ".equals(" + version2 + ") to be true", registry.same(version1, version2));
+         assertTrue("Expected " + version2 + ".equals(" + version1 + ") to be true", registry.same(version2, version1));
+      }
+      else
+      {
+         assertFalse("Expected " + version1 + ".equals(" + version2 + ") to be false", registry.same(version1, version2));
+         assertFalse("Expected " + version2 + ".equals(" + version1 + ") to be false", registry.same(version2, version1));
+      }
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionRangeUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionRangeUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionRangeUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,447 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.version.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * VersionRangeUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VersionRangeUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(VersionRangeUnitTestCase.class);
+   }
+
+   public VersionRangeUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testAllVersions() throws Exception
+   {
+      VersionRange range = VersionRange.ALL_VERSIONS;
+      assertVersionRange(range, Version.DEFAULT_VERSION, null);
+   }
+   
+   public void testLow() throws Exception
+   {
+      testVersionRangeFromString("1.2.3");
+      testVersionRangeFromString(null);
+   }
+   
+   public void testLowHigh() throws Exception
+   {
+      testVersionRangeFromString(null, null);
+      testVersionRangeFromString("1.2.3", null);
+      testVersionRangeFromString(null, "4.5.6");
+      testVersionRangeFromString("1.2.3", "4.5.6");
+      
+      assertBadVersionRangeFromString("2", "1");
+      assertBadVersionRangeFromString("1.1", "1.0");
+      assertBadVersionRangeFromString("1.1.1", "1.1.0");
+
+      assertBadVersionRangeFromString("1", "1");
+      assertBadVersionRangeFromString("1.1", "1.1");
+      assertBadVersionRangeFromString("1.1.1", "1.1.1");
+   }
+   
+   public void testLowHighWithInclusive() throws Exception
+   {
+      testVersionRangeFromStringAllPerms(null, null);
+      testVersionRangeFromStringAllPerms("1.2.3", null);
+      testVersionRangeFromStringAllPerms(null, "4.5.6");
+      testVersionRangeFromStringAllPerms("1.2.3", "4.5.6");
+
+      testVersionRangeFromString(null, true, "0.0.0", true);
+      testVersionRangeFromString("1.0.0", true, "1.0.0", true);
+
+      
+      assertBadVersionRangeFromStringAllPerms("2", "1");
+      assertBadVersionRangeFromStringAllPerms("1.1", "1.0");
+      assertBadVersionRangeFromStringAllPerms("1.1.1", "1.1.0");
+
+      assertBadVersionRangeFromStringNotBoth("1.1", "1.1");
+      assertBadVersionRangeFromStringNotBoth("1.1.1", "1.1.1");
+      
+      assertBadVersionRangeFromStringNotBoth(null, "0.0.0");
+   }
+   
+   public void testEquals() throws Exception
+   {
+      testEqualsFromString(null, null, null, null, true);
+      testEqualsFromString("0.0.0", null, null, null, true);
+      testEqualsFromString("0.0.0", null, "0.0.0", null, true);
+
+      testEquals(Version.DEFAULT_VERSION, null, null, null, true);
+      testEquals(Version.DEFAULT_VERSION, null, Version.DEFAULT_VERSION, null, true);
+
+      testEquals(Version.DEFAULT_VERSION, null, "0.0.0", null, true);
+
+      testEqualsFromString("1.0.0", null, "1.0.0", null, true);
+      testEqualsFromString(null, "1.0.0", null, "1.0.0", true);
+      testEqualsFromString("1.2.3", "4.5.6", "1.2.3", "4.5.6", true);
+
+      testEqualsFromString(null, false, null, false, null, false, null, false, true);
+      testEqualsFromString(null, false, null, false, null, false, null, true, true);
+      testEqualsFromString(null, false, null, false, null, true, null, false, false);
+      testEqualsFromString(null, false, null, false, null, true, null, true, false);
+      testEqualsFromString(null, false, null, true, null, false, null, false, true);
+      testEqualsFromString(null, false, null, true, null, false, null, true, true);
+      testEqualsFromString(null, false, null, true, null, true, null, false, false);
+      testEqualsFromString(null, false, null, true, null, true, null, true, false);
+      testEqualsFromString(null, true, null, false, null, false, null, false, false);
+      testEqualsFromString(null, true, null, false, null, false, null, true, false);
+      testEqualsFromString(null, true, null, false, null, true, null, false, true);
+      testEqualsFromString(null, true, null, false, null, true, null, true, true);
+      testEqualsFromString(null, true, null, true, null, false, null, false, false);
+      testEqualsFromString(null, true, null, true, null, false, null, true, false);
+      testEqualsFromString(null, true, null, true, null, true, null, false, true);
+      testEqualsFromString(null, true, null, true, null, true, null, true, true);
+
+      testEqualsFromString(null, false, null, false, "0.0.0", false, null, false, true);
+      testEqualsFromString(null, false, null, false, "0.0.0", true, null, false, false);
+
+      testEqualsFromString("1.0.0", true, "1.0.0", true, "0.0.0", false, null, false, false);
+      testEqualsFromString("1.0.0", true, "1.0.0", true, "0.0.0", false, null, true, false);
+      testEqualsFromString("1.0.0", true, "1.0.0", true, "0.0.0", true, null, false, false);
+      testEqualsFromString("1.0.0", true, "1.0.0", true, "0.0.0", true, null, true, false);
+
+      testEqualsFromString("1.2.3", false, "4.5.6", false, "1.2.3", false, "4.5.6", false, true);
+      testEqualsFromString("1.2.3", false, "4.5.6", false, "1.2.3", false, "4.5.6", true, false);
+      testEqualsFromString("1.2.3", false, "4.5.6", false, "1.2.3", true, "4.5.6", false, false);
+      testEqualsFromString("1.2.3", false, "4.5.6", false, "1.2.3", true, "4.5.6", true, false);
+      testEqualsFromString("1.2.3", false, "4.5.6", true, "1.2.3", false, "4.5.6", false, false);
+      testEqualsFromString("1.2.3", false, "4.5.6", true, "1.2.3", false, "4.5.6", true, true);
+      testEqualsFromString("1.2.3", false, "4.5.6", true, "1.2.3", true, "4.5.6", false, false);
+      testEqualsFromString("1.2.3", false, "4.5.6", true, "1.2.3", true, "4.5.6", true, false);
+      testEqualsFromString("1.2.3", true, "4.5.6", false, "1.2.3", false, "4.5.6", false, false);
+      testEqualsFromString("1.2.3", true, "4.5.6", false, "1.2.3", false, "4.5.6", true, false);
+      testEqualsFromString("1.2.3", true, "4.5.6", false, "1.2.3", true, "4.5.6", false, true);
+      testEqualsFromString("1.2.3", true, "4.5.6", false, "1.2.3", true, "4.5.6", true, false);
+      testEqualsFromString("1.2.3", true, "4.5.6", true, "1.2.3", false, "4.5.6", false, false);
+      testEqualsFromString("1.2.3", true, "4.5.6", true, "1.2.3", false, "4.5.6", true, false);
+      testEqualsFromString("1.2.3", true, "4.5.6", true, "1.2.3", true, "4.5.6", false, false);
+      testEqualsFromString("1.2.3", true, "4.5.6", true, "1.2.3", true, "4.5.6", true, true);
+   }
+   
+   public void testIsInRange() throws Exception
+   {
+      testIsInRangeFromString(null, null, "0.0.0", true);
+      testIsInRangeFromString(null, null, "1.2.3", true);
+      testIsInRangeFromString("0.0.0", null, "0.0.0", true);
+      testIsInRangeFromString("0.0.0", null, "1.2.3", true);
+
+      testIsInRangeFromString("1.2.3", "4.5.6", "1.2.3", true);
+      testIsInRangeFromString("1.2.3", "4.5.6", "4.5.6", false);
+
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "1.2.4", true);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "4.5.5", true);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "1.3", true);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "4.4", true);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "2.3.4", true);
+      
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "0.0.0", false);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "1.1", false);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "1.2.2", false);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "1.0", false);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "0.9", false);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "4.6", false);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "4.5.7", false);
+      testIsInRangeFromStringAllPerms("1.2.3", "4.5.6", "5.0", false);
+
+      testIsInRangeFromString(null, false, null, false, "0.0.0", false);
+      testIsInRangeFromString(null, false, null, true, "0.0.0", false);
+      testIsInRangeFromString(null, true, null, false, "0.0.0", true);
+      testIsInRangeFromString(null, true, null, true, "0.0.0", true);
+      testIsInRangeFromString("0.0.0", false, null, false, "0.0.0", false);
+      testIsInRangeFromString("0.0.0", false, null, true, "0.0.0", false);
+      testIsInRangeFromString("0.0.0", true, null, false, "0.0.0", true);
+      testIsInRangeFromString("0.0.0", true, null, true, "0.0.0", true);
+
+      testIsInRangeFromString("1.2.3", false, "4.5.6", false, "1.2.3", false);
+      testIsInRangeFromString("1.2.3", false, "4.5.6", true, "1.2.3", false);
+      testIsInRangeFromString("1.2.3", true, "4.5.6", false, "1.2.3", true);
+      testIsInRangeFromString("1.2.3", true, "4.5.6", true, "1.2.3", true);
+
+      testIsInRangeFromString("1.2.3", false, "4.5.6", false, "4.5.6", false);
+      testIsInRangeFromString("1.2.3", false, "4.5.6", true, "4.5.6", true);
+      testIsInRangeFromString("1.2.3", true, "4.5.6", false, "4.5.6", false);
+      testIsInRangeFromString("1.2.3", true, "4.5.6", true, "4.5.6", true);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      VersionRange range = new VersionRange("1.0.0", "2.0.0");;
+      VersionRange other = serializeDeserialize(range, VersionRange.class);
+      assertVersionRange(other, "1.0.0", "2.0.0");
+      assertEquals(range, other);
+   }
+   
+   protected void testVersionRangeFromString(String low)
+   {
+      testVersionRange(low);
+      
+      Version lowVersion = null;
+      if (low != null)
+         lowVersion = Version.parseVersion(low);
+      testVersionRange(lowVersion);
+   }
+   
+   protected void testVersionRangeFromString(String low, String high)
+   {
+      testVersionRange(low, high);
+      
+      Version lowVersion = null;
+      if (low != null)
+         lowVersion = Version.parseVersion(low);
+      Version highVersion = null;
+      if (high != null)
+         highVersion = Version.parseVersion(high);
+      testVersionRange(lowVersion, highVersion);
+   }
+   
+   protected void testVersionRangeFromStringAllPerms(String low, String high)
+   {
+      testVersionRangeFromString(low, false, high, false);
+      testVersionRangeFromString(low, true, high, false);
+      testVersionRangeFromString(low, false, high, true);
+      testVersionRangeFromString(low, true, high, true);
+   }
+   
+   protected void testVersionRangeFromString(String low, boolean lowInclusive, String high, boolean highInclusive)
+   {
+      testVersionRange(low, lowInclusive, high, highInclusive);
+      
+      Version lowVersion = null;
+      if (low != null)
+         lowVersion = Version.parseVersion(low);
+      Version highVersion = null;
+      if (high != null)
+         highVersion = Version.parseVersion(high);
+      testVersionRange(lowVersion, lowInclusive, highVersion, highInclusive);
+   }
+   
+   protected void testVersionRange(Object low)
+   {
+      VersionRange range = new VersionRange(low);
+      assertVersionRange(range, low, null);
+      testToString(range, low, true, null, false);
+   }
+   
+   protected void testVersionRange(Object low, Object high)
+   {
+      VersionRange range = new VersionRange(low, high);
+      assertVersionRange(range, low, high);
+      testToString(range, low, true, high, false);
+   }
+   
+   protected void testVersionRange(Object low, boolean lowInclusive, Object high, boolean highInclusive)
+   {
+      VersionRange range = new VersionRange(low, lowInclusive, high, highInclusive);
+      assertVersionRange(range, low, lowInclusive, high, highInclusive);
+      testToString(range, low, lowInclusive, high, highInclusive);
+   }
+   
+   protected void testToString(VersionRange range, Object low, boolean lowInclusive, Object high, boolean highInclusive)
+   {
+      StringBuilder expected = new StringBuilder();
+      if (low == null)
+         low = Version.DEFAULT_VERSION;
+      if (lowInclusive)
+         expected.append("[").append(low);
+      else
+         expected.append("(").append(low);
+      expected.append(",");
+      if (high == null)
+         expected.append("?").append(")");
+      else if (highInclusive)
+         expected.append(high).append("]");
+      else
+         expected.append(high).append(")");
+      assertEquals(expected.toString(), range.toString());
+   }
+   
+   protected void assertBadVersionRangeFromString(String low, String high)
+   {
+      assertBadVersionRange(low, high);
+
+      Version lowVersion = null;
+      if (low != null)
+         lowVersion = Version.parseVersion(low);
+      Version highVersion = null;
+      if (high != null)
+         highVersion = Version.parseVersion(high);
+      assertBadVersionRange(lowVersion, highVersion);
+   }
+   
+   protected void assertBadVersionRange(Object low, Object high)
+   {
+      try
+      {
+         fail("Should not be here! Got " + new VersionRange(low, high));
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   protected void assertBadVersionRangeFromStringAllPerms(String low, String high)
+   {
+      assertBadVersionRangeFromString(low, false, high, false);
+      assertBadVersionRangeFromString(low, true, high, false);
+      assertBadVersionRangeFromString(low, false, high, true);
+      assertBadVersionRangeFromString(low, true, high, true);
+   }
+   
+   protected void assertBadVersionRangeFromStringNotBoth(String low, String high)
+   {
+      assertBadVersionRangeFromString(low, false, high, false);
+      assertBadVersionRangeFromString(low, true, high, false);
+      assertBadVersionRangeFromString(low, false, high, true);
+   }
+   
+   protected void assertBadVersionRangeFromString(String low, boolean lowInclusive, String high, boolean highInclusive)
+   {
+      assertBadVersionRange(low, lowInclusive, high, highInclusive);
+
+      Version lowVersion = null;
+      if (low != null)
+         lowVersion = Version.parseVersion(low);
+      Version highVersion = null;
+      if (high != null)
+         highVersion = Version.parseVersion(high);
+      assertBadVersionRange(lowVersion, lowInclusive, highVersion, highInclusive);
+   }
+   
+   protected void assertBadVersionRange(Object low, boolean lowInclusive, Object high, boolean highInclusive)
+   {
+      try
+      {
+         fail("Should not be here! Got: " + new VersionRange(low, lowInclusive, high, highInclusive));
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   protected void testEqualsFromString(String low1, String high1, String low2, String high2, boolean result)
+   {
+      testEqualsFromString(low1, true, high1, false, low2, true, high2, false, result);
+   }
+   
+   protected void testEqualsFromString(String low1, boolean low1Inclusive, String high1, boolean high1Inclusive, String low2, boolean low2Inclusive, String high2, boolean high2Inclusive, boolean result)
+   {
+      testEquals(low1, low1Inclusive, high1, high1Inclusive, low2, low2Inclusive, high2, high2Inclusive, result);
+      
+      Version versionLow1 = null;
+      if (low1 != null)
+         versionLow1 = Version.parseVersion(low1);
+      Version versionHigh1 = null;
+      if (high1 != null)
+         versionHigh1 = Version.parseVersion(high1);
+      Version versionLow2 = null;
+      if (low2 != null)
+         versionLow2 = Version.parseVersion(low2);
+      Version versionHigh2 = null;
+      if (high2 != null)
+         versionHigh2 = Version.parseVersion(high2);
+      testEquals(versionLow1, low1Inclusive, versionHigh1, high1Inclusive, versionLow2, low2Inclusive, versionHigh2, high2Inclusive, result);
+   }
+   
+   protected void testEquals(Object low1, Object high1, Object low2, Object high2, boolean result)
+   {
+      testEquals(low1, true, high1, false, low2, true, high2, false, result);
+   }
+   
+   protected void testEquals(Object low1, boolean low1Inclusive, Object high1, boolean high1Inclusive, Object low2, boolean low2Inclusive, Object high2, boolean high2Inclusive, boolean result)
+   {
+      VersionRange range1 = new VersionRange(low1, low1Inclusive, high1, high1Inclusive);
+      VersionRange range2 = new VersionRange(low2, low2Inclusive, high2, high2Inclusive);
+      testEquals(range1, range2, result);
+   }
+   
+   protected void testEquals(VersionRange range1, VersionRange range2, boolean result)
+   {
+      if (result)
+      {
+         assertTrue("Expected " + range1 + ".equals(" + range2 + ") to be true", range1.equals(range2));
+         assertTrue("Expected " + range2 + ".equals(" + range1 + ") to be true", range2.equals(range1));
+      }
+      else
+      {
+         assertFalse("Expected " + range1 + ".equals(" + range2 + ") to be false", range1.equals(range2));
+         assertFalse("Expected " + range2 + ".equals(" + range1 + ") to be false", range2.equals(range1));
+      }
+   }
+   
+   protected void testIsInRangeFromString(String low, String high, String test, boolean result)
+   {
+      testIsInRangeFromString(low, true, high, false, test, result);
+   }
+   
+   protected void testIsInRangeFromStringAllPerms(String low, String high, String test, boolean result)
+   {
+      testIsInRangeFromString(low, false, high, false, test, result);
+      testIsInRangeFromString(low, false, high, true, test, result);
+      testIsInRangeFromString(low, true, high, false, test, result);
+      testIsInRangeFromString(low, true, high, true, test, result);
+   }
+   
+   protected void testIsInRangeFromString(String low, boolean lowInclusive, String high, boolean highInclusive, String test, boolean result)
+   {
+      testIsInRange(low, lowInclusive, high, highInclusive, test, result);
+
+      Version lowVersion = null;
+      if (low != null)
+         lowVersion = Version.parseVersion(low);
+      Version highVersion = null;
+      if (high != null)
+         highVersion = Version.parseVersion(high);
+      Version version = Version.parseVersion(test);
+      testIsInRange(lowVersion, lowInclusive, highVersion, highInclusive, version, result);
+   }
+   
+   protected void testIsInRange(Object low, boolean lowInclusive, Object high, boolean highInclusive, Object version, boolean result)
+   {
+      VersionRange range = new VersionRange(low, lowInclusive, high, highInclusive);
+      testIsInRange(range, version, result);
+   }
+   
+   protected void testIsInRange(VersionRange range, Object version, boolean result)
+   {
+      if (result)
+         assertTrue("Expected " + range + ".isInRange(" + version + ") to be true", range.isInRange(version));
+      else
+         assertFalse("Expected " + range + ".isInRange(" + version + ") to be false", range.isInRange(version));
+   }
+}

Added: projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/classloading/src/tests/org/jboss/test/classloading/version/test/VersionUnitTestCase.java	2008-02-18 13:30:09 UTC (rev 69878)
@@ -0,0 +1,520 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.classloading.version.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionComparatorRegistry;
+import org.jboss.test.classloading.AbstractClassLoadingTestWithSecurity;
+
+/**
+ * VersionUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VersionUnitTestCase extends AbstractClassLoadingTestWithSecurity
+{
+   public static Test suite()
+   {
+      return suite(VersionUnitTestCase.class);
+   }
+
+   public VersionUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testDefaultVersion() throws Exception
+   {
+      Version version = Version.DEFAULT_VERSION;
+      assertVersion(version, 0, 0, 0, null);
+   }
+   
+   public void testMajorMinorMicro() throws Exception
+   {
+      testVersion(0, 0, 0);
+      testVersion(1, 2, 3);
+      testVersion(3, 2, 1);
+      
+      assertBadVersion(-1, 0, 0);
+      assertBadVersion(0, -1, 0);
+      assertBadVersion(0, 0, -1);
+   }
+   
+   public void testMajorMinorMicroQualifier() throws Exception
+   {
+      testVersion(0, 0, 0, "GA");
+      testVersion(1, 2, 3, "CR");
+      testVersion(3, 2, 1, "Beta1");
+      testVersion(0, 0, 0, "1234567890");
+      testVersion(0, 0, 0, "abcdefghijklmnopqrstuvwxyz");
+      testVersion(0, 0, 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+      testVersion(0, 0, 0, "_");
+      testVersion(0, 0, 0, "-");
+      testVersion(0, 0, 0, null);
+      
+      assertBadVersion(-1, 0, 0, "GA");
+      assertBadVersion(0, -1, 0, "GA");
+      assertBadVersion(0, 0, -1, "GA");
+      assertBadVersion(0, 0, 0, "G A");
+      assertBadVersion(0, 0, 0, "!");
+   }
+   
+   public void testParseVersion() throws Exception
+   {
+      testVersion(null, 0, 0, 0, null);
+      testVersion("", 0, 0, 0, null);
+      testVersion("1", 1, 0, 0, null);
+      testVersion("1.2", 1, 2, 0, null);
+      testVersion("1.2.3", 1, 2, 3, null);
+      testVersion("1.2.3.GA", 1, 2, 3, "GA");
+      testVersion("10.2.3.GA", 10, 2, 3, "GA");
+      testVersion("1.20.3.GA", 1, 20, 3, "GA");
+      testVersion("1.2.30.GA", 1, 2, 30, "GA");
+      testVersion("0.0.0.1234567890", 0, 0, 0, "1234567890");
+      testVersion("0.0.0.abcdefghijklmnopqrstuvwxyz", 0, 0, 0, "abcdefghijklmnopqrstuvwxyz");
+      testVersion("0.0.0.ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, 0, 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+      testVersion("0.0.0._", 0, 0, 0, "_");
+      testVersion("0.0.0.-", 0, 0, 0, "-");
+      testVersion(" ", 0, 0, 0, null);
+      testVersion(" 1.2.3.GA", 1, 2, 3, "GA");
+      testVersion("1 .2.3.GA", 1, 2, 3, "GA");
+      testVersion("1. 2.3.GA", 1, 2, 3, "GA");
+      testVersion("1.2 .3.GA", 1, 2, 3, "GA");
+      testVersion("1.2. 3.GA", 1, 2, 3, "GA");
+      testVersion("1.2.3 .GA", 1, 2, 3, "GA");
+      testVersion("1.2.3. GA", 1, 2, 3, "GA");
+      testVersion("1.2.3.GA ", 1, 2, 3, "GA");
+      
+      assertBadVersion("x");
+      assertBadVersion("1.x");
+      assertBadVersion("1.2.x");
+      assertBadVersion("1.2.3.GA.x");
+      assertBadVersion("1.2.3.G A");
+      assertBadVersion("1.2.3.!");
+      assertBadVersion("1 0.2.3.GA");
+      assertBadVersion("1.2 0.3.GA");
+      assertBadVersion("1.2.3 0.GA");
+      assertBadVersion(".2.3.GA");
+      assertBadVersion("1..3.GA");
+      assertBadVersion("1.2..GA");
+      assertBadVersion("1.2.3.");
+   }
+   
+   public void testEquals() throws Exception
+   {
+      testEquals(null, Version.DEFAULT_VERSION, true);
+      testEquals("", Version.DEFAULT_VERSION, true);
+      testEquals(" ", Version.DEFAULT_VERSION, true);
+      testEquals(0, Version.DEFAULT_VERSION, true);
+
+      testEquals(1, Version.DEFAULT_VERSION, false);
+      testEquals(0, 1, Version.DEFAULT_VERSION, false);
+      testEquals(0, 0, 1, Version.DEFAULT_VERSION, false);
+      testEquals(0, 0, 0, "GA", Version.DEFAULT_VERSION, false);
+
+      testEquals(null, (String) null, true);
+      testEquals(null, "", true);
+      testEquals(null, " ", true);
+      testEquals("", " ", true);
+      testEquals("", 0, true);
+      testEquals("1", 1, true);
+      testEquals("1.2", 1, 2, true);
+      testEquals("1.2.3", 1, 2, 3, true);
+      testEquals("1.2.3.GA", 1, 2, 3, "GA", true);
+
+      testEquals("1", 1, 2, 3, "GA", false);
+      testEquals("1.2", 1, 2, 3, "GA", false);
+      testEquals("1.2.3", 1, 2, 3, "GA", false);
+      testEquals("2.2.3.GA", 1, 2, 3, "GA", false);
+      testEquals("1.2.2.GA", 1, 2, 3, "GA", false);
+      testEquals("1.2.2.AG", 1, 2, 3, "GA", false);
+      testEquals("10.2.3.GA", 1, 2, 3, "GA", false);
+      testEquals("1.20.3.GA", 1, 2, 3, "GA", false);
+      testEquals("1.2.30.GA", 1, 2, 3, "GA", false);
+   }
+   
+   public void testComareTo() throws Exception
+   {
+      testCompare(null, Version.DEFAULT_VERSION, 0);
+      testCompare("", Version.DEFAULT_VERSION, 0);
+      testCompare("0", Version.DEFAULT_VERSION, 0);
+
+      testCompare("0", "0", 0);
+      testCompare("0", "0.0", 0);
+      testCompare("0", "0.0.0", 0);
+      testCompare("0.0", "0.0.0", 0);
+
+      testCompare("1", "1", 0);
+      testCompare("1", "1.0", 0);
+      testCompare("1", "1.0.0", 0);
+      testCompare("1.0", "1.0.0", 0);
+
+      testCompare("1", "2", -1);
+      testCompare("1", "2.0", -1);
+      testCompare("1", "2.0.0", -1);
+
+      testCompare("1.0", "1.1", -1);
+      testCompare("1.0", "1.1.0", -1);
+      testCompare("1.0", "1.2", -1);
+      testCompare("1.0", "1.2.0", -1);
+
+      testCompare("1.1", "1.2", -1);
+      testCompare("1.1", "1.2.0", -1);
+      testCompare("1.1", "1.3", -1);
+      testCompare("1.1", "1.3.0", -1);
+
+      testCompare("1.0.0", "1.0.1", -1);
+      testCompare("1.0.0", "1.0.2", -1);
+
+      testCompare("1.1.1", "1.1.2", -1);
+      testCompare("1.1.1", "1.1.3", -1);
+
+      testCompare("1.0.0", "1.0.0.A", -1);
+      testCompare("1.0.0.A", "1.0.0.B", -1);
+      testCompare("1.0.0.AA", "1.0.0.AB", -1);
+      testCompare("1.0.0.Beta1", "1.0.0.Beta2", -1);
+      testCompare("1.0.0.Beta10", "1.0.0.Beta2", -1);
+   }
+   
+   public void testSerialization() throws Exception
+   {
+      Version version = new Version(1, 0, 0, "GA");;
+      Version other = serializeDeserialize(version, Version.class);
+      assertVersion(other, 1, 0, 0, "GA");
+      assertEquals(version, other);
+   }
+   
+   protected void testVersion(int major, int minor, int micro)
+   {
+      Version version = new Version(major, minor, micro);
+      assertVersion(version, major, minor, micro);
+      testToString(version, major, minor, micro, null);
+   }
+   
+   protected void testVersion(int major, int minor, int micro, String qualifier)
+   {
+      Version version = new Version(major, minor, micro, qualifier);
+      assertVersion(version, major, minor, micro, qualifier);
+      testToString(version, major, minor, micro, qualifier);
+   }
+   
+   protected void testVersion(String test, int major, int minor, int micro, String qualifier)
+   {
+      Version version = Version.parseVersion(test);
+      assertVersion(version, major, minor, micro, qualifier);
+      testToString(version, major, minor, micro, qualifier);
+   }
+   
+   protected void testToString(Version version, int major, int minor, int micro, String qualifier)
+   {
+      String expected = major + "." + minor + "." + micro;
+      if (qualifier != null)
+      {
+         qualifier = qualifier.trim();
+         if (qualifier.length() > 0)
+            expected += "." + qualifier;
+      }
+      assertEquals(expected, version.toString());
+   }
+   
+   protected void assertBadVersion(int major, int minor, int micro)
+   {
+      try
+      {
+         new Version(major, minor, micro);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   protected void assertBadVersion(int major, int minor, int micro, String qualifier)
+   {
+      try
+      {
+         new Version(major, minor, micro, qualifier);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   protected void assertBadVersion(String version)
+   {
+      try
+      {
+         Version.parseVersion(version);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+   
+   protected void testEquals(String test1, String test2, boolean result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      Version version2 = Version.parseVersion(test2);
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(String test1, int major, boolean result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      Version version2 = Version.parseVersion("" + major);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(" " + major);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion("" + major + " ");
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(" " + major + " ");
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + ".0");
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + ".0.0");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(String test1, int major, int minor, boolean result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      Version version2 = Version.parseVersion(major + "." + minor);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + ". " + minor);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + "." + minor + " ");
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + ". " + minor + " ");
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + ". " + minor + ".0");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(String test1, int major, int minor, int micro, boolean result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      Version version2 = Version.parseVersion(major + "." + minor + "." + micro);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + "." + minor + ". " + micro);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + "." + minor + "." + micro + " ");
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + "." + minor + ". " + micro + " ");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(String test1, int major, int minor, int micro, String qualifier, boolean result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      Version version2 = Version.parseVersion(major + "." + minor + "." + micro + "." + qualifier);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + "." + minor + "." + micro + ". " + qualifier);
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + "." + minor + "." + micro + "." + qualifier + " ");
+      testVersionEquals(version1, version2, result);
+      version2 = Version.parseVersion(major + "." + minor + "." + micro + ". " + qualifier + " ");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(String test1, Version version2, boolean result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(int major, Version version2, boolean result)
+   {
+      Version version1 = Version.parseVersion("" + major);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(" " + major);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + " ");
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(" " + major + " ");
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + ".0");
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + ".0.0");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(int major, int minor, Version version2, boolean result)
+   {
+      Version version1 = Version.parseVersion(major + "." + minor);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + ". " + minor);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + " ");
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + ". " + minor + " ");
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + ".0");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(int major, int minor, int micro, Version version2, boolean result)
+   {
+      Version version1 = Version.parseVersion(major + "." + minor + "." + micro);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + ". " + micro);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + "." + micro + " ");
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + ". " + micro + " ");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testEquals(int major, int minor, int micro, String qualifier, Version version2, boolean result)
+   {
+      Version version1 = Version.parseVersion(major + "." + minor + "." + micro + "." + qualifier);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + "." + micro + ". " + qualifier);
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + "." + micro + "." + qualifier + " ");
+      testVersionEquals(version1, version2, result);
+      version1 = Version.parseVersion(major + "." + minor + "." + micro + ". " + qualifier + " ");
+      testVersionEquals(version1, version2, result);
+   }
+   
+   protected void testVersionEquals(Version version1, Version version2, boolean result)
+   {
+      if (result)
+      {
+         assertTrue("Expected " + version1 + ".equals(" + version2 + ") to be true", version1.equals(version2));
+         assertTrue("Expected " + version2 + ".equals(" + version1 + ") to be true", version2.equals(version1));
+      }
+      else
+      {
+         assertFalse("Expected " + version1 + ".equals(" + version2 + ") to be false", version1.equals(version2));
+         assertFalse("Expected " + version2 + ".equals(" + version1 + ") to be false", version2.equals(version1));
+      }
+   }
+   
+   protected void testCompare(String test1, String test2, int result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      Version version2 = Version.parseVersion(test2);
+      testVersionCompare(version1, version2, result);
+      testVersionCompareViaRegistry(test1, test2, result);
+   }
+   
+   protected void testCompare(String test1, Version version2, int result)
+   {
+      Version version1 = Version.parseVersion(test1);
+      testVersionCompare(version1, version2, result);
+      testVersionCompareViaRegistry(test1, version2, result);
+   }
+   
+   protected void testVersionCompare(Version version1, Version version2, int result)
+   {
+      if (result < 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be negative " + version1.compareTo(version2), version1.compareTo(version2) < 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be positive " + version2.compareTo(version1), version2.compareTo(version1) > 0);
+      }
+      else if (result > 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be positive " + version1.compareTo(version2), version1.compareTo(version2) > 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be negative" + version2.compareTo(version1), version2.compareTo(version1) < 0);
+      }
+      else
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be zero " + version1.compareTo(version2), version1.compareTo(version2) == 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be zero" + version2.compareTo(version1), version2.compareTo(version1) == 0);
+      }
+      testVersionCompareViaRegistry(version1, version2, result);
+   }
+   
+   protected void testVersionCompareViaRegistry(String version1, String version2, int result)
+   {
+      if (version1 == null)
+         return;
+      VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
+      if (result < 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be negative " + registry.compare(version1, version2), registry.compare(version1, version2) < 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be positive " + registry.compare(version2, version1), registry.compare(version2, version1) > 0);
+      }
+      else if (result > 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be positive " + registry.compare(version1, version2), registry.compare(version1, version2) > 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be negative" + registry.compare(version2, version1), registry.compare(version2, version1) < 0);
+      }
+      else
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be zero " + registry.compare(version1, version2), registry.compare(version1, version2) == 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be zero" + registry.compare(version2, version1), registry.compare(version2, version1) == 0);
+      }
+   }
+   
+   protected void testVersionCompareViaRegistry(String version1, Version version2, int result)
+   {
+      if (version1 == null)
+         return;
+      VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
+      if (result < 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be negative " + registry.compare(version1, version2), registry.compare(version1, version2) < 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be positive " + registry.compare(version2, version1), registry.compare(version2, version1) > 0);
+      }
+      else if (result > 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be positive " + registry.compare(version1, version2), registry.compare(version1, version2) > 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be negative" + registry.compare(version2, version1), registry.compare(version2, version1) < 0);
+      }
+      else
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be zero " + registry.compare(version1, version2), registry.compare(version1, version2) == 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be zero" + registry.compare(version2, version1), registry.compare(version2, version1) == 0);
+      }
+   }
+   
+   protected void testVersionCompareViaRegistry(Version version1, Version version2, int result)
+   {
+      if (version1 == null)
+         return;
+      VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
+      if (result < 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be negative " + registry.compare(version1, version2), registry.compare(version1, version2) < 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be positive " + registry.compare(version2, version1), registry.compare(version2, version1) > 0);
+      }
+      else if (result > 0)
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be positive " + registry.compare(version1, version2), registry.compare(version1, version2) > 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be negative" + registry.compare(version2, version1), registry.compare(version2, version1) < 0);
+      }
+      else
+      {
+         assertTrue("Expected " + version1 + ".compareTo(" + version2 + ") to be zero " + registry.compare(version1, version2), registry.compare(version1, version2) == 0);
+         assertTrue("Expected " + version2 + ".compareTo(" + version1 + ") to be zero" + registry.compare(version2, version1), registry.compare(version2, version1) == 0);
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list