Rename DOMDataTreeChangeService
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / FixedDOMSchemaService.java
1 /*
2  * Copyright (c) 2019 Red Hat, Inc. 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.mdsal.dom.spi;
9
10 import static java.util.Objects.requireNonNull;
11
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;
21
22 /**
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.
26  *
27  * @author Michael Vorburger.ch
28  */
29 @Beta
30 @NonNullByDefault
31 public record FixedDOMSchemaService(
32         Supplier<EffectiveModelContext> modelContextSupplier,
33         @Nullable YangTextSourceExtension extension) implements DOMSchemaService {
34     public FixedDOMSchemaService {
35         requireNonNull(modelContextSupplier);
36     }
37
38     public FixedDOMSchemaService(final Supplier<EffectiveModelContext> modelContextSupplier) {
39         this(modelContextSupplier, null);
40     }
41
42     public FixedDOMSchemaService(final EffectiveModelContext effectiveModel) {
43         this(() -> effectiveModel, null);
44         requireNonNull(effectiveModel);
45     }
46
47     @Override
48     public List<Extension> supportedExtensions() {
49         final var local = extension;
50         return local == null ? List.of() : List.of(local);
51     }
52
53     @Override
54     public final EffectiveModelContext getGlobalContext() {
55         return modelContextSupplier.get();
56     }
57
58     @Override
59     public final Registration registerSchemaContextListener(final Consumer<EffectiveModelContext> listener) {
60         listener.accept(getGlobalContext());
61         return () -> { };
62     }
63 }