Source Code Cross Referenced for SdlPrinterImpl.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 com.completex.objective.components.sdl.writer.SdlWriter;
012:
013:        import java.io.IOException;
014:        import java.io.Writer;
015:        import java.sql.Timestamp;
016:        import java.text.SimpleDateFormat;
017:        import java.util.*;
018:
019:        /**
020:         * @author Andrew Suprun
021:         */
022:        public class SdlPrinterImpl extends AbstractSdlWriter implements 
023:                SdlWriter {
024:
025:            static final private SimpleDateFormat SDF_LONG = new SimpleDateFormat(
026:                    "@yyyy-MM-dd'T'HH:mm:ss");
027:            static final private SimpleDateFormat SDF_SHORT = new SimpleDateFormat(
028:                    "@yyyy-MM-dd");
029:
030:            public void write(Writer target, Object object) throws IOException {
031:                write(target, object, 0);
032:                target.write("\n");
033:            }
034:
035:            private void write(Writer target, Object object, int level)
036:                    throws IOException {
037:                if ("keyGenerator".equals(object)) {
038:                    int k = 0;
039:                }
040:                if (object == null) {
041:                    target.write("NULL");
042:                } else if (object instanceof  Map) {
043:                    writeMap(target, (Map) object, level);
044:                } else if (object instanceof  List) {
045:                    writeList(target, (List) object, level);
046:                } else if (object instanceof  String) {
047:                    writeStr(target, (String) object);
048:                } else if (object instanceof  Timestamp) {
049:                    writeTimestamp((Timestamp) object, target);
050:                } else if (object instanceof  Number) {
051:                    target.write(object.toString());
052:                } else if (object instanceof  Boolean) {
053:                    target.write(((Boolean) object).booleanValue() ? "TRUE"
054:                            : "FALSE");
055:                } else {
056:                    Map map = get(object);
057:                    writeMap(target, map, level);
058:                }
059:            }
060:
061:            private void writeMap(Writer target, Map map, int level)
062:                    throws IOException {
063:                target.write('{');
064:                if (map.size() > 0) {
065:                    int nextLevel = level + 1;
066:                    Set set = map.entrySet();
067:                    for (Iterator iterator = set.iterator(); iterator.hasNext();) {
068:                        Map.Entry entry = (Map.Entry) iterator.next();
069:                        Object value = entry.getValue();
070:                        if (value != null || isPreserveNulls()) {
071:                            ident(target, nextLevel);
072:                            Object key = entry.getKey();
073:                            if (!isComment(((String) key))) {
074:                                write(target, entry.getKey(), nextLevel);
075:                                target.write(" = ");
076:                                write(target, value, nextLevel);
077:                            } else {
078:                                writeComment(target, key + " = " + value);
079:                            }
080:
081:                        }
082:                    }
083:                    ident(target, level);
084:                }
085:                target.write("}");
086:            }
087:
088:            private void writeList(Writer target, List list, int level)
089:                    throws IOException {
090:                target.write('[');
091:                if (list.size() > 0) {
092:                    int nextLevel = level + 1;
093:                    for (Iterator iterator = list.iterator(); iterator
094:                            .hasNext();) {
095:                        ident(target, nextLevel);
096:                        write(target, iterator.next(), nextLevel);
097:                    }
098:                    ident(target, level);
099:                }
100:                target.write("]");
101:            }
102:
103:            private void writeStr(Writer target, String s) throws IOException {
104:                if (!isComment(s)) {
105:                    if (isSymbol(s)) {
106:                        target.write(s);
107:                    } else {
108:                        writeString(target, s);
109:                    }
110:                } else {
111:                    writeComment(target, s);
112:                }
113:            }
114:
115:            private boolean isComment(String s) {
116:                return s.trim().startsWith("#");
117:            }
118:
119:            private void ident(Writer target, int level) throws IOException {
120:                target.write('\n');
121:                for (int i = 0; i < level; i++) {
122:                    target.write("    ");
123:                }
124:            }
125:
126:            private void writeString(Writer target, String s)
127:                    throws IOException {
128:                target.write('\"');
129:                for (int i = 0; i < s.length(); i++) {
130:                    if (s.charAt(i) == '\"' || s.charAt(i) == '\\') {
131:                        target.write('\\');
132:                    }
133:                    target.write(s.charAt(i));
134:                }
135:                target.write('\"');
136:            }
137:
138:            private void writeComment(Writer target, String s)
139:                    throws IOException {
140:                for (int i = 0; i < s.length(); i++) {
141:                    target.write(s.charAt(i));
142:                }
143:            }
144:
145:            private boolean isSymbol(String s) {
146:                if (s.length() == 0) {
147:                    return false;
148:                }
149:                char ch = s.charAt(0);
150:                if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
151:                        || ch == '_' || ch == '$' || ch == '/') {
152:                    for (int i = 1; i < s.length(); i++) {
153:                        if (!isSymbolChar(s.charAt(i))) {
154:                            return false;
155:                        }
156:                    }
157:                    return true;
158:                } else {
159:                    return false;
160:                }
161:            }
162:
163:            private boolean isSymbolChar(char c) {
164:                return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')
165:                        || (c >= 'A' && c <= 'Z') || c == '-' || c == '_'
166:                        || c == ':' || c == '.' || c == '$' || c == '/';
167:            }
168:
169:            private void writeTimestamp(Timestamp timestamp, Writer target)
170:                    throws IOException {
171:                GregorianCalendar calendar = new GregorianCalendar();
172:                calendar.setTime(new Date(timestamp.getTime()));
173:                if (calendar.get(Calendar.HOUR_OF_DAY) == 0
174:                        && calendar.get(Calendar.MINUTE) == 0
175:                        && calendar.get(Calendar.SECOND) == 0
176:                        && calendar.get(Calendar.MILLISECOND) == 0) {
177:                    target.write(SDF_SHORT.format(timestamp));
178:                } else {
179:                    target.write(SDF_LONG.format(timestamp));
180:                }
181:            }
182:        }
w_w__w.__j_a__v__a___2___s_.c__o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.