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;
10 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
12 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
13 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
14 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
15 import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.SchemaUtils;
16 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
18 import com.google.common.base.Preconditions;
19 import com.google.common.base.Supplier;
21 public class ImmutableChoiceNodeSchemaAwareBuilder extends ImmutableChoiceNodeBuilder {
23 private final org.opendaylight.yangtools.yang.model.api.ChoiceNode schema;
24 private ChoiceCaseNode detectedCase;
25 private DataNodeContainerValidator validator;
27 protected ImmutableChoiceNodeSchemaAwareBuilder(org.opendaylight.yangtools.yang.model.api.ChoiceNode schema) {
28 this.schema = Preconditions.checkNotNull(schema);
29 super.withNodeIdentifier(new InstanceIdentifier.NodeIdentifier(schema.getQName()));
33 public DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ChoiceNode> withNodeIdentifier(InstanceIdentifier.NodeIdentifier nodeIdentifier) {
34 throw new UnsupportedOperationException("Node identifier created from schema");
38 public DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ChoiceNode> withChild(final DataContainerChild<?, ?> child) {
39 if(detectedCase == null) {
40 detectedCase = SchemaUtils.detectCase(schema, child).or(new Supplier<ChoiceCaseNode>() {
42 public ChoiceCaseNode get() {
43 throw new IllegalArgumentException(String.format("Unknown child node: %s, for choice: %s", child.getNodeType(),
47 validator = new DataNodeContainerValidator(detectedCase);
50 validator.validateChild(child.getIdentifier());
52 return super.withChild(child);
56 public ChoiceNode build() {
57 // TODO validate when statement
61 public static DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ChoiceNode> create(org.opendaylight.yangtools.yang.model.api.ChoiceNode schema) {
62 return new ImmutableChoiceNodeSchemaAwareBuilder(schema);