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.YangInstanceIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
12 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
13 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
14 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
15 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
17 public final class ImmutableContainerNodeSchemaAwareBuilder extends ImmutableContainerNodeBuilder {
19 private final DataNodeContainerValidator validator;
21 private ImmutableContainerNodeSchemaAwareBuilder(final ContainerSchemaNode schema) {
22 this.validator = new DataNodeContainerValidator(schema);
23 super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
26 private ImmutableContainerNodeSchemaAwareBuilder(final ContainerSchemaNode schema, final ImmutableContainerNode node) {
28 this.validator = new DataNodeContainerValidator(schema);
29 super.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
32 public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> create(final ContainerSchemaNode schema) {
33 return new ImmutableContainerNodeSchemaAwareBuilder(schema);
36 public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> create(final ContainerSchemaNode schema, final ContainerNode node) {
37 if (!(node instanceof ImmutableContainerNode)) {
38 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
40 return new ImmutableContainerNodeSchemaAwareBuilder(schema, (ImmutableContainerNode)node);
44 public DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> withNodeIdentifier(final YangInstanceIdentifier.NodeIdentifier nodeIdentifier) {
45 throw new UnsupportedOperationException("Node identifier created from schema");
49 public DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> withChild(final DataContainerChild<?, ?> child) {
50 validator.validateChild(child.getIdentifier());
51 return super.withChild(child);
55 public ContainerNode build() {
56 // TODO check when statements... somewhere