[jboss-cvs] JBossAS SVN: r92576 - in projects/profileservice/trunk: core/src/main/java/org/jboss/profileservice and 11 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 19 09:07:25 EDT 2009


Author: emuckenhuber
Date: 2009-08-19 09:07:25 -0400 (Wed, 19 Aug 2009)
New Revision: 92576

Added:
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/metadata/VirtualProfileDeploymentMetaData.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/package-info.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/Version.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparator.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparatorRegistry.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionRange.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractCapability.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractRequirement.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionRangeSupport.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionSupport.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionMetaMapper.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionValueAdapter.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeploymentRequirement.java
Modified:
   projects/profileservice/trunk/core/pom.xml
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileContextFactory.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileMetaData.java
   projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeployment.java
   projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/test/VirtualDeploymentAssemblyUnitTestCase.java
   projects/profileservice/trunk/core/src/test/resources/org/jboss/test/profileservice/virtual/test/repository.xml
   projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/dependency/ProfileRequirement.java
   projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/ProfileDeploymentMetaData.java
   projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyCapability.java
   projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyMetaData.java
   projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileMetaData.java
   projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractSubProfileKeyMetaData.java
Log:
add cl version range for testing purpose

Modified: projects/profileservice/trunk/core/pom.xml
===================================================================
--- projects/profileservice/trunk/core/pom.xml	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/core/pom.xml	2009-08-19 13:07:25 UTC (rev 92576)
@@ -20,7 +20,7 @@
 			<version>2.1.0.GA</version>
 			<scope>provided</scope>
 		</dependency>
-	
+
 		<dependency>
 			<groupId>org.jboss.deployers</groupId>
 			<artifactId>jboss-deployers-vfs</artifactId>

Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileContextFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileContextFactory.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileContextFactory.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -40,11 +40,11 @@
 import org.jboss.profileservice.dependency.ProfileServiceController;
 import org.jboss.profileservice.dependency.ProfileStartAction;
 import org.jboss.profileservice.profile.FilteredProfile;
+import org.jboss.profileservice.profile.metadata.BasicProfileDeploymentMetaData;
 import org.jboss.profileservice.spi.Profile;
 import org.jboss.profileservice.spi.ProfileFactory;
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.profileservice.spi.dependency.ProfileDependencyContext;
-import org.jboss.profileservice.spi.metadata.ProfileDeploymentMetaData;
 import org.jboss.profileservice.spi.metadata.ProfileMetaData;
 
 /**
@@ -100,7 +100,7 @@
       return new FilteredProfile(key, getDeploymentNames(metaData), getRepositoryURIs(metaData));
    }
    
-   protected URI[] getRepositoryURIs(ProfileMetaData metaData) throws URISyntaxException 
+   protected URI[] getRepositoryURIs(BootstrapProfileMetaData metaData) throws URISyntaxException 
    {
       if(metaData.getSource() == null)
          throw new IllegalArgumentException("null profile source");
@@ -115,12 +115,12 @@
       return repositoryURIs.toArray( new URI[ repositoryURIs.size() ]);
    }
    
-   protected List<String> getDeploymentNames(ProfileMetaData metaData)
+   protected List<String> getDeploymentNames(BootstrapProfileMetaData metaData)
    {
       List<String> deploymentNames = new ArrayList<String>();
       if(metaData.getDeployments() != null && metaData.getDeployments().isEmpty() == false)
       {
-         for(ProfileDeploymentMetaData deployment : metaData.getDeployments())
+         for(BasicProfileDeploymentMetaData deployment : metaData.getDeployments())
          {
             deploymentNames.add(deployment.getName());
          }

Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileMetaData.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileMetaData.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileMetaData.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -32,7 +32,6 @@
 import org.jboss.profileservice.profile.metadata.BasicProfileSourceMetaData;
 import org.jboss.profileservice.profile.metadata.BasicSubProfileMetaData;
 import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.profileservice.spi.metadata.ProfileDeploymentMetaData;
 import org.jboss.profileservice.spi.metadata.ProfileMetaDataVisitor;
 import org.jboss.profileservice.spi.metadata.ProfileSourceMetaData;
 import org.jboss.profileservice.spi.metadata.SubProfileMetaData;
@@ -50,7 +49,7 @@
    private ProfileSourceMetaData source;
    
    /** The deployments. */
