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