1 21 package com.db4o.config; 22 23 import java.util.*; 24 25 import com.db4o.*; 26 27 31 public class TMap implements ObjectTranslator { 32 33 public Object onStore(ObjectContainer con, Object object){ 34 Map map = (Map)object; 35 Entry[] entries = new Entry[map.size()]; 36 Iterator it = map.keySet().iterator(); 37 int i = 0; 38 while(it.hasNext()){ 39 entries[i] = new Entry(); 40 entries[i].key = it.next(); 41 entries[i].value = map.get(entries[i].key); 42 i++; 43 } 44 return entries; 45 } 46 47 public void onActivate(ObjectContainer con, Object object, Object members){ 48 Map map = (Map)object; 49 map.clear(); 50 if(members != null){ 51 Entry[] entries = (Entry[]) members; 52 for(int i = 0; i < entries.length; i++){ 53 if(entries[i] != null){ 54 if(entries[i].key != null && entries[i].value != null){ 55 map.put(entries[i].key,entries[i].value); 56 } 57 } 58 } 59 } 60 } 61 62 public Class storedClass(){ 63 return Entry[].class; 64 } 65 } 66 | Popular Tags |