[jboss-cvs] JBossAS SVN: r73141 - in projects/jboss-reflect/trunk/src: tests/org/jboss/test/beaninfo/support and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 8 02:11:47 EDT 2008


Author: alesj
Date: 2008-05-08 02:11:47 -0400 (Thu, 08 May 2008)
New Revision: 73141

Added:
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/support/MethodsClass.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTest.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/FieldAccessRestrictionTestCase.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/MethodAccessRestrictionTestCase.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/support/MethodsClass.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTest.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/FieldAccessRestrictionTestCase.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/MethodAccessRestrictionTestCase.java
Removed:
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTestCase.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTestCase.java
Modified:
   projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java
   projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
Log:
Enable private/protected methods.
Similar way we did fields.

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java	2008-05-08 06:05:53 UTC (rev 73140)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -193,21 +193,27 @@
    }
 
    @SuppressWarnings("deprecation")
-   public MethodInfoImpl[] getMethods(ClassInfoImpl classInfo)
+   public MethodInfoImpl[] getMethods(final ClassInfoImpl classInfo)
    {
-      Class<?> clazz = classInfo.getType();
-      Method[] methods = getDeclaredMethods(clazz);
-      if (methods == null || methods.length == 0)
-         return null;
+      return AccessController.doPrivileged(new PrivilegedAction<MethodInfoImpl[]>()
+      {
+         public MethodInfoImpl[] run()
+         {
+            Class<?> clazz = classInfo.getType();
+            Method[] methods = getDeclaredMethods(clazz);
+            if (methods == null || methods.length == 0)
+               return null;
 
-      ReflectMethodInfoImpl[] infos = new ReflectMethodInfoImpl[methods.length];
-      for (int i = 0; i < methods.length; ++i)
-      {
-         AnnotationValue[] annotations = getAnnotations(methods[i]);
-         infos[i] = new ReflectMethodInfoImpl(annotations, methods[i].getName(), getTypeInfo(methods[i].getGenericReturnType()), getTypeInfos(methods[i].getGenericParameterTypes()), getParameterAnnotations(methods[i].getParameterAnnotations()), getClassInfos(methods[i].getGenericExceptionTypes()), methods[i].getModifiers(), (ClassInfo) getTypeInfo(methods[i].getDeclaringClass()));
-         infos[i].setMethod(methods[i]);
-      }
-      return infos;
+            ReflectMethodInfoImpl[] infos = new ReflectMethodInfoImpl[methods.length];
+            for (int i = 0; i < methods.length; ++i)
+            {
+               AnnotationValue[] annotations = getAnnotations(methods[i]);
+               infos[i] = new ReflectMethodInfoImpl(annotations, methods[i].getName(), getTypeInfo(methods[i].getGenericReturnType()), getTypeInfos(methods[i].getGenericParameterTypes()), getParameterAnnotations(methods[i].getParameterAnnotations()), getClassInfos(methods[i].getGenericExceptionTypes()), methods[i].getModifiers(), (ClassInfo) getTypeInfo(methods[i].getDeclaringClass()));
+               infos[i].setMethod(methods[i]);
+            }
+            return infos;
+         }
+      });
    }
 
    @SuppressWarnings("deprecation")

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java	2008-05-08 06:05:53 UTC (rev 73140)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -24,6 +24,11 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.lang.reflect.Method;
+import java.lang.reflect.ReflectPermission;
+import java.lang.reflect.Modifier;
+import java.security.Permission;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import org.jboss.reflect.plugins.MethodInfoImpl;
 import org.jboss.reflect.spi.AnnotationValue;
@@ -36,12 +41,16 @@
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
 public class ReflectMethodInfoImpl extends MethodInfoImpl
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 2;
    
+   /** The permission */
+   private static Permission accessCheck = new ReflectPermission("suppressAccessChecks");
+
    /** The method */
    protected transient Method method;
 
@@ -92,7 +101,13 @@
     */
    public void setMethod(Method method)
    {
+      if (method != null)
+         accessCheck(Modifier.isPublic(method.getModifiers()));
+
       this.method = method;
+
+      if (isPublic() == false && method != null)
+         setAccessible();
    }
 
    /**
@@ -102,11 +117,36 @@
     */
    public Method getMethod()
    {
+      accessCheck();
       return method;
    }
    
