00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sleepycat.bind.serial.test;
00011
00012 import java.io.ObjectStreamClass;
00013 import java.util.HashMap;
00014
00015 import com.sleepycat.bind.serial.ClassCatalog;
00016 import com.sleepycat.db.DatabaseException;
00017
00021 public class TestClassCatalog implements ClassCatalog {
00022
00023 private HashMap idToDescMap = new HashMap();
00024 private HashMap nameToIdMap = new HashMap();
00025 private int nextId = 1;
00026
00027 public TestClassCatalog() {
00028 }
00029
00030 public void close()
00031 throws DatabaseException {
00032 }
00033
00034 public synchronized byte[] getClassID(ObjectStreamClass desc)
00035 throws DatabaseException {
00036
00037 String className = desc.getName();
00038 byte[] id = (byte[]) nameToIdMap.get(className);
00039 if (id == null) {
00040 String strId = String.valueOf(nextId);
00041 id = strId.getBytes();
00042 nextId += 1;
00043
00044 idToDescMap.put(strId, desc);
00045 nameToIdMap.put(className, id);
00046 }
00047 return id;
00048 }
00049
00050 public synchronized ObjectStreamClass getClassFormat(byte[] id)
00051 throws DatabaseException {
00052
00053 String strId = new String(id);
00054 ObjectStreamClass desc = (ObjectStreamClass) idToDescMap.get(strId);
00055 if (desc == null) {
00056 throw new DatabaseException("classID not found");
00057 }
00058 return desc;
00059 }
00060 }