2 * Copyright (c) 2014 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.mdsal.binding.dom.codec.impl;
10 import com.google.common.collect.ImmutableMap;
11 import java.util.List;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
14 import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.DataObjectSerializer;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
21 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
24 * Location specific context for schema nodes, which contains codec specific information to properly serialize
25 * and deserialize from Java YANG Binding data to NormalizedNode data.
28 * Two core subtypes of codec context are available:
30 * <li>{@link LeafNodeCodecContext} - Context for nodes, which does not contain any nested YANG modeled substructures.
32 * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain nested YANG modeled substructures. This
33 * context nodes contains context for children nodes.</li>
36 abstract class NodeCodecContext<D extends DataObject> implements BindingCodecTreeNode<D> {
39 * Returns Yang Instance Identifier Path Argument of current node.
41 * @return DOM Path Argument of node
43 protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
46 * Immutable factory, which provides access to runtime context, create leaf nodes and provides path argument codecs.
49 * During lifetime of factory all calls for same arguments to method must return equal result (not necessary same
50 * instance of result).
52 protected interface CodecContextFactory {
54 * Returns immutable runtime context associated with this factory.
56 * @return runtime context
58 BindingRuntimeContext getRuntimeContext();
61 * Returns leaf nodes for supplied data container and parent class.
63 * @param type Binding type for which leaves should be loaded.
64 * @param schema Instantiated schema of binding type.
65 * @return Map of local name to leaf node context.
67 ImmutableMap<String, LeafNodeCodecContext<?>> getLeafNodes(Class<?> type, DataNodeContainer schema);
70 * Returns Path argument codec for list item.
72 * @param type Type of list item
73 * @param schema Schema of list item
74 * @return Path argument codec for supplied list item.
76 IdentifiableItemCodec getPathArgumentCodec(Class<?> type, ListSchemaNode schema);
78 DataObjectSerializer getEventStreamSerializer(Class<?> type);
82 * Serializes supplied Binding Path Argument and adds all necessary YANG instance identifiers to supplied list.
84 * @param arg Binding Path Argument
85 * @param builder DOM Path argument.
87 protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg,
88 final List<YangInstanceIdentifier.PathArgument> builder) {
89 if (builder != null) {
90 builder.add(getDomPathArgument());
95 * Return the default value object. Implementations of this method are explicitly allowed to throw unchecked
96 * exceptions, which are propagated as-is upwards the stack.
98 * @return The default value object, or null if the default value is not defined.
100 @Nullable Object defaultObject() {
104 protected abstract Object deserializeObject(NormalizedNode<?, ?> normalizedNode);