+   /**
+    * Check access permission.
+    */
+   protected final void accessCheck() // final because we don't want subclasses to disable it
+   {
+      accessCheck(isPublic());
+   }
+
+   /**
+    * Check access permission.
+    *
+    * @param isPublic whether the field is public
+    */
+   protected final void accessCheck(final boolean isPublic) // final because we don't want subclasses to disable it
+   {
+      if (isPublic == false)
+      {
+         SecurityManager sm = System.getSecurityManager();
+         if (sm != null)
+            sm.checkPermission(accessCheck);
+      }
+   }
+
    public Object invoke(Object target, Object[] args) throws Throwable
    {
+      accessCheck();
       return ReflectionUtils.invoke(method, target, args);
    }
 
@@ -129,4 +169,28 @@
          classes[i] = parameterTypes[i].getType();
       method = ReflectionUtils.findExactMethod(getDeclaringClass().getType(), name, classes);
    }
+
+   /**
+    * Set field accessible to true
+    */
+   private void setAccessible()
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if (sm == null)
+         method.setAccessible(true);
+      else
+         AccessController.doPrivileged(new SetAccessible());
+   }
+
+   /**
+    * Set accessible privileged block
+    */
+   private class SetAccessible implements PrivilegedAction<Object>
+   {
+      public Object run()
+      {
+         method.setAccessible(true);
+         return null;
+      }
+   }
 }

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/support/MethodsClass.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/support/FieldsClass.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/support/MethodsClass.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/support/MethodsClass.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,68 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beaninfo.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MethodsClass
+{
+   @SuppressWarnings("unused")
+   private String privString;
+   protected String protString;
+   public String pubString;
+
+   public String getPrivStringNotGetter()
+   {
+      return privString;     
+   }
+
+   private String getPrivString()
+   {
+      return privString;
+   }
+
+   private void setPrivString(String privString)
+   {
+      this.privString = privString;
+   }
+
+   protected String getProtStringNotGetter()
+   {
+      return protString;
+   }
+
+   protected void setProtString(String protString)
+   {
+      this.protString = protString;
+   }
+
+   public String getPubString()
+   {
+      return pubString;
+   }
+
+   public void setPubString(String pubString)
+   {
+      this.pubString = pubString;
+   }
+}
\ No newline at end of file

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTest.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTestCase.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTest.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTest.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,151 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beaninfo.test;
+
+import java.security.AccessControlException;
+
+import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.config.plugins.BasicConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * Access restriction test.
+ *
+ * @param <T> exact tester class
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AccessRestrictionTest<T> extends AbstractTestCaseWithSetup
+{
+   /** The bean info factory */
+   private Configuration configuration = new BasicConfiguration();
+
+   /**
+    * Create a new AccessRestrictionTest.
+    *
+    * @param name the test name
+    */
+   protected AccessRestrictionTest(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Default setup with security manager enabled
+    *
+    * @param clazz the class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
+      delegate.enableSecurity = true;
+      return delegate;
+   }
+
+   protected abstract T getInstance();
+   protected abstract Class<T> getInstanceClass();
+   protected abstract String getPublicString(T instance);
+   protected abstract String getPrivateString(T instance);
+
+   public void testBeanFieldAccess() throws Throwable
+   {
+      // First try to get the Bean info without the priviledge on the private field
+      T test = getInstance();
+      // This should work
+      BeanInfo beanInfo = configuration.getBeanInfo(getInstanceClass(), BeanAccessMode.ALL);
+      
+      // We should be able to set the public field
+      beanInfo.setProperty(test, "pubString", "public");
+      assertEquals("public", getPublicString(test));
+      
+      // But we shouldn't be able to set the private field
+      try
+      {
+         beanInfo.setProperty(test, "privString", "private");
+         fail("should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(AccessControlException.class, t);
+      }
+      try
+      {
+         beanInfo.getProperty(test, "privString");
+         fail("should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(AccessControlException.class, t);
+      }
+      assertNull(getPrivateString(test));
+
+      // Repeat for the properties
+      PropertyInfo pubProp = beanInfo.getProperty("pubString");
+      test = getInstance();
+      
+      pubProp.set(test, "public");
+      assertEquals("public", getPublicString(test));
+      
+      PropertyInfo privProp = beanInfo.getProperty("privString");
+      try
+      {
+         privProp.set(test, "private");
+         fail("should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(AccessControlException.class, t);
+      }
+      try
+      {
+         privProp.get(test);
+         fail("should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(AccessControlException.class, t);
+      }
+      assertNull(getPrivateString(test));
+      
+      // Now lets disable security and check we can do what we couldn't do before
+      SecurityManager sm = suspendSecurity();
+      try
+      {
+         test = getInstance();
+         beanInfo.setProperty(test, "privString", "private");
+         assertEquals("private", beanInfo.getProperty(test, "privString"));
+
+         test = getInstance();
+         privProp.set(test, "private");
+         assertEquals("private", privProp.get(test));
+      }
+      finally
+      {
+         resumeSecurity(sm);
+      }
+   }
+}

Deleted: projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTestCase.java	2008-05-08 06:05:53 UTC (rev 73140)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTestCase.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -1,153 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.beaninfo.test;
-
-import java.security.AccessControlException;
-
-import junit.framework.Test;
-
-import org.jboss.beans.info.spi.BeanAccessMode;
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.config.plugins.BasicConfiguration;
-import org.jboss.config.spi.Configuration;
-import org.jboss.test.AbstractTestCaseWithSetup;
-import org.jboss.test.AbstractTestDelegate;
-import org.jboss.test.beaninfo.support.FieldsClass;
-
-/**
- * Access restriction test.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
-public class AccessRestrictionTestCase extends AbstractTestCaseWithSetup
-{
-   /** The bean info factory */
-   private Configuration configuration = new BasicConfiguration();
-
-   /**
-    * Create a new ContainerTest.
-    *
-    * @param name the test name
-    */
-   public AccessRestrictionTestCase(String name)
-   {
-      super(name);
-   }
-
-   public static Test suite()
-   {
-      return suite(AccessRestrictionTestCase.class);
-   }
-
-   /**
-    * Default setup with security manager enabled
-    *
-    * @param clazz the class
-    * @return the delegate
-    * @throws Exception for any error
-    */
-   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
-   {
-      AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
-      delegate.enableSecurity = true;
-      return delegate;
-   }
-
-   public void testBeanFieldAccess() throws Throwable
-   {
-      // First try to get the Bean info without the priviledge on the private field
-      FieldsClass test = new FieldsClass();
-      // This should work
-      BeanInfo beanInfo = configuration.getBeanInfo(FieldsClass.class, BeanAccessMode.ALL);
-      
-      // We should be able to set the public field
-      beanInfo.setProperty(test, "pubString", "public");
-      assertEquals("public", test.pubString);
-      
-      // But we shouldn't be able to set the private field
-      try
-      {
-         beanInfo.setProperty(test, "privString", "private");
-         fail("should not be here");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(AccessControlException.class, t);
-      }
-      try
-      {
-         beanInfo.getProperty(test, "privString");
-         fail("should not be here");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(AccessControlException.class, t);
-      }
-      assertNull(test.getPrivStringNotGetter());
-
-      // Repeat for the properties
-      PropertyInfo pubProp = beanInfo.getProperty("pubString");
-      test = new FieldsClass();
-      
-      pubProp.set(test, "public");
-      assertEquals("public", test.pubString);
-      
-      PropertyInfo privProp = beanInfo.getProperty("privString");
-      try
-      {
-         privProp.set(test, "private");
-         fail("should not be here");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(AccessControlException.class, t);
-      }
-      try
-      {
-         privProp.get(test);
-         fail("should not be here");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(AccessControlException.class, t);
-      }
-      assertNull(test.getPrivStringNotGetter());
-      
-      // Now lets disable security and check we can do what we couldn't do before
-      SecurityManager sm = suspendSecurity();
-      try
-      {
-         test = new FieldsClass();
-         beanInfo.setProperty(test, "privString", "private");
-         assertEquals("private", beanInfo.getProperty(test, "privString"));
-
-         test = new FieldsClass();
-         privProp.set(test, "private");
-         assertEquals("private", privProp.get(test));
-      }
-      finally
-      {
-         resumeSecurity(sm);
-      }
-   }
-}

Modified: projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java	2008-05-08 06:05:53 UTC (rev 73140)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -44,7 +44,8 @@
 
       suite.addTest(BeanInfoUnitTestCase.suite());
       suite.addTest(BeanInfoUtilTestCase.suite());
-      suite.addTest(AccessRestrictionTestCase.suite());
+      suite.addTest(FieldAccessRestrictionTestCase.suite());
+      suite.addTest(MethodAccessRestrictionTestCase.suite());
 
       return suite;
    }

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/FieldAccessRestrictionTestCase.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/AccessRestrictionTestCase.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/FieldAccessRestrictionTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/FieldAccessRestrictionTestCase.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,63 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beaninfo.test;
+
+import junit.framework.Test;
+import org.jboss.test.beaninfo.support.FieldsClass;
+
+/**
+ * Field access restriction test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FieldAccessRestrictionTestCase extends AccessRestrictionTest<FieldsClass>
+{
+   public FieldAccessRestrictionTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(FieldAccessRestrictionTestCase.class);
+   }
+
+   protected FieldsClass getInstance()
+   {
+      return new FieldsClass();
+   }
+
+   protected Class<FieldsClass> getInstanceClass()
+   {
+      return FieldsClass.class;
+   }
+
+   protected String getPublicString(FieldsClass instance)
+   {
+      return instance.pubString;
+   }
+
+   protected String getPrivateString(FieldsClass instance)
+   {
+      return instance.getPrivStringNotGetter();
+   }
+}
\ No newline at end of file

Added: projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/MethodAccessRestrictionTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/MethodAccessRestrictionTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/beaninfo/test/MethodAccessRestrictionTestCase.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,63 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beaninfo.test;
+
+import junit.framework.Test;
+import org.jboss.test.beaninfo.support.MethodsClass;
+
+/**
+ * Field access restriction test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MethodAccessRestrictionTestCase extends AccessRestrictionTest<MethodsClass>
+{
+   public MethodAccessRestrictionTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(MethodAccessRestrictionTestCase.class);
+   }
+
+   protected MethodsClass getInstance()
+   {
+      return new MethodsClass();
+   }
+
+   protected Class<MethodsClass> getInstanceClass()
+   {
+      return MethodsClass.class;
+   }
+
+   protected String getPublicString(MethodsClass instance)
+   {
+      return instance.getPubString();
+   }
+
+   protected String getPrivateString(MethodsClass instance)
+   {
+      return instance.getPrivStringNotGetter();
+   }
+}
\ No newline at end of file

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/support/MethodsClass.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/support/FieldsClass.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/support/MethodsClass.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/support/MethodsClass.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.classinfo.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MethodsClass
+{
+   private String privString;
+   protected String protString;
+   public String pubString;
+
+   public String getPrivStringNotGetter()
+   {
+      return privString;
+   }
+
+   @SuppressWarnings("unused")
+   private String getPrivString()
+   {
+      return privString;
+   }
+
+   @SuppressWarnings("unused")
+   private void setPrivString(String privString)
+   {
+      this.privString = privString;
+   }
+
+   protected String getProtString()
+   {
+      return protString;
+   }
+
+   protected void setProtString(String protString)
+   {
+      this.protString = protString;
+   }
+
+   public String getPubString()
+   {
+      return pubString;
+   }
+
+   public void setPubString(String pubString)
+   {
+      this.pubString = pubString;
+   }
+}
\ No newline at end of file

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTest.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTestCase.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTest.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTest.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,237 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.classinfo.test;
+
+import java.lang.reflect.AccessibleObject;
+import java.security.AccessControlException;
+
+import org.jboss.config.plugins.BasicConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.reflect.spi.AnnotatedInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.classinfo.support.ErrorHolderThread;
+
+/**
+ * Access restriction test.
+ *
+ * @param <T> exact tester type
+ * @param <U> exact annotated info
+ * @param <V> exact accessible object
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AccessRestrictionTest<T, U extends AnnotatedInfo, V extends AccessibleObject> extends AbstractTestCaseWithSetup
+{
+   /** The bean info factory */
+   protected Configuration configuration = new BasicConfiguration();
+
+   /**
+    * Create a new AccessRestrictionTest.
+    *
+    * @param name the test name
+    */
+   protected AccessRestrictionTest(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Default setup with security manager enabled
+    *
+    * @param clazz the class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
+      delegate.enableSecurity = true;
+      return delegate;
+   }
+
+   protected ClassInfo getClassInfo(Class<?> clazz)
+   {
+      SecurityManager sm = suspendSecurity();
+      try
+      {
+         return configuration.getClassInfo(clazz);
+      }
+      finally
+      {
+         resumeSecurity(sm);
+      }
+   }
+
+   protected abstract T getInstance();
+   protected abstract Class<T> getInstanceClass();
+   protected abstract U getInfo();
+   protected abstract U getSetAnnotatedInfo(ClassInfo info, String member);
+   protected abstract U getGetAnnotatedInfo(ClassInfo info, String member);
+   protected abstract V getAccessibleObject(String member) throws Exception;
+   protected abstract void set(U annotatedInfo, T instance, String string) throws Throwable;
+   protected abstract Object get(U annotatedInfo, T instance) throws Throwable;
+   protected abstract void set(V accessibleObject, T instance, String string) throws Exception;
+   protected abstract void set(U info, V accessibleObject);
+   protected abstract String getPrivateString(T instance);
+   protected abstract V getAccessibleObject(U info);
+
+   public void testFieldAcessFromMain() throws Throwable
+   {
+      final T tester = getInstance();
+      final U impl = getInfo();
+
+      // I can't do setAccesible
+      V accessibleObject = getAccessibleObject("privString");
+      // let's try accessible
+      try
+      {
+         accessibleObject.setAccessible(true);
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         assertInstanceOf(t, AccessControlException.class);
+      }
+      // ok, setAccessible not set, so set should also fail
+      try
+      {
+         set(accessibleObject, tester, "foobar");
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         assertInstanceOf(t, IllegalAccessException.class);
+      }
+
+      try
+      {
+         set(impl, accessibleObject);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(AccessControlException.class, t);
+      }
+      try
+      {
+         set(accessibleObject, tester, "foobar");
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalAccessException.class, t);
+      }
+      assertNull(getPrivateString(tester));
+
+      Runnable runnable = new Runnable()
+      {
+         public void run()
+         {
+            try
+            {
+               V ao = getAccessibleObject(impl); // This should have an access check
+               set(ao, tester, "something"); // this should check for caller
+            }
+            catch (Throwable t)
+            {
+               throw new RuntimeException(t);
+            }
+         }
+      };
+      ErrorHolderThread other = new ErrorHolderThread(runnable);
+      other.start();
+      other.join();
+      // we should get an error here
+      assertNotNull("Should get access restriction exception.", other.getError());
+      RuntimeException re = assertInstanceOf(other.getError(), RuntimeException.class);
+      Throwable cause = re.getCause();
+      assertNotNull(cause);
+      assertInstanceOf(cause, AccessControlException.class, false);
+   }
+
+   public void testFieldAccessFromOther() throws Throwable
+   {
+      final T tester = getInstance();
+      ClassInfo classInfo = configuration.getClassInfo(getInstanceClass());
+      // we should not fail
+      U pub = getGetAnnotatedInfo(classInfo, "pubString");
+      assertNotNull(pub);
+      final U priSet = getSetAnnotatedInfo(classInfo, "privString");
+      final U priGet = getGetAnnotatedInfo(classInfo, "privString");
+
+      // Shouldn't be able to set the private field
+      try
+      {
+         set(priSet, tester, "foobar");
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         assertInstanceOf(t, AccessControlException.class);
+      }
+      // Shouldn't be able to get the private field
+      try
+      {
+         get(priGet, tester);
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         assertInstanceOf(t, AccessControlException.class);
+      }
+      // Shouldn't be able to steal the private field which has setAccessible(true)
+      try
+      {
+         getAccessibleObject(priGet);
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         assertInstanceOf(t, AccessControlException.class);
+      }
+      ErrorHolderThread other = new ErrorHolderThread(new Runnable()
+      {
+         public void run()
+         {
+            SecurityManager sm = suspendSecurity();
+            try
+            {
+               set(priSet, tester, "foobar");
+            }
+            catch(Throwable t)
+            {
+               throw new RuntimeException(t);
+            }
+            finally
+            {
+               resumeSecurity(sm);
+            }
+         }
+      });
+      assertNull(getPrivateString(tester));
+      other.start();
+      other.join();
+      assertNull(other.getError());
+      assertEquals("foobar", getPrivateString(tester));
+   }
+}

