Populate parser/ hierarchy
[yangtools.git] / yang / rfc8528-data-api / src / main / java / org / opendaylight / yangtools / rfc8528 / data / api / MountPointContext.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech s.r.o. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.rfc8528.data.api;
9
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
14
15 /**
16  * A context of either an explicit (RFC8528 Schema Mount instance) or implicit (system root). It encapsulates a data
17  * {@link org.opendaylight.yangtools.yang.model.api.EffectiveModelContext} and information resident in
18  * {@code schema-mounts} within this hierarchy.
19  *
20  * <p>
21  * Note this interface should be part of yang-data-api, as it really defines how a NormalizedNode-containerized data
22  * operates w.r.t. mount points. Further evolution is expected.
23  */
24 /*
25  * FIXME: 7.0.0: consider yang-data-api integration
26  *
27  * The above note does not give the subject enough attention. RFC8528 redefines the YANG data metamodel is significant
28  * ways in that it ties it with RFC8525/RFC7895. The content of 'schema-mounts' is critical to interpreting
29  * inter-mountpoint data, notably in XML/JSON parsers, which need to be able to correctly infer their mode of
30  * encapsulation (nested mount points).
31  *
32  * Integration with DataTree is questionable here, as MountPointNode has enough information for InMemoryDataTree to
33  * operate efficiently -- all it needs to is switch the resolution root.
34  *
35  * On the other hand, requiring that a YANG data world is identified by MountPointIdentifer (which is QName) adds
36  * interpretation flexibility to SchemaContext which is currently hard-coded. For example operations which require
37  * encapsulation of an entire tree have to assume that a SchemaContext has a NodeIdentifier which it uses for the name
38  * of its top-level node. MountPointIdentifier solves this, as it can easily be converted to a unique world identifier.
39  *
40  * That allows, for example NETCONF to specify the root data identifier, properly matching the data it receives from
41  * the device to the native datastore format. Rehosting root identifier means rehosting top-level nodes of
42  * a ContainerNode, which is a simple and relatively-inexpensive operation (i.e. O(N) where N is the number of
43  * top-level nodes).
44  *
45  * To support this case, MountPointContext really wants to be Identifiable<MountPointIdentifier>, where it would also
46  * provide a 'default NodeIdentifier getRootIdentifier()' method. In PathArgument contexts, MountPointIdentifier is
47  * directly usable anyway.
48  *
49  * 6.0.0-timeframe review:
50  *
51  * The idea with Identifiable is not really that grand, as it goes against our desire to peel identifiers from nodes,
52  * as detailed in YANGTOOLS-1074. This will end up meaning that the root of a NormalizedNode tree does not have to have
53  * an identifier and very much can live on its own -- solving both the SchemaContext name problem as well as NETCONF
54  * interoperability.
55  */
56 @Beta
57 public interface MountPointContext extends EffectiveModelContextProvider {
58     /**
59      * Attempt to acquire a {@link MountPointContextFactory} to resolve schemas for the purposes of interpreting
60      * this mount point. An empty result indicates the mount point is not attached.
61      *
62      * @param label Mount point label, as defined via the use of {@code mount-point} statement
63      * @return An optional handler for mount point data
64      * @throws NullPointerException if label is null
65      */
66     Optional<MountPointContextFactory> findMountPoint(@NonNull MountPointIdentifier label);
67 }