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.controller.md.sal.dom.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import java.util.Objects;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 * Identifier of a RPC context. This is an extension of the YANG RPC, which
21 * always has global context. It allows an RPC to have a instance identifier
22 * attached, so that there can be multiple implementations bound to different
23 * contexts concurrently.
25 * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMRpcIdentifier} instead.
28 public abstract class DOMRpcIdentifier {
30 private static final class Global extends DOMRpcIdentifier {
31 private Global(final @NonNull SchemaPath type) {
36 public YangInstanceIdentifier getContextReference() {
37 return YangInstanceIdentifier.EMPTY;
41 private static final class Local extends DOMRpcIdentifier {
42 private final YangInstanceIdentifier contextReference;
44 private Local(final @NonNull SchemaPath type, final @NonNull YangInstanceIdentifier contextReference) {
46 this.contextReference = requireNonNull(contextReference);
50 public YangInstanceIdentifier getContextReference() {
51 return contextReference;
55 private final SchemaPath type;
57 private DOMRpcIdentifier(final SchemaPath type) {
58 this.type = requireNonNull(type);
62 * Create a global RPC identifier.
64 * @param type RPC type, SchemaPath of its definition, may not be null
65 * @return A global RPC identifier, guaranteed to be non-null.
67 public static @NonNull DOMRpcIdentifier create(final @NonNull SchemaPath type) {
68 return new Global(type);
72 * Create an RPC identifier with a particular context reference.
74 * @param type RPC type, SchemaPath of its definition, may not be null
75 * @param contextReference Context reference, null means a global RPC identifier.
76 * @return A global RPC identifier, guaranteed to be non-null.
78 public static @NonNull DOMRpcIdentifier create(final @NonNull SchemaPath type,
79 final @Nullable YangInstanceIdentifier contextReference) {
80 if (contextReference == null || contextReference.isEmpty()) {
81 return new Global(type);
83 return new Local(type, contextReference);
86 public static DOMRpcIdentifier fromMdsal(final org.opendaylight.mdsal.dom.api.DOMRpcIdentifier mdsal) {
87 return create(mdsal.getType(), mdsal.getContextReference());
90 public org.opendaylight.mdsal.dom.api.DOMRpcIdentifier toMdsal() {
91 return org.opendaylight.mdsal.dom.api.DOMRpcIdentifier.create(type, getContextReference());
95 * Return the RPC type.
99 public final @NonNull SchemaPath getType() {
104 * Return the RPC context reference. Null value indicates global context.
106 * @return RPC context reference.
108 public abstract @NonNull YangInstanceIdentifier getContextReference();
111 public final int hashCode() {
112 final int prime = 31;
114 result = prime * result + type.hashCode();
115 result = prime * result + getContextReference().hashCode();
120 public final boolean equals(final Object obj) {
124 if (!(obj instanceof DOMRpcIdentifier)) {
127 DOMRpcIdentifier other = (DOMRpcIdentifier) obj;
128 if (!type.equals(other.type)) {
131 return Objects.equals(getContextReference(), other.getContextReference());
135 public final String toString() {
136 return MoreObjects.toStringHelper(this).omitNullValues().add("type", type).add("contextReference",
137 getContextReference()).toString();