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.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
14 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 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(NodeIdentifier.create(schema.getQName()));
26 private ImmutableContainerNodeSchemaAwareBuilder(final ContainerSchemaNode schema,
27 final ImmutableContainerNode node) {
29 this.validator = new DataNodeContainerValidator(schema);
30 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
33 public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(
34 final ContainerSchemaNode schema) {
35 return new ImmutableContainerNodeSchemaAwareBuilder(schema);
38 public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(
39 final ContainerSchemaNode schema, final ContainerNode node) {
40 if (!(node instanceof ImmutableContainerNode)) {
41 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
43 return new ImmutableContainerNodeSchemaAwareBuilder(schema, (ImmutableContainerNode)node);
47 public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withNodeIdentifier(
48 final NodeIdentifier withNodeIdentifier) {
49 throw new UnsupportedOperationException("Node identifier created from schema");
53 public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withChild(final DataContainerChild<?, ?> child) {
54 validator.validateChild(child.getIdentifier());
55 return super.withChild(child);
59 public ContainerNode build() {
60 // TODO check when statements... somewhere