Deleted: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTestCase.java	2008-05-08 06:05:53 UTC (rev 73140)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTestCase.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -1,229 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.classinfo.test;
-
-import java.lang.reflect.Field;
-import java.security.AccessControlException;
-
-import junit.framework.Test;
-
-import org.jboss.config.plugins.BasicConfiguration;
-import org.jboss.config.spi.Configuration;
-import org.jboss.reflect.plugins.introspection.ReflectFieldInfoImpl;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.FieldInfo;
-import org.jboss.test.AbstractTestCaseWithSetup;
-import org.jboss.test.AbstractTestDelegate;
-import org.jboss.test.classinfo.support.ErrorHolderThread;
-import org.jboss.test.classinfo.support.FieldsClass;
-
-/**
- * Access restriction test.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
-public class AccessRestrictionTestCase extends AbstractTestCaseWithSetup
-{
-   /** The bean info factory */
-   private Configuration configuration = new BasicConfiguration();
-
-   /**
-    * Create a new ContainerTest.
-    *
-    * @param name the test name
-    */
-   public AccessRestrictionTestCase(String name)
-   {
-      super(name);
-   }
-
-   public static Test suite()
-   {
-      return suite(AccessRestrictionTestCase.class);
-   }
-
-   /**
-    * Default setup with security manager enabled
-    *
-    * @param clazz the class
-    * @return the delegate
-    * @throws Exception for any error
-    */
-   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
-   {
-      AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
-      delegate.enableSecurity = true;
-      return delegate;
-   }
-
-   protected ClassInfo getClassInfo(Class<?> clazz)
-   {
-      SecurityManager sm = suspendSecurity();
-      try
-      {
-         return configuration.getClassInfo(clazz);
-      }
-      finally
-      {
-         resumeSecurity(sm);
-      }
-   }
-
-   public void testFieldAcessFromMain() throws Throwable
-   {
-      final FieldsClass tester = new FieldsClass();
-      final ReflectFieldInfoImpl impl = new ReflectFieldInfoImpl();
-
-      // I can't do setAccesible
-      Field field = FieldsClass.class.getDeclaredField("privString");
-      // let's try accessible
-      try
-      {
-         field.setAccessible(true);
-         fail("Should not be here.");
-      }
-      catch (Throwable t)
-      {
-         assertInstanceOf(t, AccessControlException.class);
-      }
-      // ok, setAccessible not set, so set should also fail
-      try
-      {
-         field.set(tester, "foobar");
-         fail("Should not be here.");
-      }
-      catch (Throwable t)
-      {
-         assertInstanceOf(t, IllegalAccessException.class);
-      }
-
-      try
-      {
-         impl.setField(field);
-         fail("Should not be here");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(AccessControlException.class, t);
-      }
-      try
-      {
-         field.set(tester, "foobar");
-         fail("Should not be here");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalAccessException.class, t);
-      }
-      assertNull("foobar", tester.getPrivString());
-
-      Runnable runnable = new Runnable()
-      {
-         public void run()
-         {
-            try
-            {
-               Field fi = impl.getField(); // This should have an access check
-               fi.set(tester, "something"); // this should check for caller
-            }
-            catch (Throwable t)
-            {
-               throw new RuntimeException(t);
-            }
-         }
-      };
-      ErrorHolderThread other = new ErrorHolderThread(runnable);
-      other.start();
-      other.join();
-      // we should get an error here
-      assertNotNull("Should get access restriction exception.", other.getError());
-      RuntimeException re = assertInstanceOf(other.getError(), RuntimeException.class);
-      Throwable cause = re.getCause();
-      assertNotNull(cause);
-      assertInstanceOf(cause, AccessControlException.class, false);
-   }
-
-   public void testFieldAccessFromOther() throws Throwable
-   {
-      final FieldsClass tester = new FieldsClass();
-      ClassInfo classInfo = configuration.getClassInfo(FieldsClass.class);
-      // we should not fail
-      FieldInfo pub = classInfo.getDeclaredField("pubString");
-      assertNotNull(pub);
-      final FieldInfo pri = classInfo.getDeclaredField("privString");
-
-      // Shouldn't be able to set the private field
-      try
-      {
-         pri.set(tester, "foobar");
-         fail("Should not be here.");
-      }
-      catch (Throwable t)
-      {
-         assertInstanceOf(t, AccessControlException.class);
-      }
-      // Shouldn't be able to get the private field
-      try
-      {
-         pri.get(tester);
-         fail("Should not be here.");
-      }
-      catch (Throwable t)
-      {
-         assertInstanceOf(t, AccessControlException.class);
-      }
-      // Shouldn't be able to steal the private field which has setAccessible(true)
-      try
-      {
-         ((ReflectFieldInfoImpl) pri).getField();
-         fail("Should not be here.");
-      }
-      catch (Throwable t)
-      {
-         assertInstanceOf(t, AccessControlException.class);
-      }
-      ErrorHolderThread other = new ErrorHolderThread(new Runnable()
-      {
-         public void run()
-         {
-            SecurityManager sm = suspendSecurity();
-            try
-            {
-               pri.set(tester, "foobar");
-            }
-            catch(Throwable t)
-            {
-               throw new RuntimeException(t);
-            }
-            finally
-            {
-               resumeSecurity(sm);
-            }
-         }
-      });
-      assertNull(tester.getPrivString());
-      other.start();
-      other.join();
-      assertNull(other.getError());
-      assertEquals("foobar", tester.getPrivString());
-   }
-}

