2 * Copyright (c) 2024 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.restconf.server.api;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.opendaylight.restconf.api.ApiPath;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.util.DataSchemaContext;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
17 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
24 * An {@link ApiPath} resolved against a {@link DatabindContext}. This can be either
26 * <li>a {@link Data} pointing to a datastore resource, or</li>
27 * <li>an {@link Rpc} pointing to a YANG {@code rpc} statement, or</li>
28 * <li>an {@link Action} pointing to an instantiation of a YANG {@code action} statement</li>
32 public sealed interface DatabindPath extends DatabindAware {
34 * Returns the {@link EffectiveStatementInference} made by this path.
36 * @return the {@link EffectiveStatementInference} made by this path
38 Inference inference();
41 * A {@link DatabindPath} denoting an invocation of a YANG {@code action}.
43 * @param databind the {@link DatabindContext} to which this path is bound
44 * @param inference the {@link EffectiveStatementInference} made by this path
45 * @param instance the {@link YangInstanceIdentifier} of the instance being referenced, guaranteed to be
47 * @param action the {@code action}
50 DatabindContext databind,
52 YangInstanceIdentifier instance,
53 ActionEffectiveStatement action) implements OperationPath, InstanceReference {
55 requireNonNull(inference);
56 requireNonNull(action);
57 if (instance.isEmpty()) {
58 throw new IllegalArgumentException("action must be instantiated on a data resource");
63 public InputEffectiveStatement inputStatement() {
64 return action.input();
68 public OutputEffectiveStatement outputStatement() {
69 return action.output();
74 * A {@link DatabindPath} denoting a datastore instance.
76 * @param databind the {@link DatabindContext} to which this path is bound
77 * @param inference the {@link EffectiveStatementInference} made by this path
78 * @param instance the {@link YangInstanceIdentifier} of the instance being referenced,
79 * {@link YangInstanceIdentifier#empty()} denotes the datastore
80 * @param schema the {@link DataSchemaContext} of the datastore instance
82 // FIXME: split into 'Datastore' and 'Data' with non-empty instance, so we can bind to correct
83 // instance-identifier semantics, which does not allow YangInstanceIdentifier.empty()
85 DatabindContext databind,
87 YangInstanceIdentifier instance,
88 DataSchemaContext schema) implements InstanceReference {
90 requireNonNull(inference);
91 requireNonNull(instance);
92 requireNonNull(schema);
95 // FIXME: this is the 'Datastore' constructor
96 public Data(final DatabindContext databind) {
97 this(databind, Inference.ofDataTreePath(databind.modelContext()), YangInstanceIdentifier.of(),
98 databind.schemaTree().getRoot());
103 * A {@link DatabindPath} denoting an invocation of a YANG {@code rpc}.
105 * @param databind the {@link DatabindContext} to which this path is bound
106 * @param inference the {@link EffectiveStatementInference} made by this path
107 * @param rpc the {@code rpc}
109 record Rpc(DatabindContext databind, Inference inference, RpcEffectiveStatement rpc) implements OperationPath {
111 requireNonNull(inference);
116 public InputEffectiveStatement inputStatement() {
121 public OutputEffectiveStatement outputStatement() {
127 * An intermediate trait of {@link DatabindPath}s which are referencing a YANG data resource. This can be either
128 * a {@link Data}, or an {@link Action}}.
130 sealed interface InstanceReference extends DatabindPath {
132 * Returns the {@link YangInstanceIdentifier} of the instance being referenced.
134 * @return the {@link YangInstanceIdentifier} of the instance being referenced,
135 * {@link YangInstanceIdentifier#empty()} denotes the data root
137 YangInstanceIdentifier instance();
140 * Returns this reference as a {@link ServerErrorPath}.
142 * @return this reference as a {@link ServerErrorPath}
144 default ServerErrorPath toErrorPath() {
145 return new ServerErrorPath(databind(), instance());
150 * An intermediate trait of {@link DatabindPath}s which are referencing a YANG operation. This can be either
151 * an {@link Action}, as defined in
152 * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.4.2">RFC8040 Invoke Operation Mode</a> or
153 * an {@link Rpc}, as defined in
154 * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.6">RFC8040 Operation Resource</a>.
156 sealed interface OperationPath extends DatabindPath {
158 * Returns the {@code input} statement of this operation.
160 * @return the {@code input} statement of this operation
162 InputEffectiveStatement inputStatement();
165 * Returns the {@code output} statement of this operation.
167 * @return the {@code output} statement of this operation
169 OutputEffectiveStatement outputStatement();