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.yangtools.yang.data.impl.schema;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import java.util.Iterator;
13 import org.opendaylight.yangtools.yang.common.Empty;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
21 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
25 * Base strategy for converting an instance identifier into a normalized node structure for leaf and leaf-list types.
27 abstract class InstanceIdToSimpleNodes<T extends PathArgument> extends InstanceIdToNodes<T> {
29 InstanceIdToSimpleNodes(final T identifier) {
34 final NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others) {
35 return getBuilder(first).build();
39 final InstanceIdToNodes<?> getChild(final PathArgument child) {
44 final boolean isMixin() {
48 abstract NormalizedNodeBuilder<? extends PathArgument, Object, ? extends NormalizedNode> getBuilder(
51 static final class LeafNormalization extends InstanceIdToSimpleNodes<NodeIdentifier> {
52 LeafNormalization(final LeafSchemaNode potential) {
53 super(new NodeIdentifier(potential.getQName()));
57 NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> getBuilder(final PathArgument node) {
58 return Builders.leafBuilder().withNodeIdentifier(getIdentifier());
62 static final class LeafListEntryNormalization extends InstanceIdToSimpleNodes<NodeWithValue> {
63 LeafListEntryNormalization(final LeafListSchemaNode potential) {
64 // We are fudging a value here
65 super(new NodeWithValue<>(potential.getQName(), Empty.value()));
69 NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> getBuilder(final PathArgument node) {
70 checkArgument(node instanceof NodeWithValue);
71 return Builders.leafSetEntryBuilder().withNodeIdentifier((NodeWithValue<?>) node)
72 .withValue(((NodeWithValue<?>) node).getValue());