Migrate OSGI compendium reference
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / test / SchemaContextSingleton.java
1 /*
2  * Copyright (c) 2016 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.controller.md.sal.binding.test;
9
10 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
11
12 /**
13  * {@link SchemaContext} singleton holder (static).
14  *
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
17  * SchemaContext.
18  *
19  * @author Michael Vorburger
20  * @deprecated This class should not be used, as it pollutes the classpath.
21  */
22 @Deprecated
23 public final class SchemaContextSingleton {
24
25     private static SchemaContext staticSchemaContext;
26
27     public static synchronized SchemaContext getSchemaContext(final Supplier<SchemaContext> supplier) throws Exception {
28         if (staticSchemaContext == null) {
29             staticSchemaContext = supplier.get();
30         }
31         return staticSchemaContext;
32     }
33
34     private SchemaContextSingleton() {
35
36     }
37
38     @FunctionalInterface
39     public interface Supplier<T> {
40         T get() throws Exception;
41     }
42 }