Merge "Bug 1354: Added rpcReplyToDomNodes method."
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetEntryNodeSchemaAwareBuilder.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.YangInstanceIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
12 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
13 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
14
15 import com.google.common.base.Preconditions;
16
17 public final class ImmutableLeafSetEntryNodeSchemaAwareBuilder<T> extends ImmutableLeafSetEntryNodeBuilder<T> {
18
19     private final LeafListSchemaNode schema;
20
21     private ImmutableLeafSetEntryNodeSchemaAwareBuilder(LeafListSchemaNode schema) {
22         this.schema = Preconditions.checkNotNull(schema);
23     }
24
25     public static <T> NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeWithValue, T, LeafSetEntryNode<T>> create(LeafListSchemaNode schema) {
26         return new ImmutableLeafSetEntryNodeSchemaAwareBuilder<>(schema);
27     }
28
29     @Override
30     public NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeWithValue, T, LeafSetEntryNode<T>> withValue(T value) {
31         super.withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue(schema.getQName(), value));
32         // TODO check value type using TypeProvider ?
33         return super.withValue(value);
34     }
35
36     @Override
37     public NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeWithValue, T, LeafSetEntryNode<T>> withNodeIdentifier(YangInstanceIdentifier.NodeWithValue nodeIdentifier) {
38         throw new UnsupportedOperationException("Node identifier created from schema");
39     }
40
41 }