Import YangInstanceIdentifier inner classes
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableAugmentationNodeBuilder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
9
10 import java.util.Map;
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;
18
19 public class ImmutableAugmentationNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> {
20
21     protected ImmutableAugmentationNodeBuilder() {
22         super();
23     }
24
25     protected ImmutableAugmentationNodeBuilder(final int sizeHint) {
26         super(sizeHint);
27     }
28
29     public ImmutableAugmentationNodeBuilder(final ImmutableAugmentationNode node) {
30         super(node);
31     }
32
33     public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create() {
34         return new ImmutableAugmentationNodeBuilder();
35     }
36
37     public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(final int sizeHint) {
38         return new ImmutableAugmentationNodeBuilder(sizeHint);
39     }
40
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()));
44         }
45
46         return new ImmutableAugmentationNodeBuilder((ImmutableAugmentationNode)node);
47     }
48
49     @Override
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());
56
57         return super.withChild(child);
58     }
59
60     @Override
61     public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withoutChild(final PathArgument key) {
62         return super.withoutChild(key);
63     }
64
65     @Override
66     public AugmentationNode build() {
67         return new ImmutableAugmentationNode(getNodeIdentifier(), buildValue());
68     }
69
70     private static final class ImmutableAugmentationNode extends AbstractImmutableDataContainerNode<AugmentationIdentifier> implements AugmentationNode {
71
72         ImmutableAugmentationNode(final AugmentationIdentifier nodeIdentifier, final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children) {
73             super(children, nodeIdentifier);
74         }
75     }
76
77 }