2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.mdsal.binding.dom.codec.impl;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.mdsal.binding.dom.codec.impl.CodecDataObjectGenerator.Fixed;
18 * Bridge for initializing {@link CodecDataObject} instance constants during class loading time. This class is public
19 * only due to implementation restrictions and can change at any time.
22 public final class CodecDataObjectBridge {
23 private static final ThreadLocal<Fixed<?>> CURRENT_CUSTOMIZER = new ThreadLocal<>();
25 private CodecDataObjectBridge() {
29 public static @NonNull NodeContextSupplier resolve(final @NonNull String methodName) {
30 return current().resolve(methodName);
33 static @Nullable Fixed<?> setup(final @NonNull Fixed<?> next) {
34 final Fixed<?> prev = CURRENT_CUSTOMIZER.get();
35 CURRENT_CUSTOMIZER.set(verifyNotNull(next));
39 static void tearDown(final @Nullable Fixed<?> prev) {
41 CURRENT_CUSTOMIZER.remove();
43 CURRENT_CUSTOMIZER.set(prev);
47 private static @NonNull Fixed<?> current() {
48 return verifyNotNull(CURRENT_CUSTOMIZER.get(), "No customizer attached");