Merge "BUG-614: migrate RpcMetadata"
authorTony Tkacik <ttkacik@cisco.com>
Tue, 10 Jun 2014 11:29:34 +0000 (11:29 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 10 Jun 2014 11:29:34 +0000 (11:29 +0000)
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcMetadata.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend

diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcMetadata.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcMetadata.java
new file mode 100644 (file)
index 0000000..6f9f85f
--- /dev/null
@@ -0,0 +1,95 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.binding.codegen.impl;
+
+import javassist.CtClass;
+import javassist.CtMethod;
+
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+final class RpcMetadata {
+    private final Class<? extends BaseIdentity> context;
+    private final CtMethod inputRouteGetter;
+    private final Boolean routeEncapsulated;
+    private final CtClass inputType;
+    private final String methodName;
+
+    public Class<? extends BaseIdentity> getContext() {
+        return context;
+    }
+
+    public CtMethod getInputRouteGetter() {
+        return inputRouteGetter;
+    }
+
+    public CtClass getInputType() {
+        return inputType;
+    }
+
+    public boolean isRouteEncapsulated() {
+        return routeEncapsulated;
+    }
+
+    public RpcMetadata(final String methodName, final Class<? extends BaseIdentity> context, final CtMethod inputRouteGetter, final boolean routeEncapsulated, final CtClass inputType) {
+        this.inputRouteGetter = Preconditions.checkNotNull(inputRouteGetter);
+        this.methodName = Preconditions.checkNotNull(methodName);
+        this.inputType = Preconditions.checkNotNull(inputType);
+        this.context = Preconditions.checkNotNull(context);
+        this.routeEncapsulated = routeEncapsulated;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + methodName.hashCode();
+        result = prime * result + context.hashCode();
+        result = prime * result + inputRouteGetter.hashCode();
+        result = prime * result + routeEncapsulated.hashCode();
+        result = prime * result +  inputType.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof RpcMetadata)) {
+            return false;
+        }
+        final RpcMetadata other = (RpcMetadata) obj;
+        if (!methodName.equals(other.methodName)) {
+            return false;
+        }
+        if (!context.equals(other.context)) {
+            return false;
+        }
+        if (!inputRouteGetter.equals(other.inputRouteGetter)) {
+            return false;
+        }
+        if (!routeEncapsulated.equals(other.routeEncapsulated)) {
+            return false;
+        }
+        return inputType.equals(other.inputType);
+    }
+
+    @Override
+    public String toString() {
+        return Objects.toStringHelper(this)
+                .add("context", context)
+                .add("inputRouteGetter", inputRouteGetter)
+                .add("inputType", inputType)
+                .add("methodName", methodName)
+                .add("routeEncapsulated", routeEncapsulated)
+                .toString();
+    }
+}
index eea9ad6..63a1b21 100644 (file)
@@ -16,17 +16,15 @@ import javassist.LoaderClassPath
 import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper
 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory
 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker
-import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils
 import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils
-import org.opendaylight.yangtools.yang.binding.BaseIdentity
 import org.opendaylight.yangtools.yang.binding.DataContainer
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
 import org.opendaylight.yangtools.yang.binding.Notification
 import org.opendaylight.yangtools.yang.binding.NotificationListener
 import org.opendaylight.yangtools.yang.binding.RpcImplementation
 import org.opendaylight.yangtools.yang.binding.RpcService
-import org.opendaylight.yangtools.yang.binding.annotations.QName
 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext
+import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils
 
 import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification.*
 import static extension org.opendaylight.controller.sal.binding.codegen.YangtoolsMappingHelper.*
@@ -161,13 +159,13 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
         return inputClass.rpcMethodMetadata(inputClass,method.name);
     }
 
-    private def RpcMetadata rpcMethodMetadata(CtClass dataClass,CtClass inputClass,String rpcMethod) {
+    private def RpcMetadata rpcMethodMetadata(CtClass dataClass, CtClass inputClass, String rpcMethod) {
         for (method : dataClass.methods) {
             if (method.name.startsWith("get") && method.parameterTypes.size === 0) {
                 for (annotation : method.availableAnnotations) {
                     if (annotation instanceof RoutingContext) {
                         val encapsulated = !method.returnType.equals(InstanceIdentifier.asCtClass);
-                        return new RpcMetadata(null,rpcMethod,(annotation as RoutingContext).value, method, encapsulated,inputClass);
+                        return new RpcMetadata(rpcMethod,(annotation as RoutingContext).value, method, encapsulated,inputClass);
                     }
                 }
             }
@@ -265,24 +263,3 @@ package class RuntimeGeneratedInvoker implements NotificationInvoker {
     override close() {
     }
 }
-
-@Data
-package class RpcMetadata {
-
-    @Property
-    val QName qname;
-
-    @Property
-    val String methodName;
-
-    @Property
-    val Class<? extends BaseIdentity> context;
-    @Property
-    val CtMethod inputRouteGetter;
-
-    @Property
-    val boolean routeEncapsulated;
-
-    @Property
-    val CtClass inputType;
-}