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.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
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.impl.schema.builder.api.DataContainerNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 import com.google.common.collect.Sets;
23 public class ImmutableAugmentationNodeSchemaAwareBuilder extends ImmutableAugmentationNodeBuilder {
25 private final DataNodeContainerValidator validator;
27 protected ImmutableAugmentationNodeSchemaAwareBuilder(AugmentationSchema schema) {
28 this.validator = new DataNodeContainerValidator(schema);
29 // TODO no QName for augmentation
30 super.withNodeIdentifier(new InstanceIdentifier.AugmentationIdentifier(null, getChildQNames(schema)));
33 // TODO move somewhere to UTIL
34 public static Set<QName> getChildQNames(AugmentationSchema schema) {
35 Set<QName> qnames = Sets.newHashSet();
37 for (DataSchemaNode dataSchemaNode : schema.getChildNodes()) {
38 qnames.add(dataSchemaNode.getQName());
45 public DataContainerNodeBuilder<InstanceIdentifier.AugmentationIdentifier, AugmentationNode> withNodeIdentifier(InstanceIdentifier.AugmentationIdentifier nodeIdentifier) {
46 throw new UnsupportedOperationException("Node identifier created from schema");
50 public DataContainerNodeBuilder<InstanceIdentifier.AugmentationIdentifier, AugmentationNode> withChild(DataContainerChild<?, ?> child) {
51 validator.validateChild(child.getIdentifier());
52 return super.withChild(child);
55 public static DataContainerNodeBuilder<InstanceIdentifier.AugmentationIdentifier, AugmentationNode> create(AugmentationSchema schema) {
56 return new ImmutableAugmentationNodeSchemaAwareBuilder(schema);