Source Code Cross Referenced for Reflection.java in  » Database-DBMS » db4o-6.4 » com » db4o » test » reflect » 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.test.reflect 
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.test.reflect;
022:
023:        import com.db4o.reflect.*;
024:        import com.db4o.reflect.generic.*;
025:        import com.db4o.reflect.jdk.*;
026:
027:        /**
028:         * test for custom reflection implementations.
029:         * <br><br>
030:         * db4o internally uses java.lang.reflect.* by default. On platforms that
031:         * do not support this package, customized implementations may be written
032:         * to supply all the functionality of the interfaces in the com.db4o.reflect
033:         * package. The sources in this sample packages demonstrate, how db4o
034:         * accesses the java.lang.reflect.* functionality.
035:         * <br><br>
036:         * This TestReflect method may be used to test, if you own implementation
037:         * provides the functionality that db4o needs. You may call the test from
038:         * the command line by specifying the classname of your own class that
039:         * implements IReflect. Alternatively you can call the test(IReflect) method.
040:         */
041:        public class Reflection extends Test {
042:
043:            private final Reflector _reflector;
044:            private final ReflectClass _classReflector;
045:
046:            public Reflection() throws ClassNotFoundException {
047:                this (new GenericReflector(null, new JdkReflector(Thread
048:                        .currentThread().getContextClassLoader())));
049:            }
050:
051:            public Reflection(Reflector reflector) {
052:                _reflector = reflector;
053:                _classReflector = _reflector.forName(TestReflectClass.class
054:                        .getName());
055:            }
056:
057:            public void testIClass() throws ClassNotFoundException {
058:                ReflectField[] fields = _classReflector.getDeclaredFields();
059:                _assert(fields.length == TestReflectClass.FIELD_COUNT,
060:                        "getDeclaredFields method failed.");
061:                for (int i = 0; i < fields.length; i++) {
062:                    _assert(fields != null, "getDeclaredFields[" + i
063:                            + "] is valid");
064:                    String fieldName = fields[i].getName();
065:                    ReflectField fieldReflector = _classReflector
066:                            .getDeclaredField(fieldName);
067:                    _assert(fieldReflector != null, "getDeclaredField('"
068:                            + fieldName + "') is valid");
069:                }
070:
071:                tstIField();
072:
073:                ReflectClass abstractReflector = _reflector
074:                        .forName(TestReflectAbstractClass.class.getName());
075:                _assert(abstractReflector.isAbstract(), "isAbstract");
076:                ReflectClass interfaceReflector = _reflector
077:                        .forName(TestReflectInterface.class.getName());
078:                _assert(interfaceReflector.isInterface(), "isInterface");
079:                Object instance = _classReflector.newInstance();
080:                _assert(instance != null, "newInstance");
081:
082:            }
083:
084:            private void tstIField() {
085:                tstIField1("myString", "HiBabe", String.class);
086:                tstIField1("myInt", new Integer(10), int.class);
087:                tstIField1("myTyped", new TestReflectClass(),
088:                        TestReflectClass.class);
089:                tstIField1("myUntyped", "Foooo", Object.class);
090:                tstIField1("myUntyped", new TestReflectClass(), Object.class);
091:                _assert(
092:                        _classReflector.getDeclaredField("myStatic").isStatic(),
093:                        "IField.isStatic()");
094:                _assert(_classReflector.getDeclaredField("myTransient")
095:                        .isTransient(), "IField.isTransient()");
096:            }
097:
098:            private void tstIField1(String fieldName, Object obj, Class clazz) {
099:                ReflectClass claxx = _reflector.forClass(clazz);
100:                String fieldMessage = TestReflectClass.class.getName() + ":"
101:                        + fieldName;
102:                TestReflectClass onObject = new TestReflectClass();
103:                ReflectField fieldReflector = _classReflector
104:                        .getDeclaredField(fieldName);
105:                fieldReflector.set(onObject, obj);
106:                Object got = fieldReflector.get(onObject);
107:                _assert(got != null, fieldMessage + " IField.get returns NULL");
108:                _assert(obj.equals(got), fieldMessage
109:                        + " IField.get returns strange Object");
110:                _assert(fieldReflector.getName().equals(fieldName),
111:                        "IField.getName()");
112:                _assert(fieldReflector.isPublic(), "IField.isPublic()");
113:                _assert(!fieldReflector.isStatic(), "IField.isStatic()");
114:                _assert(!fieldReflector.isTransient(), "IField.isTransient()");
115:                _assert(fieldReflector.getFieldType().equals(claxx),
116:                        "IField.getType()");
117:            }
118:
119:            public void testIArray() {
120:                tstIArray1(new Object[] { "", "hi", "Cool" });
121:                tstIArray1(new Object[] { new Object(), new TestReflectClass(),
122:                        "Woooa", new Integer(3) });
123:                tstIArray1(new Object[] { new TestReflectClass(),
124:                        new TestReflectClass() });
125:                tstIArray2(new int[] { 1, 2, 3 });
126:                tstIArray2(new long[] { 1L, 2L, 3L });
127:            }
128:
129:            public void tstEverything() throws ClassNotFoundException {
130:                testIClass();
131:                testIArray();
132:            }
133:
134:            private void tstIArray1(Object[] elements) {
135:                ReflectArray array = _reflector.array();
136:                ReflectClass clazz = _reflector.forObject(elements[0]);
137:                Object obj = array.newInstance(clazz, 0);
138:                _assert(obj != null, "Creation of zero length array");
139:                _assert(array.getLength(obj) == 0, "Zero length array length");
140:                obj = array.newInstance(clazz, elements.length);
141:                _assert(obj != null, "Creation of variable length array");
142:                _assert(array.getLength(obj) == elements.length,
143:                        "Variable length array length");
144:                for (int i = 0; i < elements.length; i++) {
145:                    array.set(obj, i, elements[i]);
146:                }
147:                for (int i = 0; i < elements.length; i++) {
148:                    _assert(elements[i].equals(array.get(obj, i)),
149:                            "Array element comparison");
150:                }
151:            }
152:
153:            private void tstIArray2(Object arr) {
154:                ReflectArray array = _reflector.array();
155:                Object element = array.get(arr, 0);
156:                ReflectClass clazz = _reflector.forObject(element);
157:                Object obj = array.newInstance(clazz, 0);
158:                _assert(obj != null, "Creation of zero length array");
159:                _assert(array.getLength(obj) == 0, "Zero length array length");
160:                int length = array.getLength(arr);
161:                obj = array.newInstance(clazz, length);
162:                _assert(obj != null, "Creation of variable length array");
163:                _assert(array.getLength(obj) == length,
164:                        "Variable length array length");
165:                for (int i = 0; i < length; i++) {
166:                    array.set(obj, i, array.get(arr, i));
167:                }
168:                for (int i = 0; i < length; i++) {
169:                    _assert(array.get(arr, i).equals(array.get(obj, i)),
170:                            "Array element comparison");
171:                }
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.