Source Code Cross Referenced for XMLBootstrapParser.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » mashup » db » bootstrap » 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 » IDE Netbeans » etl.project » org.netbeans.modules.mashup.db.bootstrap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * XMLBootstrapParser.java
003:         *
004:         * Created on April 3, 2007, 12:56 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package org.netbeans.modules.mashup.db.bootstrap;
011:
012:        import com.sun.sql.framework.utils.StringUtil;
013:        import java.io.File;
014:        import java.io.FileInputStream;
015:        import java.io.InputStream;
016:        import java.net.URL;
017:        import java.sql.SQLException;
018:        import java.sql.Types;
019:        import java.util.ArrayList;
020:        import java.util.List;
021:        import javax.xml.parsers.DocumentBuilder;
022:        import javax.xml.parsers.DocumentBuilderFactory;
023:
024:        import org.netbeans.modules.mashup.db.common.FlatfileDBException;
025:        import org.netbeans.modules.mashup.db.common.PropertyKeys;
026:        import org.netbeans.modules.mashup.db.common.SQLUtils;
027:        import org.netbeans.modules.mashup.db.model.FlatfileDBColumn;
028:        import org.netbeans.modules.mashup.db.model.FlatfileDBTable;
029:        import org.netbeans.modules.mashup.db.model.impl.FlatfileDBColumnImpl;
030:        import org.netbeans.modules.mashup.db.model.impl.FlatfileDBTableImpl;
031:        import org.w3c.dom.Document;
032:        import org.w3c.dom.Element;
033:        import org.w3c.dom.Node;
034:        import org.w3c.dom.NodeList;
035:
036:        /**
037:         *
038:         * @author ks161616
039:         */
040:        public class XMLBootstrapParser implements  FlatfileBootstrapParser {
041:
042:            /** Creates a new instance of XMLBootstrapParser */
043:            public XMLBootstrapParser() {
044:            }
045:
046:            public List buildFlatfileDBColumns(FlatfileDBTable table)
047:                    throws FlatfileDBException {
048:                int defaultPrecision = 60;
049:                int jdbcType = SQLUtils.getStdJdbcType(table
050:                        .getProperty(PropertyKeys.WIZARDDEFAULTSQLTYPE));
051:                if (jdbcType == SQLUtils.JDBCSQL_TYPE_UNDEFINED) {
052:                    jdbcType = Types.VARCHAR;
053:                }
054:                try {
055:                    defaultPrecision = Integer
056:                            .valueOf(
057:                                    table
058:                                            .getProperty(PropertyKeys.WIZARDDEFAULTPRECISION))
059:                            .intValue();
060:                } catch (Exception e) {
061:                    defaultPrecision = 60;
062:                }
063:                FlatfileDBColumn[] columns = getColumns(table);
064:                List<FlatfileDBColumn> colList = new ArrayList<FlatfileDBColumn>(
065:                        columns.length);
066:                Element root = null;
067:                try {
068:                    root = getRootElement(table.getProperty(PropertyKeys.URL));
069:                } catch (Exception ex) {
070:                    //ignore
071:                }
072:                if (root != null) {
073:                    Element row = getRowElement(root);
074:                    if (row != null) {
075:                        int count = getColumnCount(row);
076:                        for (int i = 1; i <= count; i++) {
077:                            FlatfileDBColumn column = null;
078:                            if (columns != null && i <= columns.length) {
079:                                column = columns[i - 1];
080:                            }
081:                            if (column == null) {
082:                                String columnName = getColumnName(row, i);
083:                                if (columnName != null
084:                                        && !columnName.equals("")
085:                                        && !StringUtil.isNullString(columnName)) {
086:                                    columnName = StringUtil
087:                                            .escapeNonAlphaNumericCharacters(columnName
088:                                                    .trim());
089:                                    columnName = StringUtil
090:                                            .createColumnNameFromFieldName(columnName
091:                                                    .trim());
092:                                    column = new FlatfileDBColumnImpl(
093:                                            columnName, jdbcType,
094:                                            defaultPrecision, 0, true);
095:                                } else {
096:                                    column = new FlatfileDBColumnImpl("FIELD_"
097:                                            + String.valueOf(i), jdbcType,
098:                                            defaultPrecision, 0, true);
099:                                }
100:                                column.setCardinalPosition(i);
101:                            }
102:                            colList.add(column);
103:                        }
104:                    }
105:                }
106:                return colList;
107:            }
108:
109:            public void makeGuess(FlatfileDBTable table)
110:                    throws FlatfileDBException {
111:            }
112:
113:            public boolean acceptable(FlatfileDBTable table)
114:                    throws FlatfileDBException {
115:                try {
116:                    getRootElement(table.getProperty(PropertyKeys.URL));
117:                } catch (Exception ex) {
118:                    return false;
119:                }
120:                return true;
121:            }
122:
123:            private FlatfileDBColumn[] getColumns(FlatfileDBTable table) {
124:                FlatfileDBColumn[] columns = new FlatfileDBColumn[0];
125:                if (table.getColumnList().size() > 0) {
126:                    columns = (FlatfileDBColumn[]) table.getColumnList()
127:                            .toArray(columns);
128:                }
129:                return columns;
130:            }
131:
132:            private Element getRootElement(String file) throws Exception {
133:                file = StringUtil.escapeControlChars(file.trim());
134:                File f = new File(file);
135:                InputStream is = null;
136:                if (f.exists()) {
137:                    is = new FileInputStream(f);
138:                } else {
139:                    is = new URL(file).openStream();
140:                }
141:                DocumentBuilderFactory factory = DocumentBuilderFactory
142:                        .newInstance();
143:                DocumentBuilder builder = factory.newDocumentBuilder();
144:                Document document = builder.parse(is);
145:                return document.getDocumentElement();
146:            }
147:
148:            private Element getRowElement(Element root) {
149:                NodeList children = root.getChildNodes();
150:                for (int i = 0; i < children.getLength(); i++) {
151:                    Node nd = children.item(i);
152:                    if (nd.getNodeType() == Node.ELEMENT_NODE) {
153:                        return (Element) nd;
154:                    }
155:                }
156:                return null;
157:            }
158:
159:            private int getColumnCount(Element row) {
160:                int count = 0;
161:                NodeList children = row.getChildNodes();
162:                for (int i = 0; i < children.getLength(); i++) {
163:                    Node nd = children.item(i);
164:                    if (nd.getNodeType() == Node.ELEMENT_NODE) {
165:                        count++;
166:                    }
167:                }
168:                return count;
169:            }
170:
171:            private String getColumnName(Element row, int i) {
172:                NodeList children = row.getChildNodes();
173:                int count = 0;
174:                Element column = null;
175:                for (int j = 0; j < children.getLength(); j++) {
176:                    Node nd = children.item(j);
177:                    if (nd.getNodeType() == Node.ELEMENT_NODE) {
178:                        count++;
179:                        if (count == i) {
180:                            column = (Element) nd;
181:                            break;
182:                        }
183:                    }
184:                }
185:                String name = "";
186:                if (column != null) {
187:                    name = column.getNodeName();
188:                }
189:                return name;
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.