2 * Copyright (c) 2015 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.adapter;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
14 import org.opendaylight.mdsal.binding.dom.codec.spi.AbstractBindingLazyContainerNode;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
19 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
22 * FIXME: This is a bit of functionality which should really live in binding-dom-codec, but for to happen we need
23 * to extend BindingNormalizedNodeSerializer with the concept of a routing context -- which would be deprecated,
24 * as we want to move to actions in the long term.
26 * Even then, BindingNormalizedNodeCodecRegistry provides background updates to the context used in
27 * deserialization, which is currently being used.
29 class LazySerializedContainerNode
30 extends AbstractBindingLazyContainerNode<DataObject, BindingNormalizedNodeSerializer> {
32 private LazySerializedContainerNode(final @NonNull NodeIdentifier identifier, final DataObject binding,
33 final BindingNormalizedNodeSerializer codec) {
34 super(identifier, binding, requireNonNull(codec));
37 static ContainerNode create(final @NonNull NodeIdentifier identifier, final DataObject data,
38 final BindingNormalizedNodeSerializer codec) {
39 return data == null ? null : new LazySerializedContainerNode(identifier, data, codec);
42 static ContainerNode withContextRef(final @NonNull NodeIdentifier identifier, final DataObject data,
43 final LeafNode<?> contextRef, final BindingNormalizedNodeSerializer serializer) {
44 return new WithContextRef(identifier, data, contextRef, serializer);
48 protected final ContainerNode computeContainerNode(final BindingNormalizedNodeSerializer context) {
49 return context.toNormalizedNodeRpcData(getDataObject());
53 * Lazy Serialized Node with pre-cached serialized leaf holding routing information.
55 private static final class WithContextRef extends LazySerializedContainerNode {
56 private final LeafNode<?> contextRef;
58 protected WithContextRef(final @NonNull NodeIdentifier identifier, final DataObject binding,
59 final LeafNode<?> contextRef, final BindingNormalizedNodeSerializer codec) {
60 super(identifier, binding, codec);
61 this.contextRef = requireNonNull(contextRef);
65 public DataContainerChild childByArg(final NodeIdentifier child) {
66 // Use pre-cached value of routing field and do not run full serialization if we are accessing it.
67 return contextRef.getIdentifier().equals(child) ? contextRef : super.childByArg(child);