BUG-1305: improved antlr grammar handling of unknown nodes.
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableChoiceNodeBuilder.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
12 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
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.nodes.AbstractImmutableDataContainerNode;
17
18 public class ImmutableChoiceNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ChoiceNode> {
19
20     protected ImmutableChoiceNodeBuilder() {
21         super();
22     }
23
24     protected ImmutableChoiceNodeBuilder(final ImmutableChoiceNode node) {
25         super(node);
26     }
27
28     public static DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ChoiceNode> create() {
29         return new ImmutableChoiceNodeBuilder();
30     }
31
32     public static DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ChoiceNode> create(final ChoiceNode node) {
33         if (!(node instanceof ImmutableChoiceNode)) {
34             throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
35         }
36
37         return new ImmutableChoiceNodeBuilder((ImmutableChoiceNode)node);
38     }
39
40     @Override
41     public ChoiceNode build() {
42         return new ImmutableChoiceNode(getNodeIdentifier(), buildValue());
43     }
44
45     private static final class ImmutableChoiceNode
46             extends AbstractImmutableDataContainerNode<InstanceIdentifier.NodeIdentifier>
47             implements ChoiceNode {
48
49         ImmutableChoiceNode(final InstanceIdentifier.NodeIdentifier nodeIdentifier,
50                             final Map<InstanceIdentifier.PathArgument, DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> children) {
51             super(children, nodeIdentifier);
52         }
53     }
54 }