2 * Copyright © 2018 Red Hat, Inc. and others.
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.mdsal.binding.util;
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 * Strongly-typed representation of a datastore (configuration or operational).
17 // FIXME Base this on ietf-datastores.yang (RFC 8342)
18 public abstract sealed class Datastore {
20 /** Class representing the configuration datastore. */
21 public static final Class<Configuration> CONFIGURATION = Configuration.class;
23 /** Class representing the operational datastore. */
24 public static final Class<Operational> OPERATIONAL = Operational.class;
26 public static final class Configuration extends Datastore {
30 public static final class Operational extends Datastore {
39 * Returns the logical datastore type corresponding to the given datastore class.
41 * @param datastoreClass The datastore class to convert.
42 * @return The corresponding logical datastore type.
43 * @throws IllegalArgumentException if the provided datastore class isn’t handled.
45 public static LogicalDatastoreType toType(final Class<? extends Datastore> datastoreClass) {
46 if (datastoreClass.equals(Configuration.class)) {
47 return LogicalDatastoreType.CONFIGURATION;
48 } else if (Operational.class.equals(datastoreClass)) {
49 return LogicalDatastoreType.OPERATIONAL;
51 throw new IllegalArgumentException("Unknown datastore class " + datastoreClass);
56 * Returns the datastore class corresponding to the given logical datastore type.
57 * @param datastoreType The logical datastore type to convert.
58 * @return The corresponding datastore class.
59 * @throws IllegalArgumentException if the provided logical datastore type isn’t handled.
61 public static Class<? extends Datastore> toClass(final LogicalDatastoreType datastoreType) {
62 return switch (datastoreType) {
63 case CONFIGURATION -> CONFIGURATION;
64 case OPERATIONAL -> OPERATIONAL;