ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [47/93] [abbrv] incubator-ignite git commit: Minor utility method add.
Date Fri, 06 Mar 2015 19:23:18 GMT
Minor utility method add.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/42e94854
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/42e94854
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/42e94854

Branch: refs/heads/ignite-394
Commit: 42e94854f1faa3c87a18c90b57f7064eb07cc26e
Parents: 6423cf0
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Thu Mar 5 10:59:05 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Thu Mar 5 10:59:05 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/util/IgniteUtils.java       | 61 +++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/42e94854/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index de71f59..6b12554 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -7431,6 +7431,66 @@ public abstract class IgniteUtils {
      * @param cls Object.
      * @param obj Object.
      * @param mtdName Field name.
+     * @param params Parameters.
+     * @return Field value.
+     * @throws IgniteCheckedException If static field with given name cannot be retreived.
+     */
+    public static <T> T invoke(@Nullable Class<?> cls, @Nullable Object obj,
String mtdName,
+        Object... params) throws IgniteCheckedException {
+        assert cls != null || obj != null;
+        assert mtdName != null;
+
+        try {
+            for (Class<?> c = cls != null ? cls : obj.getClass(); cls != Object.class;
cls = cls.getSuperclass()) {
+                Method[] mtds = c.getDeclaredMethods();
+
+                Method mtd = null;
+
+                for (Method declaredMtd : c.getDeclaredMethods()) {
+                    if (declaredMtd.getName().equals(mtdName)) {
+                        if (mtd == null)
+                            mtd = declaredMtd;
+                        else
+                            throw new IgniteCheckedException("Failed to invoke (ambigous
method name) [mtdName=" +
+                                mtdName + ", cls=" + cls + ']');
+                    }
+                }
+
+                if (mtd == null)
+                    continue;
+
+                boolean accessible = mtd.isAccessible();
+
+                T res;
+
+                try {
+                    mtd.setAccessible(true);
+
+                    res = (T)mtd.invoke(obj, params);
+                }
+                finally {
+                    if (!accessible)
+                        mtd.setAccessible(false);
+                }
+
+                return res;
+            }
+        }
+        catch (Exception e) {
+            throw new IgniteCheckedException("Failed to invoke [mtdName=" + mtdName + ",
cls=" + cls + ']',
+                e);
+        }
+
+        throw new IgniteCheckedException("Failed to invoke (method was not found) [mtdName="
+ mtdName +
+            ", cls=" + cls + ']');
+    }
+
+    /**
+     * Invokes method.
+     *
+     * @param cls Object.
+     * @param obj Object.
+     * @param mtdName Field name.
      * @param paramTypes Parameter types.
      * @param params Parameters.
      * @return Field value.
@@ -7478,7 +7538,6 @@ public abstract class IgniteUtils {
             ", cls=" + cls + ']');
     }
 
-
     /**
      * Gets property value.
      *


Mime
View raw message