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.UserMapNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 public class ImmutableUserMapNodeSchemaAwareBuilder extends ImmutableUserMapNodeBuilder {
22 private final ListSchemaNode schema;
24 protected ImmutableUserMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
25 this.schema = requireNonNull(schema);
26 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
29 protected ImmutableUserMapNodeSchemaAwareBuilder(final ListSchemaNode schema,
30 final ImmutableUserMapNode node) {
32 this.schema = requireNonNull(schema);
33 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
36 public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final ListSchemaNode schema) {
37 return new ImmutableUserMapNodeSchemaAwareBuilder(schema);
40 public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final ListSchemaNode schema,
41 final UserMapNode node) {
42 if (!(node instanceof ImmutableUserMapNode)) {
43 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
46 return new ImmutableUserMapNodeSchemaAwareBuilder(schema, (ImmutableUserMapNode) node);
50 public CollectionNodeBuilder<MapEntryNode, UserMapNode> withChild(final MapEntryNode child) {
51 DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
52 schema, Collections.singleton(schema.getQName()));
53 return super.withChild(child);
57 public CollectionNodeBuilder<MapEntryNode, UserMapNode> withNodeIdentifier(
58 final NodeIdentifier withNodeIdentifier) {
59 throw new UnsupportedOperationException("Node identifier created from schema");