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;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
16 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
18 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 final class SchemaAwareImmutableMapNodeBuilder extends ImmutableMapNodeBuilder {
21 private final ListSchemaNode schema;
23 SchemaAwareImmutableMapNodeBuilder(final ListSchemaNode schema) {
24 this.schema = requireNonNull(schema);
25 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
28 SchemaAwareImmutableMapNodeBuilder(final ListSchemaNode schema, final ImmutableMapNode node) {
30 this.schema = requireNonNull(schema);
31 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
35 public ImmutableMapNodeBuilder withChild(final MapEntryNode child) {
36 final NodeIdentifierWithPredicates childId = child.getIdentifier();
37 final QName qname = schema.getQName();
39 DataValidationException.checkLegalChild(qname.equals(childId.getNodeType()), childId, schema, Set.of(qname));
40 return super.withChild(child);
44 public ImmutableMapNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
45 throw new UnsupportedOperationException("Node identifier created from schema");