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.HashMap;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16 public class NodeIdentifierFactory {
17 private static final Map<String, YangInstanceIdentifier.PathArgument> CACHE = new HashMap<>();
19 public static YangInstanceIdentifier.PathArgument getArgument(String id) {
20 YangInstanceIdentifier.PathArgument value = CACHE.get(id);
22 synchronized (CACHE) {
23 value = CACHE.get(id);
25 value = createPathArgument(id, null);
33 public static YangInstanceIdentifier.PathArgument createPathArgument(String id, DataSchemaNode schemaNode) {
34 final NodeIdentifierWithPredicatesGenerator
35 nodeIdentifierWithPredicatesGenerator = new NodeIdentifierWithPredicatesGenerator(id, schemaNode);
36 if (nodeIdentifierWithPredicatesGenerator.matches()) {
37 return nodeIdentifierWithPredicatesGenerator.getPathArgument();
40 final NodeIdentifierWithValueGenerator
41 nodeWithValueGenerator = new NodeIdentifierWithValueGenerator(id, schemaNode);
42 if (nodeWithValueGenerator.matches()) {
43 return nodeWithValueGenerator.getPathArgument();
46 final AugmentationIdentifierGenerator augmentationIdentifierGenerator = new AugmentationIdentifierGenerator(id);
47 if (augmentationIdentifierGenerator.matches()) {
48 return augmentationIdentifierGenerator.getPathArgument();
51 return new NodeIdentifierGenerator(id).getArgument();