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 DataObjectStreamer} instance constants during class loading time. This class is public
18 * only due to implementation restrictions and can change at any time.
20 // FIXME: this bridge is only necessary to work around Javassist compiler resolution of dependencies. If we switch to
21 // a more bytecode-oriented framework, this bridge becomes superfluous.
24 public final class DataObjectStreamerBridge {
25 private static final ThreadLocal<DataObjectStreamerCustomizer> CURRENT_CUSTOMIZER = new ThreadLocal<>();
27 private DataObjectStreamerBridge() {
31 public static @NonNull DataObjectStreamer<?> resolve(final @NonNull String methodName) {
32 return verifyNotNull(CURRENT_CUSTOMIZER.get(), "No customizer attached").resolve(methodName);
35 static @Nullable DataObjectStreamerCustomizer setup(final @NonNull DataObjectStreamerCustomizer next) {
36 final DataObjectStreamerCustomizer prev = CURRENT_CUSTOMIZER.get();
37 CURRENT_CUSTOMIZER.set(verifyNotNull(next));
41 static void tearDown(final @Nullable DataObjectStreamerCustomizer prev) {
43 CURRENT_CUSTOMIZER.remove();
45 CURRENT_CUSTOMIZER.set(prev);