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;
17 * Bridge for initializing {@link CodecDataObject} instance constants during class loading time. This class is public
18 * only due to implementation restrictions and can change at any time.
21 public final class CodecDataObjectBridge {
22 private static final ThreadLocal<CodecDataObjectCustomizer> CURRENT_CUSTOMIZER = new ThreadLocal<>();
24 private CodecDataObjectBridge() {
28 public static @NonNull NodeContextSupplier resolve(final @NonNull String methodName) {
29 return current().resolve(methodName);
32 public static @NonNull IdentifiableItemCodec resolveKey(final @NonNull String methodName) {
33 return current().resolveKey(methodName);
36 static @Nullable CodecDataObjectCustomizer setup(final @NonNull CodecDataObjectCustomizer next) {
37 final CodecDataObjectCustomizer prev = CURRENT_CUSTOMIZER.get();
38 CURRENT_CUSTOMIZER.set(verifyNotNull(next));
42 static void tearDown(final @Nullable CodecDataObjectCustomizer prev) {
44 CURRENT_CUSTOMIZER.remove();
46 CURRENT_CUSTOMIZER.set(prev);
50 private static @NonNull CodecDataObjectCustomizer current() {
51 return verifyNotNull(CURRENT_CUSTOMIZER.get(), "No customizer attached");