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.concepts.Codec;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.DataObjectSerializer;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
24 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
27 * Location specific context for schema nodes, which contains codec specific information to properly serialize
28 * and deserialize from Java YANG Binding data to NormalizedNode data.
31 * Two core subtypes of codec context are available:
33 * <li>{@link LeafNodeCodecContext} - Context for nodes, which does not contain any nested YANG modeled substructures.
35 * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain nested YANG modeled substructures. This
36 * context nodes contains context for children nodes.</li>
39 abstract class NodeCodecContext<D extends DataObject> implements BindingCodecTreeNode<D> {
42 * Returns Yang Instance Identifier Path Argument of current node.
44 * @return DOM Path Argument of node
46 protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
49 * Immutable factory, which provides access to runtime context, create leaf nodes and provides path argument codecs.
52 * During lifetime of factory all calls for same arguments to method must return equal result (not necessary same
53 * instance of result).
55 protected interface CodecContextFactory {
57 * Returns immutable runtime context associated with this factory.
59 * @return runtime context
61 BindingRuntimeContext getRuntimeContext();
64 * Returns leaf nodes for supplied data container and parent class.
66 * @param type Binding type for which leaves should be loaded.
67 * @param schema Instantiated schema of binding type.
68 * @return Map of local name to leaf node context.
70 ImmutableMap<String, LeafNodeCodecContext<?>> getLeafNodes(Class<?> type, DataNodeContainer schema);
73 * Returns Path argument codec for list item.
75 * @param type Type of list item
76 * @param schema Schema of list item
77 * @return Path argument codec for supplied list item.
79 Codec<NodeIdentifierWithPredicates, IdentifiableItem<?, ?>> getPathArgumentCodec(Class<?> type,
80 ListSchemaNode schema);
82 DataObjectSerializer getEventStreamSerializer(Class<?> type);
86 * Serializes supplied Binding Path Argument and adds all necessary YANG instance identifiers to supplied list.
88 * @param arg Binding Path Argument
89 * @param builder DOM Path argument.
91 protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg,
92 final List<YangInstanceIdentifier.PathArgument> builder) {
93 if (builder != null) {
94 builder.add(getDomPathArgument());
99 * Return the default value object. Implementations of this method are explicitly allowed to throw unchecked
100 * exceptions, which are propagated as-is upwards the stack.
102 * @return The default value object, or null if the default value is not defined.
104 @Nullable Object defaultObject() {
108 protected abstract Object deserializeObject(NormalizedNode<?, ?> normalizedNode);