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.transform.base.parser;
10 import java.util.Collections;
11 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
12 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
13 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
14 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
15 import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
16 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
19 * Abstract(base) parser for LeafSetNodes, parses elements of type E.
21 * @param <E> type of elements to be parsed
23 public abstract class LeafSetNodeBaseParser<E> implements
24 ToNormalizedNodeParser<E, LeafSetNode<?>, LeafListSchemaNode> {
27 public final LeafSetNode<?> parse(Iterable<E> childNodes, LeafListSchemaNode schema) {
29 ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafListBuilder =
30 (schema.isUserOrdered() ? Builders.orderedLeafSetBuilder(schema) : Builders.leafSetBuilder(schema));
31 for (E childNode : childNodes) {
32 LeafSetEntryNode<?> builtChild = getLeafSetEntryNodeParser().parse(
33 Collections.singletonList(childNode), schema);
35 // TODO: can we get rid of this cast/SuppressWarnings somehow?
36 @SuppressWarnings("unchecked")
37 final LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>) builtChild;
38 leafListBuilder.withChild(child);
41 return leafListBuilder.build();
46 * @return parser for inner LeafSetEntryNodes used to parse every entry of LeafSetNode, might be the same instance in case its immutable
48 protected abstract ToNormalizedNodeParser<E, LeafSetEntryNode<?>, LeafListSchemaNode> getLeafSetEntryNodeParser();