2 * Copyright (c) 2013 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.builder.impl;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Collections;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
22 public class ImmutableOrderedMapNodeSchemaAwareBuilder extends ImmutableOrderedMapNodeBuilder {
23 private final ListSchemaNode schema;
25 protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
26 this.schema = requireNonNull(schema);
27 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
30 protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema,
31 final ImmutableOrderedMapNode node) {
33 this.schema = requireNonNull(schema);
34 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
37 public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema) {
38 return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema);
41 public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema,
43 if (!(node instanceof ImmutableOrderedMapNode)) {
44 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
47 return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema, (ImmutableOrderedMapNode) node);
51 public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withChild(final MapEntryNode child) {
52 DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
53 schema, Collections.singleton(schema.getQName()));
54 return super.withChild(child);
58 public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withNodeIdentifier(
59 final NodeIdentifier withNodeIdentifier) {
60 throw new UnsupportedOperationException("Node identifier created from schema");