org.apache.jackrabbit.spi.commons.nodetype.constraint
Class ValueConstraint

java.lang.Object
  extended by 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
static ValueConstraint[] EMPTY_ARRAY
           
protected static org.slf4j.Logger log
           
 
Constructor Summary
protected ValueConstraint(String definition)
           
 
Method Summary
static void checkValueConstraints(QPropertyDefinition pd, QValue[] values)
          Tests if the value constraints defined in the property definition pd are satisfied by the the specified values.
static ValueConstraint create(int type, String definition)
          Create a new ValueConstraint from the String representation.
static ValueConstraint[] create(int type, String[] definition)
          Create a new ValueConstraint array from the String representation.
static ValueConstraint[] create(int type, String[] jcrDefinition, NamePathResolver resolver)
          Create a new ValueConstraint 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 String
 String toString()
          Same as getString()
 
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 and ReferenceConstraint) use the given nsResolver 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 the Names or Path 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 and ReferenceConstraint) return an internal string.

Specified by:
getString in interface QValueConstraint
Returns:
the internal definition String
See Also:
QValueConstraint.getString()

toString

public String toString()
Same as getString()

Overrides:
toString in class Object
Returns:
the internal definition String
See Also:
Object.toString()

equals

public boolean equals(Object other)
Overrides:
equals in class Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Returns the hashCode of the definition String

Overrides:
hashCode in class Object
Returns:
the hashCode of the definition String
See Also:
Object.hashCode()

create

public static ValueConstraint create(int type,
                                     String definition)
                              throws InvalidConstraintException
Create a new ValueConstraint from the String representation. Note, that the definition must be independant of session specific namespace mappings in case of the following constraint types:

Parameters:
type - required type
definition - 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 new ValueConstraint 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 type
definition - 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 new ValueConstraint array from the specified JCR representations.

Parameters:
type - the required type
jcrDefinition - 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 type
jcrDefinition - 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 definition pd are satisfied by the the specified values.

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 - propert definition
values - values to check
Throws:
ConstraintViolationException - if the constraints are violated
RepositoryException


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