Modified: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2008-05-08 06:05:53 UTC (rev 73140)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -58,7 +58,8 @@
       suite.addTest(JavassistAnnotatedClassInfoTestCase.suite());
       suite.addTest(IntrospectionGenericInterfaceUnitTestCase.suite());
       suite.addTest(IntrospectionGenericClassUnitTestCase.suite());
-      suite.addTest(AccessRestrictionTestCase.suite());
+      suite.addTest(FieldAccessRestrictionTestCase.suite());
+      suite.addTest(MethodAccessRestrictionTestCase.suite());
 
       return suite;
    }

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/FieldAccessRestrictionTestCase.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AccessRestrictionTestCase.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/FieldAccessRestrictionTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/FieldAccessRestrictionTestCase.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,113 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.classinfo.test;
+
+import java.lang.reflect.Field;
+
+import junit.framework.Test;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.FieldInfo;
+import org.jboss.reflect.plugins.introspection.ReflectFieldInfoImpl;
+import org.jboss.test.classinfo.support.FieldsClass;
+
+/**
+ * Access restriction test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FieldAccessRestrictionTestCase extends AccessRestrictionTest<FieldsClass, FieldInfo, Field>
+{
+   /**
+    * Create a new FieldAccessRestrictionTestCase.
+    *
+    * @param name the test name
+    */
+   public FieldAccessRestrictionTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(FieldAccessRestrictionTestCase.class);
+   }
+
+   protected FieldsClass getInstance()
+   {
+      return new FieldsClass();
+   }
+
+   protected Class<FieldsClass> getInstanceClass()
+   {
+      return FieldsClass.class;
+   }
+
+   protected FieldInfo getInfo()
+   {
+      return new ReflectFieldInfoImpl();
+   }
+
+   protected FieldInfo getSetAnnotatedInfo(ClassInfo info, String member)
+   {
+      return info.getDeclaredField(member);  
+   }
+
+   protected FieldInfo getGetAnnotatedInfo(ClassInfo info, String member)
+   {
+      return info.getDeclaredField(member);
+   }
+
+   protected Field getAccessibleObject(String member) throws NoSuchFieldException
+   {
+      return getInstanceClass().getDeclaredField(member);
+   }
+
+   protected void set(FieldInfo annotatedInfo, FieldsClass instance, String string) throws Throwable
+   {
+      annotatedInfo.set(instance, string);
+   }
+
+   protected Object get(FieldInfo annotatedInfo, FieldsClass instance) throws Throwable
+   {
+      return annotatedInfo.get(instance);
+   }
+
+   protected void set(Field accessibleObject, FieldsClass instance, String string) throws IllegalAccessException
+   {
+      accessibleObject.set(instance, string);
+   }
+
+   protected void set(FieldInfo info, Field accessibleObject)
+   {
+      ((ReflectFieldInfoImpl)info).setField(accessibleObject);
+   }
+
+   protected String getPrivateString(FieldsClass instance)
+   {
+      return instance.getPrivString();
+   }
+
+   protected Field getAccessibleObject(FieldInfo info)
+   {
+      return ((ReflectFieldInfoImpl)info).getField();
+   }
+}
\ No newline at end of file

