Class ValueConstraint
- java.lang.Object
-
- org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint
-
- All Implemented Interfaces:
QValueConstraint
public abstract class ValueConstraint extends Object implements QValueConstraint
ValueConstraint
and its subclasses are used to check the syntax of a value constraint and to test if a specific value satisfies it.
-
-
Field Summary
Fields Modifier and Type Field Description static ValueConstraint[]
EMPTY_ARRAY
protected static org.slf4j.Logger
log
-
Constructor Summary
Constructors Modifier Constructor Description protected
ValueConstraint(String definition)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
checkValueConstraints(QPropertyDefinition pd, QValue[] values)
Tests if the value constraints defined in the property definitionpd
are satisfied by the the specifiedvalues
.static ValueConstraint
create(int type, String definition)
Create a newValueConstraint
from the String representation.static ValueConstraint[]
create(int type, String[] definition)
Create a newValueConstraint
array from the String representation.static ValueConstraint[]
create(int type, String[] jcrDefinition, NamePathResolver resolver)
Create a newValueConstraint
array from the specified JCR representations.static ValueConstraint
create(int type, String jcrDefinition, NamePathResolver resolver)
boolean
equals(Object other)
String
getDefinition(NamePathResolver resolver)
For constraints that are not namespace prefix mapping sensitive this method returns the same result as
.getString()
String
getString()
For constraints that are not namespace prefix mapping sensitive this method returns the same defined in
.PropertyDefinition.getValueConstraints()
int
hashCode()
Returns the hashCode of the definition StringString
toString()
Same asgetString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.jackrabbit.spi.QValueConstraint
check
-
-
-
-
Field Detail
-
log
protected static org.slf4j.Logger log
-
EMPTY_ARRAY
public static final ValueConstraint[] EMPTY_ARRAY
-
-
Constructor Detail
-
ValueConstraint
protected ValueConstraint(String definition)
-
-
Method Detail
-
getDefinition
public String getDefinition(NamePathResolver resolver)
For constraints that are not namespace prefix mapping sensitive this method returns the same result as
.getString()
Those that are namespace prefix mapping sensitive (e.g.
NameConstraint
,PathConstraint
andReferenceConstraint
) use the givennsResolver
to reflect the current mapping in the returned value. In other words: subclasses, that need to make a conversion to JCR value must overwrite this and return a value that has theName
s orPath
properly resolved to their JCR representation.- Parameters:
resolver
- name-path resolver- Returns:
- the definition of this constraint.
- See Also:
()
,NameResolver.getJCRName(org.apache.jackrabbit.spi.Name)
,PathResolver.getJCRPath(org.apache.jackrabbit.spi.Path)
-
getString
public String getString()
Description copied from interface:QValueConstraint
For constraints that are not namespace prefix mapping sensitive this method returns the same defined in
.PropertyDefinition.getValueConstraints()
Those that are namespace prefix mapping sensitive (e.g.
NameConstraint
,PathConstraint
andReferenceConstraint
) return an internal string.- Specified by:
getString
in interfaceQValueConstraint
- Returns:
- the internal definition String
- See Also:
QValueConstraint.getString()
-
toString
public String toString()
Same asgetString()
- Overrides:
toString
in classObject
- Returns:
- the internal definition String
- See Also:
Object.toString()
-
equals
public boolean equals(Object other)
- Overrides:
equals
in classObject
- See Also:
Object.equals(Object)
-
hashCode
public int hashCode()
Returns the hashCode of the definition String- Overrides:
hashCode
in classObject
- Returns:
- the hashCode of the definition String
- See Also:
Object.hashCode()
-
create
public static ValueConstraint create(int type, String definition) throws InvalidConstraintException
Create a newValueConstraint
from the String representation. Note, that the definition must be independent of session specific namespace mappings in case of the following constraint types:- Parameters:
type
- required typedefinition
- The internal definition string.- Returns:
- a new value constraint
- Throws:
InvalidConstraintException
- if the constraint is not valid.- See Also:
for the corresponding method that allows to pass the JCR representation of a constraint definition.
-
create
public static ValueConstraint[] create(int type, String[] definition) throws InvalidConstraintException
Create a newValueConstraint
array from the String representation. Note, that the definition must be in the internal format in case of the following types:- Parameters:
type
- the required typedefinition
- internal definition strings- Returns:
- the array of constraints
- Throws:
InvalidConstraintException
- if one of the constraints is invalid
-
create
public static ValueConstraint[] create(int type, String[] jcrDefinition, NamePathResolver resolver) throws InvalidConstraintException
Create a newValueConstraint
array from the specified JCR representations.- Parameters:
type
- the required typejcrDefinition
- The definition strings as exposed through the JCR API.resolver
- name-path resolver- Returns:
- the array of constraints
- Throws:
InvalidConstraintException
- if one of the constraints is invalid
-
create
public static ValueConstraint create(int type, String jcrDefinition, NamePathResolver resolver) throws InvalidConstraintException
- Parameters:
type
- required typejcrDefinition
- A JCR representation of a value constraint definition.resolver
- name-path resolver- Returns:
- a new value constraint
- Throws:
InvalidConstraintException
- if the constraint is invalid
-
checkValueConstraints
public static void checkValueConstraints(QPropertyDefinition pd, QValue[] values) throws ConstraintViolationException, RepositoryException
Tests if the value constraints defined in the property definitionpd
are satisfied by the the specifiedvalues
.Note that the protected flag is not checked. Also note that no type conversions are attempted if the type of the given values does not match the required type as specified in the given definition.
- Parameters:
pd
- property definitionvalues
- values to check- Throws:
ConstraintViolationException
- if the constraints are violatedRepositoryException
-
-