Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[controller.git] / opendaylight / md-sal / sal-dom-api / src / main / java / org / opendaylight / controller / md / sal / dom / api / DOMRpcIdentifier.java
index 1976913a1744e9ff8ba782a85dd83fdd79e2682c..63e646debd7a884699c73ff4fb881d851ec8892e 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.md.sal.dom.api;
 
+import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
 import java.util.Objects;
 import javax.annotation.Nonnull;
@@ -21,6 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  * contexts concurrently.
  */
 public abstract class DOMRpcIdentifier {
+
     private static final class Global extends DOMRpcIdentifier {
         private Global(final @Nonnull SchemaPath type) {
             super(type);
@@ -28,7 +30,7 @@ public abstract class DOMRpcIdentifier {
 
         @Override
         public YangInstanceIdentifier getContextReference() {
-            return null;
+            return YangInstanceIdentifier.EMPTY;
         }
     }
 
@@ -69,12 +71,20 @@ public abstract class DOMRpcIdentifier {
      * @param contextReference Context reference, null means a global RPC identifier.
      * @return A global RPC identifier, guaranteed to be non-null.
      */
-    public static @Nonnull DOMRpcIdentifier create(final @Nonnull SchemaPath type, final @Nullable YangInstanceIdentifier contextReference) {
-        if (contextReference == null) {
+    public static @Nonnull DOMRpcIdentifier create(final @Nonnull SchemaPath type,
+            final @Nullable YangInstanceIdentifier contextReference) {
+        if (contextReference == null || contextReference.isEmpty()) {
             return new Global(type);
-        } else {
-            return new Local(type, contextReference);
         }
+        return new Local(type, contextReference);
+    }
+
+    public static DOMRpcIdentifier fromMdsal(final org.opendaylight.mdsal.dom.api.DOMRpcIdentifier mdsal) {
+        return create(mdsal.getType(), mdsal.getContextReference());
+    }
+
+    public org.opendaylight.mdsal.dom.api.DOMRpcIdentifier toMdsal() {
+        return org.opendaylight.mdsal.dom.api.DOMRpcIdentifier.create(type, getContextReference());
     }
 
     /**
@@ -91,14 +101,14 @@ public abstract class DOMRpcIdentifier {
      *
      * @return RPC context reference.
      */
-    public abstract @Nullable YangInstanceIdentifier getContextReference();
+    public abstract @Nonnull YangInstanceIdentifier getContextReference();
 
     @Override
     public final int hashCode() {
         final int prime = 31;
         int result = 1;
         result = prime * result + type.hashCode();
-        result = prime * result + (getContextReference() == null ? 0 : getContextReference().hashCode());
+        result = prime * result + getContextReference().hashCode();
         return result;
     }
 
@@ -119,6 +129,7 @@ public abstract class DOMRpcIdentifier {
 
     @Override
     public final String toString() {
-        return com.google.common.base.Objects.toStringHelper(this).omitNullValues().add("type", type).add("contextReference", getContextReference()).toString();
+        return MoreObjects.toStringHelper(this).omitNullValues().add("type", type).add("contextReference",
+                getContextReference()).toString();
     }
 }