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.serializer;
10 import java.util.List;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
16 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializer;
18 import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.AugmentationSchemaProxy;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import com.google.common.base.Preconditions;
23 import com.google.common.collect.Iterables;
24 import com.google.common.collect.Lists;
27 * Abstract(base) Serializer for DataContainerNodes e.g. ContainerNode, AugmentationNode.
29 public abstract class BaseDispatcherSerializer<E, N extends DataContainerNode<?>, S> implements
30 FromNormalizedNodeSerializer<E, N, S> {
35 * @param augmentationSchema
36 * @return Set of real schema objects that represent child nodes of an
37 * augmentation. Augmentation schema child nodes, if further
38 * augmented, do not contain further augmented, that are crucial for
39 * parsing. The real schema object can be retrieved from parent schema: schema.
41 protected abstract Set<DataSchemaNode> getRealSchemasForAugment(S schema, AugmentationSchema augmentationSchema);
47 * @return Schema object associated with child node identified as: childNode.
48 * Schema should be retrieved from parent schema: schema.
50 protected abstract DataSchemaNode getSchemaForChild(S schema,
51 DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> childNode);
56 * @param augmentationNode
57 * @return Schema object associated with augmentation child node identified as: augmentationNode.
58 * Schema should be retrieved from parent schema: schema.
60 protected abstract AugmentationSchema getAugmentedCase(S schema, AugmentationNode augmentationNode);
64 * @return Dispatcher object to dispatch serialization of child elements, might be
65 * the same instance if provided serializers are immutable.
67 protected abstract NodeSerializerDispatcher<E> getNodeDispatcher();
70 public Iterable<E> serialize(S schema, N node) {
71 List<Iterable<E>> choiceChildren = Lists.newArrayList();
73 for (DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> choiceChild : node.getValue()) {
77 if (choiceChild instanceof AugmentationNode) {
79 AugmentationSchema augSchema = getAugmentedCase(schema, (AugmentationNode) choiceChild);
80 Set<DataSchemaNode> realChildSchemas = getRealSchemasForAugment(schema, augSchema);
81 childSchema = new AugmentationSchemaProxy(augSchema, realChildSchemas);
84 childSchema = getSchemaForChild(schema, choiceChild);
87 Iterable<E> childElements = getNodeDispatcher().dispatchChildElement(childSchema, choiceChild);
88 choiceChildren.add(Preconditions.checkNotNull(childElements));
91 return Iterables.concat(choiceChildren);