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.ContainerLike;
18 public final class ImmutableContainerNodeSchemaAwareBuilder extends ImmutableContainerNodeBuilder {
19 private final DataNodeContainerValidator validator;
21 private ImmutableContainerNodeSchemaAwareBuilder(final ContainerLike schema) {
22 this.validator = new DataNodeContainerValidator(schema);
23 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
26 private ImmutableContainerNodeSchemaAwareBuilder(final ContainerLike schema, final ImmutableContainerNode node) {
28 this.validator = new DataNodeContainerValidator(schema);
29 super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
32 public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerLike schema) {
33 return new ImmutableContainerNodeSchemaAwareBuilder(schema);
36 public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerLike schema,
37 final ContainerNode node) {
38 if (!(node instanceof ImmutableContainerNode)) {
39 throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
41 return new ImmutableContainerNodeSchemaAwareBuilder(schema, (ImmutableContainerNode)node);
45 public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withNodeIdentifier(
46 final NodeIdentifier withNodeIdentifier) {
47 throw new UnsupportedOperationException("Node identifier created from schema");
51 public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withChild(final DataContainerChild<?, ?> child) {
52 validator.validateChild(child.getIdentifier());
53 return super.withChild(child);
57 public ContainerNode build() {
58 // TODO check when statements... somewhere