Fix factored out operatations context
[netconf.git] / restconf / restconf-common / src / main / java / org / opendaylight / restconf / common / util / OperationsRestconfModule.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.restconf.common.util;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.net.URI;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.Optional;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19
20 final class OperationsRestconfModule extends AbstractOperationsModule {
21     // There is no need to intern this nor add a revision, as we are providing the corresponding context anyway
22     static final QNameModule NAMESPACE = QNameModule.create(URI.create("urn:ietf:params:xml:ns:yang:ietf-restconf"));
23
24     private final OperationsContainerSchemaNode operations;
25
26     OperationsRestconfModule(final OperationsContainerSchemaNode operations) {
27         this.operations = requireNonNull(operations);
28     }
29
30     @Override
31     public String getName() {
32         return "ietf-restconf";
33     }
34
35     @Override
36     public QNameModule getQNameModule() {
37         return NAMESPACE;
38     }
39
40     @Override
41     public Collection<DataSchemaNode> getChildNodes() {
42         return Collections.singleton(operations);
43     }
44
45     @Override
46     public Optional<DataSchemaNode> findDataChildByName(final QName name) {
47         return operations.getQName().equals(requireNonNull(name)) ? Optional.of(operations) : Optional.empty();
48     }
49
50     @Override
51     public String getPrefix() {
52         return "rc";
53     }
54 }