BindingReflections' cache should use cached references
authorRobert Varga <rovarga@cisco.com>
Wed, 3 Jun 2015 17:32:11 +0000 (19:32 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 5 Jun 2015 09:34:41 +0000 (09:34 +0000)
Since we will be giving out these all over the place, it is a good idea
to make sure the returned reference is system-global.

Change-Id: I46c4f62c5ea8f8ee13e7745e6c9efd7d865bd6d4
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit 47e801b7f26d9e8ce68738bdfd0d1b6e6c83ae0c)

yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/BindingReflections.java

index 46bd9327d15ff0aec0c8de6d6c0e814712768150..d2456f52ba092479ff445be5395364e762252d3f 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.binding.util;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
-
 import com.google.common.base.Optional;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
@@ -245,7 +244,7 @@ public class BindingReflections {
         return match.group(0);
     }
 
-    public static final QNameModule getQNameModule(Class<?> clz) {
+    public static final QNameModule getQNameModule(final Class<?> clz) {
         if(DataContainer.class.isAssignableFrom(clz) || BaseIdentity.class.isAssignableFrom(clz)) {
             return findQName(clz).getModule();
         }
@@ -257,7 +256,7 @@ public class BindingReflections {
         }
     }
 
-    public static final QNameModule getQNameModule(YangModuleInfo modInfo) {
+    public static final QNameModule getQNameModule(final YangModuleInfo modInfo) {
         return QNameModule.create(URI.create(modInfo.getNamespace()), QName.parseRevision(modInfo.getRevision()));
     }
 
@@ -567,19 +566,19 @@ public class BindingReflections {
             } catch (Exception e) {
                 throw new IllegalStateException("Unable to get QName for " + key + ". YangModuleInfo was not found.", e);
             }
-            final QName module = getModuleQName(moduleInfo);
+            final QName module = QName.cachedReference(getModuleQName(moduleInfo));
             if (Augmentation.class.isAssignableFrom(key)) {
                 return module;
             } else if (isRpcType(key)) {
                 final String className = key.getSimpleName();
                 if (className.endsWith(BindingMapping.RPC_OUTPUT_SUFFIX)) {
-                    return QName.create(module, "output");
+                    return QName.cachedReference(QName.create(module, "output"));
                 } else {
-                    return QName.create(module, "input");
+                    return QName.cachedReference(QName.create(module, "input"));
                 }
             }
             /*
-             * Fallback for Binding types which fo not have QNAME field
+             * Fallback for Binding types which do not have QNAME field
              */
             return module;
         } else {