/** * If the provided path is canonical, it is prefixed with the {@code canonicalPrefix} and returned. If the provided * path is relative, it is resolved against the {@code relativeOrigin} and then converted to a canonical path. * <p> * <p>The path can be partially untyped. * * @param path the string representation of a path (either canonical or relative) * @param canonicalPrefix the prefix to apply to a canonical path * @param relativeOrigin origin to resolve a relative path against * @param intendedFinalType the intended type of the final segment of the path * @return the canonical path represented by the provided path string * @see Path#fromPartiallyUntypedString(String, CanonicalPath, CanonicalPath, SegmentType) */ public static CanonicalPath canonicalize(String path, CanonicalPath canonicalPrefix, CanonicalPath relativeOrigin, SegmentType intendedFinalType) { Path p = Path.fromPartiallyUntypedString(path, canonicalPrefix, relativeOrigin, intendedFinalType); if (p instanceof RelativePath) { return ((RelativePath) p).applyTo(relativeOrigin); } else { return p.toCanonicalPath(); } }
/** * Tries to find an element at given path. * * @param tx current transaction in the traversal (if path is canonical, this is not used) * @param path either canonical or relative path of the element to find * @return the element * @throws ElementNotFoundException if the element is not found */ @SuppressWarnings("unchecked") public static <BE> BE find(Transaction<BE> tx, Query sourcePath, Path path) throws EntityNotFoundException { BE element; if (path.isCanonical()) { try { element = tx.find(path.toCanonicalPath()); } catch (ElementNotFoundException e) { throw new EntityNotFoundException("Entity not found on path: " + path); } } else { Query query = queryTo(sourcePath, path); element = getSingle(tx, query, null); } return element; }