Source Code Cross Referenced for JdbcDriverFinder.java in  » Database-ORM » XORM » org » xorm » tools » 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 » XORM » org.xorm.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:            $Header: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/JdbcDriverFinder.java,v 1.3 2003/04/19 20:01:05 dcheckoway Exp $
003:
004:            This file is part of XORM.
005:
006:            XORM is free software; you can redistribute it and/or modify
007:            it under the terms of the GNU General Public License as published by
008:            the Free Software Foundation; either version 2 of the License, or
009:            (at your option) any later version.
010:
011:            XORM is distributed in the hope that it will be useful,
012:            but WITHOUT ANY WARRANTY; without even the implied warranty of
013:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:            GNU General Public License for more details.
015:
016:            You should have received a copy of the GNU General Public License
017:            along with Foobar; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:        package org.xorm.tools;
021:
022:        import java.io.File;
023:        import java.io.FileInputStream;
024:        import java.io.InputStream;
025:        import java.io.IOException;
026:        import java.util.ArrayList;
027:        import java.util.Collection;
028:        import java.util.Iterator;
029:        import javax.swing.JFileChooser;
030:        import javax.swing.UIManager;
031:        import javax.swing.filechooser.FileFilter;
032:        import org.xorm.tools.jar.JarClassFinder;
033:
034:        /** Utility for finding JDBC driver classes in JAR files
035:         @author Dan Checkoway
036:         */
037:        public class JdbcDriverFinder {
038:            JarClassFinder finder = new JarClassFinder();
039:
040:            /** Create a JdbcDriverFinder */
041:            public JdbcDriverFinder() {
042:            }
043:
044:            /** Find JDBC driver classes by browsing for JAR files
045:                @return a Collection of matching class objects, or an empty
046:                Collection if no driver classes are found
047:             */
048:            public Collection findJdbcDrivers() throws IOException {
049:                File jarFile = chooseJarFile();
050:                if (jarFile == null) {
051:                    return new ArrayList();
052:                } else {
053:                    return finder.findClassesOfType(java.sql.Driver.class,
054:                            jarFile);
055:                }
056:            }
057:
058:            /** Find JDBC driver classes within a JAR file
059:                @param jarFileName the name/path of the JAR file to examine
060:                @return a Collection of matching class objects, or an empty
061:                Collection if no driver classes are found
062:             */
063:            public Collection findJdbcDrivers(String jarFileName)
064:                    throws IOException {
065:                return finder.findClassesOfType(java.sql.Driver.class,
066:                        jarFileName);
067:            }
068:
069:            /** Find JDBC driver classes within a JAR file
070:                @param jarFile the JAR file to examine
071:                @return a Collection of matching class objects, or an empty
072:                Collection if no driver classes are found
073:             */
074:            public Collection findJdbcDrivers(File jarFile) throws IOException {
075:                return finder.findClassesOfType(java.sql.Driver.class, jarFile);
076:            }
077:
078:            /** Find JDBC driver classes within a JAR file
079:                @param inputStream an input stream with the JAR content to examine
080:                @return a Collection of matching class objects, or an empty
081:                Collection if no driver classes are found
082:             */
083:            public Collection findJdbcDrivers(InputStream inputStream)
084:                    throws IOException {
085:                return finder.findClassesOfType(java.sql.Driver.class,
086:                        inputStream);
087:            }
088:
089:            /** Test stub */
090:            public static void main(String[] args) {
091:                int exitCode = 0;
092:                try {
093:                    // I *hate* the stock swing look and feel...use native if able
094:                    String nativeLNF = UIManager
095:                            .getSystemLookAndFeelClassName();
096:                    if (nativeLNF != null) {
097:                        UIManager.setLookAndFeel(nativeLNF);
098:                    }
099:
100:                    if (args.length <= 0) {
101:                        File jarFile = chooseJarFile();
102:                        if (jarFile != null) {
103:                            displayJdbcDriversInFile(jarFile);
104:                        }
105:                    } else {
106:                        for (int k = 0; k < args.length; ++k) {
107:                            displayJdbcDriversInFile(new File(args[k]));
108:                        }
109:                    }
110:                } catch (Throwable t) {
111:                    t.printStackTrace(System.out);
112:                    exitCode = 1;
113:                } finally {
114:                    Runtime.getRuntime().exit(exitCode);
115:                }
116:            }
117:
118:            public static File chooseJarFile() {
119:                return chooseJarFile(".");
120:            }
121:
122:            public static File chooseJarFile(String startingDir) {
123:                JFileChooser fc = new JFileChooser(startingDir);
124:                fc.setFileFilter(new FileFilter() {
125:                    public boolean accept(File file) {
126:                        return file.isDirectory()
127:                                || file.getName().endsWith(".jar")
128:                                || file.getName().endsWith(".zip");
129:                    }
130:
131:                    public String getDescription() {
132:                        return "JAR Files";
133:                    }
134:                });
135:                fc.setFileSelectionMode(fc.FILES_ONLY);
136:                fc.setDialogTitle("Please Select Your JDBC Driver JAR File");
137:                if (fc.showOpenDialog(null) == fc.APPROVE_OPTION) {
138:                    return fc.getSelectedFile();
139:                } else {
140:                    return null;
141:                }
142:            }
143:
144:            public static void displayJdbcDriversInFile(File jarFile)
145:                    throws IOException {
146:                System.out.println("Looking for drivers in: "
147:                        + jarFile.getCanonicalPath());
148:                JdbcDriverFinder jdf = new JdbcDriverFinder();
149:                Collection classes = jdf.findJdbcDrivers(jarFile);
150:                if (classes.isEmpty()) {
151:                    System.out.println("No matching driver classes found.");
152:                } else {
153:                    System.out.println("Driver classes found:");
154:                    for (Iterator iter = classes.iterator(); iter.hasNext();) {
155:                        Class clazz = (Class) iter.next();
156:                        System.out.println(clazz.getName());
157:                    }
158:                }
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.