Eliminate NormalizedNodePayload
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / spi / OneOperation.java
1 /*
2  * Copyright (c) 2024 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.server.spi;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import java.io.IOException;
14 import java.io.Writer;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17
18 final class OneOperation extends OperationsBody {
19     private final QName rpc;
20
21     OneOperation(final EffectiveModelContext modelContext, final QName rpc) {
22         super(modelContext);
23         this.rpc = requireNonNull(rpc);
24     }
25
26     @Override
27     void formatToJSON(final Writer out) throws IOException {
28         // https://www.rfc-editor.org/rfc/rfc8040#page-84:
29         //
30         //            In JSON, the YANG module name identifies the module:
31         //
32         //              { 'ietf-system:system-restart' : [null] }
33         out.write("{ ");
34         appendJSON(out, jsonPrefix(rpc.getModule()), rpc);
35         out.write(" }");
36     }
37
38     @Override
39     void formatToXML(final Writer out) throws IOException {
40         // https://www.rfc-editor.org/rfc/rfc8040#page-84:
41         //
42         //            In XML, the YANG module namespace identifies the module:
43         //
44         //              <system-restart
45         //                 xmlns='urn:ietf:params:xml:ns:yang:ietf-system'/>
46         appendXML(out, rpc);
47     }
48
49     @Override
50     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
51         return helper.add("rpc", rpc);
52     }
53 }