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 = 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();