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.adapter;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkState;
12 import static java.util.Objects.requireNonNull;
14 import com.google.common.util.concurrent.FluentFuture;
15 import com.google.common.util.concurrent.MoreExecutors;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadOperations;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction;
21 import org.opendaylight.yangtools.concepts.Delegator;
22 import org.opendaylight.yangtools.concepts.Identifiable;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 abstract class AbstractForwardedTransaction<T extends DOMDataTreeTransaction> implements Delegator<T>,
27 Identifiable<Object> {
29 private final @NonNull BindingToNormalizedNodeCodec codec;
30 private final @NonNull T delegate;
32 AbstractForwardedTransaction(final T delegateTx, final BindingToNormalizedNodeCodec codec) {
33 this.delegate = requireNonNull(delegateTx, "Delegate must not be null");
34 this.codec = requireNonNull(codec, "Codec must not be null");
38 public final Object getIdentifier() {
39 return delegate.getIdentifier();
43 public final T getDelegate() {
47 protected final <S extends DOMDataTreeTransaction> S getDelegateChecked(final Class<S> txType) {
48 checkState(txType.isInstance(delegate));
49 return txType.cast(delegate);
52 protected final BindingToNormalizedNodeCodec getCodec() {
56 protected final <D extends DataObject> @NonNull FluentFuture<Optional<D>> doRead(
57 final DOMDataTreeReadOperations readOps, final LogicalDatastoreType store,
58 final InstanceIdentifier<D> path) {
59 checkArgument(!path.isWildcarded(), "Invalid read of wildcarded path %s", path);
61 return readOps.read(store, codec.toYangInstanceIdentifierBlocking(path))
62 .transform(codec.getCodecRegistry().deserializeFunction(path)::apply, MoreExecutors.directExecutor());
65 protected final @NonNull FluentFuture<Boolean> doExists(final DOMDataTreeReadOperations readOps,
66 final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
67 checkArgument(!path.isWildcarded(), "Invalid exists of wildcarded path %s", path);
68 return readOps.exists(store, codec.toYangInstanceIdentifierBlocking(path));