2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.util;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ForwardingObject;
14 import java.util.Collection;
16 import java.util.Optional;
17 import javax.annotation.concurrent.GuardedBy;
18 import javax.annotation.concurrent.ThreadSafe;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
30 * A {@link ContainerNode} backed by a binding {@link DataObject}, with lazy instantiation of the ContainerNode view.
32 * @param <T> Binding DataObject type
33 * @author Robert Varga
37 public abstract class AbstractBindingLazyContainerNode<T extends DataObject, C> extends ForwardingObject
38 implements BindingLazyContainerNode<T> {
39 private final @NonNull NodeIdentifier identifier;
40 private final @NonNull T bindingData;
42 private volatile @Nullable ContainerNode delegate;
44 private @Nullable C context;
46 protected AbstractBindingLazyContainerNode(final @NonNull NodeIdentifier identifier, final @NonNull T bindingData,
48 this.identifier = requireNonNull(identifier);
49 this.bindingData = requireNonNull(bindingData);
50 this.context = context;
54 public final @NonNull T getDataObject() {
59 public final @NonNull NodeIdentifier getIdentifier() {
64 public final QName getNodeType() {
65 return identifier.getNodeType();
69 public final ContainerNode getDelegate() {
74 public Map<QName, String> getAttributes() {
75 return delegate().getAttributes();
79 public Object getAttributeValue(final QName name) {
80 return delegate().getAttributeValue(name);
84 public Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
85 return delegate().getValue();
89 public Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
90 return delegate().getChild(child);
94 public int hashCode() {
95 return delegate().hashCode();
99 public boolean equals(final @Nullable Object obj) {
103 if (!(obj instanceof ContainerNode)) {
106 final ContainerNode other = (ContainerNode) obj;
107 return delegate().equals(other);
111 protected final @NonNull ContainerNode delegate() {
112 ContainerNode local = delegate;
114 synchronized (this) {
117 local = delegate = requireNonNull(computeContainerNode(context));
127 protected abstract @NonNull ContainerNode computeContainerNode(C context);