KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > impl > ReadOnlyCatalog


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: ReadOnlyCatalog.java,v 1.8 2006/10/30 21:14:32 bostic Exp $
7  */

8
9 package com.sleepycat.persist.impl;
10
11 import java.util.IdentityHashMap JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.NoSuchElementException JavaDoc;
15
16 import com.sleepycat.persist.raw.RawObject;
17
18 /**
19  * Read-only catalog operations used when initializing new formats. This
20  * catalog is used temprarily when the main catalog has not been updated yet,
21  * but the new formats need to do catalog lookups.
22  *
23  * @see PersistCatalog#addNewFormat
24  *
25  * @author Mark Hayes
26  */

27 class ReadOnlyCatalog implements Catalog {
28
29     private List JavaDoc<Format> formatList;
30     private Map JavaDoc<String JavaDoc,Format> formatMap;
31
32     ReadOnlyCatalog(List JavaDoc<Format> formatList, Map JavaDoc<String JavaDoc,Format> formatMap) {
33         this.formatList = formatList;
34         this.formatMap = formatMap;
35     }
36
37     public Format getFormat(int formatId) {
38         try {
39             Format format = formatList.get(formatId);
40             if (format == null) {
41                 throw new IllegalStateException JavaDoc
42                     ("Format does not exist: " + formatId);
43             }
44             return format;
45         } catch (NoSuchElementException JavaDoc e) {
46             throw new IllegalStateException JavaDoc
47                 ("Format does not exist: " + formatId);
48         }
49     }
50
51     public Format getFormat(Class JavaDoc cls) {
52         Format format = formatMap.get(cls.getName());
53         if (format == null) {
54             throw new IllegalArgumentException JavaDoc
55                 ("Class is not persistent: " + cls.getName());
56         }
57         return format;
58     }
59
60     public Format getFormat(String JavaDoc className) {
61         return formatMap.get(className);
62     }
63
64     public Format createFormat(String JavaDoc clsName, Map JavaDoc<String JavaDoc,Format> newFormats) {
65         throw new IllegalStateException JavaDoc();
66     }
67
68     public Format createFormat(Class JavaDoc type, Map JavaDoc<String JavaDoc,Format> newFormats) {
69         throw new IllegalStateException JavaDoc();
70     }
71
72     public boolean isRawAccess() {
73         return false;
74     }
75
76     public Object JavaDoc convertRawObject(RawObject o, IdentityHashMap JavaDoc converted) {
77         throw new IllegalStateException JavaDoc();
78     }
79 }
80
Popular Tags