3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
11 package org.opendaylight.controller.cluster.datastore.node.utils;
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 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
21 public class NodeIdentifierWithValueGenerator{
22 private final String id;
23 private final DataSchemaNode schemaNode;
24 private static final Pattern pattern = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
25 private final Matcher matcher;
26 private final boolean doesMatch;
28 public NodeIdentifierWithValueGenerator(String id, DataSchemaNode schemaNode){
30 this.schemaNode = schemaNode;
31 matcher = pattern.matcher(this.id);
32 doesMatch = matcher.matches();
35 public boolean matches(){
39 public YangInstanceIdentifier.PathArgument getPathArgument(){
40 final String name = matcher.group(1);
41 final String value = matcher.group(2);
43 return new YangInstanceIdentifier.NodeWithValue(
44 QNameFactory.create(name), getValue(value));
47 private Object getValue(String value){
48 if(schemaNode != null){
49 if(schemaNode instanceof LeafListSchemaNode){
50 return TypeDefinitionAwareCodec
51 .from(LeafListSchemaNode.class.cast(schemaNode).getType()).deserialize(value);