Merge "Bug 1386: Avoid commit deadlock"
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / AugmentationIdentifierGenerator.java
1 /*
2  *
3  *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  *  This program and the accompanying materials are made available under the
6  *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  */
10
11 package org.opendaylight.controller.cluster.datastore.node.utils;
12
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15
16 import java.util.HashSet;
17 import java.util.Set;
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
20
21 public class AugmentationIdentifierGenerator {
22     private final String id;
23     private static final Pattern pattern = Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
24     private final Matcher matcher;
25     private final boolean doesMatch;
26
27     public AugmentationIdentifierGenerator(String id){
28         this.id = id;
29         matcher = pattern.matcher(this.id);
30         doesMatch = matcher.matches();
31     }
32
33     public boolean matches(){
34         return doesMatch;
35     }
36
37     public YangInstanceIdentifier.AugmentationIdentifier getPathArgument(){
38         Set<QName> childNames = new HashSet<QName>();
39         final String childQNames = matcher.group(1);
40
41         final String[] splitChildQNames = childQNames.split(",");
42
43         for(String name : splitChildQNames){
44             childNames.add(
45                 org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory
46                     .create(name.trim()));
47         }
48
49         return new YangInstanceIdentifier.AugmentationIdentifier(null, childNames);
50     }
51
52 }