[Jboss-cvs] JBossAS SVN: r56324 - branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 28 01:34:56 EDT 2006


Author: bstansberry at jboss.com
Date: 2006-08-28 01:34:55 -0400 (Mon, 28 Aug 2006)
New Revision: 56324

Modified:
   branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java
Log:
Move type parsing from JBCService to Util

Modified: branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java
===================================================================
--- branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java	2006-08-28 03:41:53 UTC (rev 56323)
+++ branches/Branch_4_0/tomcat/src/main/org/jboss/web/tomcat/tc5/session/Util.java	2006-08-28 05:34:55 UTC (rev 56324)
@@ -23,11 +23,15 @@
 package org.jboss.web.tomcat.tc5.session;
 
 import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.jboss.aop.Advised;
-import org.jboss.cache.aop.CachedType;
 
 /**
  * Utility methods related to JBoss distributed sessions.
@@ -35,8 +39,27 @@
  * @author Brian Stansberry
  * @version $Revision$
  */
-public abstract class Util
+public class Util
 {
+   // Types that are considered "primitive".
+   private static final Set immediates =
+      new HashSet(Arrays.asList(new Object[]{
+         String.class,
+         Boolean.class,
+         Double.class,
+         Float.class,
+         Integer.class,
+         Long.class,
+         Short.class,
+         Character.class,
+         Boolean.TYPE,
+         Double.TYPE,
+         Float.TYPE,
+         Integer.TYPE,
+         Long.TYPE,
+         Short.TYPE,
+         Character.TYPE,
+         Class.class}));
 
    /**
     * Returns a session id with any trailing jvmRoute removed.
@@ -73,10 +96,51 @@
               || (pojo instanceof Collection) 
               || (pojo instanceof Map) 
               || (pojo instanceof Advised)
-              || (CachedType.isImmediate(pojo.getClass())));
+              || (immediates.contains(pojo.getClass())));
    }
+   
+   public static Set parseComplexFields(Class clazz)
+   {
+      Set result = new HashSet();
+      
+      while (clazz != null)
+      {
+         Field[] fields = clazz.getDeclaredFields();
+         for (int i = 0; i < fields.length; i++)
+         {
+            if (!immediates.contains(fields[i].getType()) 
+                  && isReplicatable(fields[i]))
+            {
+               result.add(fields[i].getName());
+            }
+         }
+         
+         clazz = clazz.getSuperclass();
+      }
+      return result;
+   }
 
    /**
+    * Returns false if the given field is static, transient or final.
+    * 
+    * @param f the field
+    * @return
+    */
+   public static boolean isReplicatable(Field f) {
+      int mods = f.getModifiers();
+      /**
+       * The following modifiers are ignored in the cache, i.e., they will not be stored in the cache.
+       * Whenever, user trying to access these fields, it will be accessed from the in-memory version.
+       */
+      if (Modifier.isStatic(mods)
+            || Modifier.isTransient(mods)
+            || Modifier.isFinal(mods)) {
+         return false;
+      }
+      return true;
+   }
+
+   /**
     * Prevent instantiation.
     */
    private Util() {}




More information about the jboss-cvs-commits mailing list