01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: TestClassCatalog.java,v 1.16.2.2 2008/01/07 15:14:22 cwl Exp $
07: */
08:
09: 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: /**
18: * @author Mark Hayes
19: */
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() throws DatabaseException {
30: }
31:
32: public synchronized byte[] getClassID(ObjectStreamClass desc)
33: throws DatabaseException {
34:
35: String className = desc.getName();
36: byte[] id = (byte[]) nameToIdMap.get(className);
37: if (id == null) {
38: String strId = String.valueOf(nextId);
39: id = strId.getBytes();
40: nextId += 1;
41:
42: idToDescMap.put(strId, desc);
43: nameToIdMap.put(className, id);
44: }
45: return id;
46: }
47:
48: public synchronized ObjectStreamClass getClassFormat(byte[] id)
49: throws DatabaseException {
50:
51: String strId = new String(id);
52: ObjectStreamClass desc = (ObjectStreamClass) idToDescMap
53: .get(strId);
54: if (desc == null) {
55: throw new DatabaseException("classID not found");
56: }
57: return desc;
58: }
59: }
|