-   private List<ProfileDeploymentMetaData> deployments;
+   private List<BasicProfileDeploymentMetaData> deployments;
 
    public BootstrapProfileMetaData()
    {
@@ -72,7 +71,7 @@
       super(key);
    }
    
-   public List<ProfileDeploymentMetaData> getDeployments()
+   public List<BasicProfileDeploymentMetaData> getDeployments()
    {
       return this.deployments;
    }
@@ -113,7 +112,7 @@
    }
    
    @XmlElement(name = "deployment", type = BasicProfileDeploymentMetaData.class)
-   public void setDeployments(List<ProfileDeploymentMetaData> deployments)
+   public void setDeployments(List<BasicProfileDeploymentMetaData> deployments)
    {
       this.deployments = deployments;
    }

Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/metadata/VirtualProfileDeploymentMetaData.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/metadata/VirtualProfileDeploymentMetaData.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/metadata/VirtualProfileDeploymentMetaData.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.profileservice.profile.metadata;
+
+import org.jboss.profileservice.spi.metadata.ProfileDeploymentMetaData;
+import org.jboss.profileservice.spi.metadata.ProfileMetaDataVisitor;
+
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class VirtualProfileDeploymentMetaData implements ProfileDeploymentMetaData
+{
+
+   
+   
+   public String getName()
+   {
+      // FIXME getName
+      return null;
+   }
+
+   @Override
+   public void visit(ProfileMetaDataVisitor visitor)
+   {
+      // FIXME visit
+      
+   }
+
+  
+}
+

Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/package-info.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/package-info.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/package-info.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.profileservice.repository.virtual;
+
+import org.jboss.profileservice.version.Version;
+import org.jboss.profileservice.version.helpers.VersionValueAdapter;
+import org.jboss.xb.annotations.JBossXmlAdaptedType;
+import org.jboss.xb.annotations.JBossXmlAdaptedTypes;
+

Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/Version.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/Version.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/Version.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,298 @@
+/*
+ * 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.profileservice.version;
+
+import java.io.Serializable;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.metatype.api.annotations.MetaMapping;
+import org.jboss.profileservice.version.helpers.VersionMetaMapper;
+
+/**
+ * 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 $
+ */
+ at MetaMapping(VersionMetaMapper.class)
+ at XmlType(propOrder = {})
+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/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparator.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparator.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparator.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -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.profileservice.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/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparatorRegistry.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparatorRegistry.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionComparatorRegistry.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,324 @@
+/*
+* 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.profileservice.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
+    */
+   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/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionRange.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionRange.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/VersionRange.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,300 @@
+/*
+ * 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.profileservice.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;
+   }
+
+   /**
+    * Check whether two version ranges are consistent
+    * 
+    * @param other the other version
+    * @return true when the version ranges "overlap"
+    */
+   public boolean isConsistent(VersionRange other)
+   {
+      // No version range is consistent with ours
+      if (other == null)
+         return true;
+      
+      Object otherLow = other.getLow();
+      Object otherHigh = other.getHigh();
+      
+      VersionComparatorRegistry comparator = VersionComparatorRegistry.getInstance();
+      
+      // Other low is "lower"
+      int comparison = comparator.compare(low, otherLow);
+      if (comparison > 0 || (lowInclusive == false && comparison == 0))
+      {
+         // Just need to check that the other high is not lower
+         if (otherHigh == null)
+            return true;
+         comparison = comparator.compare(low, otherHigh);
+         return (comparison > 0 || (lowInclusive == false && comparison == 0)) == false;
+      }
+
+      // So the other low is "bigger" than our low
+      
+      // We have no high so we are done
+      if (high == null)
+         return true;
+      
+      // Check the other low is not "bigger" than our higher
+      comparison = comparator.compare(high, otherLow);
+      if (comparison < 0 || (highInclusive == false && comparison == 0))
+         return false;
+      
+      // The low is in our range so we are done
+      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/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractCapability.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractCapability.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractCapability.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -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.profileservice.version.helpers;
+
+import org.jboss.profileservice.spi.dependency.ProfileCapability;
+
+/**
+ * AbstractCapability.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractCapability extends NameAndVersionSupport implements ProfileCapability
+{
+   /** 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/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractRequirement.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractRequirement.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/AbstractRequirement.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,164 @@
+/*
+* 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.profileservice.version.helpers;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+import org.jboss.profileservice.spi.dependency.ProfileRequirement;
+import org.jboss.profileservice.version.VersionRange;
+
+/**
+ * AbstractRequirement.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 1.1 $
+ */
+public class AbstractRequirement extends NameAndVersionRangeSupport implements ProfileRequirement
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -1L;
+
+   /** Whether the requirement is optional */
+   private boolean optional = 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 isConsistent(ProfileRequirement other)
+   {
+      return isConsistent(other, null);
+   }
+
+   /**
+    * Check whether the requirements are consistent
+    * 
+    * @param other the other requirement
+    * @param requirementType the class to check when looking for inconsistencies (uses getClass() when null)
+    * @return true when consistent, false otherwise
+    */
+   protected boolean isConsistent(ProfileRequirement other, Class<? extends ProfileRequirement> requirementType)
+   {
+      if (other == null)
+         throw new IllegalArgumentException("Null requirement");
+      if (requirementType == null)
+         requirementType = getClass();
+      
+      // Not our type
+      if (requirementType.isInstance(other) == false)
+         return true;
+      
+      AbstractRequirement otherRequirement = (AbstractRequirement) other;
+      // Not the same name
+      String name = getName();
+      String otherName = otherRequirement.getName();
+      if (name.equals(otherName) == false)
+         return true;
+
+      // Check the version ranges are consistent
+      VersionRange range = getVersionRange();
+      VersionRange otherRange = otherRequirement.getVersionRange();
+      return range.isConsistent(otherRange);
+   }
+
+   @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;
+      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");
+   }
+}

Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionRangeSupport.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionRangeSupport.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionRangeSupport.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,319 @@
+/*
+* 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.profileservice.version.helpers;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.jboss.metatype.api.annotations.CompositeKey;
+import org.jboss.metatype.api.annotations.CompositeValue;
+import org.jboss.profileservice.version.Version;
+import org.jboss.profileservice.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.
+    */
+   @CompositeKey
+   @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.
+    */
+   @CompositeValue(ignore=true)
+   @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.
+    */
+   @CompositeValue(ignore=true)
+   @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.
+    */
+   @CompositeKey
+   @CompositeValue(name="from")
+   @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.
+    */
+   @CompositeKey
+   @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.
+    */
+   @CompositeValue(ignore=true)
+   @XmlTransient
+   public void setTo(Object toVersion)
+   {
+      versionRange = new VersionRange(versionRange.getLow(), versionRange.isLowInclusive(), toVersion, versionRange.isHighInclusive());
+   }
+
+   /**
+    * Get the toVersion.
+    * 
+    * @return the toVersion.
+    */
+   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.
+    */
+   @CompositeKey
+   @CompositeValue(name="to")
+   @XmlAttribute(name="to")
+   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.
+    */
+   @CompositeKey
+   @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
+    */
+   @CompositeValue(ignore=true)
+   @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/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionSupport.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionSupport.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/NameAndVersionSupport.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,203 @@
+/*
+* 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.profileservice.version.helpers;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.metatype.api.annotations.CompositeKey;
+import org.jboss.metatype.api.annotations.CompositeValue;
+import org.jboss.profileservice.version.Version;
+import org.jboss.profileservice.version.VersionComparatorRegistry;
+
+/**
+ * NameAndVersionSupport.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NameAndVersionSupport implements Serializable, Cloneable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 6943685422194480909L;
+
+   /** The name  */
+   private String name = "<unknown>";
+   
+   /** 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.
+    */
+   @CompositeKey
+   @ManagementProperty
+   @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.
+    */
+   @CompositeValue(ignore=true)
+   @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.
+    */
+   @CompositeKey
+   @CompositeValue(name="version")
+   @ManagementProperty(name="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();
+   }
+
+   @Override
+   public NameAndVersionSupport clone()
+   {
+      try
+      {
+         NameAndVersionSupport clone = (NameAndVersionSupport) super.clone();
+         return clone;
+      }
+      catch (CloneNotSupportedException e)
+      {
+         throw new RuntimeException("Unexpected", e);
+      }
+   }
+}

Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionMetaMapper.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionMetaMapper.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionMetaMapper.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,61 @@
+/*
+* 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.profileservice.version.helpers;
+
+import java.lang.reflect.Type;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.profileservice.version.Version;
+
+/**
+ * VersionMetaMapper.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VersionMetaMapper extends MetaMapper<Version>
+{
+   public Type mapToType()
+   {
+      return String.class;
+   }
+
+   public MetaValue createMetaValue(MetaType metaType, Version object)
+   {
+      return SimpleValueSupport.wrap(object.toString());
+   }
+
+   public Version unwrapMetaValue(MetaValue metaValue)
+   {
+      if (SimpleMetaType.STRING.equals(metaValue.getMetaType()) == false)
+         throw new IllegalArgumentException("Not a string: " + metaValue);
+      
+      SimpleValue simple = (SimpleValue) metaValue;
+      String value = (String) simple.getValue();
+      return Version.parseVersion(value);
+   }
+}

Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionValueAdapter.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionValueAdapter.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/version/helpers/VersionValueAdapter.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -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.profileservice.version.helpers;
+
+import org.jboss.profileservice.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);
+   }
+}

Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeployment.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeployment.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeployment.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -27,9 +27,13 @@
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
 
+import org.jboss.profileservice.spi.dependency.ProfileRequirement;
 import org.jboss.profileservice.spi.virtual.ClassPathLocation;
 import org.jboss.profileservice.spi.virtual.MetaDataLocation;
 import org.jboss.profileservice.spi.virtual.VirtualDeployment;
+import org.jboss.profileservice.version.Version;
+import org.jboss.profileservice.version.helpers.AbstractCapability;
+import org.jboss.profileservice.version.helpers.NameAndVersionRangeSupport;
 
 /**
  * The virtual deployment meta data.
@@ -37,13 +41,14 @@
  * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
  * @version $Revision$
  */
