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.lang.reflect.Method;
12 import java.util.List;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
16 import org.opendaylight.mdsal.binding.dom.codec.loader.CodecClassLoader;
17 import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
18 import org.opendaylight.yangtools.yang.binding.DataObjectSerializer;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
23 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
26 * Location specific context for schema nodes, which contains codec specific information to properly serialize
27 * and deserialize from Java YANG Binding data to NormalizedNode data.
30 * Two core subtypes of codec context are available:
32 * <li>{@link ValueNodeCodecContext} - Context for nodes, which does not contain any nested YANG modeled substructures.
34 * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain nested YANG modeled substructures. This
35 * context nodes contains context for children nodes.</li>
38 abstract class NodeCodecContext implements BindingCodecTreeNode {
41 * Returns Yang Instance Identifier Path Argument of current node.
43 * @return DOM Path Argument of node
45 protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
48 * Immutable factory, which provides access to runtime context, create leaf nodes and provides path argument codecs.
51 * During lifetime of factory all calls for same arguments to method must return equal result (not necessary same
52 * instance of result).
54 protected interface CodecContextFactory {
56 * Returns immutable runtime context associated with this factory.
58 * @return runtime context
60 BindingRuntimeContext getRuntimeContext();
63 * Returns leaf nodes for supplied data container and parent class.
65 * @param type Binding type for which leaves should be loaded.
66 * @param schema Instantiated schema of binding type.
67 * @return Map of local name to leaf node context.
69 ImmutableMap<Method, ValueNodeCodecContext> getLeafNodes(Class<?> type, DataNodeContainer schema);
72 * Returns Path argument codec for list item.
74 * @param type Type of list item
75 * @param schema Schema of list item
76 * @return Path argument codec for supplied list item.
78 IdentifiableItemCodec getPathArgumentCodec(Class<?> type, ListSchemaNode schema);
81 * Return the codec loader associated with this factory.
83 * @return A codec loader instance
85 @NonNull CodecClassLoader getLoader();
87 @NonNull DataObjectStreamer<?> getDataObjectSerializer(Class<?> type);
89 DataObjectSerializer getEventStreamSerializer(Class<?> type);
93 * Serializes supplied Binding Path Argument and adds all necessary YANG instance identifiers to supplied list.
95 * @param arg Binding Path Argument
96 * @param builder DOM Path argument.
98 protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg,
99 final List<YangInstanceIdentifier.PathArgument> builder) {
100 if (builder != null) {
101 builder.add(getDomPathArgument());
106 * Return the default value object. Implementations of this method are explicitly allowed to throw unchecked
107 * exceptions, which are propagated as-is upwards the stack.
109 * @return The default value object, or null if the default value is not defined.
111 @Nullable Object defaultObject() {
115 protected abstract Object deserializeObject(NormalizedNode<?, ?> normalizedNode);