- final var type = getRuntimeContext().getTypes().findSchema(JavaTypeName.create(spec.type()))
- .orElseThrow(() -> new IllegalArgumentException("Notification " + spec + " is not known"));
- if (!(type instanceof NotificationRuntimeType notifType)) {
- throw new IllegalArgumentException("Notification " + spec + " resolved to unexpected " + type);
+ return getSchemaNodeIdentifier(spec.path(), spec.type(), NotificationRuntimeType.class,
+ NotificationEffectiveStatement.class);
+ }
+
+ private <T extends RuntimeType> @NonNull Absolute getSchemaNodeIdentifier(final @NonNull InstanceIdentifier<?> path,
+ final @NonNull Class<? extends BindingContract<?>> type, final @NonNull Class<T> expectedRuntime,
+ final @NonNull Class<? extends SchemaTreeEffectiveStatement<?>> expectedStatement) {
+ final var typeName = JavaTypeName.create(type);
+ final var runtimeType = getRuntimeContext().getTypes().findSchema(typeName)
+ .orElseThrow(() -> new IllegalArgumentException(typeName + " is not known"));
+ final T casted;
+ try {
+ casted = expectedRuntime.cast(runtimeType);
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException(typeName + " resolved to unexpected " + runtimeType, e);