2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore.node.utils;
11 import java.util.regex.Matcher;
12 import java.util.regex.Pattern;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
18 public class NodeIdentifierWithValueGenerator {
19 private static final Pattern PATTERN = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
21 private final String id;
22 private final DataSchemaNode schemaNode;
23 private final Matcher matcher;
24 private final boolean doesMatch;
26 public NodeIdentifierWithValueGenerator(String id, DataSchemaNode schemaNode) {
28 this.schemaNode = schemaNode;
29 matcher = PATTERN.matcher(this.id);
30 doesMatch = matcher.matches();
33 public boolean matches() {
37 public YangInstanceIdentifier.PathArgument getPathArgument() {
38 final String name = matcher.group(1);
39 final String value = matcher.group(2);
41 return new YangInstanceIdentifier.NodeWithValue<>(QNameFactory.create(name), getValue(value));
44 private Object getValue(String value) {
45 if (schemaNode != null) {
46 if (schemaNode instanceof LeafListSchemaNode) {
47 return TypeDefinitionAwareCodec.from(LeafListSchemaNode.class.cast(schemaNode).getType())