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;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
14 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
15 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
17 public class ImmutableLeafNodeBuilder<T>
18 extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
20 public static <T> NormalizedNodeAttrBuilder<NodeIdentifier, T, LeafNode<T>> create() {
21 return new ImmutableLeafNodeBuilder<>();
25 @SuppressWarnings("unchecked")
26 public LeafNode<T> build() {
27 final T value = getValue();
28 if (value instanceof byte[]) {
29 return (LeafNode<T>) new ImmutableBinaryLeafNode(getNodeIdentifier(), (byte[]) value, getAttributes());
32 return new ImmutableLeafNode<>(getNodeIdentifier(), value, getAttributes());
35 private static final class ImmutableLeafNode<T>
36 extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, T> implements LeafNode<T> {
37 ImmutableLeafNode(final NodeIdentifier nodeIdentifier, final T value, final Map<QName, String> attributes) {
38 super(nodeIdentifier, value, attributes);
42 private static final class ImmutableBinaryLeafNode
43 extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, byte[]> implements LeafNode<byte[]> {
44 ImmutableBinaryLeafNode(final NodeIdentifier nodeIdentifier, final byte[] value,
45 final Map<QName, String> attributes) {
46 super(nodeIdentifier, value, attributes);
50 protected byte[] wrapValue(final byte[] valueToWrap) {
51 return valueToWrap.clone();