2 * Copyright (c) 2018 Pantheon Technologies, 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.checkArgument;
12 import com.google.common.collect.ClassToInstanceMap;
13 import com.google.common.collect.ImmutableSet;
14 import java.lang.reflect.Proxy;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.opendaylight.mdsal.binding.api.ActionService;
18 import org.opendaylight.mdsal.binding.api.ActionSpec;
19 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
20 import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory;
21 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
22 import org.opendaylight.mdsal.dom.api.DOMActionService;
23 import org.opendaylight.mdsal.dom.api.DOMService;
24 import org.opendaylight.yangtools.yang.binding.Action;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 final class ActionServiceAdapter
30 extends AbstractBindingLoadingAdapter<DOMActionService, ActionSpec<?, ?>, ActionAdapter>
31 implements ActionService {
32 private static final class Builder extends BindingDOMAdapterBuilder<ActionService> {
33 Builder(final AdapterContext adapterContext) {
34 super(adapterContext);
38 public Set<? extends Class<? extends DOMService<?, ?>>> getRequiredDelegates() {
39 return ImmutableSet.of(DOMActionService.class);
43 protected ActionService createInstance(final ClassToInstanceMap<DOMService<?, ?>> delegates) {
44 return new ActionServiceAdapter(adapterContext(), delegates.getInstance(DOMActionService.class));
48 static final Factory<ActionService> BUILDER_FACTORY = Builder::new;
50 ActionServiceAdapter(final AdapterContext adapterContext, final DOMActionService delegate) {
51 super(adapterContext, delegate);
55 public <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>> A getActionHandle(
56 final ActionSpec<A, P> spec, final Set<DataTreeIdentifier<P>> nodes) {
57 final var type = spec.type();
58 final var adapter = getAdapter(spec);
59 return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type },
60 nodes.isEmpty() ? adapter : new ActionAdapterFilter(adapter, Set.copyOf(nodes))));
64 ActionAdapter loadAdapter(final ActionSpec<?, ?> key) {
65 final var type = key.type();
66 checkArgument(BindingReflections.isBindingClass(type));
67 checkArgument(type.isInterface(), "Supplied Action type must be an interface.");
68 return new ActionAdapter(adapterContext(), getDelegate(), key);