Use NormalizedNode streaming serialization in sal-remoterpc-connector
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / AugmentationIdentifierGenerator.java
1 /*
2  * Copyright (c) 2014, 2015 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.controller.cluster.datastore.node.utils;
10
11 import com.google.common.base.Splitter;
12 import java.util.HashSet;
13 import java.util.Set;
14 import java.util.regex.Matcher;
15 import java.util.regex.Pattern;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18
19 public class AugmentationIdentifierGenerator {
20     private static final Pattern PATTERN =
21             Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
22     private static final Splitter COMMA_SPLITTER = Splitter.on(',').trimResults();
23
24     private final String id;
25     private final Matcher matcher;
26     private final boolean doesMatch;
27
28     public AugmentationIdentifierGenerator(String id) {
29         this.id = id;
30         matcher = PATTERN.matcher(this.id);
31         doesMatch = matcher.matches();
32     }
33
34     public boolean matches() {
35         return doesMatch;
36     }
37
38     public YangInstanceIdentifier.AugmentationIdentifier getPathArgument() {
39         final String childQNames = matcher.group(1);
40
41         final Set<QName> childNames = new HashSet<>();
42         for (String name : COMMA_SPLITTER.split(childQNames)) {
43             childNames.add(QNameFactory.create(name));
44         }
45
46         return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
47     }
48 }