Bump yangtools to 3.0.0
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / transformer / NormalizedNodeBuilderWrapper.java
index 726f69effb2488a74c6c9b1c31eb8ecf38a85251..385376c5277ac7cc3fd29ded6bdaf85293b18fbc 100644 (file)
@@ -7,35 +7,29 @@
  */
 package org.opendaylight.controller.cluster.datastore.node.utils.transformer;
 
+import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
 
 final class NormalizedNodeBuilderWrapper {
-    private final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder;
+    @SuppressWarnings("rawtypes")
+    private final NormalizedNodeBuilder builder;
     private final PathArgument identifier;
     private final DataSchemaContextNode<?> schemaNode;
 
-    NormalizedNodeBuilderWrapper(final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder,
+    NormalizedNodeBuilderWrapper(final NormalizedNodeBuilder<?, ?, ?> builder,
             final PathArgument identifier, final @Nullable DataSchemaContextNode<?> schemaNode) {
         this.builder = requireNonNull(builder);
         this.identifier = requireNonNull(identifier);
         this.schemaNode = schemaNode;
     }
 
-    @SuppressWarnings("rawtypes")
-    NormalizedNodeContainerBuilder builder() {
-        return builder;
-    }
-
-    QName nodeType() {
-        return identifier.getNodeType();
-    }
-
     PathArgument identifier() {
         return identifier;
     }
@@ -43,4 +37,32 @@ final class NormalizedNodeBuilderWrapper {
     @Nullable DataSchemaContextNode<?> getSchema() {
         return schemaNode;
     }
+
+    @Nullable DataSchemaContextNode<?> childSchema(final PathArgument child) {
+        if (schemaNode == null) {
+            return null;
+        }
+
+        checkState(builder instanceof NormalizedNodeContainerBuilder,
+            "Attempted to lookup child %s in non-container %s", schemaNode);
+        return schemaNode.getChild(child);
+    }
+
+    NormalizedNode<?, ?> build() {
+        return builder.build();
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    void addChild(final NormalizedNode<?, ?> child) {
+        checkState(builder instanceof NormalizedNodeContainerBuilder,
+            "Attempted to add child %s to non-container builder %s", child, builder);
+        ((NormalizedNodeContainerBuilder) builder).addChild(child);
+    }
+
+    @SuppressWarnings("unchecked")
+    void setValue(final Object value) {
+        checkState(!(builder instanceof NormalizedNodeContainerBuilder),
+            "Attempted to set value %s on container builder %s", value, builder);
+        builder.withValue(value);
+    }
 }