public Node getNode() throws RepositoryException {
return perform(new PropertyOperation<Node>(dlg) {
@Override
public Node perform() throws RepositoryException {
// TODO: avoid nested calls
Value value = getValue();
switch (value.getType()) {
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
return getSession().getNodeByIdentifier(value.getString());
case PropertyType.PATH:
case PropertyType.NAME:
String path = value.getString();
if (path.startsWith("[") && path.endsWith("]")) {
// identifier path
String identifier = path.substring(1, path.length() - 1);
return getSession().getNodeByIdentifier(identifier);
}
else {
try {
return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
}
case PropertyType.STRING:
try {
Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, getValueFactory());
return getSession().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, getValueFactory());
path = pathValue.getString();
try {
return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path);
} catch (PathNotFoundException e1) {
throw new ItemNotFoundException(pathValue.getString());
}
}
default:
throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE");