2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.sal.restconf.impl;
10 import com.google.common.collect.Collections2;
11 import com.google.common.collect.ImmutableList;
12 import com.google.common.collect.ImmutableSet;
14 import java.text.ParseException;
15 import java.util.Collection;
16 import java.util.Date;
17 import java.util.List;
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;
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
43 final class FakeRestconfModule implements Module {
45 static final QNameModule QNAME;
50 date = SimpleDateFormatUtil.getRevisionFormat().parse("2016-06-28");
51 } catch (final ParseException e) {
52 throw new ExceptionInInitializerError(e);
54 QNAME = QNameModule.create(URI.create("urn:ietf:params:xml:ns:yang:ietf-restconf"), date).intern();
57 private final Collection<DataSchemaNode> children;
58 private final ImmutableSet<ModuleImport> imports;
61 * Instantiate a new fake module.
63 * @param neededModules needed import statements
64 * @param child fake child container
66 FakeRestconfModule(final Collection<Module> neededModules, final ContainerSchemaNode child) {
67 this.children = ImmutableList.of(child);
68 this.imports = ImmutableSet.copyOf(Collections2.transform(neededModules, FakeModuleImport::new));
72 public Set<TypeDefinition<?>> getTypeDefinitions() {
73 throw new UnsupportedOperationException("Not supported operations.");
77 public Collection<DataSchemaNode> getChildNodes() {
82 public Set<GroupingDefinition> getGroupings() {
83 throw new UnsupportedOperationException("Not supported operations.");
87 public DataSchemaNode getDataChildByName(final QName name) {
88 for (final DataSchemaNode node : this.children) {
89 if (node.getQName().equals(name)) {
93 throw new RestconfDocumentedException(name + " is not in child of " + FakeRestconfModule.QNAME);
97 public Set<UsesNode> getUses() {
98 throw new UnsupportedOperationException("Not supported operations.");
102 public String getModuleSourcePath() {
103 throw new UnsupportedOperationException("Not supported operations.");
107 public QNameModule getQNameModule() {
112 public String getName() {
113 return "ietf-restconf";
117 public URI getNamespace() {
118 return QNAME.getNamespace();
122 public Date getRevision() {
123 return QNAME.getRevision();
127 public String getPrefix() {
132 public String getYangVersion() {
133 throw new UnsupportedOperationException("Not supported operations.");
137 public String getDescription() {
138 throw new UnsupportedOperationException("Not supported operations.");
142 public String getReference() {
143 throw new UnsupportedOperationException("Not supported operations.");
147 public String getOrganization() {
148 throw new UnsupportedOperationException("Not supported operations.");
152 public String getContact() {
153 throw new UnsupportedOperationException("Not supported operations.");
157 public Set<ModuleImport> getImports() {
162 public Set<Module> getSubmodules() {
163 return ImmutableSet.of();
167 public Set<FeatureDefinition> getFeatures() {
168 throw new UnsupportedOperationException("Not supported operations.");
172 public Set<NotificationDefinition> getNotifications() {
173 throw new UnsupportedOperationException("Not supported operations.");
177 public Set<AugmentationSchema> getAugmentations() {
178 throw new UnsupportedOperationException("Not supported operations.");
182 public Set<RpcDefinition> getRpcs() {
183 throw new UnsupportedOperationException("Not supported operations.");
187 public Set<Deviation> getDeviations() {
188 throw new UnsupportedOperationException("Not supported operations.");
192 public Set<IdentitySchemaNode> getIdentities() {
193 throw new UnsupportedOperationException("Not supported operations.");
197 public List<ExtensionDefinition> getExtensionSchemaNodes() {
198 throw new UnsupportedOperationException("Not supported operations.");
202 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
203 throw new UnsupportedOperationException("Not supported operations.");
207 public String getSource() {
208 throw new UnsupportedOperationException("Not supported operations.");