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;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
18 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
20 public class ImmutableAugmentationNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> {
22 protected ImmutableAugmentationNodeBuilder() {
26 protected ImmutableAugmentationNodeBuilder(final int sizeHint) {
30 public ImmutableAugmentationNodeBuilder(final ImmutableAugmentationNode node) {
34 public static DataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> create() {
35 return new ImmutableAugmentationNodeBuilder();
38 public static DataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> create(final int sizeHint) {
39 return new ImmutableAugmentationNodeBuilder(sizeHint);
42 public static DataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> create(final AugmentationNode node) {
43 if (!(node instanceof ImmutableAugmentationNode)) {
44 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
47 return new ImmutableAugmentationNodeBuilder((ImmutableAugmentationNode)node);
51 public DataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> withChild(
52 final DataContainerChild<?, ?> child) {
53 // Check nested augments
54 DataValidationException.checkLegalData(!(child instanceof AugmentationNode),
55 "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getNodeType(),
56 getNodeIdentifier() == null ? this : getNodeIdentifier());
58 return super.withChild(child);
62 public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withoutChild(final PathArgument key) {
63 return super.withoutChild(key);
67 public AugmentationNode build() {
68 return new ImmutableAugmentationNode(getNodeIdentifier(), buildValue());
71 private static final class ImmutableAugmentationNode extends AbstractImmutableDataContainerNode<YangInstanceIdentifier.AugmentationIdentifier> implements AugmentationNode {
73 ImmutableAugmentationNode(final YangInstanceIdentifier.AugmentationIdentifier nodeIdentifier, final Map<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> children) {
74 super(children, nodeIdentifier);