2 * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.md.sal.binding.impl;
11 import com.google.common.base.Throwables;
12 import java.lang.invoke.MethodHandle;
13 import java.lang.invoke.MethodHandles;
14 import java.lang.invoke.MethodHandles.Lookup;
15 import java.lang.invoke.MethodType;
16 import java.lang.reflect.Method;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 @Deprecated(forRemoval = true)
21 final class DirectGetterRouteContextExtractor extends ContextReferenceExtractor {
23 private static final Lookup PUBLIC_LOOKUP = MethodHandles.publicLookup();
24 private final MethodHandle handle;
26 private DirectGetterRouteContextExtractor(final MethodHandle rawHandle) {
27 handle = rawHandle.asType(MethodType.methodType(InstanceIdentifier.class, DataObject.class));
30 static ContextReferenceExtractor create(final Method getterMethod) throws IllegalAccessException {
31 final MethodHandle getterHandle = PUBLIC_LOOKUP.unreflect(getterMethod);
32 return new DirectGetterRouteContextExtractor(getterHandle);
36 @SuppressWarnings("checkstyle:IllegalCatch")
37 InstanceIdentifier<?> extract(final DataObject obj) {
39 return (InstanceIdentifier<?>) handle.invokeExact(obj);
40 } catch (Throwable e) {
41 throw Throwables.propagate(e);