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.base.services.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.restconf.common.errors.RestconfDocumentedException;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.common.QNameModule;
22 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
23 import org.opendaylight.yangtools.yang.common.YangVersion;
24 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
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;
52 date = SimpleDateFormatUtil.getRevisionFormat().parse("2016-06-28");
53 } catch (final ParseException e) {
54 throw new ExceptionInInitializerError(e);
56 QNAME = QNameModule.create(URI.create("urn:ietf:params:xml:ns:yang:ietf-restconf"), date).intern();
59 private final Collection<DataSchemaNode> children;
60 private final ImmutableSet<ModuleImport> imports;
63 * Instantiate a new fake module.
65 * @param neededModules needed import statements
66 * @param child fake child container
68 FakeRestconfModule(final Collection<Module> neededModules, final ContainerSchemaNode child) {
69 this.children = ImmutableList.of(child);
70 this.imports = ImmutableSet.copyOf(Collections2.transform(neededModules, FakeModuleImport::new));
74 public Set<TypeDefinition<?>> getTypeDefinitions() {
75 throw new UnsupportedOperationException("Not supported operations.");
79 public Collection<DataSchemaNode> getChildNodes() {
84 public Set<GroupingDefinition> getGroupings() {
85 throw new UnsupportedOperationException("Not supported operations.");
89 public DataSchemaNode getDataChildByName(final QName name) {
90 for (final DataSchemaNode node : this.children) {
91 if (node.getQName().equals(name)) {
95 throw new RestconfDocumentedException(name + " is not in child of " + FakeRestconfModule.QNAME);
99 public Set<UsesNode> getUses() {
100 throw new UnsupportedOperationException("Not supported operations.");
104 public String getModuleSourcePath() {
105 throw new UnsupportedOperationException("Not supported operations.");
109 public QNameModule getQNameModule() {
114 public String getName() {
115 return "ietf-restconf";
119 public URI getNamespace() {
120 return QNAME.getNamespace();
124 public Date getRevision() {
125 return QNAME.getRevision();
129 public String getPrefix() {
134 public String getYangVersion() {
135 return YangVersion.VERSION_1.toString();
139 public String getDescription() {
140 throw new UnsupportedOperationException("Operation not implemented.");
144 public String getReference() {
145 throw new UnsupportedOperationException("Operation not implemented.");
149 public String getOrganization() {
150 throw new UnsupportedOperationException("Operation not implemented.");
154 public String getContact() {
155 throw new UnsupportedOperationException("Operation not implemented.");
159 public Set<ModuleImport> getImports() {
164 public Set<Module> getSubmodules() {
165 return ImmutableSet.of();
169 public Set<FeatureDefinition> getFeatures() {
170 throw new UnsupportedOperationException("Operation not implemented.");
174 public Set<NotificationDefinition> getNotifications() {
175 throw new UnsupportedOperationException("Operation not implemented.");
179 public Set<AugmentationSchema> getAugmentations() {
180 throw new UnsupportedOperationException("Operation not implemented.");
184 public Set<RpcDefinition> getRpcs() {
185 throw new UnsupportedOperationException("Operation not implemented.");
189 public Set<Deviation> getDeviations() {
190 throw new UnsupportedOperationException("Operation not implemented.");
194 public Set<IdentitySchemaNode> getIdentities() {
195 throw new UnsupportedOperationException("Operation not implemented.");
199 public List<ExtensionDefinition> getExtensionSchemaNodes() {
200 throw new UnsupportedOperationException("Operation not implemented.");
204 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
205 throw new UnsupportedOperationException("Operation not implemented.");
209 public String getSource() {
210 throw new UnsupportedOperationException("Operation not implemented.");