cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1182993 - /cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
Date Thu, 13 Oct 2011 17:15:41 GMT
Author: dkulp
Date: Thu Oct 13 17:15:40 2011
New Revision: 1182993

URL: http://svn.apache.org/viewvc?rev=1182993&view=rev
Log:
Fix compile failure

Modified:
    cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java

Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java?rev=1182993&r1=1182992&r2=1182993&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
(original)
+++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
Thu Oct 13 17:15:40 2011
@@ -23,9 +23,14 @@ import java.beans.BeanInfo;
 import java.beans.PropertyDescriptor;
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.*;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
@@ -38,7 +43,81 @@ public final class ReflectionUtil {
     private ReflectionUtil() {
         // intentionally empty
     }
+    
+    public static Field getDeclaredField(final Class<?> cls, final String name) {
+        return AccessController.doPrivileged(new PrivilegedAction<Field>() {
+            public Field run() {
+                try {
+                    return cls.getDeclaredField(name);
+                } catch (SecurityException e) {
+                    return null;
+                } catch (NoSuchFieldException e) {
+                    return null;
+                }
+            }
+        });
+    }
+
+    public static Constructor getDeclaredConstructor(final Class<?> cls, final Class<?>
... args) {
+        return AccessController.doPrivileged(new PrivilegedAction<Constructor>() {
+            public Constructor run() {
+                try {
+                    return cls.getDeclaredConstructor(args);
+                } catch (SecurityException e) {
+                    return null;
+                } catch (NoSuchMethodException e) {
+                    return null;
+                }
+            }
+        });
+        
+    }
+    public static Constructor getConstructor(final Class<?> cls, final Class<?>
... args) {
+        return AccessController.doPrivileged(new PrivilegedAction<Constructor>() {
+            public Constructor run() {
+                try {
+                    return cls.getConstructor(args);
+                } catch (SecurityException e) {
+                    return null;
+                } catch (NoSuchMethodException e) {
+                    return null;
+                }
+            }
+        });
+        
+    }
+    
+    public static Method[] getDeclaredMethods(final Class<?> cls) {
+        return AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
+            public Method[] run() {
+                return cls.getDeclaredMethods();
+            }
+        });
+    }
+    public static Field[] getDeclaredFields(final Class<?> cls) {
+        return AccessController.doPrivileged(new PrivilegedAction<Field[]>() {
+            public Field[] run() {
+                return cls.getDeclaredFields();
+            }
+        });
+    }
 
+    public static <T extends AccessibleObject> T setAccessible(final T o) {
+        return AccessController.doPrivileged(new PrivilegedAction<T>() {
+            public T run() {
+                o.setAccessible(true);
+                return o;
+            }
+        });
+    }
+    public static <T extends AccessibleObject> T setAccessible(final T o, final boolean
b) {
+        return AccessController.doPrivileged(new PrivilegedAction<T>() {
+            public T run() {
+                o.setAccessible(b);
+                return o;
+            }
+        });
+    }
     public static List<String> getPackagesFromJar(File jarFile) throws IOException
{
         List<String> packageNames = new ArrayList<String>();
         if (jarFile.isDirectory()) {



Mime
View raw message