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.AugmentationIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
17 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
19 public class ImmutableAugmentationNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> {
21 protected ImmutableAugmentationNodeBuilder() {
25 protected ImmutableAugmentationNodeBuilder(final int sizeHint) {
29 public ImmutableAugmentationNodeBuilder(final ImmutableAugmentationNode node) {
33 public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create() {
34 return new ImmutableAugmentationNodeBuilder();
37 public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(final int sizeHint) {
38 return new ImmutableAugmentationNodeBuilder(sizeHint);
41 public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(final AugmentationNode node) {
42 if (!(node instanceof ImmutableAugmentationNode)) {
43 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
46 return new ImmutableAugmentationNodeBuilder((ImmutableAugmentationNode)node);
50 public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
51 final DataContainerChild<?, ?> child) {
52 // Check nested augments
53 DataValidationException.checkLegalData(!(child instanceof AugmentationNode),
54 "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getNodeType(),
55 getNodeIdentifier() == null ? this : getNodeIdentifier());
57 return super.withChild(child);
61 public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withoutChild(final PathArgument key) {
62 return super.withoutChild(key);
66 public AugmentationNode build() {
67 return new ImmutableAugmentationNode(getNodeIdentifier(), buildValue());
70 private static final class ImmutableAugmentationNode extends AbstractImmutableDataContainerNode<AugmentationIdentifier> implements AugmentationNode {
72 ImmutableAugmentationNode(final AugmentationIdentifier nodeIdentifier, final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children) {
73 super(children, nodeIdentifier);