[jboss-cvs] JBossAS SVN: r65879 - projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 5 07:46:40 EDT 2007


Author: alesj
Date: 2007-10-05 07:46:40 -0400 (Fri, 05 Oct 2007)
New Revision: 65879

Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectConstructorInfoImpl.java
   projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectFieldInfoImpl.java
   projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java
   projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectionUtils.java
Log:
Find ReflectX class's Member instance after deserialization.

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectConstructorInfoImpl.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectConstructorInfoImpl.java	2007-10-05 11:02:23 UTC (rev 65878)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectConstructorInfoImpl.java	2007-10-05 11:46:40 UTC (rev 65879)
@@ -21,6 +21,8 @@
 */
 package org.jboss.reflect.plugins.introspection;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.lang.reflect.Constructor;
 
 import org.jboss.reflect.plugins.ConstructorInfoImpl;
@@ -103,4 +105,23 @@
    {
       return ReflectionUtils.newInstance(constructor, args);
    }
+
+   /**
+    * Read the object, handling constructor read.
+    *
+    * @param oistream the stream
+    * @throws IOException io error
+    * @throws ClassNotFoundException cnf error
+    * @throws NoSuchMethodException no such method error
+    */
+   private void readObject(ObjectInputStream oistream)
+         throws IOException, ClassNotFoundException, NoSuchMethodException
+   {
+      oistream.defaultReadObject();
+      int length = parameterTypes != null ? parameterTypes.length : 0;
+      Class<?>[] classes = new Class<?>[length];
+      for(int i = 0; i < length; i++)
+         classes[i] = parameterTypes[i].getType();
+      constructor = ReflectionUtils.findExactConstructor(getDeclaringClass().getType(), classes);
+   }
 }

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectFieldInfoImpl.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectFieldInfoImpl.java	2007-10-05 11:02:23 UTC (rev 65878)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectFieldInfoImpl.java	2007-10-05 11:46:40 UTC (rev 65879)
@@ -21,6 +21,8 @@
 */
 package org.jboss.reflect.plugins.introspection;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.lang.reflect.Field;
 
 import org.jboss.reflect.plugins.FieldInfoImpl;
@@ -92,4 +94,19 @@
    {
       return ReflectionUtils.setField(field, target, value);
    }
+   
+   /**
+    * Read the object, handling field read.
+    *
+    * @param oistream the stream
+    * @throws IOException io error
+    * @throws ClassNotFoundException cnf error
+    * @throws NoSuchFieldException no such field error
+    */
+   private void readObject(ObjectInputStream oistream)
+         throws IOException, ClassNotFoundException, NoSuchFieldException
+   {
+      oistream.defaultReadObject();
+      field = ReflectionUtils.findExactField(getDeclaringClass().getType(), name);
+   }
 }

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java	2007-10-05 11:02:23 UTC (rev 65878)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectMethodInfoImpl.java	2007-10-05 11:46:40 UTC (rev 65879)
@@ -21,6 +21,8 @@
 */
 package org.jboss.reflect.plugins.introspection;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.lang.reflect.Method;
 
 import org.jboss.reflect.plugins.MethodInfoImpl;
@@ -107,4 +109,23 @@
    {
       return ReflectionUtils.invoke(method, target, args);
    }
+
+   /**
+    * Read the object, handling method read.
+    *
+    * @param oistream the stream
+    * @throws IOException io error
+    * @throws ClassNotFoundException cnf error
+    * @throws NoSuchMethodException no such method error
+    */
+   private void readObject(ObjectInputStream oistream)
+         throws IOException, ClassNotFoundException, NoSuchMethodException
+   {
+      oistream.defaultReadObject();
+      int length = parameterTypes != null ? parameterTypes.length : 0;
+      Class<?>[] classes = new Class<?>[length];
+      for(int i = 0; i < length; i++)
+         classes[i] = parameterTypes[i].getType();
+      method = ReflectionUtils.findExactMethod(getDeclaringClass().getType(), name, classes);
+   }
 }

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectionUtils.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectionUtils.java	2007-10-05 11:02:23 UTC (rev 65878)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/introspection/ReflectionUtils.java	2007-10-05 11:46:40 UTC (rev 65879)
@@ -26,6 +26,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import org.jboss.util.Strings;
 
