2 * Copyright (c) 2021 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.adapter;
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
13 import java.lang.reflect.InvocationHandler;
14 import java.lang.reflect.Method;
16 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 final class ActionAdapterFilter implements InvocationHandler {
21 private final Set<DataTreeIdentifier<?>> nodes;
22 private final ActionAdapter delegate;
24 ActionAdapterFilter(final ActionAdapter delegate, final Set<DataTreeIdentifier<?>> nodes) {
25 this.delegate = requireNonNull(delegate);
26 this.nodes = requireNonNull(nodes);
30 public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
31 if (method.getName().equals("invoke") && args.length == 2) {
32 final InstanceIdentifier<?> path = (InstanceIdentifier<?>) requireNonNull(args[0]);
33 checkState(nodes.contains(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, path)),
34 "Cannot service %s", path);
36 return delegate.invoke(proxy, method, args);