Switch to MD-SAL APIs
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / util / ModificationUtil.java
1 /*
2  * Copyright (c) 2016 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.openflowplugin.applications.frsync.util;
9
10 import org.opendaylight.mdsal.binding.api.DataObjectModification;
11 import org.opendaylight.mdsal.binding.api.DataTreeModification;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
15
16 /**
17  * Basic {@link DataTreeModification} related tools.
18  */
19 public final class ModificationUtil {
20
21     private ModificationUtil() {
22         throw new IllegalStateException("This class should not be instantiated.");
23     }
24
25     public static String nodeIdValue(DataTreeModification<Node> modification) {
26         final NodeId nodeId = nodeId(modification);
27
28         if (nodeId == null) {
29             return null;
30         }
31
32         return nodeId.getValue();
33     }
34
35     public static NodeId nodeId(DataTreeModification<Node> modification) {
36         final DataObjectModification<Node> rootNode = modification.getRootNode();
37         final Node dataAfter = rootNode.getDataAfter();
38
39         if (dataAfter != null) {
40             return dataAfter.getId();
41         }
42
43         final Node dataBefore = rootNode.getDataBefore();
44         if (dataBefore != null) {
45             return dataBefore.getId();
46         }
47
48         return null;
49     }
50
51     public static FlowCapableNode flowCapableNodeAfter(DataTreeModification<Node> modification) {
52         final Node dataAfter = modification.getRootNode().getDataAfter();
53         if (dataAfter == null) {
54             return null;
55         }
56         return dataAfter.augmentation(FlowCapableNode.class);
57     }
58 }