01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: ReadOnlyCatalog.java,v 1.8.2.3 2008/01/07 15:14:20 cwl Exp $
07: */
08:
09: package com.sleepycat.persist.impl;
10:
11: import java.util.IdentityHashMap;
12: import java.util.List;
13: import java.util.Map;
14: import java.util.NoSuchElementException;
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<Format> formatList;
30: private Map<String, Format> formatMap;
31:
32: ReadOnlyCatalog(List<Format> formatList,
33: Map<String, Format> formatMap) {
34: this .formatList = formatList;
35: this .formatMap = formatMap;
36: }
37:
38: public int getInitVersion(Format format, boolean forReader) {
39: return Catalog.CURRENT_VERSION;
40: }
41:
42: public Format getFormat(int formatId) {
43: try {
44: Format format = formatList.get(formatId);
45: if (format == null) {
46: throw new IllegalStateException(
47: "Format does not exist: " + formatId);
48: }
49: return format;
50: } catch (NoSuchElementException e) {
51: throw new IllegalStateException("Format does not exist: "
52: + formatId);
53: }
54: }
55:
56: public Format getFormat(Class cls) {
57: Format format = formatMap.get(cls.getName());
58: if (format == null) {
59: throw new IllegalArgumentException(
60: "Class is not persistent: " + cls.getName());
61: }
62: return format;
63: }
64:
65: public Format getFormat(String className) {
66: return formatMap.get(className);
67: }
68:
69: public Format createFormat(String clsName,
70: Map<String, Format> newFormats) {
71: throw new IllegalStateException();
72: }
73:
74: public Format createFormat(Class type,
75: Map<String, Format> newFormats) {
76: throw new IllegalStateException();
77: }
78:
79: public boolean isRawAccess() {
80: return false;
81: }
82:
83: public Object convertRawObject(RawObject o,
84: IdentityHashMap converted) {
85: throw new IllegalStateException();
86: }
87: }
|