use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class NodeImpl method createProperty.
/**
* Create a new multi valued property
*
* @param qName
* @param type
* @param values
* @return
* @throws ConstraintViolationException
* @throws RepositoryException
*/
private Property createProperty(Name qName, Value[] values, int type) throws ConstraintViolationException, RepositoryException {
QPropertyDefinition def = getApplicablePropertyDefinition(qName, type, true);
int targetType = def.getRequiredType();
// make sure, the final type is not set to undefined
if (targetType == PropertyType.UNDEFINED) {
if (type == PropertyType.UNDEFINED) {
// try to retrieve type from the values array
if (values.length > 0) {
for (Value value : values) {
if (value != null) {
targetType = value.getType();
break;
}
}
}
if (targetType == PropertyType.UNDEFINED) {
// fallback
targetType = PropertyType.STRING;
}
} else {
targetType = type;
}
}
Value[] targetValues = ValueHelper.convert(values, targetType, session.getValueFactory());
QValue[] qvs = ValueFormat.getQValues(targetValues, session.getNamePathResolver(), session.getQValueFactory());
return createProperty(qName, targetType, def, qvs);
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class AccessControlManagerImpl method addProperty.
private void addProperty(SetTree treeOperation, NodeState parent, Name propName, int propType, QValue[] values) throws RepositoryException {
QPropertyDefinition definition = definitionProvider.getQPropertyDefinition(parent.getAllNodeTypeNames(), propName, propType);
Operation ap = treeOperation.addChildProperty(parent, propName, propType, values, definition);
itemStateMgr.execute(ap);
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class ItemStateValidator method validate.
/**
* Checks whether the given node state satisfies the constraints specified
* by its primary and mixin node types. The following validations/checks are
* performed:
* <ul>
* <li>check if its node type satisfies the 'required node types' constraint
* specified in its definition</li>
* <li>check if all 'mandatory' child items exist</li>
* <li>for every property: check if the property value satisfies the
* value constraints specified in the property's definition</li>
* </ul>
*
* @param nodeState state of node to be validated
* @throws ConstraintViolationException if any of the validations fail
* @throws RepositoryException if another error occurs
*/
public void validate(NodeState nodeState) throws ConstraintViolationException, RepositoryException {
// effective primary node type
EffectiveNodeType entPrimary = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeState.getNodeTypeName());
QNodeDefinition def = nodeState.getDefinition();
// check if primary type satisfies the 'required node types' constraint
Name[] requiredPrimaryTypes = def.getRequiredPrimaryTypes();
for (int i = 0; i < requiredPrimaryTypes.length; i++) {
if (!entPrimary.includesNodeType(requiredPrimaryTypes[i])) {
String msg = safeGetJCRPath(nodeState) + ": missing required primary type " + requiredPrimaryTypes[i];
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
// mandatory properties
// effective node type (primary type incl. mixins)
Name[] ntNames = nodeState.getAllNodeTypeNames();
EffectiveNodeType entPrimaryAndMixins = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
QPropertyDefinition[] pda = entPrimaryAndMixins.getMandatoryQPropertyDefinitions();
for (int i = 0; i < pda.length; i++) {
QPropertyDefinition pd = pda[i];
if (!nodeState.hasPropertyName(pd.getName())) {
String msg = safeGetJCRPath(nodeState) + ": mandatory property " + pd.getName() + " does not exist";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
// mandatory child nodes
QNodeDefinition[] cnda = entPrimaryAndMixins.getMandatoryQNodeDefinitions();
for (int i = 0; i < cnda.length; i++) {
QNodeDefinition cnd = cnda[i];
if (!nodeState.getNodeEntry().hasNodeEntry(cnd.getName())) {
String msg = safeGetJCRPath(nodeState) + ": mandatory child node " + cnd.getName() + " does not exist";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class ItemStateValidator method checkSetProperty.
/**
*
* @param propState
* @param options bit-wise OR'ed flags specifying the checks that should be
* performed; any combination of the following constants:
* <ul>
* <li><code>{@link #CHECK_ACCESS}</code>: make sure current session is
* granted read access on parent node and can add a child node with the
* given name.</li>
* <li><code>{@link #CHECK_LOCK}</code>: make sure there's no foreign lock
* on parent node</li>
* <li><code>{@link #CHECK_VERSIONING}</code>: make sure parent node is
* checked-out</li>
* <li><code>{@link #CHECK_CONSTRAINTS}</code>: make sure no node type
* constraints would be violated</li>
* <li><code>{@link #CHECK_COLLISION}</code>: check for collision with
* existing properties or nodes</li>
* </ul>
*
* @throws ConstraintViolationException
* @throws AccessDeniedException
* @throws VersionException
* @throws LockException
* @throws ItemNotFoundException
* @throws ItemExistsException
* @throws PathNotFoundException
* @throws RepositoryException
*/
public void checkSetProperty(PropertyState propState, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ItemExistsException, PathNotFoundException, RepositoryException {
NodeState parent = propState.getParent();
QPropertyDefinition def = propState.getDefinition();
checkWriteProperty(parent, propState.getName(), def, options);
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class PropertyDefinitionImpl method getDefaultValues.
//-------------------------------------------------< PropertyDefinition >---
/**
* {@inheritDoc}
*/
public Value[] getDefaultValues() {
QPropertyDefinition pDef = ((QPropertyDefinition) itemDef);
QValue[] defVals = pDef.getDefaultValues();
if (defVals == null) {
return null;
}
Value[] values = new Value[defVals.length];
for (int i = 0; i < defVals.length; i++) {
try {
values[i] = ValueFormat.getJCRValue(defVals[i], resolver, valueFactory);
} catch (RepositoryException e) {
// should never get here
String propName = (getName() == null) ? "[null]" : getName();
log.error("illegal default value specified for property " + propName + " in node type " + getDeclaringNodeType(), e);
return null;
}
}
return values;
}
Aggregations