2 * Copyright (c) 2019 Red Hat, Inc. 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.mdsal.dom.spi;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import java.util.List;
14 import java.util.function.Consumer;
15 import java.util.function.Supplier;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
19 import org.opendaylight.yangtools.concepts.Registration;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 * {@link DOMSchemaService} backed by a {@code Supplier<EffectiveModelContext>}
24 * (and potentially a {@link YangTextSourceExtension}) which are known to be fixed
25 * and never change schemas.
27 * @author Michael Vorburger.ch
31 public record FixedDOMSchemaService(
32 Supplier<EffectiveModelContext> modelContextSupplier,
33 @Nullable YangTextSourceExtension extension) implements DOMSchemaService {
34 public FixedDOMSchemaService {
35 requireNonNull(modelContextSupplier);
38 public FixedDOMSchemaService(final Supplier<EffectiveModelContext> modelContextSupplier) {
39 this(modelContextSupplier, null);
42 public FixedDOMSchemaService(final EffectiveModelContext effectiveModel) {
43 this(() -> effectiveModel, null);
44 requireNonNull(effectiveModel);
48 public List<Extension> supportedExtensions() {
49 final var local = extension;
50 return local == null ? List.of() : List.of(local);
54 public final EffectiveModelContext getGlobalContext() {
55 return modelContextSupplier.get();
59 public final Registration registerSchemaContextListener(final Consumer<EffectiveModelContext> listener) {
60 listener.accept(getGlobalContext());