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