Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / blueprint / src / main / java / org / opendaylight / controller / blueprint / ext / RpcUtil.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.blueprint.ext;
9
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.function.Predicate;
13 import org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy;
14 import org.opendaylight.yangtools.yang.binding.RpcService;
15 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Utility methods for dealing with various aspects of RPCs and actions.
26  *
27  * @author Robert Varga
28  */
29 final class RpcUtil {
30     private static final Logger LOG = LoggerFactory.getLogger(RpcUtil.class);
31
32     private RpcUtil() {
33         throw new UnsupportedOperationException();
34     }
35
36     static Collection<SchemaPath> decomposeRpcService(final Class<RpcService> service,
37             final SchemaContext schemaContext, final Predicate<RpcRoutingStrategy> filter) {
38         final QNameModule moduleName = BindingReflections.getQNameModule(service);
39         final Module module = schemaContext.findModule(moduleName).get();
40         LOG.debug("Resolved service {} to module {}", service, module);
41
42         final Collection<RpcDefinition> rpcs = module.getRpcs();
43         final Collection<SchemaPath> ret = new ArrayList<>(rpcs.size());
44         for (RpcDefinition rpc : rpcs) {
45             final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(rpc);
46             if (filter.test(strategy)) {
47                 ret.add(rpc.getPath());
48             }
49         }
50
51         return ret;
52     }
53 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.