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