2 * Copyright (c) 2015 Cisco Systems, Inc. and others. 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.controller.cluster.datastore.node.utils.transformer;
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
18 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
20 final class NormalizedNodeBuilderWrapper {
21 @SuppressWarnings("rawtypes")
22 private final NormalizedNodeBuilder builder;
23 private final PathArgument identifier;
24 private final DataSchemaContextNode<?> schemaNode;
26 NormalizedNodeBuilderWrapper(final NormalizedNodeBuilder<?, ?, ?> builder,
27 final PathArgument identifier, final @Nullable DataSchemaContextNode<?> schemaNode) {
28 this.builder = requireNonNull(builder);
29 this.identifier = requireNonNull(identifier);
30 this.schemaNode = schemaNode;
33 PathArgument identifier() {
37 @Nullable DataSchemaContextNode<?> getSchema() {
41 @Nullable DataSchemaContextNode<?> childSchema(final PathArgument child) {
42 if (schemaNode == null) {
46 checkState(builder instanceof NormalizedNodeContainerBuilder,
47 "Attempted to lookup child %s in non-container %s", schemaNode);
48 return schemaNode.getChild(child);
51 NormalizedNode<?, ?> build() {
52 return builder.build();
55 @SuppressWarnings({ "rawtypes", "unchecked" })
56 void addChild(final NormalizedNode<?, ?> child) {
57 checkState(builder instanceof NormalizedNodeContainerBuilder,
58 "Attempted to add child %s to non-container builder %s", child, builder);
59 ((NormalizedNodeContainerBuilder) builder).addChild(child);
62 @SuppressWarnings("unchecked")
63 void setValue(final Object value) {
64 checkState(!(builder instanceof NormalizedNodeContainerBuilder),
65 "Attempted to set value %s on container builder %s", value, builder);
66 builder.withValue(value);