Sonar fix: LeafListHolderNode.java
[ccsdk/sli/plugins.git] / restconf-client / provider / src / main / java / org / onap / ccsdk / sli / plugins / yangserializers / pnserializer / LeafListHolderNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - CCSDK
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright © 2018 IBM
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
24
25 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
26
27 /**
28  * Representation of leaf list holder node which will hold multi instance leaf
29  * node in properties data tree.
30  */
31 public class LeafListHolderNode extends HolderNode<LeafListHolderChild> implements DataNodeChild {
32
33     private static final String node = " holder node";
34
35     /**
36      * Creates an instance of LeafListHolderNode.
37      *
38      * @param name name of the leaf-list node
39      * @param namespace namespace of the leaf-list node
40      * @param uri uri of the leaf-list node
41      * @param parent parent node of the leaf-list
42      * @param appInfo application info
43      * @param nodeType node type
44      */
45     public LeafListHolderNode(String name, Namespace namespace,
46                               String uri, PropertiesNode parent,
47                               Object appInfo, NodeType nodeType) {
48         super(name, namespace, uri, parent, appInfo, nodeType);
49     }
50
51     @Override
52     public PropertiesNode addChild(String name, Namespace namespace,
53                                    NodeType type, String value,
54                                    Namespace valueNs,
55                                    Object appInfo) throws SvcLogicException {
56         throw new SvcLogicException("Leaf cannot be child of leaf-list" +
57                                                    node);
58     }
59
60     @Override
61     public PropertiesNode addChild(String name, Namespace namespace,
62                                    NodeType type,
63                                    Object appInfo) throws SvcLogicException {
64         throw new SvcLogicException("Container cannot be child of leaf-list" +
65                                                    node);
66     }
67
68     @Override
69     public PropertiesNode addChild(String index, String name,
70                                    Namespace namespace,
71                                    NodeType type,
72                                    Object appInfo) throws SvcLogicException {
73         throw new SvcLogicException("List cannot be child of leaf-list" +
74                                                    node);
75     }
76
77     @Override
78     public PropertiesNode addChild(String index, String name,
79                                    Namespace namespace, NodeType type,
80                                    String value, Namespace valueNs,
81                                    Object appInfo) throws SvcLogicException {
82         LeafNode node = ((LeafNode) children().get(index));
83         if (index == null) {
84             index = String.valueOf(children().size());
85         }
86         String uri = this.uri() + "[" + index + "]";
87         node = (node != null) ? node : new LeafNode(name, namespace, uri,
88                                                     this, appInfo, type, value);
89         node.valueNs(valueNs);
90         children().put(index, node);
91         return node;
92     }
93 }