Add attributes to nodes that can take attributes
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetNodeSchemaAwareBuilder.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.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
12 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
13 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
14
15 import com.google.common.base.Preconditions;
16
17 public final class ImmutableLeafSetNodeSchemaAwareBuilder<T> extends ImmutableLeafSetNodeBuilder<T> {
18
19     private final LeafListSchemaNode schema;
20
21     private ImmutableLeafSetNodeSchemaAwareBuilder(LeafListSchemaNode schema) {
22         this.schema = Preconditions.checkNotNull(schema);
23         super.withNodeIdentifier(new InstanceIdentifier.NodeIdentifier(schema.getQName()));
24     }
25
26     public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(LeafListSchemaNode schema) {
27         return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema);
28     }
29
30     @Override
31     public ListNodeBuilder<T, LeafSetEntryNode<T>> withChildValue(T value) {
32         // TODO check value type
33         return super.withChildValue(value);
34     }
35
36     @Override
37     public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(LeafSetEntryNode<T> child) {
38         Preconditions.checkArgument(schema.getQName().equals(child.getNodeType()),
39                 "Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType());
40         return super.withChild(child);
41     }
42
43     @Override
44     public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(InstanceIdentifier.NodeIdentifier nodeIdentifier) {
45         throw new UnsupportedOperationException("Node identifier created from schema");
46     }
47 }