- public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final Optional<NormalizedNode<?, ?>> deepestElement, final Optional<Map.Entry<QName, ModifyAction>> operation) {
- Preconditions.checkNotNull(ctx);
- Preconditions.checkNotNull(id);
- final YangInstanceIdentifier.PathArgument topLevelElement = id.getPathArguments().get(0);
- final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType());
- Preconditions.checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement);
- final InstanceIdToNodes<?> instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType());
- return instanceIdToNodes.create(id, deepestElement, operation);
+ public static @NonNull NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
+ final Optional<NormalizedNode<?, ?>> deepestElement) {
+ final PathArgument topLevelElement;
+ final InstanceIdToNodes<?> instanceIdToNodes;
+ final Iterator<PathArgument> it = id.getPathArguments().iterator();
+ if (it.hasNext()) {
+ topLevelElement = it.next();
+ final DataSchemaNode dataChildByName = ctx.dataChildByName(topLevelElement.getNodeType());
+ checkNotNull(dataChildByName,
+ "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement);
+ instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType());
+ } else {
+ topLevelElement = SCHEMACONTEXT_NAME;
+ instanceIdToNodes = InstanceIdToNodes.fromDataSchemaNode(ctx);
+ }
+
+ return instanceIdToNodes.create(topLevelElement, it, deepestElement);