Source Code Cross Referenced for SchemaGen.java in  » Report » datavision-1.1.0 » jimm » datavision » testdata » 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 » Report » datavision 1.1.0 » jimm.datavision.testdata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision.testdata;
002:
003:        import java.io.File;
004:        import javax.xml.parsers.SAXParserFactory;
005:        import org.xml.sax.*;
006:        import org.xml.sax.helpers.DefaultHandler;
007:
008:        /**
009:         * Skeleton for creating a schema.sql file by reading an XML description
010:         * of a schema.
011:         * 
012:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
013:         */
014:
015:        public abstract class SchemaGen extends DefaultHandler {
016:
017:            protected String type;
018:            protected int size;
019:            protected boolean notNull;
020:            protected boolean primaryKey;
021:            protected boolean isFirstColumn;
022:
023:            public void run(String schemaXMLFile) {
024:                try {
025:                    SAXParserFactory.newInstance().newSAXParser().parse(
026:                            new File(schemaXMLFile), this );
027:                } catch (Exception e) {
028:                    e.printStackTrace();
029:                    System.exit(1);
030:                }
031:            }
032:
033:            public void startElement(final String namespaceURI,
034:                    final String localName, final String qName,
035:                    final Attributes attributes) throws SAXException {
036:                String tagName = localName;
037:                if (tagName == null || tagName.length() == 0)
038:                    tagName = qName;
039:
040:                if ("table".equals(tagName))
041:                    table(attributes);
042:                else if ("column".equals(tagName))
043:                    column(attributes);
044:            }
045:
046:            public void endElement(final String namespaceURI,
047:                    final String localName, final String qName)
048:                    throws SAXException {
049:                String tagName = localName;
050:                if (tagName == null || tagName.length() == 0)
051:                    tagName = qName;
052:
053:                if ("table".equals(tagName))
054:                    endTable();
055:            }
056:
057:            /**
058:             * Parses a table XML tag and calls <code>makeTable</code>.
059:             *
060:             * @param attributes XML element attributes
061:             * @see #makeTable
062:             */
063:            protected void table(Attributes attributes) {
064:                makeTable(attributes.getValue("name"));
065:                isFirstColumn = true;
066:            }
067:
068:            /**
069:             * Parses a column XML tag and calls <code>printColumn</code>. Also handles
070:             * commas and indentation.
071:             *
072:             * @param attributes XML element attributes
073:             * @see #makeTable
074:             */
075:            protected void column(Attributes attributes) {
076:                String name = attributes.getValue("name");
077:                String type = attributes.getValue("type");
078:                String sizeStr = attributes.getValue("size");
079:                int size = 0;
080:                if (sizeStr != null)
081:                    size = Integer.parseInt(sizeStr);
082:                boolean notNull = (attributes.getValue("not-null") != null);
083:                boolean primaryKey = (attributes.getValue("primary-key") != null);
084:
085:                if (!isFirstColumn)
086:                    System.out.print(",");
087:                System.out.println();
088:                System.out.print("\t");
089:
090:                printColumn(name, type, size, notNull, primaryKey);
091:                isFirstColumn = false;
092:            }
093:
094:            /**
095:             * Outputs the SQL needed to create a database table. Optionally prints
096:             * the SQL needed to destroy the table first.
097:             */
098:            protected abstract void makeTable(String tableName);
099:
100:            protected String printableName(String name) {
101:                if (name.indexOf(' ') >= 0 || !name.equals(name.toLowerCase()))
102:                    return "\"" + name + "\"";
103:                else
104:                    return name;
105:            }
106:
107:            /**
108:             * Outputs the SQL needed to close a create table statement.
109:             */
110:            protected abstract void endTable();
111:
112:            /**
113:             * Prints the SQL needed to create a database column within a create table
114:             * statement.
115:             */
116:            protected void printColumn(String columnName, String type,
117:                    int size, boolean notNull, boolean primaryKey) {
118:                printColumnName(columnName);
119:                printType(type, size);
120:                if (notNull)
121:                    printNotNull();
122:                if (primaryKey)
123:                    printPrimaryKey();
124:            }
125:
126:            /**
127:             * Prints the column name, taking into account case, blanks, and other
128:             * possibly funky things.
129:             */
130:            protected void printColumnName(String columnName) {
131:                System.out.print(printableName(columnName));
132:            }
133:
134:            /**
135:             * Prints the SQL that defines a column's type.
136:             */
137:            protected abstract void printType(String type, int size);
138:
139:            /**
140:             * Prints the SQL that defines a column as NOT NULL.
141:             */
142:            protected abstract void printNotNull();
143:
144:            /**
145:             * Prints the SQL that defines a column as a primary key.
146:             */
147:            protected abstract void printPrimaryKey();
148:
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.