Source Code Cross Referenced for AbstractSdlWriter.java in  » Database-ORM » ODAL » com » completex » objective » components » sdl » writer » 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 » Database ORM » ODAL » com.completex.objective.components.sdl.writer.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Objective Database Abstraction Layer (ODAL)
003:         *  Copyright (c) 2004, The ODAL Development Group
004:         *  All rights reserved.
005:         *  For definition of the ODAL Development Group please refer to LICENCE.txt file
006:         *
007:         *  Distributable under LGPL license.
008:         *  See terms of license at gnu.org.
009:         */package com.completex.objective.components.sdl.writer.impl;
010:
011:        import java.beans.BeanInfo;
012:        import java.beans.IntrospectionException;
013:        import java.beans.Introspector;
014:        import java.beans.PropertyDescriptor;
015:        import java.lang.reflect.Field;
016:        import java.lang.reflect.Method;
017:        import java.util.*;
018:
019:        /**
020:         * @author Andrew Suprun
021:         */
022:        public class AbstractSdlWriter {
023:            private boolean preserveOrder; // By default will be sorted
024:            private boolean preserveNulls; // By default null fields will not appear
025:            private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
026:            private static final Map getterMaps = new HashMap();
027:
028:            protected Map get(Object object) {
029:                Map values = new LinkedHashMap();
030:                Class aClass = object.getClass();
031:                Map getters = getGetters(aClass);
032:                Set set = getters.entrySet();
033:                for (Iterator iterator = set.iterator(); iterator.hasNext();) {
034:                    Map.Entry entry = (Map.Entry) iterator.next();
035:                    String propertyName = (String) entry.getKey();
036:                    if (propertyName.startsWith("_")) {
037:                        propertyName = propertyName.substring(1);
038:                    }
039:                    if (!"class".equals(propertyName)) {
040:                        Method readMethod = (Method) entry.getValue();
041:                        try {
042:                            Object v = readMethod.invoke(object,
043:                                    EMPTY_OBJECT_ARRAY);
044:                            if (v != null || preserveNulls) {
045:                                values.put(propertyName, v);
046:                            }
047:                        } catch (Throwable t) {
048:                            throw new RuntimeException(t);
049:                        }
050:                    }
051:                }
052:                return values;
053:            }
054:
055:            private synchronized Map getGetters(Class aClass) {
056:                String className = aClass.getName();
057:                Map getters = (Map) getterMaps.get(className);
058:                if (getters != null) {
059:                    return getters;
060:                }
061:
062:                getters = new LinkedHashMap();
063:                if (!preserveOrder) {
064:                    BeanInfo beanInfo = null;
065:                    try {
066:                        beanInfo = Introspector.getBeanInfo(aClass);
067:                    } catch (IntrospectionException e) {
068:                        throw new RuntimeException(e);
069:                    }
070:                    PropertyDescriptor[] propertyDescriptors = beanInfo
071:                            .getPropertyDescriptors();
072:                    for (int i = 0; i < propertyDescriptors.length; i++) {
073:                        PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
074:                        Method readMethod = propertyDescriptor.getReadMethod();
075:                        if (readMethod != null) {
076:                            getters.put(propertyDescriptor.getName(),
077:                                    readMethod);
078:                        }
079:                    }
080:                } else {
081:                    Field[] fields = getAllFields(aClass);
082:                    String fname = null;
083:                    String mname = null;
084:                    for (int i = 0; i < fields.length; i++) {
085:                        try {
086:                            fname = fields[i].getName();
087:                            mname = "get"
088:                                    + ((fname.startsWith("_")) ? "" : "_")
089:                                    + fname;
090:                            getters.put(fname, aClass.getMethod(mname,
091:                                    (java.lang.Class[]) null));
092:                        } catch (NoSuchMethodException e) {
093:                        }
094:                    }
095:                }
096:                getterMaps.put(className, getters);
097:                return getters;
098:            }
099:
100:            /**
101:             * Returns array of all fields belonging to Class cl (including inherited from parent classes)
102:             */
103:            private Field[] getAllFields(Class cl) {
104:                Class super class = cl.getSuperclass();
105:                Field[] fieldsup = new Field[0];
106:                if (super class != null) {
107:                    fieldsup = getAllFields(super class);
108:                }
109:                Field[] fieldshere = cl.getDeclaredFields();
110:                Field[] fields = new Field[fieldsup.length + fieldshere.length];
111:                System.arraycopy(fieldsup, 0, fields, 0, fieldsup.length);
112:                System.arraycopy(fieldshere, 0, fields, fieldsup.length,
113:                        fieldshere.length);
114:                return fields;
115:            }
116:
117:            public boolean isPreserveOrder() {
118:                return preserveOrder;
119:            }
120:
121:            public void setPreserveOrder(boolean preserveOrder) {
122:                this .preserveOrder = preserveOrder;
123:            }
124:
125:            public boolean isPreserveNulls() {
126:                return preserveNulls;
127:            }
128:
129:            public void setPreserveNulls(boolean preserveNulls) {
130:                this.preserveNulls = preserveNulls;
131:            }
132:        }
w_w__w___.__jav_a2_s___._co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.