Remove DelegatingNormalizedNodeStreamWriter 16/30916/2
authorTomas Cere <tcere@cisco.com>
Mon, 7 Dec 2015 16:09:04 +0000 (17:09 +0100)
committerTomas Cere <tcere@cisco.com>
Tue, 8 Dec 2015 09:20:23 +0000 (10:20 +0100)
We already have ForwardingNormalizedNodeStreamWriter
in yangtools.

Needs to be merged after:
https://git.opendaylight.org/gerrit/#/c/30914/

Change-Id: I4eb17f41dd086976045da2981397008f2cd75f93
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/restconf/sal-rest-connector/pom.xml
opendaylight/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java

index 41d746284b07d603298980dd2df67396c6368341..c6e5cf66973a778dbfcbd74245dfa9b8b3d73476 100644 (file)
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-remote</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-data-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-data-impl</artifactId>
index 22dabf42efbd20ebd8d2fba6ee5cc0d65a12b9ef..6cdb33bf8cfc7a4edfb36c1aef39dabbf08b12dc 100644 (file)
@@ -37,7 +37,6 @@ import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -46,6 +45,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.ForwardingNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory;
@@ -239,7 +239,12 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         // stream writer validates the node type against the schema and thus will expect a LeafSchemaNode but
         // the schema has a ContainerSchemaNode so, to avoid an error, we override the leafNode behavior
         // for error-info.
-        final NormalizedNodeStreamWriter streamWriter = new DelegatingNormalizedNodeStreamWriter(jsonStreamWriter) {
+        final NormalizedNodeStreamWriter streamWriter = new ForwardingNormalizedNodeStreamWriter() {
+            @Override
+            protected NormalizedNodeStreamWriter delegate() {
+                return jsonStreamWriter;
+            }
+
             @Override
             public void leafNode(final NodeIdentifier name, final Object value) throws IOException {
                 if(name.getNodeType().equals(Draft02.RestConfModule.ERROR_INFO_QNAME)) {
@@ -301,7 +306,12 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         // stream writer validates the node type against the schema and thus will expect a LeafSchemaNode but
         // the schema has a ContainerSchemaNode so, to avoid an error, we override the leafNode behavior
         // for error-info.
-        final NormalizedNodeStreamWriter streamWriter = new DelegatingNormalizedNodeStreamWriter(xmlStreamWriter) {
+        final NormalizedNodeStreamWriter streamWriter = new ForwardingNormalizedNodeStreamWriter() {
+            @Override
+            protected NormalizedNodeStreamWriter delegate() {
+                return xmlStreamWriter;
+            }
+
             @Override
             public void leafNode(final NodeIdentifier name, final Object value) throws IOException {
                 if(name.getNodeType().equals(Draft02.RestConfModule.ERROR_INFO_QNAME)) {
@@ -365,99 +375,4 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
             nnWriter.flush();
         }
     }
-
-    private static class DelegatingNormalizedNodeStreamWriter implements NormalizedNodeStreamWriter {
-        private final NormalizedNodeStreamWriter delegate;
-
-        DelegatingNormalizedNodeStreamWriter(NormalizedNodeStreamWriter delegate) {
-            this.delegate = delegate;
-        }
-
-        @Override
-        public void leafNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException {
-            delegate.leafNode(name, value);
-        }
-
-        @Override
-        public void startLeafSet(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
-            delegate.startLeafSet(name, childSizeHint);
-        }
-
-        @Override
-        public void leafSetEntryNode(Object value) throws IOException, IllegalArgumentException {
-            delegate.leafSetEntryNode(value);
-        }
-
-        @Override
-        public void startContainerNode(NodeIdentifier name, int childSizeHint) throws IOException,
-                IllegalArgumentException {
-            delegate.startContainerNode(name, childSizeHint);
-        }
-
-        @Override
-        public void startUnkeyedList(NodeIdentifier name, int childSizeHint) throws IOException,
-                IllegalArgumentException {
-            delegate.startUnkeyedList(name, childSizeHint);
-        }
-
-        @Override
-        public void startUnkeyedListItem(NodeIdentifier name, int childSizeHint) throws IOException,
-                IllegalStateException {
-            delegate.startUnkeyedListItem(name, childSizeHint);
-        }
-
-        @Override
-        public void startMapNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException {
-            delegate.startMapNode(name, childSizeHint);
-        }
-
-        @Override
-        public void startMapEntryNode(NodeIdentifierWithPredicates identifier, int childSizeHint) throws IOException,
-                IllegalArgumentException {
-            delegate.startMapEntryNode(identifier, childSizeHint);
-        }
-
-        @Override
-        public void startOrderedMapNode(NodeIdentifier name, int childSizeHint) throws IOException,
-                IllegalArgumentException {
-            delegate.startOrderedMapNode(name, childSizeHint);
-        }
-
-        @Override
-        public void startChoiceNode(NodeIdentifier name, int childSizeHint) throws IOException,
-                IllegalArgumentException {
-            delegate.startChoiceNode(name, childSizeHint);
-        }
-
-        @Override
-        public void startAugmentationNode(AugmentationIdentifier identifier) throws IOException,
-                IllegalArgumentException {
-            delegate.startAugmentationNode(identifier);
-        }
-
-        @Override
-        public void anyxmlNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException {
-            delegate.anyxmlNode(name, value);
-        }
-
-        @Override
-        public void startYangModeledAnyXmlNode(NodeIdentifier name, int childSizeHint) throws IOException {
-            delegate.startYangModeledAnyXmlNode(name, childSizeHint);
-        }
-
-        @Override
-        public void endNode() throws IOException, IllegalStateException {
-            delegate.endNode();
-        }
-
-        @Override
-        public void close() throws IOException {
-            delegate.close();
-        }
-
-        @Override
-        public void flush() throws IOException {
-            delegate.flush();
-        }
-    }
 }