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.DataObjectSerializer;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
23 * Location specific context for schema nodes, which contains codec specific information to properly serialize
24 * and deserialize from Java YANG Binding data to NormalizedNode data.
27 * Two core subtypes of codec context are available:
29 * <li>{@link ValueNodeCodecContext} - Context for nodes, which does not contain any nested YANG modeled substructures.
31 * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain nested YANG modeled substructures. This
32 * context nodes contains context for children nodes.</li>
35 abstract class NodeCodecContext implements BindingCodecTreeNode {
38 * Returns Yang Instance Identifier Path Argument of current node.
40 * @return DOM Path Argument of node
42 protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
45 * Immutable factory, which provides access to runtime context, create leaf nodes and provides path argument codecs.
48 * During lifetime of factory all calls for same arguments to method must return equal result (not necessary same
49 * instance of result).
51 protected interface CodecContextFactory {
53 * Returns immutable runtime context associated with this factory.
55 * @return runtime context
57 BindingRuntimeContext getRuntimeContext();
60 * Returns leaf nodes for supplied data container and parent class.
62 * @param type Binding type for which leaves should be loaded.
63 * @param schema Instantiated schema of binding type.
64 * @return Map of local name to leaf node context.
66 ImmutableMap<String, ValueNodeCodecContext> getLeafNodes(Class<?> type, DataNodeContainer schema);
69 * Returns Path argument codec for list item.
71 * @param type Type of list item
72 * @param schema Schema of list item
73 * @return Path argument codec for supplied list item.
75 IdentifiableItemCodec getPathArgumentCodec(Class<?> type, ListSchemaNode schema);
77 DataObjectSerializer getEventStreamSerializer(Class<?> type);
81 * Serializes supplied Binding Path Argument and adds all necessary YANG instance identifiers to supplied list.
83 * @param arg Binding Path Argument
84 * @param builder DOM Path argument.
86 protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg,
87 final List<YangInstanceIdentifier.PathArgument> builder) {
88 if (builder != null) {
89 builder.add(getDomPathArgument());
94 * Return the default value object. Implementations of this method are explicitly allowed to throw unchecked
95 * exceptions, which are propagated as-is upwards the stack.
97 * @return The default value object, or null if the default value is not defined.
99 @Nullable Object defaultObject() {
103 protected abstract Object deserializeObject(NormalizedNode<?, ?> normalizedNode);