Source Code Cross Referenced for listpackage.java in  » Database-Client » SQLMinus » isql » 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 Client » SQLMinus » isql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package isql;
002:
003:        import java.util.*;
004:        import java.io.*;
005:        import java.util.zip.*;
006:        import util.*;
007:
008:        /** given a package like 'java.lan.reflect.*' will return
009:         * the classes within it.
010:         * Passing a dot as parameter needs to be looked into.
011:         */
012:        public class listpackage {
013:
014:            public static boolean verbose = false;
015:
016:            public static void main(String args[]) {
017:                System.err.println("package:" + args[0]);
018:                listpackage lp = new listpackage(args[0]);
019:                System.out.println("\n\n++++++++++\n " + lp.getClasses());
020:
021:            }
022:
023:            ArrayList al = new ArrayList();
024:
025:            public listpackage(String pack) {
026:                // 1. read classpath and split
027:                // 2. recurse through directories and jar/zips or classes
028:                // 3. if dir, list all contents (class files) 
029:                // 4. if jar/zip, list contents (should come as a class file)
030:                // 5. if you find a path matching given one then notify
031:                String classpath = System.getProperty("java.class.path", ".");
032:                String newpack = new String(pack);
033:                if (pack.endsWith(".*"))
034:                    newpack = newpack.substring(0, pack.length() - 2);
035:                if (!newpack.equals(".")) // existing directory is in classpath
036:                    newpack = newpack.replace('.', '/');
037:                if (verbose)
038:                    System.out.println("CP:" + classpath);
039:                if (verbose)
040:                    System.out.println("JH:"
041:                            + System.getProperty("JAVA_HOME", "."));
042:                String rtpath = System.getProperty("JAVA_HOME", ".");
043:                rtpath += "/jre/lib/rt.jar:";
044:                //if (verbose)
045:                System.out.println("   newpack:" + newpack);
046:                classpath = rtpath + classpath;
047:                String paths[] = ArrayUtil.split(classpath, ':');
048:                //System.out.println( "Paths:" + paths);
049:                // recurse through classpath searching for the packages
050:                // imported
051:                for (int i = 0; i < paths.length; i++) {
052:                    //if (verbose)
053:                    System.out.println("****** Path:" + paths[i]
054:                            + "***********");
055:                    java.io.File f = new java.io.File(paths[i]);
056:                    if (f.isDirectory()) {
057:                        if (newpack.equals(".")) {
058:                            if (paths[i].equals(newpack)) {
059:                                System.out.println("filling for current dir");
060:                                String[] flist = f.list(new FilenameFilter() {
061:                                    public boolean accept(File dir, String name) {
062:                                        if (name.endsWith(".class"))
063:                                            return true;
064:                                        return false;
065:                                    }
066:                                });
067:                                for (int j = 0; j < flist.length; j++) {
068:                                    //System.out.println("XX  "+ flist[j] + " in " + paths[i]);
069:                                    String tmp = classbasename(flist[j]);
070:                                    if (tmp != null)
071:                                        al.add(tmp);
072:                                }
073:                            }
074:                        } else {
075:                            File f1 = new File(paths[i] + '/' + newpack);
076:                            if (f1.exists()) {
077:                                //if (verbose)
078:                                System.out.println("FND  " + newpack + " in "
079:                                        + paths[i]);
080:                                String tmp = classbasename(newpack);
081:                                if (tmp != null)
082:                                    al.add(tmp);
083:                            }
084:                        }
085:
086:                    } else // is not directory
087:                    if (f.isFile()) {
088:                        if (paths[i].endsWith(".jar")
089:                                || paths[i].endsWith(".zip")) {
090:                            if (verbose)
091:                                System.out.println("+++" + paths[i]);
092:                            try {
093:                                java.util.zip.ZipFile z = new java.util.zip.ZipFile(
094:                                        paths[i]);
095:                                Enumeration e = z.entries();
096:                                while (e.hasMoreElements()) {
097:                                    String name = ((java.util.zip.ZipEntry) e
098:                                            .nextElement()).getName();
099:                                    if (verbose)
100:                                        System.out.println("   " + name);
101:                                    if (newpack.equals(dirname(name))) {
102:                                        if (verbose)
103:                                            System.out
104:                                                    .println("   FOUND n zip  "
105:                                                            + name + " in "
106:                                                            + paths[i]);
107:                                        String tmp = classbasename(name);
108:                                        if (tmp != null)
109:                                            al.add(tmp);
110:                                    }
111:                                }
112:                            } catch (Exception exc) {
113:                                System.err.println("ZIP:" + exc.toString());
114:                            }
115:                        } // jar or zip
116:                        else if (paths[i].endsWith(".class")) {
117:                            if (newpack.equals(paths[i])) {
118:                                if (verbose)
119:                                    System.out.println("    FOUND:" + paths[i]);
120:                                String tmp = classbasename(newpack);
121:                                if (tmp != null)
122:                                    al.add(tmp);
123:                            }
124:
125:                        }
126:                    } // if file
127:                } // for i
128:                Collections.sort(al);
129:            } // listpackage
130:
131:            public static String dirname(String filename) {
132:                int pos = filename.lastIndexOf('/');
133:                if (pos == -1)
134:                    return filename;
135:                return filename.substring(0, pos);
136:            }
137:
138:            public static String classbasename(String filename) {
139:                if (filename.indexOf('$') != -1)
140:                    return null;
141:                int pos = filename.lastIndexOf(".class");
142:                if (pos != -1)
143:                    filename = filename.substring(0, pos);
144:                pos = filename.lastIndexOf('/');
145:                if (pos == -1)
146:                    return filename;
147:                if (pos == filename.length() - 1)
148:                    return null;
149:                return filename.substring(pos + 1);
150:            }
151:
152:            public ArrayList getClasses() {
153:                return al;
154:            }
155:
156:        } // class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.