2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.mdsal.binding.javav2.dom.codec.impl.context.base;
11 import com.google.common.annotations.Beta;
12 import com.google.common.collect.ImmutableMap;
13 import java.util.List;
14 import org.opendaylight.mdsal.binding.javav2.dom.codec.api.codecs.BindingTreeNodeCodec;
15 import org.opendaylight.mdsal.binding.javav2.runtime.context.BindingRuntimeContext;
16 import org.opendaylight.mdsal.binding.javav2.spec.base.IdentifiableItem;
17 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeArgument;
18 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
19 import org.opendaylight.mdsal.binding.javav2.spec.runtime.TreeNodeSerializer;
20 import org.opendaylight.yangtools.concepts.Codec;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
25 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
29 * Location specific context for schema nodes, which contains codec specific
30 * information to properly serialize / deserialize from Java YANG Binding data
31 * to NormalizedNode data.
33 * Two core subtypes of codec context are available:
35 * <li>{@link LeafNodeCodecContext} - Context for nodes, which does not contain
36 * any nested YANG modeled substructures.</li>
37 * <li>{@link TreeNodeCodecContext} - Context for nodes, which does contain
38 * nested YANG modeled substructures. This context nodes contains context
39 * for children nodes.</li>
44 abstract class NodeCodecContext<D extends TreeNode> implements BindingTreeNodeCodec<D>{
46 * Returns Yang Instance Identifier Path Argument of current node
48 * @return DOM Path Argument of node
50 protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
54 * Immutable factory, which provides access to runtime context,
55 * create leaf nodes and provides path argument codecs.
57 * During lifetime of factory all calls for same arguments to method must return
58 * equal result (not necessary same instance of result).
61 protected interface CodecContextFactory {
63 * Returns immutable runtime context associated with this factory.
64 * @return runtime context
66 BindingRuntimeContext getRuntimeContext();
69 * Returns leaf nodes for supplied data container and parent class.
71 * @param type Binding type for which leaves should be loaded.
72 * @param schema Instantiated schema of binding type.
73 * @return Map of local name to leaf node context.
75 ImmutableMap<String, LeafNodeCodecContext<?>> getLeafNodes(Class<?> type, DataNodeContainer schema);
78 * Returns Path argument codec for list item
80 * @param type Type of list item
81 * @param schema Schema of list item
82 * @return Path argument codec for supplied list item.
84 Codec<NodeIdentifierWithPredicates, IdentifiableItem<?, ?>> getPathArgumentCodec(Class<?> type,
85 ListSchemaNode schema);
87 TreeNodeSerializer getEventStreamSerializer(Class<?> type);
92 * Serializes supplied Binding Path Argument
93 * and adds all necessary YANG instance identifiers to supplied list.
95 * @param arg Binding Path Argument
96 * @param builder DOM Path argument.
98 @SuppressWarnings("rawtypes")
99 protected void addYangPathArgument(final TreeArgument arg,
100 final List<YangInstanceIdentifier.PathArgument> builder) {
101 if (builder != null) {
102 builder.add(getDomPathArgument());
106 protected abstract Object deserializeObject(NormalizedNode<?, ?> normalizedNode);