1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: TestClassCatalog.java,v 12.6 2008/01/08 20:58:55 bostic Exp $ 7 */ 8 9package com.sleepycat.bind.serial.test; 10 11import java.io.ObjectStreamClass; 12import java.util.HashMap; 13 14import com.sleepycat.bind.serial.ClassCatalog; 15import com.sleepycat.db.DatabaseException; 16 17/** 18 * @author Mark Hayes 19 */ 20public 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