Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / mapping / BindingContextProvider.java
1 /*
2  * Copyright (c) 2013, 2017 Cisco Systems, 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.controller.config.manager.impl.osgi.mapping;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
12 import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
13 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
14
15 /**
16  * Creates and initializes {@link BindingRuntimeContext}, which is used to
17  * resolve Identity classes from QName. An instance of
18  * {@link BindingRuntimeContext} is available only after first schema context
19  * was successfully built.
20  */
21 // TODO move to yang runtime
22 public class BindingContextProvider implements AutoCloseable {
23
24     private BindingRuntimeContext current;
25
26     public synchronized void update(final ClassLoadingStrategy classLoadingStrategy,
27             final SchemaContextProvider ctxProvider) {
28         this.current = BindingRuntimeContext.create(classLoadingStrategy, ctxProvider.getSchemaContext());
29     }
30
31     public synchronized BindingRuntimeContext getBindingContext() {
32         Preconditions.checkState(this.current != null, "Binding context not yet initialized");
33         return this.current;
34     }
35
36     @Override
37     public synchronized void close() throws Exception {
38         this.current = null;
39     }
40 }