2 * Copyright © 2019 FRINX s.r.o. 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.jersey.providers.errors;
10 import java.io.IOException;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.stream.ForwardingNormalizedNodeStreamWriter;
17 * Created delegating writer to special-case error-info as error-info is defined as an empty container in the restconf
18 * yang schema but we create a leaf node so we can output it. The delegate stream writer validates the node type against
19 * the schema and thus will expect a LeafSchemaNode but the schema has a ContainerSchemaNode so, to avoid an error,
20 * we override the leafNode behavior for error-info.
22 abstract class StreamWriterWithDisabledValidation extends ForwardingNormalizedNodeStreamWriter {
24 private final QName excludedQName;
25 private boolean inOurLeaf;
28 * Creation of the {@link NormalizedNode} stream-writer with {@link QName} that is excluded from type-check.
30 * @param excludedQName QName of the element that is excluded from type-check.
32 StreamWriterWithDisabledValidation(final QName excludedQName) {
33 this.excludedQName = excludedQName;
37 public void startLeafNode(final NodeIdentifier name) throws IOException {
38 if (name.getNodeType().equals(excludedQName)) {
40 startLeafNodeWithDisabledValidation(name);
42 super.startLeafNode(name);
47 * Writing of the excluded leaf to the output stream.
49 * @param nodeIdentifier Node identifier of the leaf to be written to output stream.
50 * @throws IOException Writing of the leaf to output stream failed.
52 abstract void startLeafNodeWithDisabledValidation(NodeIdentifier nodeIdentifier) throws IOException;
55 public void scalarValue(final Object value) throws IOException {
57 scalarValueWithDisabledValidation(value);
59 super.scalarValue(value);
64 * Writing of the value of the excluded leaf to the output stream.
66 * @param value Value of the excluded leaf.
67 * @throws IOException Writing of the leaf value to the output stream failed.
69 abstract void scalarValueWithDisabledValidation(Object value) throws IOException;
72 public void endNode() throws IOException {
75 endNodeWithDisabledValidation();
82 * Writing of the end element with disabled validation.
84 * @throws IOException Writing of the end element to the output stream failed.
86 abstract void endNodeWithDisabledValidation() throws IOException;