Remove NormalizedNodeStreamReader
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / NodeIdentifierFactory.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.node.utils;
10
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
13
14 import java.util.HashMap;
15 import java.util.Map;
16
17 public class NodeIdentifierFactory {
18     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);
21         if(value == null){
22             synchronized (cache){
23                 value = cache.get(id);
24                 if(value == null) {
25                     value = createPathArgument(id, null);
26                     cache.put(id, value);
27                 }
28             }
29         }
30         return value;
31     }
32
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();
38         }
39
40         final NodeIdentifierWithValueGenerator
41             nodeWithValueGenerator = new NodeIdentifierWithValueGenerator(id, schemaNode);
42         if(nodeWithValueGenerator.matches()){
43             return nodeWithValueGenerator.getPathArgument();
44         }
45
46         final AugmentationIdentifierGenerator augmentationIdentifierGenerator = new AugmentationIdentifierGenerator(id);
47         if(augmentationIdentifierGenerator.matches()){
48             return augmentationIdentifierGenerator.getPathArgument();
49         }
50
51         return new NodeIdentifierGenerator(id).getArgument();
52     }
53 }