Source Code Cross Referenced for SimpleCatalog.java in  » JMX » je » com » sleepycat » persist » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » je » com.sleepycat.persist.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2002,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: SimpleCatalog.java,v 1.19.2.5 2008/01/07 15:14:20 cwl Exp $
007:         */
008:
009:        package com.sleepycat.persist.impl;
010:
011:        import java.util.ArrayList;
012:        import java.util.HashMap;
013:        import java.util.IdentityHashMap;
014:        import java.util.List;
015:        import java.util.Map;
016:        import java.util.NoSuchElementException;
017:
018:        import com.sleepycat.persist.model.EntityModel;
019:        import com.sleepycat.persist.raw.RawObject;
020:
021:        /**
022:         * A static catalog containing simple types only.  Once created, this catalog
023:         * is immutable.
024:         *
025:         * For bindings accessed by a PersistComparator during recovery, the
026:         * SimpleCatalog provides formats for all simple types.  To reduce redundant
027:         * format objects, the SimpleCatalog's formats are copied when creating a
028:         * regular PersistCatalog.
029:         *
030:         * This class also contains utility methods for dealing with primitives.
031:         *
032:         * @author Mark Hayes
033:         */
034:        public class SimpleCatalog implements  Catalog {
035:
036:            private static final Map<String, Class> keywordToPrimitive;
037:            static {
038:                keywordToPrimitive = new HashMap<String, Class>(8);
039:                keywordToPrimitive.put("boolean", Boolean.TYPE);
040:                keywordToPrimitive.put("char", Character.TYPE);
041:                keywordToPrimitive.put("byte", Byte.TYPE);
042:                keywordToPrimitive.put("short", Short.TYPE);
043:                keywordToPrimitive.put("int", Integer.TYPE);
044:                keywordToPrimitive.put("long", Long.TYPE);
045:                keywordToPrimitive.put("float", Float.TYPE);
046:                keywordToPrimitive.put("double", Double.TYPE);
047:            }
048:
049:            private static final Map<Class, Class> primitiveTypeToWrapper;
050:            static {
051:                primitiveTypeToWrapper = new HashMap<Class, Class>(8);
052:                primitiveTypeToWrapper.put(Boolean.TYPE, Boolean.class);
053:                primitiveTypeToWrapper.put(Character.TYPE, Character.class);
054:                primitiveTypeToWrapper.put(Byte.TYPE, Byte.class);
055:                primitiveTypeToWrapper.put(Short.TYPE, Short.class);
056:                primitiveTypeToWrapper.put(Integer.TYPE, Integer.class);
057:                primitiveTypeToWrapper.put(Long.TYPE, Long.class);
058:                primitiveTypeToWrapper.put(Float.TYPE, Float.class);
059:                primitiveTypeToWrapper.put(Double.TYPE, Double.class);
060:            }
061:
062:            private static final SimpleCatalog instance = new SimpleCatalog();
063:
064:            static SimpleCatalog getInstance() {
065:                return instance;
066:            }
067:
068:            static boolean isSimpleType(Class type) {
069:                return instance.formatMap.containsKey(type.getName());
070:            }
071:
072:            static Class primitiveToWrapper(Class type) {
073:                Class cls = primitiveTypeToWrapper.get(type);
074:                if (cls == null) {
075:                    throw new IllegalStateException(type.getName());
076:                }
077:                return cls;
078:            }
079:
080:            public static Class keyClassForName(String className) {
081:                Class cls = keywordToPrimitive.get(className);
082:                if (cls != null) {
083:                    cls = primitiveTypeToWrapper.get(cls);
084:                } else {
085:                    try {
086:                        cls = EntityModel.classForName(className);
087:                    } catch (ClassNotFoundException e) {
088:                        throw new IllegalArgumentException(
089:                                "Key class not found: " + className);
090:                    }
091:                }
092:                return cls;
093:            }
094:
095:            public static String keyClassName(String className) {
096:                Class cls = keywordToPrimitive.get(className);
097:                if (cls != null) {
098:                    cls = primitiveTypeToWrapper.get(cls);
099:                    return cls.getName();
100:                } else {
101:                    return className;
102:                }
103:            }
104:
105:            public static Class classForName(String className)
106:                    throws ClassNotFoundException {
107:
108:                Class cls = keywordToPrimitive.get(className);
109:                if (cls == null) {
110:                    cls = EntityModel.classForName(className);
111:                }
112:                return cls;
113:            }
114:
115:            static SimpleFormat getSimpleFormat(Class type) {
116:                return instance.formatMap.get(type.getName());
117:            }
118:
119:            static List<Format> copyFormatList() {
120:                return new ArrayList<Format>(instance.formatList);
121:            }
122:
123:            static boolean copyMissingFormats(List<Format> copyToList) {
124:                boolean anyCopied = false;
125:                for (int i = 0; i <= Format.ID_PREDEFINED; i += 1) {
126:                    Format this Format = instance.formatList.get(i);
127:                    Format otherFormat = copyToList.get(i);
128:                    if (this Format != null && otherFormat == null) {
129:                        copyToList.set(i, this Format);
130:                        anyCopied = true;
131:                    }
132:                }
133:                return anyCopied;
134:            }
135:
136:            private List<SimpleFormat> formatList;
137:            private Map<String, SimpleFormat> formatMap;
138:
139:            private SimpleCatalog() {
140:
141:                /*
142:                 * Reserve slots for all predefined IDs, so that that next ID assigned
143:                 * will be Format.ID_PREDEFINED plus one.
144:                 */
145:                int initCapacity = Format.ID_PREDEFINED * 2;
146:                formatList = new ArrayList<SimpleFormat>(initCapacity);
147:                formatMap = new HashMap<String, SimpleFormat>(initCapacity);
148:
149:                for (int i = 0; i <= Format.ID_PREDEFINED; i += 1) {
150:                    formatList.add(null);
151:                }
152:
153:                /* Initialize all predefined formats.  */
154:                setFormat(Format.ID_BOOL, new SimpleFormat.FBool(true));
155:                setFormat(Format.ID_BOOL_W, new SimpleFormat.FBool(false));
156:                setFormat(Format.ID_BYTE, new SimpleFormat.FByte(true));
157:                setFormat(Format.ID_BYTE_W, new SimpleFormat.FByte(false));
158:                setFormat(Format.ID_SHORT, new SimpleFormat.FShort(true));
159:                setFormat(Format.ID_SHORT_W, new SimpleFormat.FShort(false));
160:                setFormat(Format.ID_INT, new SimpleFormat.FInt(true));
161:                setFormat(Format.ID_INT_W, new SimpleFormat.FInt(false));
162:                setFormat(Format.ID_LONG, new SimpleFormat.FLong(true));
163:                setFormat(Format.ID_LONG_W, new SimpleFormat.FLong(false));
164:                setFormat(Format.ID_FLOAT, new SimpleFormat.FFloat(true));
165:                setFormat(Format.ID_FLOAT_W, new SimpleFormat.FFloat(false));
166:                setFormat(Format.ID_DOUBLE, new SimpleFormat.FDouble(true));
167:                setFormat(Format.ID_DOUBLE_W, new SimpleFormat.FDouble(false));
168:                setFormat(Format.ID_CHAR, new SimpleFormat.FChar(true));
169:                setFormat(Format.ID_CHAR_W, new SimpleFormat.FChar(false));
170:                setFormat(Format.ID_STRING, new SimpleFormat.FString());
171:                setFormat(Format.ID_BIGINT, new SimpleFormat.FBigInt());
172:                /*
173:                setFormat(Format.ID_BIGDEC,   new SimpleFormat.FBigDec());
174:                 */
175:                setFormat(Format.ID_DATE, new SimpleFormat.FDate());
176:
177:                /* Tell primitives about their wrapper class. */
178:                setWrapper(Format.ID_BOOL, Format.ID_BOOL_W);
179:                setWrapper(Format.ID_BYTE, Format.ID_BYTE_W);
180:                setWrapper(Format.ID_SHORT, Format.ID_SHORT_W);
181:                setWrapper(Format.ID_INT, Format.ID_INT_W);
182:                setWrapper(Format.ID_LONG, Format.ID_LONG_W);
183:                setWrapper(Format.ID_FLOAT, Format.ID_FLOAT_W);
184:                setWrapper(Format.ID_DOUBLE, Format.ID_DOUBLE_W);
185:                setWrapper(Format.ID_CHAR, Format.ID_CHAR_W);
186:            }
187:
188:            /**
189:             * Sets a format for which space in the formatList has been preallocated,
190:             * and makes it the current format for the class.
191:             */
192:            private void setFormat(int id, SimpleFormat format) {
193:                format.setId(id);
194:                format.initializeIfNeeded(this );
195:                formatList.set(id, format);
196:                formatMap.put(format.getClassName(), format);
197:            }
198:
199:            /**
200:             * Tells a primitive format about the format for its corresponding
201:             * primitive wrapper class.
202:             */
203:            private void setWrapper(int primitiveId, int wrapperId) {
204:                SimpleFormat primitiveFormat = formatList.get(primitiveId);
205:                SimpleFormat wrapperFormat = formatList.get(wrapperId);
206:                primitiveFormat.setWrapperFormat(wrapperFormat);
207:            }
208:
209:            public int getInitVersion(Format format, boolean forReader) {
210:                return Catalog.CURRENT_VERSION;
211:            }
212:
213:            public Format getFormat(int formatId) {
214:                Format format;
215:                try {
216:                    format = formatList.get(formatId);
217:                    if (format == null) {
218:                        throw new IllegalStateException("Not a simple type: "
219:                                + formatId);
220:                    }
221:                    return format;
222:                } catch (NoSuchElementException e) {
223:                    throw new IllegalStateException("Not a simple type: "
224:                            + formatId);
225:                }
226:            }
227:
228:            public Format getFormat(Class cls) {
229:                Format format = formatMap.get(cls.getName());
230:                if (format == null) {
231:                    throw new IllegalArgumentException("Not a simple type: "
232:                            + cls.getName());
233:                }
234:                return format;
235:            }
236:
237:            public Format getFormat(String className) {
238:                return formatMap.get(className);
239:            }
240:
241:            public Format createFormat(String clsName,
242:                    Map<String, Format> newFormats) {
243:                throw new IllegalStateException();
244:            }
245:
246:            public Format createFormat(Class type,
247:                    Map<String, Format> newFormats) {
248:                throw new IllegalStateException();
249:            }
250:
251:            public boolean isRawAccess() {
252:                return false;
253:            }
254:
255:            public Object convertRawObject(RawObject o,
256:                    IdentityHashMap converted) {
257:                throw new IllegalStateException();
258:            }
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.