1 10 11 package com.triactive.jdo.sco; 12 13 import com.triactive.jdo.PersistenceManager; 14 import com.triactive.jdo.SCO; 15 import com.triactive.jdo.store.Mapping; 16 import com.triactive.jdo.store.MapMapping; 17 import com.triactive.jdo.store.MapStore; 18 import com.triactive.jdo.store.SetMapping; 19 import com.triactive.jdo.store.SetStore; 20 import javax.jdo.JDOHelper; 21 import javax.jdo.JDOUserException; 22 23 24 32 33 public abstract class SCOProcessor 34 { 35 private static final java.util.HashMap processors = new java.util.HashMap (); 36 37 static 38 { 39 SCOProcessor hashMapProcessor = new HashMapProcessor(); 40 SCOProcessor hashSetProcessor = new HashSetProcessor(); 41 42 processors.put(java.util.Collection .class, hashSetProcessor); 43 processors.put(java.util.Date .class, new DateProcessor()); 44 processors.put(java.util.HashMap .class, hashMapProcessor); 45 processors.put(java.util.HashSet .class, hashSetProcessor); 46 processors.put(java.util.Hashtable .class, new HashtableProcessor()); 47 processors.put(java.util.Map .class, hashMapProcessor); 48 processors.put(java.util.Set .class, hashSetProcessor); 49 processors.put(java.sql.Date .class, new SqlDateProcessor()); 50 processors.put(java.sql.Timestamp .class, new SqlTimestampProcessor()); 51 } 52 53 54 65 66 public static boolean isSecondClassMutableType(Class c) 67 { 68 return processors.containsKey(c); 69 } 70 71 72 80 81 public static SCOProcessor forFieldType(Class c) 82 { 83 return (SCOProcessor)processors.get(c); 84 } 85 86 87 102 103 public abstract SCO newSCOInstance(Object owner, String fieldName, Object value); 104 105 106 private static Mapping getMapping(Object owner, String fieldName) 107 { 108 return ((PersistenceManager)JDOHelper.getPersistenceManager(owner)) 109 .getStoreManager() 110 .getClassBaseTable(owner.getClass()) 111 .getFieldMapping(fieldName); 112 } 113 114 115 118 119 public static abstract class MapProcessor extends SCOProcessor 120 { 121 124 protected MapStore getMapStore(Object owner, String fieldName) 125 { 126 return ((MapMapping)getMapping(owner, fieldName)).getMapStore(); 127 } 128 129 148 public abstract SCO newSCOInstance(Object owner, String fieldName, MapStore mapStore); 149 } 150 151 152 155 156 public static abstract class SetProcessor extends SCOProcessor 157 { 158 161 protected SetStore getSetStore(Object owner, String fieldName) 162 { 163 return ((SetMapping)getMapping(owner, fieldName)).getSetStore(); 164 } 165 166 185 public abstract SCO newSCOInstance(Object owner, String fieldName, SetStore setStore); 186 } 187 188 189 192 public static class DateProcessor extends SCOProcessor 193 { 194 public SCO newSCOInstance(Object owner, String fieldName, Object value) 195 { 196 return new com.triactive.jdo.sco.Date(owner, fieldName, (java.util.Date )value); 197 } 198 } 199 200 203 public static class HashMapProcessor extends MapProcessor 204 { 205 public SCO newSCOInstance(Object owner, String fieldName, MapStore mapStore) 206 { 207 return new com.triactive.jdo.sco.HashMap(owner, fieldName, mapStore); 208 } 209 210 public SCO newSCOInstance(Object owner, String fieldName, Object value) 211 { 212 return new com.triactive.jdo.sco.HashMap(owner, 213 fieldName, 214 getMapStore(owner, fieldName), 215 (java.util.Map )value); 216 } 217 } 218 219 222 public static class HashSetProcessor extends SetProcessor 223 { 224 public SCO newSCOInstance(Object owner, String fieldName, SetStore setStore) 225 { 226 return new com.triactive.jdo.sco.HashSet(owner, fieldName, setStore); 227 } 228 229 public SCO newSCOInstance(Object owner, String fieldName, Object value) 230 { 231 return new com.triactive.jdo.sco.HashSet(owner, 232 fieldName, 233 getSetStore(owner, fieldName), 234 (java.util.Collection )value); 235 } 236 } 237 238 241 public static class HashtableProcessor extends MapProcessor 242 { 243 public SCO newSCOInstance(Object owner, String fieldName, MapStore mapStore) 244 { 245 return new com.triactive.jdo.sco.Hashtable(owner, fieldName, mapStore); 246 } 247 248 public SCO newSCOInstance(Object owner, String fieldName, Object value) 249 { 250 return new com.triactive.jdo.sco.Hashtable(owner, 251 fieldName, 252 getMapStore(owner, fieldName), 253 (java.util.Map )value); 254 } 255 } 256 257 260 public static class SqlDateProcessor extends SCOProcessor 261 { 262 public SCO newSCOInstance(Object owner, String fieldName, Object value) 263 { 264 return new com.triactive.jdo.sco.SqlDate(owner, fieldName, (java.sql.Date )value); 265 } 266 } 267 268 271 public static class SqlTimestampProcessor extends SCOProcessor 272 { 273 public SCO newSCOInstance(Object owner, String fieldName, Object value) 274 { 275 return new com.triactive.jdo.sco.SqlTimestamp(owner, fieldName, (java.sql.Timestamp )value); 276 } 277 } 278 } 279 | Popular Tags |