Source Code Cross Referenced for DomUtils.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » tools » dbloader » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.tools.dbloader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2001 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.tools.dbloader;
007:
008:        import java.io.File;
009:
010:        import org.w3c.dom.Document;
011:        import org.w3c.dom.Element;
012:        import org.w3c.dom.Node;
013:        import org.w3c.dom.NodeList;
014:        import org.w3c.dom.Text;
015:
016:        /**
017:         * Utility class centralizing various DOM related functions used during
018:         * loading of the database.
019:         *
020:         * @author Ken Weiner, kweiner@unicon.net
021:         * @author Mark Boyd  {@link <a href="mailto:mark.boyd@engineer.com">mark.boyd@engineer.com</a>}
022:         * @version $Revision: 36690 $
023:         */
024:        class DomUtils {
025:            static void replaceDataTypes(Configuration config,
026:                    Document tablesDoc) {
027:                Element tables = tablesDoc.getDocumentElement();
028:                NodeList types = tables.getElementsByTagName("type");
029:
030:                for (int i = 0; i < types.getLength(); i++) {
031:                    Node type = (Node) types.item(i);
032:                    NodeList typeChildren = type.getChildNodes();
033:
034:                    for (int j = 0; j < typeChildren.getLength(); j++) {
035:                        Node text = (Node) typeChildren.item(j);
036:                        String genericType = text.getNodeValue();
037:
038:                        // Replace generic type with mapped local type
039:                        text.setNodeValue(DbUtils.getLocalDataTypeName(config,
040:                                genericType));
041:                    }
042:                }
043:            }
044:
045:            private static String getNodeValue(Node node) {
046:                String nodeVal = null;
047:
048:                for (Node ch = node.getFirstChild(); ch != null; ch = ch
049:                        .getNextSibling()) {
050:                    if (ch instanceof  Text)
051:                        nodeVal = ch.getNodeValue();
052:                }
053:
054:                return nodeVal;
055:            }
056:
057:            private static Element getTableWithName(Document tablesDoc,
058:                    String tableName) {
059:                Element tableElement = null;
060:                NodeList tables = tablesDoc.getElementsByTagName("table");
061:
062:                for (int i = 0; i < tables.getLength(); i++) {
063:                    Node table = (Node) tables.item(i);
064:
065:                    for (Node tableChild = table.getFirstChild(); tableChild != null; tableChild = tableChild
066:                            .getNextSibling()) {
067:                        if (tableChild instanceof  Element
068:                                && tableChild.getNodeName() != null
069:                                && tableChild.getNodeName().equals("name")) {
070:                            if (tableName.equals(getNodeValue(tableChild))) {
071:                                tableElement = (Element) table;
072:                                break;
073:                            }
074:                        }
075:                    }
076:                }
077:
078:                return tableElement;
079:            }
080:
081:            static int getJavaSqlDataTypeOfColumn(Configuration config,
082:                    String tableName, String columnName) {
083:                Document tablesDocGeneric = config.getGenericTablesDoc();
084:                int dataType = 0;
085:                String hashKey = tableName + File.separator + columnName;
086:
087:                // Try to use cached version first
088:                if (config.getTableColumnTypes().get(hashKey) != null) {
089:                    dataType = ((Integer) config.getTableColumnTypes().get(
090:                            hashKey)).intValue();
091:                } else {
092:                    // Find the right table element
093:                    Element table = getTableWithName(tablesDocGeneric,
094:                            tableName);
095:
096:                    // Find the columns element within
097:                    Element columns = getFirstChildWithName(table, "columns");
098:
099:                    // Search for the first column who's name is columnName
100:                    for (Node ch = columns.getFirstChild(); ch != null; ch = ch
101:                            .getNextSibling()) {
102:                        if (ch instanceof  Element
103:                                && ch.getNodeName().equals("column")) {
104:                            Element name = getFirstChildWithName((Element) ch,
105:                                    "name");
106:                            if (getNodeValue(name).equals(columnName)) {
107:                                // Get the corresponding type and return it's type code
108:                                Element value = getFirstChildWithName(
109:                                        (Element) ch, "type");
110:                                dataType = DbUtils
111:                                        .getJavaSqlType(getNodeValue(value));
112:                            }
113:                        }
114:                    }
115:
116:                    // Store value in hashtable for next call to this method.
117:                    // This prevents repeating xml parsing which takes a very long time
118:                    config.getTableColumnTypes().put(hashKey,
119:                            new Integer(dataType));
120:                }
121:
122:                return dataType;
123:            }
124:
125:            private static Element getFirstChildWithName(Element parent,
126:                    String name) {
127:                Element child = null;
128:                for (Node ch = parent.getFirstChild(); ch != null; ch = ch
129:                        .getNextSibling()) {
130:                    if (ch instanceof  Element && ch.getNodeName().equals(name)) {
131:                        child = (Element) ch;
132:                        break;
133:                    }
134:                }
135:
136:                return child;
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.