cd3e663d6030d94baf42e95a4dcae543a7e7afd0
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / AbstractDOMSchemaService.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 java.util.List;
11 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
12 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
13 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
14 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
15
16 /**
17  * Base class to implement DOMSchemaService more easily while providing a bridge between MD-SAL DOM Schema services
18  * and YANG Tools Schema consumers.
19  *
20  * @author Michael Vorburger.ch
21  */
22 public abstract class AbstractDOMSchemaService implements DOMSchemaService, EffectiveModelContextProvider {
23     public abstract static class WithYangTextSources extends AbstractDOMSchemaService
24             implements DOMYangTextSourceProvider {
25         @Override
26         public List<Extension> supportedExtensions() {
27             return List.of(this);
28         }
29     }
30
31     @Override
32     public final EffectiveModelContext getEffectiveModelContext() {
33         final var ret = getGlobalContext();
34         if (ret == null) {
35             throw new IllegalStateException("Global context is not available in " + this);
36         }
37         return ret;
38     }
39 }