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 org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
13 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
16 import java.util.regex.Matcher;
17 import java.util.regex.Pattern;
19 public class NodeIdentifierWithValueGenerator{
20 private final String id;
21 private final DataSchemaNode schemaNode;
22 private static final Pattern pattern = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
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(
42 QNameFactory.create(name), getValue(value));
45 private Object getValue(String value){
46 if(schemaNode != null){
47 if(schemaNode instanceof LeafListSchemaNode){
48 return TypeDefinitionAwareCodec
49 .from(LeafListSchemaNode.class.cast(schemaNode).getType()).deserialize(value);