use of javax.jcr.Value in project jackrabbit by apache.
the class NodeLocalNameTest method testReferenceLiteral.
public void testReferenceLiteral() throws RepositoryException, NotExecutableException {
ensureMixinType(node1, mixReferenceable);
superuser.save();
Value literal = superuser.getValueFactory().createValue(node1);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
checkQOM(qom, new Node[] {});
}
use of javax.jcr.Value in project jackrabbit by apache.
the class NodeLocalNameTest method checkOperatorSingleLiteral.
private void checkOperatorSingleLiteral(String literal, String operator, boolean matches) throws RepositoryException {
Value value = superuser.getValueFactory().createValue(literal);
QueryObjectModel qom = createQuery(operator, value);
checkQOM(qom, matches ? new Node[] { node1 } : new Node[0]);
}
use of javax.jcr.Value in project jackrabbit by apache.
the class NodeImpl method createProperty.
/**
* Create a new single valued property
*
* @param qName
* @param type
* @param value
* @return
* @throws ConstraintViolationException if no applicable property definition
* could be found.
* @throws RepositoryException if another error occurs.
*/
private Property createProperty(Name qName, Value value, int type) throws ConstraintViolationException, RepositoryException {
QPropertyDefinition def = getApplicablePropertyDefinition(qName, type, false);
int targetType = def.getRequiredType();
if (targetType == PropertyType.UNDEFINED) {
targetType = type;
}
QValue qvs;
if (targetType == PropertyType.UNDEFINED) {
qvs = ValueFormat.getQValue(value, session.getNamePathResolver(), session.getQValueFactory());
targetType = qvs.getType();
} else {
Value targetValue = ValueHelper.convert(value, targetType, session.getValueFactory());
qvs = ValueFormat.getQValue(targetValue, session.getNamePathResolver(), session.getQValueFactory());
}
return createProperty(qName, targetType, def, new QValue[] { qvs });
}
use of javax.jcr.Value in project jackrabbit by apache.
the class PropertyImpl method setValue.
/**
*
* @param value
* @param requiredType
* @throws RepositoryException
*/
private void setValue(Value value, int requiredType) throws RepositoryException {
if (requiredType == PropertyType.UNDEFINED) {
// should never get here since calling methods assert valid type
throw new IllegalArgumentException("Property type of a value cannot be undefined (" + safeGetJCRPath() + ").");
}
if (value == null) {
setInternalValues(null, requiredType);
return;
}
QValue qValue;
if (requiredType != value.getType()) {
// type conversion required
Value v = ValueHelper.convert(value, requiredType, session.getValueFactory());
qValue = ValueFormat.getQValue(v, session.getNamePathResolver(), session.getQValueFactory());
} else {
// no type conversion required
qValue = ValueFormat.getQValue(value, session.getNamePathResolver(), session.getQValueFactory());
}
setInternalValues(new QValue[] { qValue }, requiredType);
}
use of javax.jcr.Value in project jackrabbit by apache.
the class PropertyImpl method getNode.
/**
* @see Property#getNode()
*/
public Node getNode() throws ValueFormatException, RepositoryException {
Value value = getValue();
switch(value.getType()) {
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
return session.getNodeByIdentifier(value.getString());
case PropertyType.PATH:
case PropertyType.NAME:
String path = value.getString();
Path p = session.getPathResolver().getQPath(path);
try {
return (p.isAbsolute()) ? session.getNode(path) : getParent().getNode(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
case PropertyType.STRING:
try {
Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, session.getValueFactory());
return session.getNodeByIdentifier(refValue.getString());
} catch (ItemNotFoundException e) {
throw e;
} catch (RepositoryException e) {
// try if STRING value can be interpreted as PATH value
Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory());
p = session.getPathResolver().getQPath(pathValue.getString());
try {
return (p.isAbsolute()) ? session.getNode(pathValue.getString()) : getParent().getNode(pathValue.getString());
} catch (PathNotFoundException e1) {
throw new ItemNotFoundException(pathValue.getString());
}
}
default:
throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE");
}
}
Aggregations