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 com.google.common.base.Preconditions;
11 import java.util.Collections;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
17 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
19 public class ImmutableMapNodeSchemaAwareBuilder extends ImmutableMapNodeBuilder {
21 private final ListSchemaNode schema;
23 protected ImmutableMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
24 this.schema = Preconditions.checkNotNull(schema);
25 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
28 protected ImmutableMapNodeSchemaAwareBuilder(final ListSchemaNode schema, final ImmutableMapNode node) {
30 this.schema = Preconditions.checkNotNull(schema);
31 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
34 public static CollectionNodeBuilder<MapEntryNode, MapNode> create(final ListSchemaNode schema) {
35 return new ImmutableMapNodeSchemaAwareBuilder(schema);
38 public static CollectionNodeBuilder<MapEntryNode, MapNode> create(final ListSchemaNode schema, final MapNode node) {
39 if (!(node instanceof ImmutableMapNode)) {
40 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
43 return new ImmutableMapNodeSchemaAwareBuilder(schema, (ImmutableMapNode) node);
47 public CollectionNodeBuilder<MapEntryNode, MapNode> withChild(final MapEntryNode child) {
48 DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
49 schema, Collections.singleton(schema.getQName()));
50 return super.withChild(child);
54 public CollectionNodeBuilder<MapEntryNode, MapNode> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
55 throw new UnsupportedOperationException("Node identifier created from schema");