Remove DOMSchemaService.getSessionContext()
[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 static com.google.common.base.Preconditions.checkState;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ClassToInstanceMap;
14 import com.google.common.collect.ImmutableClassToInstanceMap;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
17 import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
18 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
19 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
21
22 /**
23  * Base class to implement DOMSchemaService more easily while providing a bridge between MD-SAL DOM Schema services
24  * and YANG Tools Schema consumers.
25  *
26  * @author Michael Vorburger.ch
27  */
28 @Beta
29 @NonNullByDefault
30 public abstract class AbstractDOMSchemaService implements DOMSchemaService, EffectiveModelContextProvider {
31     public abstract static class WithYangTextSources extends AbstractDOMSchemaService
32             implements DOMYangTextSourceProvider {
33         @Override
34         public ClassToInstanceMap<DOMSchemaServiceExtension> getExtensions() {
35             return ImmutableClassToInstanceMap.of(DOMYangTextSourceProvider.class, this);
36         }
37     }
38
39     @Override
40     public final EffectiveModelContext getEffectiveModelContext() {
41         final EffectiveModelContext ret = getGlobalContext();
42         checkState(ret != null, "Global context is not available in %s", this);
43         return ret;
44     }
45 }