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 com.google.common.collect.Sets;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
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.api.schema.OrderedMapNode;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
18 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 public class ImmutableOrderedMapNodeSchemaAwareBuilder extends ImmutableOrderedMapNodeBuilder {
22 private final ListSchemaNode schema;
24 protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
25 this.schema = Preconditions.checkNotNull(schema);
26 super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
29 protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema, final ImmutableOrderedMapNode node) {
31 this.schema = Preconditions.checkNotNull(schema);
32 super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
35 public static CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema) {
36 return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema);
39 public static CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema,
41 if (!(node instanceof ImmutableOrderedMapNode)) {
42 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
45 return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema, (ImmutableOrderedMapNode) node);
49 public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withChild(final MapEntryNode child) {
50 DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(), schema, Sets.newHashSet(schema.getQName()));
51 return super.withChild(child);
55 public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withNodeIdentifier(final YangInstanceIdentifier.NodeIdentifier nodeIdentifier) {
56 throw new UnsupportedOperationException("Node identifier created from schema");