Source Code Cross Referenced for SelfReflectionRegistry.java in  » Database-DBMS » db4o-6.4 » com » db4o » reflect » self » 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 » Database DBMS » db4o 6.4 » com.db4o.reflect.self 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com
002:
003:        This file is part of the db4o open source object database.
004:
005:        db4o is free software; you can redistribute it and/or modify it under
006:        the terms of version 2 of the GNU General Public License as published
007:        by the Free Software Foundation and as clarified by db4objects' GPL 
008:        interpretation policy, available at
009:        http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010:        Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011:        Suite 350, San Mateo, CA 94403, USA.
012:
013:        db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:        for more details.
017:
018:        You should have received a copy of the GNU General Public License along
019:        with this program; if not, write to the Free Software Foundation, Inc.,
020:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
021:        package com.db4o.reflect.self;
022:
023:        /**
024:         * Contains the application-specific reflection information (that would
025:         * be generated by a bytecode enhancer), as opposed to the 'generic'
026:         * functionality contained in SelfReflector.
027:         */
028:        public abstract class SelfReflectionRegistry {
029:
030:            private final static Class[] ARRAYTYPES = { int[].class,
031:                    long[].class, short[].class, char[].class, byte[].class,
032:                    boolean[].class, float[].class, double[].class,
033:                    String[].class };
034:            private final static Class[] PRIMITIVES = { Integer.class,
035:                    Long.class, Short.class, Character.class, Byte.class,
036:                    Boolean.class, Float.class, Double.class, String.class };
037:
038:            public boolean isPrimitive(Class clazz) {
039:                for (int idx = 0; idx < PRIMITIVES.length; idx++) {
040:                    if (PRIMITIVES[idx].equals(clazz)) {
041:                        return true;
042:                    }
043:                }
044:                return false;
045:            }
046:
047:            public abstract ClassInfo infoFor(Class clazz);
048:
049:            public Object arrayFor(Class clazz, int length) {
050:                if (Integer.class.isAssignableFrom(clazz)
051:                        || int.class.isAssignableFrom(clazz)) {
052:                    return new int[length];
053:                }
054:                if (Long.class.isAssignableFrom(clazz)
055:                        || long.class.isAssignableFrom(clazz)) {
056:                    return new long[length];
057:                }
058:                if (Short.class.isAssignableFrom(clazz)
059:                        || short.class.isAssignableFrom(clazz)) {
060:                    return new short[length];
061:                }
062:                if (Boolean.class.isAssignableFrom(clazz)
063:                        || boolean.class.isAssignableFrom(clazz)) {
064:                    return new boolean[length];
065:                }
066:                if (Byte.class.isAssignableFrom(clazz)
067:                        || byte.class.isAssignableFrom(clazz)) {
068:                    return new byte[length];
069:                }
070:                if (Character.class.isAssignableFrom(clazz)
071:                        || char.class.isAssignableFrom(clazz)) {
072:                    return new char[length];
073:                }
074:                if (Float.class.isAssignableFrom(clazz)
075:                        || float.class.isAssignableFrom(clazz)) {
076:                    return new float[length];
077:                }
078:                if (Double.class.isAssignableFrom(clazz)
079:                        || double.class.isAssignableFrom(clazz)) {
080:                    return new double[length];
081:                }
082:                if (String.class.isAssignableFrom(clazz)) {
083:                    return new String[length];
084:                }
085:                return null;
086:            }
087:
088:            public Class componentType(Class clazz) {
089:                for (int i = 0; i < ARRAYTYPES.length; i++) {
090:                    if (ARRAYTYPES[i].equals(clazz)) {
091:                        return PRIMITIVES[i];
092:                    }
093:                }
094:                return null;
095:            }
096:
097:            public int arrayLength(Object array) {
098:                if (array instanceof  boolean[]) {
099:                    return ((boolean[]) array).length;
100:                }
101:                if (array instanceof  byte[]) {
102:                    return ((byte[]) array).length;
103:                }
104:                if (array instanceof  short[]) {
105:                    return ((short[]) array).length;
106:                }
107:                if (array instanceof  char[]) {
108:                    return ((char[]) array).length;
109:                }
110:                if (array instanceof  int[]) {
111:                    return ((int[]) array).length;
112:                }
113:                if (array instanceof  long[]) {
114:                    return ((long[]) array).length;
115:                }
116:                if (array instanceof  float[]) {
117:                    return ((float[]) array).length;
118:                }
119:                if (array instanceof  double[]) {
120:                    return ((double[]) array).length;
121:                }
122:                return 0;
123:            }
124:
125:            public void setArray(Object array, int index, Object element) {
126:                if (array instanceof  boolean[]) {
127:                    ((boolean[]) array)[index] = ((Boolean) element)
128:                            .booleanValue();
129:                }
130:                if (array instanceof  byte[]) {
131:                    ((byte[]) array)[index] = ((Byte) element).byteValue();
132:                }
133:                if (array instanceof  short[]) {
134:                    ((short[]) array)[index] = ((Short) element).shortValue();
135:                }
136:                if (array instanceof  char[]) {
137:                    ((char[]) array)[index] = ((Character) element).charValue();
138:                }
139:                if (array instanceof  int[]) {
140:                    ((int[]) array)[index] = ((Integer) element).intValue();
141:                }
142:                if (array instanceof  long[]) {
143:                    ((long[]) array)[index] = ((Long) element).longValue();
144:                }
145:                if (array instanceof  float[]) {
146:                    ((float[]) array)[index] = ((Float) element).floatValue();
147:                }
148:                if (array instanceof  double[]) {
149:                    ((double[]) array)[index] = ((Double) element)
150:                            .doubleValue();
151:                }
152:            }
153:
154:            public Object getArray(Object array, int index) {
155:                if (array instanceof  boolean[]) {
156:                    return new Boolean(((boolean[]) array)[index]);
157:                }
158:                if (array instanceof  byte[]) {
159:                    return new Byte(((byte[]) array)[index]);
160:                }
161:                if (array instanceof  short[]) {
162:                    return new Short(((short[]) array)[index]);
163:                }
164:                if (array instanceof  char[]) {
165:                    return new Character(((char[]) array)[index]);
166:                }
167:                if (array instanceof  int[]) {
168:                    return new Integer(((int[]) array)[index]);
169:                }
170:                if (array instanceof  long[]) {
171:                    return new Long(((long[]) array)[index]);
172:                }
173:                if (array instanceof  float[]) {
174:                    return new Float(((float[]) array)[index]);
175:                }
176:                if (array instanceof  double[]) {
177:                    return new Double(((double[]) array)[index]);
178:                }
179:                return null;
180:            }
181:
182:            public int flattenArray(Object array, Object[] a_flat) {
183:                if (array instanceof  boolean[]) {
184:                    boolean[] shaped = (boolean[]) array;
185:                    for (int i = 0; i < shaped.length; i++) {
186:                        a_flat[i] = new Boolean(shaped[i]);
187:                    }
188:                    return shaped.length;
189:                }
190:                if (array instanceof  byte[]) {
191:                    byte[] shaped = (byte[]) array;
192:                    for (int i = 0; i < shaped.length; i++) {
193:                        a_flat[i] = new Byte(shaped[i]);
194:                    }
195:                    return shaped.length;
196:                }
197:                if (array instanceof  short[]) {
198:                    short[] shaped = (short[]) array;
199:                    for (int i = 0; i < shaped.length; i++) {
200:                        a_flat[i] = new Short(shaped[i]);
201:                    }
202:                    return shaped.length;
203:                }
204:                if (array instanceof  char[]) {
205:                    char[] shaped = (char[]) array;
206:                    for (int i = 0; i < shaped.length; i++) {
207:                        a_flat[i] = new Character(shaped[i]);
208:                    }
209:                    return shaped.length;
210:                }
211:                if (array instanceof  int[]) {
212:                    int[] shaped = (int[]) array;
213:                    for (int i = 0; i < shaped.length; i++) {
214:                        a_flat[i] = new Integer(shaped[i]);
215:                    }
216:                    return shaped.length;
217:                }
218:                if (array instanceof  long[]) {
219:                    long[] shaped = (long[]) array;
220:                    for (int i = 0; i < shaped.length; i++) {
221:                        a_flat[i] = new Long(shaped[i]);
222:                    }
223:                    return shaped.length;
224:                }
225:                if (array instanceof  float[]) {
226:                    float[] shaped = (float[]) array;
227:                    for (int i = 0; i < shaped.length; i++) {
228:                        a_flat[i] = new Float(shaped[i]);
229:                    }
230:                    return shaped.length;
231:                }
232:                if (array instanceof  double[]) {
233:                    double[] shaped = (double[]) array;
234:                    for (int i = 0; i < shaped.length; i++) {
235:                        a_flat[i] = new Double(shaped[i]);
236:                    }
237:                    return shaped.length;
238:                }
239:                return 0;
240:            }
241:
242:            public int shapeArray(Object[] a_flat, Object array) {
243:                if (array instanceof  boolean[]) {
244:                    boolean[] shaped = (boolean[]) array;
245:                    for (int i = 0; i < shaped.length; i++) {
246:                        shaped[i] = ((Boolean) a_flat[i]).booleanValue();
247:                    }
248:                    return a_flat.length;
249:                }
250:                if (array instanceof  byte[]) {
251:                    byte[] shaped = (byte[]) array;
252:                    for (int i = 0; i < shaped.length; i++) {
253:                        shaped[i] = ((Byte) a_flat[i]).byteValue();
254:                    }
255:                    return a_flat.length;
256:                }
257:                if (array instanceof  short[]) {
258:                    short[] shaped = (short[]) array;
259:                    for (int i = 0; i < shaped.length; i++) {
260:                        shaped[i] = ((Short) a_flat[i]).shortValue();
261:                    }
262:                    return a_flat.length;
263:                }
264:                if (array instanceof  char[]) {
265:                    char[] shaped = (char[]) array;
266:                    for (int i = 0; i < shaped.length; i++) {
267:                        shaped[i] = ((Character) a_flat[i]).charValue();
268:                    }
269:                    return a_flat.length;
270:                }
271:                if (array instanceof  int[]) {
272:                    int[] shaped = (int[]) array;
273:                    for (int i = 0; i < shaped.length; i++) {
274:                        shaped[i] = ((Integer) a_flat[i]).intValue();
275:                    }
276:                    return a_flat.length;
277:                }
278:                if (array instanceof  long[]) {
279:                    long[] shaped = (long[]) array;
280:                    for (int i = 0; i < shaped.length; i++) {
281:                        shaped[i] = ((Long) a_flat[i]).longValue();
282:                    }
283:                    return a_flat.length;
284:                }
285:                if (array instanceof  float[]) {
286:                    float[] shaped = (float[]) array;
287:                    for (int i = 0; i < shaped.length; i++) {
288:                        shaped[i] = ((Float) a_flat[i]).floatValue();
289:                    }
290:                    return a_flat.length;
291:                }
292:                if (array instanceof  double[]) {
293:                    double[] shaped = (double[]) array;
294:                    for (int i = 0; i < shaped.length; i++) {
295:                        shaped[i] = ((Double) a_flat[i]).doubleValue();
296:                    }
297:                    return a_flat.length;
298:                }
299:                return 0;
300:            }
301:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.