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.binding.spec.naming.BindingMapping;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 final class ActionAdapterFilter implements InvocationHandler {
22 private final Set<DataTreeIdentifier<?>> nodes;
23 private final ActionAdapter delegate;
25 ActionAdapterFilter(final ActionAdapter delegate, final Set<DataTreeIdentifier<?>> nodes) {
26 this.delegate = requireNonNull(delegate);
27 this.nodes = requireNonNull(nodes);
31 public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
32 if (BindingMapping.ACTION_INVOKE_NAME.equals(method.getName()) && args.length == 2) {
33 final InstanceIdentifier<?> path = (InstanceIdentifier<?>) requireNonNull(args[0]);
34 checkState(nodes.contains(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, path)),
35 "Cannot service %s", path);
37 return delegate.invoke(proxy, method, args);