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