NormalizedMetadata is not Identifiable
[yangtools.git] / data / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / MountPointContextFactory.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.yang.data.api.schema;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.Map;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.eclipse.jdt.annotation.Nullable;
16
17 /**
18  * An entity able to resolve the SchemaContext for embedded mount points based on generic data provided by the current
19  * interpretation context.
20  */
21 @Beta
22 @NonNullByDefault
23 public interface MountPointContextFactory {
24     /**
25      * Top-level containers which hold YANG Library information, ordered by descending preference, with more modern
26      * and/or preferred entries first.
27      */
28     enum ContainerName {
29         // Note: order this enum from most-preferred to least-preferred name
30         /**
31          * Container in RFC8525 (NMDA) YANG Library.
32          */
33         RFC8525("yang-library"),
34         /**
35          * Container in RFC7895 (pre-NMDA) YANG Library.
36          */
37         RFC7895("modules-state");
38
39         private final String localName;
40
41         ContainerName(final String localName) {
42             this.localName = requireNonNull(localName);
43         }
44
45         public String getLocalName() {
46             return localName;
47         }
48
49         public static ContainerName ofLocalName(final String localName) {
50             final var ret = forLocalName(localName);
51             if (ret == null) {
52                 throw new IllegalArgumentException("Unrecognized container name '" + localName + "'");
53             }
54             return ret;
55         }
56
57         public static @Nullable ContainerName forLocalName(final String localName) {
58             return switch (localName) {
59                 case "yang-library" -> RFC8525;
60                 case "modules-state" -> RFC7895;
61                 default -> null;
62             };
63         }
64     }
65
66     /**
67      * Create a mount point context based on available information. Implementations are expected to attempt to interpret
68      * provided data to their best of their ability.
69      *
70      * @param libraryContainers available YANG library containers in opaque format
71      * @param schemaMounts the content of 'schema-mounts' container, if available
72      * @return A {@link MountPointContext}
73      * @throws MountPointException if the schema cannot be assembled
74      */
75     MountPointContext createContext(Map<ContainerName, MountPointChild> libraryContainers,
76             @Nullable MountPointChild schemaMounts) throws MountPointException;
77 }