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.List;
12 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
15 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
26 import com.google.common.base.Preconditions;
30 * Dispatches the parsing process of elements according to schema and returns the parsed Node.
32 * @param <E> type of elements parsed
34 public interface NodeParserDispatcher<E> {
36 DataContainerChild<?, ?> dispatchChildElement(Object schema, List<E> childNodes);
39 * Abstract implementation that implements the dispatch conditions. Only requires parsers to be provided.
40 * The same instance of parser can be provided in case it is immutable.
42 public static abstract class BaseNodeParserDispatcher<E> implements NodeParserDispatcher<E> {
45 public final DataContainerChild<?, ?> dispatchChildElement(Object schema, List<E> childNodes) {
46 Preconditions.checkArgument(childNodes.isEmpty() == false);
48 if (schema instanceof ContainerSchemaNode) {
49 return getContainerNodeParser().parse(childNodes, (ContainerSchemaNode) schema);
50 } else if (schema instanceof LeafSchemaNode) {
51 return getLeafNodeParser().parse(childNodes, (LeafSchemaNode) schema);
52 } else if (schema instanceof LeafListSchemaNode) {
53 return getLeafSetNodeParser().parse(childNodes, (LeafListSchemaNode) schema);
54 } else if (schema instanceof ListSchemaNode) {
55 return getMapNodeParser().parse(childNodes, (ListSchemaNode) schema);
56 } else if (schema instanceof ChoiceNode) {
57 return getChoiceNodeParser().parse(childNodes, (ChoiceNode) schema);
58 } else if (schema instanceof AugmentationSchema) {
59 return getAugmentationNodeParser().parse(childNodes, (AugmentationSchema) schema);
62 throw new IllegalArgumentException("Unable to parse node, unknown schema type: " + schema.getClass());
65 protected abstract ToNormalizedNodeParser<E, ContainerNode, ContainerSchemaNode> getContainerNodeParser();
67 protected abstract ToNormalizedNodeParser<E, LeafNode<?>, LeafSchemaNode> getLeafNodeParser();
69 protected abstract ToNormalizedNodeParser<E, LeafSetNode<?>, LeafListSchemaNode> getLeafSetNodeParser();
71 protected abstract ToNormalizedNodeParser<E, MapNode, ListSchemaNode> getMapNodeParser();
73 protected abstract ToNormalizedNodeParser<E, org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode, ChoiceNode> getChoiceNodeParser();
75 protected abstract ToNormalizedNodeParser<E, AugmentationNode, AugmentationSchema> getAugmentationNodeParser();