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.yangtools.binding.data.codec.impl;
10 import com.google.common.collect.ImmutableMap;
12 import java.util.List;
14 import org.opendaylight.yangtools.concepts.Codec;
15 import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
22 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
26 * Location specific context for schema nodes, which contains codec specific
27 * information to properly serialize / deserialize from Java YANG Binding data
28 * to NormalizedNode data.
30 * Two core subtypes of codec context are available:
32 * <li>{@link LeafNodeCodecContext} - Context for nodes, which does not contain
33 * any nested YANG modeled substructures.</li>
34 * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain
35 * nested YANG modeled substructures. This context nodes contains context
36 * for children nodes.</li>
40 abstract class NodeCodecContext {
43 * Returns Yang Instance Identifier Path Argument of current node
45 * @return DOM Path Argument of node
47 protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
51 * Immutable factory, which provides access to runtime context,
52 * create leaf nodes and provides path argument codecs.
54 * During lifetime of factory all calls for same arguments to method must return
55 * equal result (not necessary same instance of result).
58 protected interface CodecContextFactory {
60 * Returns immutable runtime context associated with this factory.
61 * @return runtime context
63 BindingRuntimeContext getRuntimeContext();
66 * Returns leaf nodes for supplied data container and parent class.
68 * @param type Binding type for which leaves should be loaded.
69 * @param schema Instantiated schema of binding type.
70 * @return Map of local name to leaf node context.
72 ImmutableMap<String, LeafNodeCodecContext> getLeafNodes(Class<?> type, DataNodeContainer schema);
75 * Returns Path argument codec for list item
77 * @param type Type of list item
78 * @param schema Schema of list item
79 * @return Path argument codec for supplied list item.
81 Codec<NodeIdentifierWithPredicates, IdentifiableItem<?, ?>> getPathArgumentCodec(Class<?> type,
82 ListSchemaNode schema);
87 * Serializes supplied Binding Path Argument
88 * and adds all necessary YANG instance identifiers to supplied list.
90 * @param arg Binding Path Argument
91 * @param builder DOM Path argument.
93 protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg,
94 final List<YangInstanceIdentifier.PathArgument> builder) {
95 if (builder != null) {
96 builder.add(getDomPathArgument());
101 * Return the data object for a normalized node
103 * @param normalizedNode Backing normalized node
104 * @return Data object
106 protected abstract Object dataFromNormalizedNode(NormalizedNode<?, ?> normalizedNode);