Deprecate schema-aware builders
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableContainerNodeSchemaAwareBuilder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
9
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;
17
18 @Deprecated(since = "6.0.7", forRemoval = true)
19 public final class ImmutableContainerNodeSchemaAwareBuilder extends ImmutableContainerNodeBuilder {
20     private final DataNodeContainerValidator validator;
21
22     private ImmutableContainerNodeSchemaAwareBuilder(final ContainerLike schema) {
23         this.validator = new DataNodeContainerValidator(schema);
24         super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
25     }
26
27     private ImmutableContainerNodeSchemaAwareBuilder(final ContainerLike schema, final ImmutableContainerNode node) {
28         super(node);
29         this.validator = new DataNodeContainerValidator(schema);
30         super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
31     }
32
33     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerLike schema) {
34         return new ImmutableContainerNodeSchemaAwareBuilder(schema);
35     }
36
37     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerLike schema,
38             final ContainerNode node) {
39         if (!(node instanceof ImmutableContainerNode)) {
40             throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
41         }
42         return new ImmutableContainerNodeSchemaAwareBuilder(schema, (ImmutableContainerNode)node);
43     }
44
45     @Override
46     public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withNodeIdentifier(
47             final NodeIdentifier withNodeIdentifier) {
48         throw new UnsupportedOperationException("Node identifier created from schema");
49     }
50
51     @Override
52     public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withChild(final DataContainerChild<?, ?> child) {
53         validator.validateChild(child.getIdentifier());
54         return super.withChild(child);
55     }
56
57     @Override
58     public ContainerNode build() {
59         // TODO check when statements... somewhere
60         return super.build();
61     }
62 }