@@ -186,8 +187,127 @@
          throw handleErrors("set", field, target, value, t);
       }
    }
-   
+
    /**
+    * Find the method by name and parameters.
+    *
+    * @param clazz the class to look for method
+    * @param name the name
+    * @param parameterTypes the types
+    * @return method or null if not found
+    */
+   public static Method findMethod(Class clazz, String name, Class<?>... parameterTypes)
+   {
+      if (clazz == null)
+         return null;
+
+      try
+      {
+         return clazz.getDeclaredMethod(name, parameterTypes);
+      }
+      catch(Exception ignored)
+      {
+      }
+      return findMethod(clazz.getSuperclass(), name, parameterTypes);
+   }
+
+   /**
+    * Find the method by name and parameters.
+    *
+    * @param clazz the class to look for method
+    * @param name the name
+    * @param parameterTypes the types
+    * @return method or throw exception if not found
+    * @throws NoSuchMethodException for no such method
+    */
+   public static Method findExactMethod(Class clazz, String name, Class<?>... parameterTypes)
+         throws NoSuchMethodException
+   {
+      Method method = findMethod(clazz, name, parameterTypes);
+      if (method == null)
+         throw new NoSuchMethodException(clazz + "." + name + " - " +  Arrays.asList(parameterTypes));
+      return method;
+   }
+
+   /**
+    * Find the field by name.
+    *
+    * @param clazz the class to look for field
+    * @param name the name
+    * @return field or null if not found
+    */
+   public static Field findField(Class clazz, String name)
+   {
+      if (clazz == null)
+         return null;
+
+      try
+      {
+         return clazz.getDeclaredField(name);
+      }
+      catch(Exception ignored)
+      {
+      }
+      return findField(clazz.getSuperclass(), name);
+   }
+
+   /**
+    * Find the field by name.
+    *
+    * @param clazz the class to look for field
+    * @param name the name
+    * @return field or throw exception if not found
+    * @throws NoSuchFieldException for no such field
+    */
+   public static Field findExactField(Class clazz, String name)
+         throws NoSuchFieldException
+   {
+      Field field = findField(clazz, name);
+      if (field == null)
+         throw new NoSuchFieldException(clazz + "." + name);
+      return field;
+   }
+
+   /**
+    * Find the constructor by parameters.
+    *
+    * @param clazz the class to look for constructor
+    * @param parameterTypes the types
+    * @return constructor or null if not found
+    */
+   public static Constructor findConstructor(Class clazz, Class<?>... parameterTypes)
+   {
+      if (clazz == null)
+         return null;
+
+      try
+      {
+         return clazz.getDeclaredConstructor(parameterTypes);
+      }
+      catch(Exception ignored)
+      {
+      }
+      return findConstructor(clazz.getSuperclass(), parameterTypes);
+   }
+
+   /**
+    * Find the constructor by parameters.
+    *
+    * @param clazz the class to look for constructor
+    * @param parameterTypes the types
+    * @return method or throw exception if not found
+    * @throws NoSuchMethodException for no such method
+    */
+   public static Constructor findExactConstructor(Class clazz, Class<?>... parameterTypes)
+         throws NoSuchMethodException
+   {
+      Constructor constructor = findConstructor(clazz, parameterTypes);
+      if (constructor == null)
+         throw new NoSuchMethodException(clazz + " - " +  Arrays.asList(parameterTypes));
+      return constructor;
+   }
+
+   /**
     * Handle errors
     * 
     * @param context the context




More information about the jboss-cvs-commits mailing list