Bug 5679 - renamed package rest.services to base.services
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / base / services / impl / FakeRestconfModule.java
similarity index 80%
rename from restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ModuleImpl.java
rename to restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/impl/FakeRestconfModule.java
index 4f7fa52f29c38d1d95af22b6bf2ff67b229199b7..4551acc2ee6691264c799dcba116a12e66b11ca2 100644 (file)
@@ -5,17 +5,18 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.netconf.sal.restconf.impl;
+package org.opendaylight.restconf.base.services.impl;
 
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.text.ParseException;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
@@ -39,35 +40,32 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode;
  * Special case only use by GET restconf/operations (since moment of old Yang
  * parser and old yang model API removal) to build and use fake module to create
  * new schema context
- *
  */
-class ModuleImpl implements Module {
+final class FakeRestconfModule implements Module {
 
-    private final List<DataSchemaNode> listChild = new ArrayList<>();
-    static QNameModule moduleQName;
+    static final QNameModule QNAME;
     static {
-        Date date = null;
+        Date date;
         try {
             date = SimpleDateFormatUtil.getRevisionFormat().parse("2016-06-28");
         } catch (final ParseException e) {
-            throw new RestconfDocumentedException("Problem while parsing revision.", e);
-        }
-        try {
-            moduleQName = QNameModule.create(new URI("urn:ietf:params:xml:ns:yang:ietf-restconf"), date);
-        } catch (final URISyntaxException e) {
-            throw new RestconfDocumentedException("Problem while creating URI.", e);
+            throw new ExceptionInInitializerError(e);
         }
+        QNAME = QNameModule.create(URI.create("urn:ietf:params:xml:ns:yang:ietf-restconf"), date).intern();
     }
 
+    private final Collection<DataSchemaNode> children;
+    private final ImmutableSet<ModuleImport> imports;
+
     /**
-     * Set container for this module
-     *
-     * @param fakeContSchNode
-     *            - fake container schema node
+     * Instantiate a new fake module
      *
+     * @param neededModules needed import statements
+     * @param child fake child container
      */
-    public ModuleImpl(final ContainerSchemaNode fakeContSchNode) {
-        this.listChild.add(fakeContSchNode);
+    public FakeRestconfModule(final Collection<Module> neededModules, final ContainerSchemaNode child) {
+        this.children = ImmutableList.of(child);
+        this.imports = ImmutableSet.copyOf(Collections2.transform(neededModules, FakeModuleImport::new));
     }
 
     @Override
@@ -77,7 +75,7 @@ class ModuleImpl implements Module {
 
     @Override
     public Collection<DataSchemaNode> getChildNodes() {
-        return this.listChild;
+        return this.children;
     }
 
     @Override
@@ -87,12 +85,12 @@ class ModuleImpl implements Module {
 
     @Override
     public DataSchemaNode getDataChildByName(final QName name) {
-        for (final DataSchemaNode node : this.listChild) {
+        for (final DataSchemaNode node : this.children) {
             if (node.getQName().equals(name)) {
                 return node;
             }
         }
-        throw new RestconfDocumentedException(name + " is not in child of " + ModuleImpl.moduleQName);
+        throw new RestconfDocumentedException(name + " is not in child of " + FakeRestconfModule.QNAME);
     }
 
     @Override
@@ -107,7 +105,7 @@ class ModuleImpl implements Module {
 
     @Override
     public QNameModule getQNameModule() {
-        return moduleQName;
+        return QNAME;
     }
 
     @Override
@@ -117,12 +115,12 @@ class ModuleImpl implements Module {
 
     @Override
     public URI getNamespace() {
-        return moduleQName.getNamespace();
+        return QNAME.getNamespace();
     }
 
     @Override
     public Date getRevision() {
-        return moduleQName.getRevision();
+        return QNAME.getRevision();
     }
 
     @Override
@@ -157,12 +155,12 @@ class ModuleImpl implements Module {
 
     @Override
     public Set<ModuleImport> getImports() {
-        return new HashSet<>();
+        return imports;
     }
 
     @Override
     public Set<Module> getSubmodules() {
-        throw new UnsupportedOperationException("Not supported operations.");
+        return ImmutableSet.of();
     }
 
     @Override