Bug 5553 - Impl get operations
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / netconf / sal / restconf / impl / ModuleImpl.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.net.URI;
11 import java.net.URISyntaxException;
12 import java.text.ParseException;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.Date;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
22 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
23 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.Deviation;
26 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
27 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
28 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
29 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
30 import org.opendaylight.yangtools.yang.model.api.Module;
31 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
32 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
33 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
34 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
35 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
36 import org.opendaylight.yangtools.yang.model.api.UsesNode;
37
38 /**
39  * Special case only use by GET restconf/operations (since moment of old Yang
40  * parser and old yang model API removal) to build and use fake module to create
41  * new schema context
42  *
43  */
44 class ModuleImpl implements Module {
45
46     private final List<DataSchemaNode> listChild = new ArrayList<>();
47     static QNameModule moduleQName;
48     static {
49         Date date = null;
50         try {
51             date = SimpleDateFormatUtil.getRevisionFormat().parse("2016-06-28");
52         } catch (final ParseException e) {
53             throw new RestconfDocumentedException("Problem while parsing revision.", e);
54         }
55         try {
56             moduleQName = QNameModule.create(new URI("urn:ietf:params:xml:ns:yang:ietf-restconf"), date);
57         } catch (final URISyntaxException e) {
58             throw new RestconfDocumentedException("Problem while creating URI.", e);
59         }
60     }
61
62     /**
63      * Set container for this module
64      *
65      * @param fakeContSchNode
66      *            - fake container schema node
67      *
68      */
69     public ModuleImpl(final ContainerSchemaNode fakeContSchNode) {
70         this.listChild.add(fakeContSchNode);
71     }
72
73     @Override
74     public Set<TypeDefinition<?>> getTypeDefinitions() {
75         throw new UnsupportedOperationException("Not supported operations.");
76     }
77
78     @Override
79     public Collection<DataSchemaNode> getChildNodes() {
80         return this.listChild;
81     }
82
83     @Override
84     public Set<GroupingDefinition> getGroupings() {
85         throw new UnsupportedOperationException("Not supported operations.");
86     }
87
88     @Override
89     public DataSchemaNode getDataChildByName(final QName name) {
90         for (final DataSchemaNode node : this.listChild) {
91             if (node.getQName().equals(name)) {
92                 return node;
93             }
94         }
95         throw new RestconfDocumentedException(name + " is not in child of " + ModuleImpl.moduleQName);
96     }
97
98     @Override
99     public DataSchemaNode getDataChildByName(final String name) {
100         for (final DataSchemaNode node : this.listChild) {
101             if (node.getQName().getLocalName().equals(name)) {
102                 return node;
103             }
104         }
105         throw new RestconfDocumentedException(name + " is not in child of " + ModuleImpl.moduleQName);
106     }
107
108     @Override
109     public Set<UsesNode> getUses() {
110         throw new UnsupportedOperationException("Not supported operations.");
111     }
112
113     @Override
114     public String getModuleSourcePath() {
115         throw new UnsupportedOperationException("Not supported operations.");
116     }
117
118     @Override
119     public QNameModule getQNameModule() {
120         return moduleQName;
121     }
122
123     @Override
124     public String getName() {
125         return "ietf-restconf";
126     }
127
128     @Override
129     public URI getNamespace() {
130         return moduleQName.getNamespace();
131     }
132
133     @Override
134     public Date getRevision() {
135         return moduleQName.getRevision();
136     }
137
138     @Override
139     public String getPrefix() {
140         return "restconf";
141     }
142
143     @Override
144     public String getYangVersion() {
145         throw new UnsupportedOperationException("Not supported operations.");
146     }
147
148     @Override
149     public String getDescription() {
150         throw new UnsupportedOperationException("Not supported operations.");
151     }
152
153     @Override
154     public String getReference() {
155         throw new UnsupportedOperationException("Not supported operations.");
156     }
157
158     @Override
159     public String getOrganization() {
160         throw new UnsupportedOperationException("Not supported operations.");
161     }
162
163     @Override
164     public String getContact() {
165         throw new UnsupportedOperationException("Not supported operations.");
166     }
167
168     @Override
169     public Set<ModuleImport> getImports() {
170         return new HashSet<>();
171     }
172
173     @Override
174     public Set<Module> getSubmodules() {
175         throw new UnsupportedOperationException("Not supported operations.");
176     }
177
178     @Override
179     public Set<FeatureDefinition> getFeatures() {
180         throw new UnsupportedOperationException("Not supported operations.");
181     }
182
183     @Override
184     public Set<NotificationDefinition> getNotifications() {
185         throw new UnsupportedOperationException("Not supported operations.");
186     }
187
188     @Override
189     public Set<AugmentationSchema> getAugmentations() {
190         throw new UnsupportedOperationException("Not supported operations.");
191     }
192
193     @Override
194     public Set<RpcDefinition> getRpcs() {
195         throw new UnsupportedOperationException("Not supported operations.");
196     }
197
198     @Override
199     public Set<Deviation> getDeviations() {
200         throw new UnsupportedOperationException("Not supported operations.");
201     }
202
203     @Override
204     public Set<IdentitySchemaNode> getIdentities() {
205         throw new UnsupportedOperationException("Not supported operations.");
206     }
207
208     @Override
209     public List<ExtensionDefinition> getExtensionSchemaNodes() {
210         throw new UnsupportedOperationException("Not supported operations.");
211     }
212
213     @Override
214     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
215         throw new UnsupportedOperationException("Not supported operations.");
216     }
217
218     @Override
219     public String getSource() {
220         throw new UnsupportedOperationException("Not supported operations.");
221     }
222
223 }