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
8 package org.opendaylight.controller.md.sal.binding.impl;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.HashSet;
13 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
14 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationRegistration;
15 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
16 import org.opendaylight.yangtools.concepts.ObjectRegistration;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.binding.RpcService;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 public class BindingDOMRpcProviderServiceAdapter {
24 private static final Set<YangInstanceIdentifier> GLOBAL = ImmutableSet.of(YangInstanceIdentifier.builder().build());
25 private final BindingToNormalizedNodeCodec codec;
26 private final DOMRpcProviderService domRpcRegistry;
28 public BindingDOMRpcProviderServiceAdapter(final DOMRpcProviderService domRpcRegistry, final BindingToNormalizedNodeCodec codec) {
30 this.domRpcRegistry = domRpcRegistry;
33 public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(final Class<S> type,
34 final T implementation) {
35 return register(type,implementation,createDomRpcIdentifiers(type,GLOBAL));
38 public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(final Class<S> type,
39 final T implementation, final Set<InstanceIdentifier<?>> paths) {
40 return register(type,implementation,createDomRpcIdentifiers(type,toYangInstanceIdentifiers(paths)));
43 private <S extends RpcService, T extends S> ObjectRegistration<T> register(final Class<S> type, final T implementation, final Set<DOMRpcIdentifier> domRpcs) {
44 final BindingRpcImplementationAdapter adapter = new BindingRpcImplementationAdapter(codec.getCodecFactory(), type, implementation);
47 final DOMRpcImplementationRegistration<?> domReg = domRpcRegistry.registerRpcImplementation(adapter, domRpcs);
48 return new BindingRpcAdapterRegistration<>(implementation, domReg);
51 private Set<DOMRpcIdentifier> createDomRpcIdentifiers(final Class<? extends RpcService> type, final Set<YangInstanceIdentifier> paths) {
52 final Set<SchemaPath> rpcs = getRpcSchemaPaths(type);
54 final Set<DOMRpcIdentifier> ret = new HashSet<>();
55 for(final YangInstanceIdentifier path : paths) {
56 for(final SchemaPath rpc : rpcs) {
57 ret.add(DOMRpcIdentifier.create(rpc, path));
63 private Set<YangInstanceIdentifier> toYangInstanceIdentifiers(final Set<InstanceIdentifier<?>> identifiers) {
64 final Set<YangInstanceIdentifier> ret = new HashSet<>();
65 for(final InstanceIdentifier<?> binding: identifiers) {
66 ret.add(codec.toNormalized(binding));
71 private Set<SchemaPath> getRpcSchemaPaths(final Class<? extends RpcService> type) {
72 return codec.getRpcMethodToSchemaPath(type).values();