- at XmlType(propOrder = {"name", "path", "metaDataLocations", "classPathLocations", "children" })
-public class AbstractVirtualDeployment implements VirtualDeployment
+ at XmlType(propOrder = {"name", "path", "theVersion", "metaDataLocations", "classPathLocations",
+      "requires", "children" })
+public class AbstractVirtualDeployment extends AbstractCapability implements VirtualDeployment
 {
+   
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -1017243455955127135L;
 
-   /** The name. */
-   private String name;
-   
    /** The path. */
    private String path;
    
@@ -55,38 +60,30 @@
    
    /** The child deployments. */
    private List<VirtualDeployment> children;
+   
+   /** The requirements. */
+   private List<NameAndVersionRangeSupport> requires;
 
    public AbstractVirtualDeployment()
    {
-
+      super();
    }
    
    public AbstractVirtualDeployment(String name)
    {
-      this.name = name;
+      super(name);
    }
    
-   /**
-    * Get the name.
-    * 
-    * @return the name.
-    */
-   @XmlAttribute(name = "name")
-   public String getName()
+   public AbstractVirtualDeployment(String name, Version version)
    {
-      return name;
+      super(name, version);
    }
 
-   /**
-    * Set the name.
-    * 
-    * @param name The name to set.
-    */
-   public void setName(String name)
+   public String getName()
    {
-      this.name = name;
+      return super.getName();
    }
-
+   
    /**
     * Get the path.
     * 
@@ -171,12 +168,49 @@
       this.children = children;
    }
 
-   String checkName()
+   /**
+    * Get the requirements.
+    * 
+    * @return the requirements
+    */
+   @XmlElement(name = "requires", type = AbstractVirtualDeploymentRequirement.class)
+   public List<NameAndVersionRangeSupport> getRequires()
    {
-      if(getName() == null)
-         throw new IllegalStateException("null virtual deployment name");
-      return getName();
+      return requires;
    }
    
+   /**
+    * Set the requirements.
+    * 
+    * @param requires the requirements
+    */
+   public void setRequires(List<NameAndVersionRangeSupport> requires)
+   {
+      this.requires = requires;
+   }
+
+   @Override
+   public boolean resolves(ProfileRequirement requirement)
+   {
+      if(requirement instanceof AbstractVirtualDeploymentRequirement)
+      {
+         AbstractVirtualDeploymentRequirement deployment = (AbstractVirtualDeploymentRequirement) requirement;
+         if(getName().equals(deployment.getName()) == false)
+            return false;
+         return deployment.getVersionRange().isInRange(getVersion());
+      }
+      return false;
+   }
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof AbstractVirtualDeployment == false)
+         return false;
+      return super.equals(obj);
+   }
+   
 }
 

Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeploymentRequirement.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeploymentRequirement.java	                        (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/virtual/deployment/AbstractVirtualDeploymentRequirement.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.profileservice.virtual.deployment;
+
+import org.jboss.profileservice.spi.dependency.ProfileRequirement;
+import org.jboss.profileservice.version.helpers.AbstractRequirement;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class AbstractVirtualDeploymentRequirement extends AbstractRequirement
+   implements ProfileRequirement
+{
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   @Override
+   public boolean isOptional()
+   {
+      return false;
+   }
+
+   @Override
+   public boolean isConsistent(ProfileRequirement other)
+   {
+      return isConsistent(other, AbstractVirtualDeploymentRequirement.class);
+   }
+   
+}
+

Modified: projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/test/VirtualDeploymentAssemblyUnitTestCase.java
===================================================================
--- projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/test/VirtualDeploymentAssemblyUnitTestCase.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/test/VirtualDeploymentAssemblyUnitTestCase.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -27,6 +27,9 @@
 import org.jboss.profileservice.repository.virtual.VirtualRepositoryMetaData;
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.profileservice.spi.virtual.VirtualDeployment;
+import org.jboss.profileservice.version.helpers.NameAndVersionRangeSupport;
+import org.jboss.profileservice.virtual.deployment.AbstractVirtualDeployment;
+import org.jboss.profileservice.virtual.deployment.AbstractVirtualDeploymentRequirement;
 import org.jboss.virtual.AssembledDirectory;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.plugins.context.jar.JarUtils;
@@ -56,13 +59,13 @@
       ProfileDeploymentFactory factory = ProfileDeploymentFactory.getInstance();
       
       // Test simple.deployer
-      VirtualDeployment simpleVD = deployments.get("simple.deployer");
+      AbstractVirtualDeployment simpleVD = (AbstractVirtualDeployment) deployments.get("simple.deployer");
       ProfileDeployment simple = factory.createDeployment(simpleVD);
       assertFalse("root must be a non-assembled file", simple.getRoot() instanceof AssembledDirectory);
       log.debug(simple.getRoot());
       
       // Test test.deployer
-      VirtualDeployment deployerVD = deployments.get("test.deployer");
+      AbstractVirtualDeployment deployerVD = (AbstractVirtualDeployment) deployments.get("test.deployer");
       ProfileDeployment deployer = factory.createDeployment(deployerVD);
       assertTrue(deployer.getRoot() instanceof AssembledDirectory);
       // Check meta data includes/excludes
@@ -73,10 +76,13 @@
       assertIncluded(deployer.getRoot(), new String[] {
          "deployer.jar", "fake.jar", "fake2.jar"});
       asssertExcluded(deployer.getRoot(), new String[] {"bad.jar"});
+      // Check requirement
+      resolves(simpleVD, deployerVD.getRequires().get(0));
+      
       log.debug(deployer.getRoot());
       
       // Test deployment
-      VirtualDeployment deploymentVD = deployments.get("test-deployment");
+      AbstractVirtualDeployment deploymentVD = (AbstractVirtualDeployment) deployments.get("test-deployment");
       ProfileDeployment deployment = factory.createDeployment(deploymentVD);
       assertTrue(deployment.getRoot() instanceof AssembledDirectory);
       // Get sub deployment
@@ -84,9 +90,21 @@
       assertNotNull(subDeploymentRoot);
       // Check the sub deployments files
       assertIncluded(subDeploymentRoot, new String[] {"jboss-beans.xml", "test.jar"} );
+      // Check requirement
+      resolves(deployerVD, deploymentVD.getRequires().get(0));
+      
       log.debug(deployment.getRoot());
       log.debug(subDeploymentRoot);
+      
    }
