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.eclipse.jdt.annotation.NonNull;
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.api.schema.builder.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
21 extends AbstractImmutableDataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> {
23 protected ImmutableAugmentationNodeBuilder() {
26 protected ImmutableAugmentationNodeBuilder(final int sizeHint) {
30 public ImmutableAugmentationNodeBuilder(final ImmutableAugmentationNode node) {
34 public static @NonNull DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create() {
35 return new ImmutableAugmentationNodeBuilder();
38 public static @NonNull DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(
40 return new ImmutableAugmentationNodeBuilder(sizeHint);
43 public static @NonNull DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(
44 final AugmentationNode node) {
45 if (!(node instanceof ImmutableAugmentationNode)) {
46 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
49 return new ImmutableAugmentationNodeBuilder((ImmutableAugmentationNode)node);
53 public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
54 final DataContainerChild child) {
55 // Check nested augments
56 if (child instanceof AugmentationNode) {
57 final AugmentationIdentifier myId = getNodeIdentifier();
58 throw new DataValidationException(String.format(
59 "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getIdentifier(),
60 myId == null ? this : myId));
63 return super.withChild(child);
67 public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withoutChild(final PathArgument key) {
68 return super.withoutChild(key);
72 public AugmentationNode build() {
73 return new ImmutableAugmentationNode(getNodeIdentifier(), buildValue());
76 private static final class ImmutableAugmentationNode
77 extends AbstractImmutableDataContainerNode<AugmentationIdentifier, AugmentationNode>
78 implements AugmentationNode {
80 ImmutableAugmentationNode(final AugmentationIdentifier nodeIdentifier,
81 final Map<PathArgument, Object> children) {
82 super(children, nodeIdentifier);
86 protected Class<AugmentationNode> implementedType() {
87 return AugmentationNode.class;