2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.api;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.common.QName;
20 public final class SchemaNodeDefaults {
21 private SchemaNodeDefaults() {
26 * Report unsupported {@link SchemaNode#getPath()} implementation. This method is guaranteed to throw an
27 * {@link UnsupportedOperationException}.
29 * @param impl {@code this} object of invoking implementation
31 * @throws NullPointerException if {@code impl} is null
32 * @throws UnsupportedOperationException always
33 * @see SchemaNode#getPath()
35 // FIXME: 8.0.0: consider deprecating this method
36 public static SchemaPath throwUnsupported(final Object impl) {
37 throw new UnsupportedOperationException(impl.getClass() + " does not support SchemaNode.getPath()");
41 * Report unsupported {@link SchemaNode#getPath()} implementation if provided path is null.
43 * @param impl {@code this} object of invoking implementation
44 * @param path A schema path
45 * @return {@code path} if non-null
46 * @throws NullPointerException if {@code impl} is null
47 * @throws UnsupportedOperationException if @{code path} is null
48 * @see SchemaNode#getPath()
50 // FIXME: 8.0.0: consider deprecating this method
51 public static SchemaPath throwUnsupportedIfNull(final Object impl, final @Nullable SchemaPath path) {
52 return path != null ? path : throwUnsupported(impl);
56 * Extract {@link QName} from a path object.
58 * @param path Path handle
59 * @return Extracted QName
60 * @throws NullPointerException if {@code path} is null
61 * @throws IllegalArgumentException if {@code path} is not supported
63 // FIXME: 8.0.0: consider deprecating this method
64 public static QName extractQName(final Immutable path) {
65 if (path instanceof QName) {
67 } else if (path instanceof SchemaPath) {
68 return verifyNotNull(((SchemaPath) path).getLastComponent());
70 throw new IllegalArgumentException("Unhandled object " + path);
75 * Extract {@link SchemaPath} from a path object.
77 * @param impl Implementation object
78 * @param path Path handle
79 * @return Extracted SchemaPath
80 * @throws UnsupportedOperationException if {@code path} does not hold a SchemaPath
82 // FIXME: 8.0.0: consider deprecating this method
83 public static SchemaPath extractPath(final Object impl, final Immutable path) {
84 return path instanceof SchemaPath ? (SchemaPath) path : SchemaNodeDefaults.throwUnsupported(impl);