+ 
+   protected void resolves(AbstractVirtualDeployment capability,
+         NameAndVersionRangeSupport requirement)
+   {
+      assertTrue(capability + " resolves " + requirement,
+            capability.resolves(
+                  ((AbstractVirtualDeploymentRequirement) requirement)));
+   }
    
 }
 

Modified: projects/profileservice/trunk/core/src/test/resources/org/jboss/test/profileservice/virtual/test/repository.xml
===================================================================
--- projects/profileservice/trunk/core/src/test/resources/org/jboss/test/profileservice/virtual/test/repository.xml	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/core/src/test/resources/org/jboss/test/profileservice/virtual/test/repository.xml	2009-08-19 13:07:25 UTC (rev 92576)
@@ -14,10 +14,11 @@
  
  	<!-- The simple.deployer -->
  	<virtual-deployment name="simple.deployer" 
-	 	path="${jboss.deployment.resources}/simple-deployer-jboss-beans.xml" />
+	 	path="${jboss.deployment.resources}/simple-deployer-jboss-beans.xml"
+	 	version="1.1.0" />
  
  	<!-- The test.depoyer -->
-	<virtual-deployment name="test.deployer">
+	<virtual-deployment name="test.deployer" version="2.0.1">
 		<meta-inf path="${jboss.deployment.resources}/test.deployer/meta-inf" />
 		<meta-inf path="${jboss.deployment.resources}/test.deployer/meta-inf2">
 			<include name="*.xml" />
