20268a67449d2ff1bcddeef240b91ef4f287a774
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / InstanceIdentifierUtils.java
1 package org.opendaylight.controller.cluster.datastore.utils;
2
3 import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
4 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
5 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 /**
13  * @author: syedbahm
14  */
15 public class InstanceIdentifierUtils {
16
17     protected static final Logger logger = LoggerFactory
18         .getLogger(InstanceIdentifierUtils.class);
19
20     public static String getParentPath(String currentElementPath) {
21         String parentPath = "";
22
23         if (currentElementPath != null) {
24             String[] parentPaths = currentElementPath.split("/");
25             if (parentPaths.length > 2) {
26                 for (int i = 0; i < parentPaths.length - 1; i++) {
27                     if (parentPaths[i].length() > 0) {
28                         parentPath += "/" + parentPaths[i];
29                     }
30                 }
31             }
32         }
33         return parentPath;
34     }
35
36     @Deprecated
37     public static YangInstanceIdentifier from(String path) {
38         String[] ids = path.split("/");
39
40         List<YangInstanceIdentifier.PathArgument> pathArguments =
41             new ArrayList<>();
42         for (String nodeId : ids) {
43             if (!"".equals(nodeId)) {
44                 pathArguments
45                     .add(NodeIdentifierFactory.getArgument(nodeId));
46             }
47         }
48         final YangInstanceIdentifier instanceIdentifier =
49             YangInstanceIdentifier.create(pathArguments);
50         return instanceIdentifier;
51     }
52
53     /**
54      * @deprecated Use {@link org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils} instead
55      * @param path
56      * @return
57      */
58     @Deprecated
59     public static NormalizedNodeMessages.InstanceIdentifier toSerializable(YangInstanceIdentifier path){
60         return org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils.toSerializable(path);
61     }
62
63     /**
64      * @deprecated Use {@link org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils} instead
65      * @param path
66      * @return
67      */
68     @Deprecated
69     public static YangInstanceIdentifier fromSerializable(NormalizedNodeMessages.InstanceIdentifier path){
70         return org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils.fromSerializable(path);
71     }
72 }