org.apache.jackrabbit.core.version
Class GenericVersionSelector

java.lang.Object
  extended byorg.apache.jackrabbit.core.version.GenericVersionSelector
All Implemented Interfaces:
VersionSelector

public class GenericVersionSelector
extends Object
implements VersionSelector

This Class implements a generic version selector that either selects a version by name, label or creation date. If no version is found and the 'returnLatest' flag is set to true, the latest version is returned.


Constructor Summary
GenericVersionSelector()
          Creates a default GenericVersionSelector that always selects the latest version.
GenericVersionSelector(Calendar date)
          Creates a GenericVersionSelector that will select the oldest version of all those that are more recent than the given date.
GenericVersionSelector(String label)
          Creates a GenericVersionSelector that will try to select a version with the given label.
 
Method Summary
 Calendar getDate()
          Returns the date hint
 String getLabel()
          Returns the label hint
 String getName()
          Returns the name hint.
 boolean isReturnLatest()
          Returns the flag, if the latest version should be selected, if no version can be found using the given hint.
 Version select(VersionHistory versionHistory)
          Selects a version from the given version history using the previously assigned hint in the following order: name, label, date, latest.
static Version selectByDate(VersionHistory history, Calendar date)
          Selects a version by date.
static Version selectByLabel(VersionHistory history, String label)
          Selects a version by label
static Version selectByName(VersionHistory history, String name)
          Selects a version by version name.
 void setDate(Calendar date)
          Sets the date hint
 void setLabel(String label)
          Sets the label hint
 void setName(String name)
          Sets the name hint
 void setReturnLatest(boolean returnLatest)
          Sets the flag, if the latest version should be selected, if no version can be found using the given hint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericVersionSelector

public GenericVersionSelector()
Creates a default GenericVersionSelector that always selects the latest version.


GenericVersionSelector

public GenericVersionSelector(String label)
Creates a GenericVersionSelector that will try to select a version with the given label.

Parameters:
label -

GenericVersionSelector

public GenericVersionSelector(Calendar date)
Creates a GenericVersionSelector that will select the oldest version of all those that are more recent than the given date.

Parameters:
date -
Method Detail

getName

public String getName()
Returns the name hint.

Returns:
the name hint.

setName

public void setName(String name)
Sets the name hint

Parameters:
name -

getLabel

public String getLabel()
Returns the label hint

Returns:
the label hint.

setLabel

public void setLabel(String label)
Sets the label hint

Parameters:
label -

getDate

public Calendar getDate()
Returns the date hint

Returns:
the date hint.

setDate

public void setDate(Calendar date)
Sets the date hint

Parameters:
date -

isReturnLatest

public boolean isReturnLatest()
Returns the flag, if the latest version should be selected, if no version can be found using the given hint.

Returns:
true if it returns latest.

setReturnLatest

public void setReturnLatest(boolean returnLatest)
Sets the flag, if the latest version should be selected, if no version can be found using the given hint.

Parameters:
returnLatest -

select

public Version select(VersionHistory versionHistory)
               throws RepositoryException
Selects a version from the given version history using the previously assigned hint in the following order: name, label, date, latest.

Specified by:
select in interface VersionSelector
Parameters:
versionHistory -
Returns:
Throws:
RepositoryException

selectByName

public static Version selectByName(VersionHistory history,
                                   String name)
                            throws RepositoryException
Selects a version by version name.

Parameters:
history -
name -
Returns:
the version with the given name or null
Throws:
RepositoryException

selectByLabel

public static Version selectByLabel(VersionHistory history,
                                    String label)
                             throws RepositoryException
Selects a version by label

Parameters:
history -
label -
Returns:
the version with the given label or null
Throws:
RepositoryException

selectByDate

public static Version selectByDate(VersionHistory history,
                                   Calendar date)
                            throws RepositoryException
Selects a version by date.

Parameters:
history -
date -
Returns:
the latest version newer than the given date date or null
Throws:
RepositoryException


Copyright © 2004-2006 The Apache Software Foundation. All Rights Reserved.