Source Code Cross Referenced for XmlDomStream.java in  » Database-ORM » ODAL » com » completex » objective » components » persistency » io » xml » 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.persistency.io.xml.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.persistency.io.xml.impl;
010:
011:        import com.completex.objective.components.persistency.xml.XmlRuntimeException;
012:        import com.completex.objective.util.XmlDomHelper;
013:        import org.w3c.dom.Document;
014:        import org.w3c.dom.Element;
015:        import org.xml.sax.SAXException;
016:
017:        import javax.xml.parsers.DocumentBuilder;
018:        import javax.xml.parsers.DocumentBuilderFactory;
019:        import javax.xml.parsers.ParserConfigurationException;
020:        import java.io.ByteArrayInputStream;
021:        import java.io.IOException;
022:        import java.math.BigDecimal;
023:        import java.math.BigInteger;
024:        import java.sql.Time;
025:        import java.sql.Timestamp;
026:        import java.util.Date;
027:        import java.util.HashMap;
028:        import java.util.Map;
029:
030:        /**
031:         * Basic XML DOM stream
032:         *
033:         * @author Gennady Krizhevsky
034:         */
035:        public abstract class XmlDomStream implements  XmlStreamTags {
036:            protected boolean useReferences = true;
037:            protected Document document;
038:            protected Element rootElement;
039:            protected Element currentElement;
040:            protected boolean useNames;
041:            protected boolean useNamesJavaStyle;
042:            protected boolean preserveOriginalValues;
043:            protected boolean initialized;
044:            protected HashMap references = new HashMap();
045:            protected XmlDomHelper xmlDomHelper;
046:            protected String rootName;
047:
048:            public static final Map NUMERIC = new HashMap();
049:            public static final LongFactory LONG_FACTORY = new LongFactory();
050:            public static final IntegerFactory INTEGER_FACTORY = new IntegerFactory();
051:            public static final ShortFactory SHORT_FACTORY = new ShortFactory();
052:            public static final FloatFactory FLOAT_FACTORY = new FloatFactory();
053:            public static final DoubleFactory DOUBLE_FACTORY = new DoubleFactory();
054:            public static final ByteFactory BYTE_FACTORY = new ByteFactory();
055:
056:            static {
057:                NUMERIC.put(Long.class.getName(), LONG_FACTORY);
058:                NUMERIC.put(Integer.class.getName(), INTEGER_FACTORY);
059:                NUMERIC.put(Short.class.getName(), SHORT_FACTORY);
060:                NUMERIC.put(Float.class.getName(), FLOAT_FACTORY);
061:                NUMERIC.put(Double.class.getName(), DOUBLE_FACTORY);
062:                NUMERIC.put(Byte.class.getName(), BYTE_FACTORY);
063:                NUMERIC
064:                        .put(BigDecimal.class.getName(),
065:                                new BigDecimalFactory());
066:                NUMERIC
067:                        .put(BigInteger.class.getName(),
068:                                new BigIntegerFactory());
069:                //
070:                // Primitives:
071:                //
072:                NUMERIC.put(long.class.getName(), LONG_FACTORY);
073:                NUMERIC.put(int.class.getName(), INTEGER_FACTORY);
074:                NUMERIC.put(short.class.getName(), SHORT_FACTORY);
075:                NUMERIC.put(float.class.getName(), FLOAT_FACTORY);
076:                NUMERIC.put(double.class.getName(), DOUBLE_FACTORY);
077:                NUMERIC.put(byte.class.getName(), BYTE_FACTORY);
078:            }
079:
080:            public static final Map DATE = new HashMap();
081:
082:            static {
083:                DATE.put(Date.class.getName(), new DateFactory());
084:                DATE.put(java.sql.Date.class.getName(), new SqlDateFactory());
085:                DATE.put(Time.class.getName(), new SqlTimeFactory());
086:                DATE.put(Timestamp.class.getName(), new SqlTimestampFactory());
087:            }
088:
089:            public static final Map BOOLEAN = new HashMap();
090:
091:            public static final BooleanFactory BOOLEAN_FACTORY = new BooleanFactory();
092:
093:            static {
094:                BOOLEAN.put(Boolean.class.getName(), BOOLEAN_FACTORY);
095:                //
096:                // Primitives:
097:                //
098:                BOOLEAN.put(boolean.class.getName(), BOOLEAN_FACTORY);
099:            }
100:
101:            public static final Map VALUE_FACTORIES = new HashMap();
102:            public static final ByteArrayInputStream NULL_BYTE_ARRAY_INPUT_STREAM = new ByteArrayInputStream(
103:                    new byte[0]);
104:            private static final boolean DEBUG = false;
105:            protected String version = "1.0.0";
106:
107:            static {
108:                VALUE_FACTORIES.putAll(NUMERIC);
109:                VALUE_FACTORIES.putAll(DATE);
110:                VALUE_FACTORIES.putAll(BOOLEAN);
111:            }
112:
113:            protected void setup() throws IOException {
114:                DocumentBuilderFactory dbf = DocumentBuilderFactory
115:                        .newInstance();
116:                //Using factory get an instance of document builder
117:                DocumentBuilder builder = null;
118:                try {
119:                    builder = dbf.newDocumentBuilder();
120:                } catch (ParserConfigurationException e) {
121:                    new IOException(e.toString());
122:                }
123:                try {
124:                    document = createDocument(builder);
125:                } catch (SAXException e) {
126:                    new IOException(e.toString());
127:                }
128:                xmlDomHelper = new XmlDomHelper(document);
129:                setupRootElement();
130:                rootName = rootElement.getTagName();
131:            }
132:
133:            protected abstract void setupRootElement();
134:
135:            protected abstract Document createDocument(DocumentBuilder builder)
136:                    throws IOException, SAXException;
137:
138:            /**
139:             * Return true if persistent object origianl values are being preserved
140:             * 
141:             * @return true if persistent object origianl values are being preserved
142:             */
143:            public boolean isPreserveOriginalValues() {
144:                return preserveOriginalValues;
145:            }
146:
147:            /**
148:             * Return true if persistent object column names are to be shown in JavaBeans style
149:             * 
150:             * @return true if persistent object column names are to be shown in JavaBeans style
151:             */
152:            public boolean isUseNamesJavaStyle() {
153:                return useNamesJavaStyle;
154:            }
155:
156:            protected void ensureOpen() {
157:                if (document == null) {
158:                    throw new XmlRuntimeException("Stream is closed");
159:                }
160:            }
161:
162:            protected Element resolveParentElement() {
163:                return initialized && currentElement != null ? currentElement
164:                        : rootElement;
165:            }
166:
167:            public void close() throws IOException {
168:                currentElement = null;
169:                references = null;
170:                rootElement = null;
171:                document = null;
172:            }
173:
174:            protected void println(String s) {
175:                if (DEBUG) {
176:                    System.out.println(s);
177:                }
178:            }
179:
180:            public Document getDocument() {
181:                return document;
182:            }
183:
184:            public Element getRootElement() {
185:                return rootElement;
186:            }
187:
188:            public String getVersion() {
189:                return version;
190:            }
191:
192:            protected boolean isNumericValue(Object value) {
193:                if (value == null) {
194:                    return false;
195:                }
196:                return isNumericClass(value.getClass().getName());
197:            }
198:
199:            protected boolean isNumericClass(String className) {
200:                return NUMERIC.containsKey(className);
201:            }
202:
203:            protected boolean isDate(Object value) {
204:                if (value == null) {
205:                    return false;
206:                }
207:                return isDateClass(value);
208:            }
209:
210:            protected boolean isDateClass(Object className) {
211:                return DATE.containsKey(className);
212:            }
213:
214:            protected boolean isBoolean(Object value) {
215:                if (value == null) {
216:                    return false;
217:                }
218:                return isBooleanClass(value.getClass().getName());
219:            }
220:
221:            protected boolean isBooleanClass(String className) {
222:                return BOOLEAN.containsKey(className);
223:            }
224:
225:            protected Object string2value0(String className, String valueString) {
226:                if (valueString == null) {
227:                    return null;
228:                }
229:
230:                ValueFactory valueFactory = (ValueFactory) VALUE_FACTORIES
231:                        .get(className);
232:                if (valueFactory == null) {
233:                    throw new XmlRuntimeException(
234:                            "Cannot find valueFactory for className "
235:                                    + className);
236:                }
237:                return valueFactory.newValueInstance(valueString);
238:            }
239:
240:            /**
241:             * Value factory
242:             */
243:            protected static interface ValueFactory {
244:                Object newValueInstance(String valueString);
245:            }
246:
247:            /**
248:             * Numeric:
249:             */
250:            protected static class LongFactory implements  ValueFactory {
251:                public Object newValueInstance(String valueString) {
252:                    return Long.valueOf(valueString);
253:                }
254:            }
255:
256:            protected static class IntegerFactory implements  ValueFactory {
257:                public Object newValueInstance(String valueString) {
258:                    return Integer.valueOf(valueString);
259:                }
260:            }
261:
262:            protected static class ShortFactory implements  ValueFactory {
263:                public Object newValueInstance(String valueString) {
264:                    return Short.valueOf(valueString);
265:                }
266:            }
267:
268:            protected static class FloatFactory implements  ValueFactory {
269:                public Object newValueInstance(String valueString) {
270:                    return Float.valueOf(valueString);
271:                }
272:            }
273:
274:            protected static class DoubleFactory implements  ValueFactory {
275:                public Object newValueInstance(String valueString) {
276:                    return Double.valueOf(valueString);
277:                }
278:            }
279:
280:            protected static class ByteFactory implements  ValueFactory {
281:                public Object newValueInstance(String valueString) {
282:                    return Byte.valueOf(valueString);
283:                }
284:            }
285:
286:            protected static class BigDecimalFactory implements  ValueFactory {
287:                public Object newValueInstance(String valueString) {
288:                    return new BigDecimal(valueString);
289:                }
290:            }
291:
292:            protected static class BigIntegerFactory implements  ValueFactory {
293:                public Object newValueInstance(String valueString) {
294:                    return new BigInteger(valueString);
295:                }
296:            }
297:
298:            /**
299:             * Date
300:             */
301:            protected static class DateFactory implements  ValueFactory {
302:                public Object newValueInstance(String valueString) {
303:                    return XmlDomHelper.S2D(valueString);
304:                }
305:            }
306:
307:            protected static class SqlDateFactory implements  ValueFactory {
308:                public Object newValueInstance(String valueString) {
309:                    Date date = XmlDomHelper.S2D(valueString);
310:                    return new java.sql.Date(date.getTime());
311:                }
312:            }
313:
314:            protected static class SqlTimeFactory implements  ValueFactory {
315:                public Object newValueInstance(String valueString) {
316:                    Date date = XmlDomHelper.S2D(valueString);
317:                    return new java.sql.Time(date.getTime());
318:                }
319:            }
320:
321:            protected static class SqlTimestampFactory implements  ValueFactory {
322:                public Object newValueInstance(String valueString) {
323:                    Date date = XmlDomHelper.S2D(valueString);
324:                    return new java.sql.Timestamp(date.getTime());
325:                }
326:            }
327:
328:            /**
329:             *  Boolean
330:             */
331:            protected static class BooleanFactory implements  ValueFactory {
332:                public Object newValueInstance(String valueString) {
333:                    return XmlDomHelper.S2B(valueString);
334:                }
335:            }
336:
337:        }
w_w_w___.___j___av__a2___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.