Add test for generated code checking list of dependencies.
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / NodeMapping.xtend
1 package org.opendaylight.controller.sal.compatibility
2
3 import org.opendaylight.controller.sal.core.Node
4 import org.opendaylight.controller.sal.core.NodeConnector
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
6 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
7
8 import static com.google.common.base.Preconditions.*;
9 import static extension org.opendaylight.controller.sal.common.util.Arguments.*;
10
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
14 import org.opendaylight.controller.sal.core.ConstructionException
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
17
18 public class NodeMapping {
19
20     public static val MD_SAL_TYPE = "MD_SAL";
21     private static val NODE_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22     private static val NODECONNECTOR_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.
23         NodeConnector;
24
25     private new() {
26         throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
27     }
28
29     public static def toADNode(InstanceIdentifier<?> node) throws ConstructionException {
30         checkNotNull(node);
31         checkNotNull(node.getPath());
32         checkArgument(node.getPath().size() >= 2);
33         val arg = node.getPath().get(1);
34         val item = arg.checkInstanceOf(IdentifiableItem);
35         val nodeKey = item.getKey().checkInstanceOf(NodeKey);
36         return new Node(MD_SAL_TYPE, nodeKey);
37     }
38
39     public static def toADNodeConnector(NodeConnectorRef source) throws ConstructionException {
40         checkNotNull(source);
41         val InstanceIdentifier<?> path = checkNotNull(source.getValue());
42         val node = path.toADNode();
43         checkArgument(path.path.size() >= 3);
44         val arg = path.getPath().get(2);
45         val item = arg.checkInstanceOf(IdentifiableItem);
46         val connectorKey = item.getKey().checkInstanceOf(NodeConnectorKey);
47         return new NodeConnector(MD_SAL_TYPE, connectorKey, node);
48     }
49
50     public static def toNodeRef(Node node) {
51         checkArgument(MD_SAL_TYPE.equals(node.getType()));
52         val nodeKey = node.ID.checkInstanceOf(NodeKey);
53         val nodePath = InstanceIdentifier.builder().node(Nodes).child(NODE_CLASS, nodeKey).toInstance();
54         return new NodeRef(nodePath);
55     }
56
57     public static def toNodeConnectorRef(NodeConnector nodeConnector) {
58         val node = nodeConnector.node.toNodeRef();
59         val nodePath = node.getValue() as InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node>
60         val connectorKey = nodeConnector.ID.checkInstanceOf(NodeConnectorKey);
61         val path = InstanceIdentifier.builder(nodePath).child(NODECONNECTOR_CLASS, connectorKey).toInstance();
62         return new NodeConnectorRef(path);
63     }
64
65     public static def toADNode(NodeRef node) throws ConstructionException {
66         return toADNode(node.getValue());
67     }
68
69 }

©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.