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.restconf.nb.rfc8040.services.simple.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.util.Collection;
15 import java.util.List;
16 import java.util.Optional;
18 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
19 import org.opendaylight.yangtools.concepts.SemVer;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.common.QNameModule;
22 import org.opendaylight.yangtools.yang.common.Revision;
23 import org.opendaylight.yangtools.yang.common.YangVersion;
24 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.Deviation;
28 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
29 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
30 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
31 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
32 import org.opendaylight.yangtools.yang.model.api.Module;
33 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
34 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
35 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
36 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
37 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
38 import org.opendaylight.yangtools.yang.model.api.UsesNode;
41 * Special case only use by GET restconf/operations (since moment of old Yang
42 * parser and old yang model API removal) to build and use fake module to create
45 final class FakeRestconfModule implements Module {
47 static final QNameModule QNAME = QNameModule.create(URI.create("urn:ietf:params:xml:ns:yang:ietf-restconf"),
48 Revision.of("2016-06-28")).intern();
50 private final Collection<DataSchemaNode> children;
51 private final ImmutableSet<ModuleImport> imports;
54 * Instantiate a new fake module.
56 * @param neededModules needed import statements
57 * @param child fake child container
59 FakeRestconfModule(final Collection<Module> neededModules, final ContainerSchemaNode child) {
60 this.children = ImmutableList.of(child);
61 this.imports = ImmutableSet.copyOf(Collections2.transform(neededModules, FakeModuleImport::new));
65 public Set<TypeDefinition<?>> getTypeDefinitions() {
66 throw new UnsupportedOperationException("Not supported operations.");
70 public Collection<DataSchemaNode> getChildNodes() {
75 public Set<GroupingDefinition> getGroupings() {
76 throw new UnsupportedOperationException("Not supported operations.");
80 public Optional<DataSchemaNode> findDataChildByName(final QName name) {
81 for (final DataSchemaNode node : this.children) {
82 if (node.getQName().equals(name)) {
83 return Optional.of(node);
86 throw new RestconfDocumentedException(name + " is not in child of " + FakeRestconfModule.QNAME);
90 public Set<UsesNode> getUses() {
91 throw new UnsupportedOperationException("Not supported operations.");
95 public QNameModule getQNameModule() {
100 public String getName() {
101 return "ietf-restconf";
105 public URI getNamespace() {
106 return QNAME.getNamespace();
110 public Optional<Revision> getRevision() {
111 return QNAME.getRevision();
115 public String getPrefix() {
120 public YangVersion getYangVersion() {
121 return YangVersion.VERSION_1;
125 public Optional<String> getDescription() {
126 throw new UnsupportedOperationException("Operation not implemented.");
130 public Optional<String> getReference() {
131 throw new UnsupportedOperationException("Operation not implemented.");
135 public Optional<String> getOrganization() {
136 throw new UnsupportedOperationException("Operation not implemented.");
140 public Optional<String> getContact() {
141 throw new UnsupportedOperationException("Operation not implemented.");
145 public Set<ModuleImport> getImports() {
150 public Set<Module> getSubmodules() {
151 return ImmutableSet.of();
155 public Set<FeatureDefinition> getFeatures() {
156 throw new UnsupportedOperationException("Operation not implemented.");
160 public Set<NotificationDefinition> getNotifications() {
161 throw new UnsupportedOperationException("Operation not implemented.");
165 public Set<AugmentationSchemaNode> getAugmentations() {
166 throw new UnsupportedOperationException("Operation not implemented.");
170 public Set<RpcDefinition> getRpcs() {
171 throw new UnsupportedOperationException("Operation not implemented.");
175 public Set<Deviation> getDeviations() {
176 throw new UnsupportedOperationException("Operation not implemented.");
180 public Set<IdentitySchemaNode> getIdentities() {
181 throw new UnsupportedOperationException("Operation not implemented.");
185 public List<ExtensionDefinition> getExtensionSchemaNodes() {
186 throw new UnsupportedOperationException("Operation not implemented.");
190 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
191 throw new UnsupportedOperationException("Operation not implemented.");
195 public Optional<SemVer> getSemanticVersion() {
196 throw new UnsupportedOperationException("Operation not implemented.");