org.apache.ivy.plugins.version
Class ChainVersionMatcher

java.lang.Object
  extended by org.apache.ivy.plugins.version.AbstractVersionMatcher
      extended by org.apache.ivy.plugins.version.ChainVersionMatcher
All Implemented Interfaces:
IvySettingsAware, VersionMatcher

public class ChainVersionMatcher
extends AbstractVersionMatcher

An implementation of VersionMatcher chaining several version matchers, and implemeting the VersionMatcher interface by returning results from the first matcher in the chain accepting the version.


Constructor Summary
ChainVersionMatcher()
          Unique Constructor.
 
Method Summary
 boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD)
          Indicates if this version matcher considers that the module found matches the asked one.
 boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid)
          Indicates if this version matcher considers that the module revision found matches the asked one.
 void add(VersionMatcher matcher)
          Adds a VersionMatcher to the chain.
 int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, java.util.Comparator staticComparator)
          This method should be overriden in most cases, because it uses the default contract to return 1 when it's not possible to know which revision is greater.
 java.util.List getMatchers()
          Returns the list of matchers in the chain.
 boolean isDynamic(ModuleRevisionId askedMrid)
          Indicates if the given asked ModuleRevisionId should be considered as dynamic for the current VersionMatcher or not.
 boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid)
          Indicates if this VersionMatcher needs module descriptors to determine if a module revision matches the asked one.
 void setSettings(IvySettings settings)
          Sets the settings this matcher will use, and set to the matcher in the chain which implements IvySettingsAware.
 
Methods inherited from class org.apache.ivy.plugins.version.AbstractVersionMatcher
getName, getSettings, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChainVersionMatcher

public ChainVersionMatcher()
Unique Constructor.

Method Detail

add

public void add(VersionMatcher matcher)
Adds a VersionMatcher to the chain.

Parameters:
matcher - the version matcher to add. Must not be null

setSettings

public void setSettings(IvySettings settings)
Sets the settings this matcher will use, and set to the matcher in the chain which implements IvySettingsAware.

Specified by:
setSettings in interface IvySettingsAware
Overrides:
setSettings in class AbstractVersionMatcher
Parameters:
settings - the settings to use in the whole chain. Must not be null.

getMatchers

public java.util.List getMatchers()
Returns the list of matchers in the chain.

The list is returned as an unmodifiable view on the actual list of matchers, and will thus reflect futher changes made in the chain.

Returns:
the list of matchers in the chain. Is never null.

isDynamic

public boolean isDynamic(ModuleRevisionId askedMrid)
Description copied from interface: VersionMatcher
Indicates if the given asked ModuleRevisionId should be considered as dynamic for the current VersionMatcher or not.

Parameters:
askedMrid - the dependency module revision id as asked by a module
Returns:
true if this revision is considered as a dynamic one, false otherwise

compare

public int compare(ModuleRevisionId askedMrid,
                   ModuleRevisionId foundMrid,
                   java.util.Comparator staticComparator)
Description copied from class: AbstractVersionMatcher
This method should be overriden in most cases, because it uses the default contract to return 1 when it's not possible to know which revision is greater.

Specified by:
compare in interface VersionMatcher
Overrides:
compare in class AbstractVersionMatcher
Parameters:
askedMrid - the dynamic revision to compare
foundMrid - the static revision to compare
staticComparator - a comparator which can be used to compare static revisions
Returns:
0 if it's not possible to know which one is greater, greater than 0 if askedMrid should be considered greater, lower than 0 if it can't be consider greater

accept

public boolean accept(ModuleRevisionId askedMrid,
                      ModuleRevisionId foundMrid)
Description copied from interface: VersionMatcher
Indicates if this version matcher considers that the module revision found matches the asked one.

Returns:

needModuleDescriptor

public boolean needModuleDescriptor(ModuleRevisionId askedMrid,
                                    ModuleRevisionId foundMrid)
Description copied from interface: VersionMatcher
Indicates if this VersionMatcher needs module descriptors to determine if a module revision matches the asked one. Note that returning true in this method may imply big performance issues.

Specified by:
needModuleDescriptor in interface VersionMatcher
Overrides:
needModuleDescriptor in class AbstractVersionMatcher
Returns:

accept

public boolean accept(ModuleRevisionId askedMrid,
                      ModuleDescriptor foundMD)
Description copied from interface: VersionMatcher
Indicates if this version matcher considers that the module found matches the asked one. This method can be called even needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) returns false, so it is required to implement it in any case, a usual default implementation being: return accept(askedMrid, foundMD.getResolvedModuleRevisionId());

Specified by:
accept in interface VersionMatcher
Overrides:
accept in class AbstractVersionMatcher
Returns: