use of org.apache.jackrabbit.spi.QValue 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.QValue in project jackrabbit by apache.
the class AccessControlManagerImpl method createAceNode.
private void createAceNode(SetTree operation, NodeState parentState, AccessControlEntry entry) throws RepositoryException {
AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
String uuid = null;
boolean isAllow = ace.isAllow();
Name nodeName = getUniqueNodeName(parentState, (isAllow) ? "allow" : "deny");
Name nodeTypeName = (isAllow) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
NodeState aceNode = addNode(operation, parentState, nodeName, uuid, nodeTypeName);
// add rep:principalName property
String valueStr = ace.getPrincipal().getName();
QValue value = qvf.create(valueStr, PropertyType.STRING);
addProperty(operation, aceNode, N_REP_PRINCIPAL_NAME, PropertyType.STRING, new QValue[] { value });
// add rep:privileges MvProperty
Privilege[] privs = ace.getPrivileges();
QValue[] vls = new QValue[privs.length];
Name privilegeName = null;
try {
for (int i = 0; i < privs.length; i++) {
privilegeName = npResolver.getQName(privs[i].getName());
vls[i] = qvf.create(privilegeName.toString(), PropertyType.NAME);
}
} catch (ValueFormatException e) {
throw new RepositoryException(e.getMessage());
}
addProperty(operation, aceNode, N_REP_PRIVILEGES, PropertyType.NAME, vls);
// TODO: add single and mv restrictions
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class PropertyState method diff.
/**
* Returns true, if type and/or values of the given property states differ.
*
* @param p1
* @param p2
* @return if the 2 <code>PropertyState</code>s are different in terms of
* type and/or values.
*/
private static boolean diff(PropertyData p1, PropertyData p2) {
// compare type
if (p1.type != p2.type) {
return true;
}
QValue[] vs1 = p1.values;
QValue[] vs2 = p2.values;
if (vs1.length != vs2.length) {
return true;
} else {
for (int i = 0; i < vs1.length; i++) {
boolean eq = (vs1[i] == null) ? vs2[i] == null : vs1[i].equals(vs2[i]);
if (!eq) {
return true;
}
}
}
// no difference
return false;
}
use of org.apache.jackrabbit.spi.QValue in project jackrabbit by apache.
the class ValueConstraint method checkValueConstraints.
/**
* Tests if the value constraints defined in the property definition
* <code>pd</code> are satisfied by the the specified <code>values</code>.
* <p>
* Note that the <i>protected</i> 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.
*
* @param pd property definition
* @param values values to check
* @throws ConstraintViolationException if the constraints are violated
*/
public static void checkValueConstraints(QPropertyDefinition pd, QValue[] values) throws ConstraintViolationException, RepositoryException {
// check multi-value flag
if (!pd.isMultiple() && values != null && values.length > 1) {
throw new ConstraintViolationException("the property is not multi-valued");
}
QValueConstraint[] constraints = pd.getValueConstraints();
if (constraints == null || constraints.length == 0) {
// no constraints to check
return;
}
if (values != null && values.length > 0) {
// check value constraints on every value
for (QValue value : values) {
// constraints are OR-ed together
boolean satisfied = false;
ConstraintViolationException cve = null;
for (int j = 0; j < constraints.length && !satisfied; j++) {
try {
constraints[j].check(value);
satisfied = true;
} catch (ConstraintViolationException e) {
cve = e;
} catch (InvalidConstraintException e) {
cve = new ConstraintViolationException(e.getMessage(), e);
}
}
if (!satisfied) {
// re-throw last exception we encountered
throw cve;
}
}
}
}
use of org.apache.jackrabbit.spi.QValue 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