@@ -28,18 +29,14 @@
 			<include name="*.jar" />
 			<exclude name="bad.jar" />
 		</classpath>
-				<!--
-		<requires name="simple.deployer" />
-		-->
+		<requires name="simple.deployer" from="1.0.0" to="2.0.0"/>
 	</virtual-deployment>
 
 	<!-- A test deployment  -->
 	<virtual-deployment name="test-deployment">
 		<meta-inf path="${jboss.deployment.resources}/test-deployment/META-INF" />
 		<classpath path="${jboss.deployment.resources}/test-deployment/lib" />
-		<!--
-		<requires name="test.deployer" />
-		-->
+		<requires name="test.deployer" from="2.0.0" to="2.1.0"/>
 		<virtual-deployment name="test-sub-deployment">
 			<meta-inf path="${jboss.deployment.resources}/test-deployment/child/META-INF" />
 			<classpath path="${jboss.deployment.resources}/test-deployment/child/test.jar" />

Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/dependency/ProfileRequirement.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/dependency/ProfileRequirement.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/dependency/ProfileRequirement.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -37,5 +37,16 @@
     */
    boolean isOptional();
    
+   /**
+    * Check whether this requirement is consistent with another requirement.<p>
+    * 
+    * Typically they will be inconsistent if they are the same type,
+    * have the same name but a different version
+    * 
+    * @param other the other requirement
+    * @return true when consistent, false when inconsistent
+    */
+   boolean isConsistent(ProfileRequirement other);
+   
 }
 

Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/ProfileDeploymentMetaData.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/ProfileDeploymentMetaData.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/ProfileDeploymentMetaData.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -30,13 +30,6 @@
  */
 public interface ProfileDeploymentMetaData extends ProfileMetaDataVisitorNode
 {
-   
-   /**
-    * Get the deployment name.
-    * 
-    * @return
-    */
-   String getName();
-   
+     
 }
 

Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyCapability.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyCapability.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyCapability.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -65,6 +65,16 @@
       }
       return false;
    }
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof AbstractProfileKeyCapability == false)
+         return false;
+      return super.equals(obj);
+   }
 
 }
 

Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyMetaData.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyMetaData.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileKeyMetaData.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -44,7 +44,7 @@
    private String domain;
    
    /** The profile key. */