Added: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/MethodAccessRestrictionTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/MethodAccessRestrictionTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/MethodAccessRestrictionTestCase.java	2008-05-08 06:11:47 UTC (rev 73141)
@@ -0,0 +1,124 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.classinfo.test;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl;
+import org.jboss.test.classinfo.support.MethodsClass;
+
+/**
+ * Access restriction test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MethodAccessRestrictionTestCase extends AccessRestrictionTest<MethodsClass, MethodInfo, Method>
+{
+   /**
+    * Create a new MethodAccessRestrictionTestCase.
+    *
+    * @param name the test name
+    */
+   public MethodAccessRestrictionTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(MethodAccessRestrictionTestCase.class);
+   }
+
+   protected MethodsClass getInstance()
+   {
+      return new MethodsClass();
+   }
+
+   protected Class<MethodsClass> getInstanceClass()
+   {
+      return MethodsClass.class;
+   }
+
+   protected MethodInfo getInfo()
+   {
+      return new ReflectMethodInfoImpl();
+   }
+
+   protected String getGetter(String member)
+   {
+      return "get" + member.substring(0, 1).toUpperCase() + member.substring(1);
+   }
+
+   protected String getSetter(String member)
+   {
+      return "set" + member.substring(0, 1).toUpperCase() + member.substring(1);
+   }
+
+   protected MethodInfo getSetAnnotatedInfo(ClassInfo info, String member)
+   {
+      return info.getDeclaredMethod(getSetter(member), new TypeInfo[]{configuration.getClassInfo(String.class)});  
+   }
+
+   protected MethodInfo getGetAnnotatedInfo(ClassInfo info, String member)
+   {
+      return info.getDeclaredMethod(getGetter(member), new TypeInfo[]{});
+   }
+
+   protected Method getAccessibleObject(String member) throws NoSuchMethodException
+   {
+      return getInstanceClass().getDeclaredMethod(getGetter(member));
+   }
+
+   protected void set(MethodInfo annotatedInfo, MethodsClass instance, String string) throws Throwable
+   {
+      annotatedInfo.invoke(instance, new Object[]{string});
+   }
+
+   protected Object get(MethodInfo annotatedInfo, MethodsClass instance) throws Throwable
+   {
+      return annotatedInfo.invoke(instance, new Object[]{});
+   }
+
+   protected void set(Method accessibleObject, MethodsClass instance, String string) throws Exception
+   {
+      accessibleObject.invoke(instance, string);
+   }
+
+   protected void set(MethodInfo info, Method accessibleObject)
+   {
+      ((ReflectMethodInfoImpl)info).setMethod(accessibleObject);
+   }
+
+   protected String getPrivateString(MethodsClass instance)
+   {
+      return instance.getPrivStringNotGetter();
+   }
+
+   protected Method getAccessibleObject(MethodInfo info)
+   {
+      return ((ReflectMethodInfoImpl)info).getMethod();
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list