Adopt binding/ components
[yangtools.git] / binding / binding-runtime-spi / src / main / java / org / opendaylight / mdsal / binding / runtime / spi / ServiceLoaderState.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.binding.runtime.spi;
9
10 import java.util.ServiceLoader;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeGenerator;
13 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
14
15 /**
16  * State derived from ServiceLoader. We statically bind to this state. If you need more dynamics, you should not be
17  * showing up here at all.
18  */
19 @NonNullByDefault
20 final class ServiceLoaderState {
21     static final class Generator {
22         static final BindingRuntimeGenerator INSTANCE = ServiceLoader.load(BindingRuntimeGenerator.class).findFirst()
23                 .orElseThrow(() -> new ExceptionInInitializerError("No BindingRuntimeGenerator found"));
24
25         private Generator() {
26             // Hidden on purpose
27         }
28     }
29
30     static final class ParserFactory {
31         static final YangParserFactory INSTANCE = ServiceLoader.load(YangParserFactory.class).findFirst()
32                 .orElseThrow(() -> new ExceptionInInitializerError("No YangParserFactory found"));
33
34         private ParserFactory() {
35             // Hodden on purpose
36         }
37     }
38
39     private ServiceLoaderState() {
40         // Hidden on purpose
41     }
42 }