-   private ProfileKey key;
+   private volatile ProfileKey key;
    
    public AbstractProfileKeyMetaData()
    {
@@ -116,15 +116,23 @@
    }
    
    @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof AbstractProfileKeyMetaData == false)
+         return false;
+      
+      return (getKey().equals(((AbstractProfileKeyMetaData)obj).getKey()));
+   }
+   
+   @Override
    public String toString()
    {
       StringBuilder builder = new StringBuilder();
       builder.append(getClass().getSimpleName());
       builder.append('@').append(Integer.toHexString(System.identityHashCode(this)));
       builder.append("{");
-      builder.append("domain=").append(getDomain());
-      builder.append(", server=").append(getServer());
-      builder.append(", name=").append(getName());
       toString(builder);
       builder.append("}");
       return builder.toString();
@@ -137,7 +145,9 @@
     */
    protected void toString(StringBuilder builder)
    {
-      //
+      builder.append("domain=").append(getDomain());
+      builder.append(", server=").append(getServer());
+      builder.append(", name=").append(getName());
    }
    
 }

Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileMetaData.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileMetaData.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractProfileMetaData.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -84,6 +84,16 @@
          }
       }
    }
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof AbstractProfileMetaData == false)
+         return false;
+      return super.equals(obj);
+   }
 
 }
 

Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractSubProfileKeyMetaData.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractSubProfileKeyMetaData.java	2009-08-19 12:57:54 UTC (rev 92575)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/metadata/helpers/AbstractSubProfileKeyMetaData.java	2009-08-19 13:07:25 UTC (rev 92576)
@@ -22,6 +22,7 @@
 package org.jboss.profileservice.spi.metadata.helpers;
 
 import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.dependency.ProfileRequirement;
 import org.jboss.profileservice.spi.metadata.ProfileMetaDataVisitor;
 import org.jboss.profileservice.spi.metadata.SubProfileMetaData;
 
@@ -65,5 +66,21 @@
       visitor.addRequirement(this);  
    }
 
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof AbstractSubProfileKeyMetaData == false)
+         return false;
+      return super.equals(obj);
+   }
+   
+   @Override
+   public boolean isConsistent(ProfileRequirement other)
+   {
+      // We don't have a version
+      return true;
+   }
 }
 




More information about the jboss-cvs-commits mailing list