1 8 9 package com.sleepycat.bind.serial.test; 10 11 import java.io.ObjectStreamClass ; 12 import java.util.HashMap ; 13 14 import com.sleepycat.bind.serial.ClassCatalog; 15 import com.sleepycat.je.DatabaseException; 16 17 20 public class TestClassCatalog implements ClassCatalog { 21 22 private HashMap idToDescMap = new HashMap (); 23 private HashMap nameToIdMap = new HashMap (); 24 private int nextId = 1; 25 26 public TestClassCatalog() { 27 } 28 29 public void close() 30 throws DatabaseException { 31 } 32 33 public synchronized byte[] getClassID(ObjectStreamClass desc) 34 throws DatabaseException { 35 36 String className = desc.getName(); 37 byte[] id = (byte[]) nameToIdMap.get(className); 38 if (id == null) { 39 String strId = String.valueOf(nextId); 40 id = strId.getBytes(); 41 nextId += 1; 42 43 idToDescMap.put(strId, desc); 44 nameToIdMap.put(className, id); 45 } 46 return id; 47 } 48 49 public synchronized ObjectStreamClass getClassFormat(byte[] id) 50 throws DatabaseException { 51 52 String strId = new String (id); 53 ObjectStreamClass desc = (ObjectStreamClass ) idToDescMap.get(strId); 54 if (desc == null) { 55 throw new DatabaseException("classID not found"); 56 } 57 return desc; 58 } 59 } 60 | Popular Tags |