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