Deprecate schema-aware builders
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableOrderedMapNodeSchemaAwareBuilder.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 static java.util.Objects.requireNonNull;
11
12 import java.util.Collections;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21
22 @Deprecated(since = "6.0.7", forRemoval = true)
23 public class ImmutableOrderedMapNodeSchemaAwareBuilder extends ImmutableOrderedMapNodeBuilder {
24     private final ListSchemaNode schema;
25
26     protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
27         this.schema = requireNonNull(schema);
28         super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
29     }
30
31     protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema,
32             final ImmutableOrderedMapNode node) {
33         super(node);
34         this.schema = requireNonNull(schema);
35         super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
36     }
37
38     public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema) {
39         return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema);
40     }
41
42     public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema,
43         final MapNode node) {
44         if (!(node instanceof ImmutableOrderedMapNode)) {
45             throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
46         }
47
48         return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema, (ImmutableOrderedMapNode) node);
49     }
50
51     @Override
52     public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withChild(final MapEntryNode child) {
53         DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
54             schema, Collections.singleton(schema.getQName()));
55         return super.withChild(child);
56     }
57
58     @Override
59     public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withNodeIdentifier(
60             final NodeIdentifier withNodeIdentifier) {
61         throw new UnsupportedOperationException("Node identifier created from schema");
62     }
63 }