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.dom.api;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.base.MoreObjects.ToStringHelper;
15 import com.google.common.collect.ImmutableSet;
16 import java.util.Objects;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.yangtools.concepts.Immutable;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
26 * An operation (RPC or action) which is subject to availability. This is a common superclass for {@link Action} and
29 * @param <T> type of operation type
31 public abstract class DOMOperationInstance<T> implements Immutable {
32 public static final class Action extends DOMOperationInstance<SchemaPath> {
33 private final Set<DOMDataTreeIdentifier> dataTrees;
35 Action(final SchemaPath type, final Set<DOMDataTreeIdentifier> dataTrees) {
37 this.dataTrees = ImmutableSet.copyOf(dataTrees);
38 checkArgument(!dataTrees.isEmpty());
42 * Return the set of data trees on which this action is available. These identifiers are required to point
43 * to concrete items, i.e. they may not be wildcards.
45 * @return Set of trees on which this action is available.
47 public Set<DOMDataTreeIdentifier> getDataTrees() {
52 public int hashCode() {
53 return Objects.hash(getType(), dataTrees);
57 public boolean equals(final @Nullable Object obj) {
61 if (!(obj instanceof Action)) {
64 final Action other = (Action) obj;
65 return getType().equals(other.getType()) && dataTrees.equals(other.dataTrees);
69 ToStringHelper addToStringAttributes(final ToStringHelper helper) {
70 return helper.add("dataTrees", dataTrees);
74 public static final class Rpc extends DOMOperationInstance<QName> {
75 Rpc(final QName type) {
80 public int hashCode() {
81 return getType().hashCode();
85 public boolean equals(final @Nullable Object obj) {
86 return this == obj || obj instanceof Rpc && getType().equals(((Rpc) obj).getType());
92 DOMOperationInstance(final T type) {
93 this.type = requireNonNull(type);
96 public static Action actionOf(final SchemaPath type, final Set<DOMDataTreeIdentifier> dataTrees) {
97 return new Action(type, dataTrees);
100 public static Action actionOf(final SchemaPath type, final DOMDataTreeIdentifier... dataTrees) {
101 return actionOf(type, ImmutableSet.copyOf(dataTrees));
104 public static Action actionOf(final SchemaPath type, final LogicalDatastoreType datastore,
105 final YangInstanceIdentifier path) {
106 return actionOf(type, ImmutableSet.of(new DOMDataTreeIdentifier(datastore, path)));
109 public static Rpc rpcOf(final QName type) {
110 return new Rpc(type);
114 * Return the operation type.
116 * @return operation type.
118 public final T getType() {
123 public abstract int hashCode();
126 public abstract boolean equals(@Nullable Object obj);
129 public final String toString() {
130 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
133 ToStringHelper addToStringAttributes(final ToStringHelper helper) {
134 return helper.add("type", type);