2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.test;
10 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
13 * {@link SchemaContext} singleton holder (static).
15 * <p>This is useful in scenarios such as unit tests, but not OSGi environments,
16 * where there is a flat classpath and thus really only one single
19 * @author Michael Vorburger
21 public final class SchemaContextSingleton {
23 private static SchemaContext staticSchemaContext;
25 public static synchronized SchemaContext getSchemaContext(Supplier<SchemaContext> supplier) throws Exception {
26 if (staticSchemaContext == null) {
27 staticSchemaContext = supplier.get();
29 return staticSchemaContext;
32 private SchemaContextSingleton() { }
35 public interface Supplier<T> {
36 T get() throws Exception;