Bug 5553 - Impl get operations
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / netconf / sal / restconf / impl / ContainerSchemaNodeImpl.java
1 /*
2  * Copyright (c) 2016 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 package org.opendaylight.netconf.sal.restconf.impl;
9
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.HashSet;
13 import java.util.List;
14 import java.util.Set;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
17 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.Status;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.UsesNode;
26
27 /**
28  * Special case only use by GET restconf/operations (since moment of pre-Beryllium Yang
29  * parser and yang model API removal) to build and use fake container for module
30  */
31 class ContainerSchemaNodeImpl implements ContainerSchemaNode {
32
33     List<DataSchemaNode> child = new ArrayList<>();
34     private final QName qname = QName.create(ModuleImpl.moduleQName, "operations");
35     private final SchemaPath path = SchemaPath.create(true, this.qname);
36
37     @Override
38     public Set<TypeDefinition<?>> getTypeDefinitions() {
39         throw new UnsupportedOperationException("Not supported.");
40     }
41
42     @Override
43     public Collection<DataSchemaNode> getChildNodes() {
44         return this.child;
45     }
46
47     @Override
48     public Set<GroupingDefinition> getGroupings() {
49         throw new UnsupportedOperationException("Not supported.");
50     }
51
52     @Override
53     public DataSchemaNode getDataChildByName(final QName name) {
54         for (final DataSchemaNode node : this.child) {
55             if (node.getQName().equals(name)) {
56                 return node;
57             }
58         }
59         throw new RestconfDocumentedException(name + " is not in child of " + this.qname);
60     }
61
62     @Override
63     public DataSchemaNode getDataChildByName(final String name) {
64         for (final DataSchemaNode node : this.child) {
65             if (node.getQName().getLocalName().equals(name)) {
66                 return node;
67             }
68         }
69         throw new RestconfDocumentedException(name + " is not in child of " + this.qname);
70     }
71
72     @Override
73     public Set<UsesNode> getUses() {
74         throw new UnsupportedOperationException("Not supported.");
75     }
76
77     @Override
78     public Set<AugmentationSchema> getAvailableAugmentations() {
79         return new HashSet<>();
80     }
81
82     @Override
83     public boolean isAugmenting() {
84         return false;
85     }
86
87     @Override
88     public boolean isAddedByUses() {
89         return false;
90     }
91
92     @Override
93     public boolean isConfiguration() {
94         return false;
95     }
96
97     @Override
98     public ConstraintDefinition getConstraints() {
99         throw new UnsupportedOperationException("Not supported.");
100     }
101
102     @Override
103     public QName getQName() {
104         return this.qname;
105     }
106
107     @Override
108     public SchemaPath getPath() {
109         return this.path;
110     }
111
112     @Override
113     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
114         throw new UnsupportedOperationException("Not supported.");
115     }
116
117     @Override
118     public String getDescription() {
119         throw new UnsupportedOperationException("Not supported.");
120     }
121
122     @Override
123     public String getReference() {
124         throw new UnsupportedOperationException("Not supported.");
125     }
126
127     @Override
128     public Status getStatus() {
129         throw new UnsupportedOperationException("Not supported.");
130     }
131
132     @Override
133     public boolean isPresenceContainer() {
134         throw new UnsupportedOperationException("Not supported.");
135     }
136
137     /**
138      * Adding new schema node to this container
139      *
140      * @param fakeLeaf
141      *            - fake schema leaf node
142      */
143     public void addNodeChild(final DataSchemaNode fakeLeaf) {
144         this.child.add(fakeLeaf);
145     }
146 }