Object getItemPathSegment() { if (itemPath.size() != 1) { throw new IllegalStateException("Expected single-item path, found '" + itemPath + "' instead."); } return itemPath.first(); }
/** * Returns the value of the first segment if it is a name segment; otherwise null. */ @Nullable default ItemName firstToNameOrNull() { return ItemPath.toNameOrNull(first()); }
/** * Returns the value of the first segment if it is a name segment; otherwise null. */ @NotNull default ItemName firstToName() { return ItemPath.toName(first()); }
/** * Returns the value of the first segment if it is a Id segment; otherwise throws an exception. */ default Long firstToId() { return ItemPath.toId(first()); }
/** * Returns the value of the first segment if it is a Id segment; otherwise null. */ default Long firstToIdOrNull() { return ItemPath.toIdOrNull(first()); }
/** * If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value. * Otherwise throws an exception. */ @NotNull default ItemName asSingleNameOrFail() { if (isSingleName()) { return ItemPath.toName(first()); } else { throw new IllegalArgumentException("Expected a single-name path, bug got "+this); } }
ItemName getItemName() { if (itemPath.size() != 1) { throw new IllegalStateException("Expected single-item path, found '" + itemPath + "' instead."); } return ItemPath.toName(itemPath.first()); }
/** * Returns true if the path starts with with value Id. */ default boolean startsWithId() { return !isEmpty() && ItemPath.isId(first()); }
/** * Returns true if the path starts with an identifier (#). */ default boolean startsWithIdentifier() { return !isEmpty() && ItemPath.isIdentifier(first()); }
/** * Returns true if the path starts with the standard segment name (i.e. NOT variable nor special symbol). */ default boolean startsWithName() { return !isEmpty() && ItemPath.isName(first()); }
/** * Returns true if the path starts with variable name ($...). */ default boolean startsWithVariable() { return !isEmpty() && ItemPath.isVariable(first()); }
/** * Returns true if the path starts with an object reference (@). */ default boolean startsWithObjectReference() { return !isEmpty() && ItemPath.isObjectReference(first()); }
/** * Returns true if the path consists of a single name segment. (Not variable nor special symbol.) */ default boolean isSingleName() { return size() == 1 && ItemPath.isName(first()); }
/** * Returns true if the path starts with the value Id of null. */ default boolean startsWithNullId() { return !isEmpty() && ItemPath.isNullId(first()); }
/** * Returns true if the path starts with a parent segment (..). */ default boolean startsWithParent() { return !isEmpty() && ItemPath.isParent(first()); }
/** * If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value. * Otherwise returns null. */ default QName asSingleName() { return isSingleName() ? ItemPath.toName(first()) : null; }
@Override public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) { if (path.size() == 1 && path.startsWithName()) { return findLocalItemDefinition(ItemPath.toName(path.first()), clazz, false); } throw new UnsupportedOperationException("TODO implement if needed"); }
/** * Returns the value of the first segment if it is a variable name segment; otherwise null. */ default QName firstToVariableNameOrNull() { if (isEmpty()) { return null; } else { Object first = first(); return isVariable(first) ? toVariableName(first) : null; } }
@Override public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) { if (ItemPath.isObjectReference(path.first())) { // returning artificially created transition definition, used to allow dereferencing target object in a generic way return new DataSearchResult<>( new JpaLinkDefinition<>(SchemaConstants.PATH_OBJECT_REFERENCE, "target", null, false, referencedEntityDefinition.getResolvedEntityDefinition()), path.rest()); } else { return null; } }
private boolean containsItem(PrismContainerValue prismContainerValue, ItemPath itemPath) { ItemName first = ItemPath.toName(itemPath.first()); Item item = prismContainerValue.findItem(first); if (item == null) { return false; } ItemPath pathTail = stripFirstIds(itemPath); if (item instanceof PrismContainer) { return containsItem((PrismContainer) item, pathTail); } else if (item instanceof PrismReference) { return pathTail.isEmpty(); // we do not want to look inside references } else if (item instanceof PrismProperty) { return pathTail.isEmpty(); // ...neither inside atomic values } else { return false; // should not occur anyway } }