Package org.apache.jackrabbit.core
Class ItemValidator
- java.lang.Object
-
- org.apache.jackrabbit.core.ItemValidator
-
- Direct Known Subclasses:
BatchedItemOperations
public class ItemValidator extends Object
Utility class for validating an item against constraints specified by its definition.
-
-
Field Summary
Fields Modifier and Type Field Description static int
CHECK_ACCESS
check access permissionsstatic int
CHECK_CHECKED_OUT
option to check checked-out statusstatic int
CHECK_CONSTRAINTS
option to check if the item is protected by it's nt definitionstatic int
CHECK_HOLD
option to check for effective holdsstatic int
CHECK_LOCK
option to check lock statusstatic int
CHECK_PENDING_CHANGES
option to check for pending changes on the sessionstatic int
CHECK_PENDING_CHANGES_ON_NODE
option to check for pending changes on the specified nodestatic int
CHECK_REFERENCES
check for referential integrity upon removalstatic int
CHECK_RETENTION
option to check for effective retention policiesprotected SessionContext
context
Component context of the associated session.
-
Constructor Summary
Constructors Constructor Description ItemValidator(SessionContext context)
Creates a newItemValidator
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canModify(ItemImpl item, int options, int permissions)
void
checkModify(ItemImpl item, int options, int permissions)
void
checkRemove(ItemImpl item, int options, int permissions)
QNodeDefinition
findApplicableNodeDefinition(Name name, Name nodeTypeName, NodeState parentState)
Helper method that finds the applicable definition for a child node with the given name and node type in the parent node's node type and mixin types.QPropertyDefinition
findApplicablePropertyDefinition(Name name, int type, boolean multiValued, NodeState parentState)
Helper method that finds the applicable definition for a property with the given name, type and multiValued characteristic in the parent node's node type and mixin types.QPropertyDefinition
findApplicablePropertyDefinition(Name name, int type, NodeState parentState)
Helper method that finds the applicable definition for a property with the given name, type in the parent node's node type and mixin types.EffectiveNodeType
getEffectiveNodeType(NodeState state)
Helper method that builds the effective (i.e.<T> T
performRelaxed(SessionOperation<T> operation, int checksToDisable)
Performs the given session operation with the specified checks disabled.String
safeGetJCRPath(ItemId id)
Failsafe translation of internalItemId
to JCR path for use in error messages etc.String
safeGetJCRPath(Path path)
Failsafe conversion of internalPath
to JCR path for use in error messages etc.void
validate(NodeState nodeState)
Checks whether the given node state satisfies the constraints specified by its primary and mixin node types.void
validate(PropertyState propState)
Checks whether the given property state satisfies the constraints specified by its definition.
-
-
-
Field Detail
-
CHECK_ACCESS
public static final int CHECK_ACCESS
check access permissions- See Also:
- Constant Field Values
-
CHECK_LOCK
public static final int CHECK_LOCK
option to check lock status- See Also:
- Constant Field Values
-
CHECK_CHECKED_OUT
public static final int CHECK_CHECKED_OUT
option to check checked-out status- See Also:
- Constant Field Values
-
CHECK_REFERENCES
public static final int CHECK_REFERENCES
check for referential integrity upon removal- See Also:
- Constant Field Values
-
CHECK_CONSTRAINTS
public static final int CHECK_CONSTRAINTS
option to check if the item is protected by it's nt definition- See Also:
- Constant Field Values
-
CHECK_PENDING_CHANGES
public static final int CHECK_PENDING_CHANGES
option to check for pending changes on the session- See Also:
- Constant Field Values
-
CHECK_PENDING_CHANGES_ON_NODE
public static final int CHECK_PENDING_CHANGES_ON_NODE
option to check for pending changes on the specified node- See Also:
- Constant Field Values
-
CHECK_HOLD
public static final int CHECK_HOLD
option to check for effective holds- See Also:
- Constant Field Values
-
CHECK_RETENTION
public static final int CHECK_RETENTION
option to check for effective retention policies- See Also:
- Constant Field Values
-
context
protected final SessionContext context
Component context of the associated session.
-
-
Constructor Detail
-
ItemValidator
public ItemValidator(SessionContext context)
Creates a newItemValidator
instance.- Parameters:
context
- component context of this session
-
-
Method Detail
-
performRelaxed
public <T> T performRelaxed(SessionOperation<T> operation, int checksToDisable) throws RepositoryException
Performs the given session operation with the specified checks disabled.- Parameters:
operation
- the session operation to be performedchecksToDisable
- bit mask of checks to be disabled- Returns:
- return value of the session operation
- Throws:
RepositoryException
- if the operation could not be performed
-
validate
public void validate(NodeState nodeState) throws ConstraintViolationException, RepositoryException
Checks whether the given node state satisfies the constraints specified by its primary and mixin node types. The following validations/checks are performed:- check if its node type satisfies the 'required node types' constraint specified in its definition
- check if all 'mandatory' child items exist
- for every property: check if the property value satisfies the value constraints specified in the property's definition
- Parameters:
nodeState
- state of node to be validated- Throws:
ConstraintViolationException
- if any of the validations failRepositoryException
- if another error occurs
-
validate
public void validate(PropertyState propState) throws ConstraintViolationException, RepositoryException
Checks whether the given property state satisfies the constraints specified by its definition. The following validations/checks are performed:- check if the type of the property values does comply with the requiredType specified in the property's definition
- check if the property values satisfy the value constraints specified in the property's definition
- Parameters:
propState
- state of property to be validated- Throws:
ConstraintViolationException
- if any of the validations failRepositoryException
- if another error occurs
-
checkModify
public void checkModify(ItemImpl item, int options, int permissions) throws RepositoryException
- Throws:
RepositoryException
-
checkRemove
public void checkRemove(ItemImpl item, int options, int permissions) throws RepositoryException
- Throws:
RepositoryException
-
canModify
public boolean canModify(ItemImpl item, int options, int permissions) throws RepositoryException
- Throws:
RepositoryException
-
getEffectiveNodeType
public EffectiveNodeType getEffectiveNodeType(NodeState state) throws RepositoryException
Helper method that builds the effective (i.e. merged and resolved) node type representation of the specified node's primary and mixin node types.- Parameters:
state
-- Returns:
- the effective node type
- Throws:
RepositoryException
-
findApplicableNodeDefinition
public QNodeDefinition findApplicableNodeDefinition(Name name, Name nodeTypeName, NodeState parentState) throws RepositoryException, ConstraintViolationException
Helper method that finds the applicable definition for a child node with the given name and node type in the parent node's node type and mixin types.- Parameters:
name
-nodeTypeName
-parentState
-- Returns:
- a
QNodeDefinition
- Throws:
ConstraintViolationException
- if no applicable child node definition could be foundRepositoryException
- if another error occurs
-
findApplicablePropertyDefinition
public QPropertyDefinition findApplicablePropertyDefinition(Name name, int type, boolean multiValued, NodeState parentState) throws RepositoryException, ConstraintViolationException
Helper method that finds the applicable definition for a property with the given name, type and multiValued characteristic in the parent node's node type and mixin types. If there more than one applicable definitions then the following rules are applied:- named definitions are preferred to residual definitions
- definitions with specific required type are preferred to definitions with required type UNDEFINED
- Parameters:
name
-type
-multiValued
-parentState
-- Returns:
- a
QPropertyDefinition
- Throws:
ConstraintViolationException
- if no applicable property definition could be foundRepositoryException
- if another error occurs
-
findApplicablePropertyDefinition
public QPropertyDefinition findApplicablePropertyDefinition(Name name, int type, NodeState parentState) throws RepositoryException, ConstraintViolationException
Helper method that finds the applicable definition for a property with the given name, type in the parent node's node type and mixin types. Other than
this method does not take the multiValued flag into account in the selection algorithm. If there more than one applicable definitions then the following rules are applied:findApplicablePropertyDefinition(Name, int, boolean, NodeState)
- named definitions are preferred to residual definitions
- definitions with specific required type are preferred to definitions with required type UNDEFINED
- single-value definitions are preferred to multiple-value definitions
- Parameters:
name
-type
-parentState
-- Returns:
- a
QPropertyDefinition
- Throws:
ConstraintViolationException
- if no applicable property definition could be foundRepositoryException
- if another error occurs
-
safeGetJCRPath
public String safeGetJCRPath(Path path)
Failsafe conversion of internalPath
to JCR path for use in error messages etc.- Parameters:
path
- path to convert- Returns:
- JCR path
-
-