1 22 23 package org.jboss.web.tomcat.tc6.session; 24 25 import java.io.Serializable ; 26 import java.lang.reflect.Field ; 27 import java.lang.reflect.Modifier ; 28 import java.util.Arrays ; 29 import java.util.Collection ; 30 import java.util.HashSet ; 31 import java.util.Map ; 32 import java.util.Set ; 33 34 import org.jboss.aop.Advised; 35 36 42 public class Util 43 { 44 private static final Set immediates = 46 new HashSet (Arrays.asList(new Object []{ 47 String .class, 48 Boolean .class, 49 Double .class, 50 Float .class, 51 Integer .class, 52 Long .class, 53 Short .class, 54 Character .class, 55 Boolean.TYPE, 56 Double.TYPE, 57 Float.TYPE, 58 Integer.TYPE, 59 Long.TYPE, 60 Short.TYPE, 61 Character.TYPE, 62 Class .class})); 63 64 72 public static String getRealId(String sessionId) 73 { 74 int index = sessionId.lastIndexOf("."); 75 if (index > 0) 76 { 77 return sessionId.substring(0, index); 78 } 79 else 80 { 81 return sessionId; 82 } 83 } 84 85 93 public static boolean checkPojoType(Object pojo) 94 { 95 return ( (pojo instanceof Serializable ) 96 || (pojo instanceof Collection ) 97 || (pojo instanceof Map ) 98 || (pojo instanceof Advised) 99 || (immediates.contains(pojo.getClass()))); 100 } 101 102 public static Set parseComplexFields(Class clazz) 103 { 104 Set result = new HashSet (); 105 106 while (clazz != null) 107 { 108 Field [] fields = clazz.getDeclaredFields(); 109 for (int i = 0; i < fields.length; i++) 110 { 111 if (!immediates.contains(fields[i].getType()) 112 && isReplicatable(fields[i])) 113 { 114 result.add(fields[i].getName()); 115 } 116 } 117 118 clazz = clazz.getSuperclass(); 119 } 120 return result; 121 } 122 123 129 public static boolean isReplicatable(Field f) { 130 int mods = f.getModifiers(); 131 135 if (Modifier.isStatic(mods) 136 || Modifier.isTransient(mods) 137 || Modifier.isFinal(mods)) { 138 return false; 139 } 140 return true; 141 } 142 143 146 private Util() {} 147 148 } 149 | Popular Tags |