Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

TestClassCatalog.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: TestClassCatalog.java,v 12.1 2005/01/31 19:27:35 mark Exp $
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 }

Generated on Sun Dec 25 12:14:53 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2