use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class EntityDefinition method findDefinition.
@Override
public <D extends Definition> D findDefinition(ItemPath path, Class<D> type) {
if (path == null || path.isEmpty()) {
if (type.isAssignableFrom(EntityDefinition.class)) {
return (D) this;
}
}
NameItemPathSegment first = (NameItemPathSegment) path.first();
ItemPath tail = path.tail();
if (ObjectType.F_METADATA.equals(first.getName())) {
//metadata is not an repository entity
first = (NameItemPathSegment) tail.first();
tail = tail.tail();
} else if (QNameUtil.match(AssignmentType.F_CONSTRUCTION, first.getName()) && tail != null && tail.first() instanceof NameItemPathSegment && QNameUtil.match(ConstructionType.F_RESOURCE_REF, ((NameItemPathSegment) (tail.first())).getName())) {
// ugly hack: construction/resourceRef -> resourceRef
first = (NameItemPathSegment) tail.first();
tail = tail.tail();
}
if (tail.isEmpty()) {
return findDefinition(first.getName(), type);
} else {
Definition def = findDefinition(first.getName(), Definition.class);
if (def instanceof CollectionDefinition) {
CollectionDefinition collDef = (CollectionDefinition) def;
def = collDef.getDefinition();
}
if (def instanceof EntityDefinition) {
EntityDefinition nextEntity = (EntityDefinition) def;
return nextEntity.findDefinition(tail, type);
}
}
return null;
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class ObjectWrapperFactory method createPropertyPath.
private ItemPath createPropertyPath(ItemPath path, QName element) {
List<ItemPathSegment> segments = new ArrayList<>();
segments.addAll(path.getSegments());
segments.add(new NameItemPathSegment(element));
return new ItemPath(segments);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class ModificationDto method getItemName.
private static String getItemName(ItemDelta delta) {
if (delta.getDefinition() != null) {
if (delta.getDefinition().getDisplayName() != null) {
return delta.getDefinition().getDisplayName();
}
if (delta.getDefinition().getName() != null) {
return delta.getDefinition().getName().getLocalPart();
}
}
ItemPath path = delta.getPath();
for (int i = path.getSegments().size() - 1; i >= 0; i--) {
if (path.getSegments().get(i) instanceof NameItemPathSegment) {
String retval = ((NameItemPathSegment) path.getSegments().get(i)).getName().getLocalPart();
i++;
while (i < path.getSegments().size()) {
ItemPathSegment itemPathSegment = path.getSegments().get(i);
if (itemPathSegment instanceof IdItemPathSegment) {
// should always be the case
retval += "[" + ((IdItemPathSegment) itemPathSegment).getId() + "]";
}
}
return retval;
}
}
// this means there's some problem there
return delta.toString();
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class ComplexTypeDefinitionImpl method findItemDefinition.
@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
for (; ; ) {
if (path.isEmpty()) {
throw new IllegalArgumentException("Cannot resolve empty path on complex type definition " + this);
}
ItemPathSegment first = path.first();
if (first instanceof NameItemPathSegment) {
QName firstName = ((NameItemPathSegment) first).getName();
return findNamedItemDefinition(firstName, path.rest(), clazz);
} else if (first instanceof IdItemPathSegment) {
path = path.rest();
} else if (first instanceof ParentPathSegment) {
ItemPath rest = path.rest();
ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(this, rest);
if (rest.isEmpty()) {
// requires that the parent is defined as an item (container, object)
return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
} else {
return parent.findItemDefinition(rest, clazz);
}
} else if (first instanceof ObjectReferencePathSegment) {
throw new IllegalStateException("Couldn't use '@' path segment in this context. CTD=" + getTypeName() + ", path=" + path);
} else {
throw new IllegalStateException("Unexpected path segment: " + first + " in " + path);
}
}
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class PrismContainerDefinitionImpl method findItemDefinition.
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
for (; ; ) {
if (path.isEmpty()) {
if (clazz.isAssignableFrom(PrismContainerDefinition.class)) {
return (ID) this;
} else {
return null;
}
}
ItemPathSegment first = path.first();
if (first instanceof NameItemPathSegment) {
QName firstName = ((NameItemPathSegment) first).getName();
return findNamedItemDefinition(firstName, path.rest(), clazz);
} else if (first instanceof IdItemPathSegment) {
path = path.rest();
} else if (first instanceof ParentPathSegment) {
ItemPath rest = path.rest();
ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(getComplexTypeDefinition(), rest);
if (rest.isEmpty()) {
// requires that the parent is defined as an item (container, object)
return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
} else {
return parent.findItemDefinition(rest, clazz);
}
} else if (first instanceof ObjectReferencePathSegment) {
throw new IllegalStateException("Couldn't use '@' path segment in this context. PCD=" + getTypeName() + ", path=" + path);
} else {
throw new IllegalStateException("Unexpected path segment: " + first + " in " + path);
}
}
}
Aggregations